forked from 0x2620/pandora
actions, move parse_decimal
This commit is contained in:
parent
d50d242c45
commit
07dcc77950
7 changed files with 44 additions and 33 deletions
|
@ -1,6 +1,24 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
import sys
|
||||
|
||||
from ox.django.shortcuts import render_to_json_response, get_object_or_404_json, json_response
|
||||
from django.conf import settings
|
||||
|
||||
from ox.django.shortcuts import render_to_json_response, json_response
|
||||
|
||||
|
||||
def autodiscover():
|
||||
#register api actions from all installed apps
|
||||
from django.utils.importlib import import_module
|
||||
from django.utils.module_loading import module_has_submodule
|
||||
for app in settings.INSTALLED_APPS:
|
||||
if app != 'api':
|
||||
mod = import_module(app)
|
||||
try:
|
||||
import_module('%s.views'%app)
|
||||
except:
|
||||
if module_has_submodule(mod, 'views'):
|
||||
raise
|
||||
|
||||
|
||||
def trim(docstring):
|
||||
|
@ -28,7 +46,6 @@ def trim(docstring):
|
|||
# Return a single string:
|
||||
return '\n'.join(trimmed)
|
||||
|
||||
|
||||
class ApiActions(dict):
|
||||
def __init__(self):
|
||||
def api(request):
|
||||
|
|
|
@ -33,18 +33,6 @@ from pandora.archive import extract
|
|||
|
||||
from actions import actions
|
||||
|
||||
#register all api actions
|
||||
from django.utils.importlib import import_module
|
||||
from django.utils.module_loading import module_has_submodule
|
||||
for app in settings.INSTALLED_APPS:
|
||||
if app != 'api':
|
||||
mod = import_module(app)
|
||||
try:
|
||||
import_module('%s.views'%app)
|
||||
except:
|
||||
if module_has_submodule(mod, 'views'):
|
||||
raise
|
||||
|
||||
def api(request):
|
||||
if request.META['REQUEST_METHOD'] == "OPTIONS":
|
||||
response = HttpResponse('')
|
||||
|
|
|
@ -5,7 +5,6 @@ from datetime import datetime
|
|||
import os.path
|
||||
import random
|
||||
import re
|
||||
from decimal import Decimal
|
||||
import time
|
||||
|
||||
from django.db import models
|
||||
|
@ -28,13 +27,6 @@ from item.models import Item
|
|||
import extract
|
||||
|
||||
|
||||
def parse_decimal(string):
|
||||
string = string.replace(':', '/')
|
||||
if '/' not in string:
|
||||
string = '%s/1' % string
|
||||
d = string.split('/')
|
||||
return Decimal(d[0]) / Decimal(d[1])
|
||||
|
||||
class File(models.Model):
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
modified = models.DateTimeField(auto_now=True)
|
||||
|
@ -117,7 +109,7 @@ class File(models.Model):
|
|||
self.is_audio = False
|
||||
|
||||
if self.framerate:
|
||||
self.pixels = int(self.width * self.height * float(parse_decimal(self.framerate)) * self.duration)
|
||||
self.pixels = int(self.width * self.height * float(utils.parse_decimal(self.framerate)) * self.duration)
|
||||
|
||||
if not self.is_audio and not self.is_video and self.name.endswith('.srt'):
|
||||
self.is_subtitle = True
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
#
|
||||
import errno
|
||||
from decimal import Decimal
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
|
@ -14,6 +15,13 @@ import ox.iso
|
|||
from ox.normalize import normalizeName, normalizeTitle, canonicalTitle
|
||||
|
||||
|
||||
def parse_decimal(string):
|
||||
string = string.replace(':', '/')
|
||||
if '/' not in string:
|
||||
string = '%s/1' % string
|
||||
d = string.split('/')
|
||||
return Decimal(d[0]) / Decimal(d[1])
|
||||
|
||||
def plural_key(term):
|
||||
return {
|
||||
'country': 'countries',
|
||||
|
|
|
@ -157,6 +157,17 @@ TRANSMISSON_USER = 'transmission'
|
|||
TRANSMISSON_PASSWORD = 'transmission'
|
||||
|
||||
|
||||
#Movie related settings
|
||||
REVIEW_WHITELIST = {
|
||||
u'filmcritic.com': u'Filmcritic',
|
||||
u'metacritic.com': u'Metacritic',
|
||||
u'nytimes.com': u'New York Times',
|
||||
u'rottentomatoes.com': u'Rotten Tomatoes',
|
||||
u'salon.com': u'Salon.com',
|
||||
u'sensesofcinema.com': u'Senses of Cinema',
|
||||
u'villagevoice.com': u'Village Voice'
|
||||
}
|
||||
|
||||
#list of poster services, https://wiki.0x2620.org/wiki/pandora/posterservice
|
||||
POSTER_SERVICES = []
|
||||
POSTER_PRECEDENCE = (
|
||||
|
@ -170,16 +181,6 @@ POSTER_PRECEDENCE = (
|
|||
'other'
|
||||
)
|
||||
|
||||
REVIEW_WHITELIST = {
|
||||
u'filmcritic.com': u'Filmcritic',
|
||||
u'metacritic.com': u'Metacritic',
|
||||
u'nytimes.com': u'New York Times',
|
||||
u'rottentomatoes.com': u'Rotten Tomatoes',
|
||||
u'salon.com': u'Salon.com',
|
||||
u'sensesofcinema.com': u'Senses of Cinema',
|
||||
u'villagevoice.com': u'Village Voice'
|
||||
}
|
||||
|
||||
#0xdb.org
|
||||
#POSTER_SERVICES=['http://data.0xdb.org/poster/']
|
||||
|
||||
|
|
|
@ -11,6 +11,8 @@ from django.conf import settings
|
|||
from django.contrib import admin
|
||||
admin.autodiscover()
|
||||
|
||||
from api import actions
|
||||
actions.autodiscover()
|
||||
|
||||
def serve_static_file(path, location, content_type):
|
||||
return HttpFileResponse(location, content_type=content_type)
|
||||
|
|
|
@ -170,6 +170,9 @@ def findUser(request):
|
|||
actions.register(findUser)
|
||||
|
||||
def recover(request, key):
|
||||
'''
|
||||
recover user and redirect to settings
|
||||
'''
|
||||
qs = models.UserProfile.objects.filter(recover_key=key)
|
||||
if qs.count() == 1:
|
||||
user = qs[0].user
|
||||
|
|
Loading…
Reference in a new issue