actions, move parse_decimal

This commit is contained in:
j 2010-12-22 20:47:38 +05:30
parent d50d242c45
commit 07dcc77950
7 changed files with 44 additions and 33 deletions

View file

@ -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):

View file

@ -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('')

View file

@ -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

View file

@ -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',

View file

@ -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/']

View file

@ -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)

View file

@ -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