forked from 0x2620/pandora
python functions should not be camelCase
This commit is contained in:
parent
625fede7d6
commit
ff9612a3f0
8 changed files with 46 additions and 45 deletions
|
@ -27,7 +27,7 @@ import models
|
||||||
import utils
|
import utils
|
||||||
import tasks
|
import tasks
|
||||||
|
|
||||||
from pandora.user.models import getUserJSON
|
from pandora.user.models import get_user_json
|
||||||
from pandora.user.views import api_login, api_logout, api_register, api_contact, api_recover, api_preferences, api_findUser
|
from pandora.user.views import api_login, api_logout, api_register, api_contact, api_recover, api_preferences, api_findUser
|
||||||
|
|
||||||
from pandora.archive.views import api_update, api_upload, api_editFile, api_encodingProfile
|
from pandora.archive.views import api_update, api_upload, api_editFile, api_encodingProfile
|
||||||
|
@ -92,7 +92,7 @@ def api_hello(request):
|
||||||
#data = json.loads(request.POST['data'])
|
#data = json.loads(request.POST['data'])
|
||||||
response = json_response({})
|
response = json_response({})
|
||||||
if request.user.is_authenticated():
|
if request.user.is_authenticated():
|
||||||
response['data']['user'] = getUserJSON(request.user)
|
response['data']['user'] = get_user_json(request.user)
|
||||||
else:
|
else:
|
||||||
response['data']['user'] = {'name': 'Guest', 'group': 'guest', 'preferences': {}}
|
response['data']['user'] = {'name': 'Guest', 'group': 'guest', 'preferences': {}}
|
||||||
return render_to_json_response(response)
|
return render_to_json_response(response)
|
||||||
|
|
|
@ -30,7 +30,7 @@ import ox
|
||||||
import models
|
import models
|
||||||
|
|
||||||
from item.utils import oxid, parse_path
|
from item.utils import oxid, parse_path
|
||||||
from item.models import getItem
|
from item.models import get_item
|
||||||
import item.tasks
|
import item.tasks
|
||||||
|
|
||||||
@login_required_json
|
@login_required_json
|
||||||
|
@ -113,7 +113,7 @@ def api_update(request):
|
||||||
else:
|
else:
|
||||||
if not item:
|
if not item:
|
||||||
item_info = parse_path(folder)
|
item_info = parse_path(folder)
|
||||||
item = getItem(item_info)
|
item = get_item(item_info)
|
||||||
file_object = models.File()
|
file_object = models.File()
|
||||||
file_object.oshash = oshash
|
file_object.oshash = oshash
|
||||||
file_object.name = name
|
file_object.name = name
|
||||||
|
@ -228,7 +228,7 @@ def firefogg_upload(request):
|
||||||
f.available = True
|
f.available = True
|
||||||
f.save()
|
f.save()
|
||||||
#FIXME: this fails badly if rabbitmq goes down
|
#FIXME: this fails badly if rabbitmq goes down
|
||||||
item.tasks.updateStreams.delay(f.item.itemId)
|
item.tasks.update_streams.delay(f.item.itemId)
|
||||||
response['result'] = 1
|
response['result'] = 1
|
||||||
response['done'] = 1
|
response['done'] = 1
|
||||||
return render_to_json_response(response)
|
return render_to_json_response(response)
|
||||||
|
|
|
@ -27,10 +27,11 @@ from firefogg import Firefogg
|
||||||
import managers
|
import managers
|
||||||
import load
|
import load
|
||||||
import utils
|
import utils
|
||||||
|
import tasks
|
||||||
from archive import extract
|
from archive import extract
|
||||||
|
|
||||||
from layer.models import Layer
|
from layer.models import Layer
|
||||||
from person.models import getPersonSort, Person
|
from person.models import get_name_sort, Person
|
||||||
|
|
||||||
|
|
||||||
def siteJson():
|
def siteJson():
|
||||||
|
@ -126,7 +127,7 @@ def siteJson():
|
||||||
}
|
}
|
||||||
return r
|
return r
|
||||||
|
|
||||||
def getItem(info):
|
def get_item(info):
|
||||||
'''
|
'''
|
||||||
info dict with:
|
info dict with:
|
||||||
imdbId, title, director, episode_title, season, series
|
imdbId, title, director, episode_title, season, series
|
||||||
|
@ -144,9 +145,9 @@ def getItem(info):
|
||||||
}
|
}
|
||||||
#FIXME: this should be done async
|
#FIXME: this should be done async
|
||||||
#item.save()
|
#item.save()
|
||||||
#tasks.updateImdb.delay(item.itemId)
|
#tasks.update_imdb.delay(item.itemId)
|
||||||
item.updateImdb()
|
item.update_imdb()
|
||||||
tasks.updatePoster.delay(item.itemId)
|
tasks.update_poster.delay(item.itemId)
|
||||||
else:
|
else:
|
||||||
q = Item.objects.filter(find__key='title', find__value=info['title'])
|
q = Item.objects.filter(find__key='title', find__value=info['title'])
|
||||||
if q.count() > 1:
|
if q.count() > 1:
|
||||||
|
@ -268,7 +269,7 @@ class Item(models.Model):
|
||||||
_reviews[w.title] = r[0]
|
_reviews[w.title] = r[0]
|
||||||
return _reviews
|
return _reviews
|
||||||
|
|
||||||
def updateImdb(self):
|
def update_imdb(self):
|
||||||
if len(self.itemId) == 7:
|
if len(self.itemId) == 7:
|
||||||
self.external_data = ox.web.imdb.Imdb(self.itemId)
|
self.external_data = ox.web.imdb.Imdb(self.itemId)
|
||||||
self.save()
|
self.save()
|
||||||
|
@ -294,9 +295,9 @@ class Item(models.Model):
|
||||||
self.poster_height = 128
|
self.poster_height = 128
|
||||||
self.poster_width = 80
|
self.poster_width = 80
|
||||||
super(Item, self).save(*args, **kwargs)
|
super(Item, self).save(*args, **kwargs)
|
||||||
self.updateFind()
|
self.update_find()
|
||||||
self.updateSort()
|
self.update_sort()
|
||||||
self.updateFacets()
|
self.update_facets()
|
||||||
|
|
||||||
def delete(self, *args, **kwargs):
|
def delete(self, *args, **kwargs):
|
||||||
self.delete_poster()
|
self.delete_poster()
|
||||||
|
@ -306,7 +307,7 @@ class Item(models.Model):
|
||||||
os.unlink(f)
|
os.unlink(f)
|
||||||
super(Item, self).delete(*args, **kwargs)
|
super(Item, self).delete(*args, **kwargs)
|
||||||
|
|
||||||
def mergeWith(self, other):
|
def merge_with(self, other):
|
||||||
'''
|
'''
|
||||||
move all related tables to other and delete self
|
move all related tables to other and delete self
|
||||||
'''
|
'''
|
||||||
|
@ -459,7 +460,7 @@ class Item(models.Model):
|
||||||
'''
|
'''
|
||||||
Search related functions
|
Search related functions
|
||||||
'''
|
'''
|
||||||
def updateFind(self):
|
def update_find(self):
|
||||||
def save(key, value):
|
def save(key, value):
|
||||||
f, created = ItemFind.objects.get_or_create(item=self, key=key)
|
f, created = ItemFind.objects.get_or_create(item=self, key=key)
|
||||||
if value not in ('', '||'):
|
if value not in ('', '||'):
|
||||||
|
@ -496,7 +497,7 @@ class Item(models.Model):
|
||||||
all_find = ' '.join([f.value for f in ItemFind.objects.filter(item=self).exclude(key='all')])
|
all_find = ' '.join([f.value for f in ItemFind.objects.filter(item=self).exclude(key='all')])
|
||||||
save('all', all_find)
|
save('all', all_find)
|
||||||
|
|
||||||
def updateSort(self):
|
def update_sort(self):
|
||||||
try:
|
try:
|
||||||
s = self.sort
|
s = self.sort
|
||||||
except ItemSort.DoesNotExist:
|
except ItemSort.DoesNotExist:
|
||||||
|
@ -505,7 +506,7 @@ class Item(models.Model):
|
||||||
def sortNames(values):
|
def sortNames(values):
|
||||||
sort_value = ''
|
sort_value = ''
|
||||||
if values:
|
if values:
|
||||||
sort_value = '; '.join([getPersonSort(name) for name in values])
|
sort_value = '; '.join([get_name_sort(name) for name in values])
|
||||||
if not sort_value:
|
if not sort_value:
|
||||||
sort_value = ''
|
sort_value = ''
|
||||||
return sort_value
|
return sort_value
|
||||||
|
@ -558,7 +559,7 @@ class Item(models.Model):
|
||||||
#FIXME: also deal with number based rows like genre, keywords etc
|
#FIXME: also deal with number based rows like genre, keywords etc
|
||||||
s.save()
|
s.save()
|
||||||
|
|
||||||
def updateFacets(self):
|
def update_facets(self):
|
||||||
#FIXME: what to do with Unkown Director, Year, Country etc.
|
#FIXME: what to do with Unkown Director, Year, Country etc.
|
||||||
for key in self.facet_keys:
|
for key in self.facet_keys:
|
||||||
if key == 'actor':
|
if key == 'actor':
|
||||||
|
@ -575,7 +576,7 @@ class Item(models.Model):
|
||||||
if value not in saved_values:
|
if value not in saved_values:
|
||||||
value_sort = value
|
value_sort = value
|
||||||
if key in self.person_keys:
|
if key in self.person_keys:
|
||||||
value_sort = getPersonSort(value)
|
value_sort = get_name_sort(value)
|
||||||
f = Facet(key=key, value=value, value_sort=value_sort)
|
f = Facet(key=key, value=value, value_sort=value_sort)
|
||||||
f.item = self
|
f.item = self
|
||||||
f.save()
|
f.save()
|
||||||
|
@ -614,7 +615,7 @@ class Item(models.Model):
|
||||||
videos = filter(check, videos)
|
videos = filter(check, videos)
|
||||||
return videos
|
return videos
|
||||||
|
|
||||||
def updateStreams(self):
|
def update_streams(self):
|
||||||
files = {}
|
files = {}
|
||||||
for f in self.main_videos():
|
for f in self.main_videos():
|
||||||
files[utils.sort_title(f.name)] = f.video.path
|
files[utils.sort_title(f.name)] = f.video.path
|
||||||
|
@ -742,7 +743,7 @@ class Item(models.Model):
|
||||||
class ItemFind(models.Model):
|
class ItemFind(models.Model):
|
||||||
"""
|
"""
|
||||||
used to find items,
|
used to find items,
|
||||||
item.updateFind populates this table
|
item.update_find populates this table
|
||||||
its used in manager.ItemManager
|
its used in manager.ItemManager
|
||||||
"""
|
"""
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
|
@ -13,26 +13,26 @@ def cronjob(**kwargs):
|
||||||
print "do some cleanup stuff once a day"
|
print "do some cleanup stuff once a day"
|
||||||
|
|
||||||
@task(ignore_resulsts=True, queue='default')
|
@task(ignore_resulsts=True, queue='default')
|
||||||
def updatePoster(itemId):
|
def update_poster(itemId):
|
||||||
item = models.Item.objects.get(itemId=itemId)
|
item = models.Item.objects.get(itemId=itemId)
|
||||||
item.download_poster(True)
|
item.download_poster(True)
|
||||||
|
|
||||||
@task(ignore_resulsts=True, queue='default')
|
@task(ignore_resulsts=True, queue='default')
|
||||||
def updateImdb(imdbId):
|
def update_imdb(imdbId):
|
||||||
item = models.Item.objects.get(itemId=imdbId)
|
item = models.Item.objects.get(itemId=imdbId)
|
||||||
item.updateImdb()
|
item.update_imdb()
|
||||||
|
|
||||||
@task(ignore_resulsts=True)
|
@task(ignore_resulsts=True)
|
||||||
def findItem(fileId):
|
def find_item(fileId):
|
||||||
f = models.File.objects.get(pk=fileId)
|
f = models.File.objects.get(pk=fileId)
|
||||||
f.findItem()
|
f.find_item()
|
||||||
|
|
||||||
@task(ignore_resulsts=True, queue="encoding")
|
@task(ignore_resulsts=True, queue="encoding")
|
||||||
def updateStreams(itemId):
|
def update_streams(itemId):
|
||||||
'''
|
'''
|
||||||
create stream, extract timeline and create derivatives
|
create stream, extract timeline and create derivatives
|
||||||
'''
|
'''
|
||||||
item = models.Item.objects.get(itemId=itemId)
|
item = models.Item.objects.get(itemId=itemId)
|
||||||
if item.files.filter(is_main=True, is_video=True, available=False).count() == 0:
|
if item.files.filter(is_main=True, is_video=True, available=False).count() == 0:
|
||||||
item.updateStreams()
|
item.update_streams()
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ import models
|
||||||
import utils
|
import utils
|
||||||
import tasks
|
import tasks
|
||||||
|
|
||||||
from user.models import getUserJSON
|
from user.models import get_user_json
|
||||||
|
|
||||||
from archive.models import File
|
from archive.models import File
|
||||||
from archive import extract
|
from archive import extract
|
||||||
|
@ -309,7 +309,7 @@ def api_setPoster(request): #parse path and return info
|
||||||
if item.poster:
|
if item.poster:
|
||||||
item.poster.delete()
|
item.poster.delete()
|
||||||
item.save()
|
item.save()
|
||||||
tasks.updatePoster.delay(item.itemId)
|
tasks.update_poster.delay(item.itemId)
|
||||||
response = json_response(status=200, text='ok')
|
response = json_response(status=200, text='ok')
|
||||||
response['data']['poster'] = item.get_poster()
|
response['data']['poster'] = item.get_poster()
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -24,7 +24,7 @@ from ox import stripTags
|
||||||
from ox.normalize import canonicalTitle, canonicalName
|
from ox.normalize import canonicalTitle, canonicalName
|
||||||
|
|
||||||
|
|
||||||
def getPersonSort(name):
|
def get_name_sort(name):
|
||||||
person, created = Person.objects.get_or_create(name=name)
|
person, created = Person.objects.get_or_create(name=name)
|
||||||
name_sort = unicodedata.normalize('NFKD', person.name_sort)
|
name_sort = unicodedata.normalize('NFKD', person.name_sort)
|
||||||
return name_sort
|
return name_sort
|
||||||
|
|
|
@ -27,7 +27,7 @@ class Preference(models.Model):
|
||||||
key = models.CharField(blank=True, max_length=255)
|
key = models.CharField(blank=True, max_length=255)
|
||||||
value = models.TextField(blank=True)
|
value = models.TextField(blank=True)
|
||||||
|
|
||||||
def getUserJSON(user):
|
def get_user_json(user):
|
||||||
json = {}
|
json = {}
|
||||||
for key in ('username', ):
|
for key in ('username', ):
|
||||||
json[key] = getattr(user, key)
|
json[key] = getattr(user, key)
|
||||||
|
@ -36,11 +36,11 @@ def getUserJSON(user):
|
||||||
json['group'] = 'admin'
|
json['group'] = 'admin'
|
||||||
elif user.has_perm('0x.vip'): #FIXME: permissions
|
elif user.has_perm('0x.vip'): #FIXME: permissions
|
||||||
json['group'] = 'vip'
|
json['group'] = 'vip'
|
||||||
json['preferences'] = getPreferences(user)
|
json['preferences'] = get_preferences(user)
|
||||||
json['ui'] = getUI(user)
|
json['ui'] = get_ui(user)
|
||||||
return json
|
return json
|
||||||
|
|
||||||
def getUI(user):
|
def get_ui(user):
|
||||||
return {
|
return {
|
||||||
"columns": ["id", "title", "director", "country", "year", "language", "genre"],
|
"columns": ["id", "title", "director", "country", "year", "language", "genre"],
|
||||||
"findQuery": {"conditions": [{"key": "", "value": "", "operator": ""}], "operator": ""},
|
"findQuery": {"conditions": [{"key": "", "value": "", "operator": ""}], "operator": ""},
|
||||||
|
@ -61,14 +61,14 @@ def getUI(user):
|
||||||
"theme": "classic"
|
"theme": "classic"
|
||||||
}
|
}
|
||||||
|
|
||||||
def getPreferences(user):
|
def get_preferences(user):
|
||||||
prefs = {}
|
prefs = {}
|
||||||
for p in Preference.objects.filter(user=user):
|
for p in Preference.objects.filter(user=user):
|
||||||
prefs[p.key] = json.loads(p.value)
|
prefs[p.key] = json.loads(p.value)
|
||||||
prefs['email'] = user.email
|
prefs['email'] = user.email
|
||||||
return prefs
|
return prefs
|
||||||
|
|
||||||
def getPreference(user, key, value=None):
|
def get_preference(user, key, value=None):
|
||||||
if key in ('email', ):
|
if key in ('email', ):
|
||||||
value = getattr(user, key)
|
value = getattr(user, key)
|
||||||
else:
|
else:
|
||||||
|
@ -77,7 +77,7 @@ def getPreference(user, key, value=None):
|
||||||
value = json.loads(q[0].value)
|
value = json.loads(q[0].value)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def setPreference(user, key, value):
|
def set_preference(user, key, value):
|
||||||
if key in ('email', ):
|
if key in ('email', ):
|
||||||
setattr(user, key, value)
|
setattr(user, key, value)
|
||||||
user.save()
|
user.save()
|
||||||
|
|
|
@ -39,7 +39,7 @@ def api_login(request):
|
||||||
if user is not None:
|
if user is not None:
|
||||||
if user.is_active:
|
if user.is_active:
|
||||||
login(request, user)
|
login(request, user)
|
||||||
user_json = models.getUserJSON(user)
|
user_json = models.get_user_json(user)
|
||||||
response = json_response({'user': user_json},
|
response = json_response({'user': user_json},
|
||||||
text='You are logged in.')
|
text='You are logged in.')
|
||||||
else:
|
else:
|
||||||
|
@ -227,21 +227,21 @@ def api_preferences(request):
|
||||||
'''
|
'''
|
||||||
response = json_response()
|
response = json_response()
|
||||||
if 'data' not in request.POST:
|
if 'data' not in request.POST:
|
||||||
response['data']['preferences'] = models.getPreferences(request.user)
|
response['data']['preferences'] = models.get_preferences(request.user)
|
||||||
else:
|
else:
|
||||||
data = json.loads(request.POST['data'])
|
data = json.loads(request.POST['data'])
|
||||||
if isinstance(data, basestring):
|
if isinstance(data, basestring):
|
||||||
response['data']['preferences'] = {}
|
response['data']['preferences'] = {}
|
||||||
response['data']['preferences'][data] = models.getPreference(request.user, data)
|
response['data']['preferences'][data] = models.get_preference(request.user, data)
|
||||||
elif isinstance(data, list):
|
elif isinstance(data, list):
|
||||||
response['data']['preferences'] = {}
|
response['data']['preferences'] = {}
|
||||||
for preference in data:
|
for preference in data:
|
||||||
response['preferences'][preference] = models.getPreference(request.user, preference)
|
response['preferences'][preference] = models.get_preference(request.user, preference)
|
||||||
elif isinstance(data, dict):
|
elif isinstance(data, dict):
|
||||||
if not data:
|
if not data:
|
||||||
response['data']['preferences'] = models.getPreferences(request.user)
|
response['data']['preferences'] = models.get_preferences(request.user)
|
||||||
else:
|
else:
|
||||||
del response['data']
|
del response['data']
|
||||||
for key in data:
|
for key in data:
|
||||||
models.setPreference(request.user, key, data[key])
|
models.set_preference(request.user, key, data[key])
|
||||||
return render_to_json_response(response)
|
return render_to_json_response(response)
|
||||||
|
|
Loading…
Reference in a new issue