python functions should not be camelCase

This commit is contained in:
j 2010-11-27 13:12:53 +01:00
parent 625fede7d6
commit ff9612a3f0
8 changed files with 46 additions and 45 deletions

View file

@ -27,7 +27,7 @@ import models
import utils
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.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'])
response = json_response({})
if request.user.is_authenticated():
response['data']['user'] = getUserJSON(request.user)
response['data']['user'] = get_user_json(request.user)
else:
response['data']['user'] = {'name': 'Guest', 'group': 'guest', 'preferences': {}}
return render_to_json_response(response)

View file

@ -30,7 +30,7 @@ import ox
import models
from item.utils import oxid, parse_path
from item.models import getItem
from item.models import get_item
import item.tasks
@login_required_json
@ -113,7 +113,7 @@ def api_update(request):
else:
if not item:
item_info = parse_path(folder)
item = getItem(item_info)
item = get_item(item_info)
file_object = models.File()
file_object.oshash = oshash
file_object.name = name
@ -228,7 +228,7 @@ def firefogg_upload(request):
f.available = True
f.save()
#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['done'] = 1
return render_to_json_response(response)

View file

@ -27,10 +27,11 @@ from firefogg import Firefogg
import managers
import load
import utils
import tasks
from archive import extract
from layer.models import Layer
from person.models import getPersonSort, Person
from person.models import get_name_sort, Person
def siteJson():
@ -126,7 +127,7 @@ def siteJson():
}
return r
def getItem(info):
def get_item(info):
'''
info dict with:
imdbId, title, director, episode_title, season, series
@ -144,9 +145,9 @@ def getItem(info):
}
#FIXME: this should be done async
#item.save()
#tasks.updateImdb.delay(item.itemId)
item.updateImdb()
tasks.updatePoster.delay(item.itemId)
#tasks.update_imdb.delay(item.itemId)
item.update_imdb()
tasks.update_poster.delay(item.itemId)
else:
q = Item.objects.filter(find__key='title', find__value=info['title'])
if q.count() > 1:
@ -268,7 +269,7 @@ class Item(models.Model):
_reviews[w.title] = r[0]
return _reviews
def updateImdb(self):
def update_imdb(self):
if len(self.itemId) == 7:
self.external_data = ox.web.imdb.Imdb(self.itemId)
self.save()
@ -294,9 +295,9 @@ class Item(models.Model):
self.poster_height = 128
self.poster_width = 80
super(Item, self).save(*args, **kwargs)
self.updateFind()
self.updateSort()
self.updateFacets()
self.update_find()
self.update_sort()
self.update_facets()
def delete(self, *args, **kwargs):
self.delete_poster()
@ -306,7 +307,7 @@ class Item(models.Model):
os.unlink(f)
super(Item, self).delete(*args, **kwargs)
def mergeWith(self, other):
def merge_with(self, other):
'''
move all related tables to other and delete self
'''
@ -459,7 +460,7 @@ class Item(models.Model):
'''
Search related functions
'''
def updateFind(self):
def update_find(self):
def save(key, value):
f, created = ItemFind.objects.get_or_create(item=self, key=key)
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')])
save('all', all_find)
def updateSort(self):
def update_sort(self):
try:
s = self.sort
except ItemSort.DoesNotExist:
@ -505,7 +506,7 @@ class Item(models.Model):
def sortNames(values):
sort_value = ''
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:
sort_value = ''
return sort_value
@ -558,7 +559,7 @@ class Item(models.Model):
#FIXME: also deal with number based rows like genre, keywords etc
s.save()
def updateFacets(self):
def update_facets(self):
#FIXME: what to do with Unkown Director, Year, Country etc.
for key in self.facet_keys:
if key == 'actor':
@ -575,7 +576,7 @@ class Item(models.Model):
if value not in saved_values:
value_sort = value
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.item = self
f.save()
@ -614,7 +615,7 @@ class Item(models.Model):
videos = filter(check, videos)
return videos
def updateStreams(self):
def update_streams(self):
files = {}
for f in self.main_videos():
files[utils.sort_title(f.name)] = f.video.path
@ -742,7 +743,7 @@ class Item(models.Model):
class ItemFind(models.Model):
"""
used to find items,
item.updateFind populates this table
item.update_find populates this table
its used in manager.ItemManager
"""
class Meta:

View file

@ -13,26 +13,26 @@ def cronjob(**kwargs):
print "do some cleanup stuff once a day"
@task(ignore_resulsts=True, queue='default')
def updatePoster(itemId):
def update_poster(itemId):
item = models.Item.objects.get(itemId=itemId)
item.download_poster(True)
@task(ignore_resulsts=True, queue='default')
def updateImdb(imdbId):
def update_imdb(imdbId):
item = models.Item.objects.get(itemId=imdbId)
item.updateImdb()
item.update_imdb()
@task(ignore_resulsts=True)
def findItem(fileId):
def find_item(fileId):
f = models.File.objects.get(pk=fileId)
f.findItem()
f.find_item()
@task(ignore_resulsts=True, queue="encoding")
def updateStreams(itemId):
def update_streams(itemId):
'''
create stream, extract timeline and create derivatives
'''
item = models.Item.objects.get(itemId=itemId)
if item.files.filter(is_main=True, is_video=True, available=False).count() == 0:
item.updateStreams()
item.update_streams()

View file

@ -28,7 +28,7 @@ import models
import utils
import tasks
from user.models import getUserJSON
from user.models import get_user_json
from archive.models import File
from archive import extract
@ -309,7 +309,7 @@ def api_setPoster(request): #parse path and return info
if item.poster:
item.poster.delete()
item.save()
tasks.updatePoster.delay(item.itemId)
tasks.update_poster.delay(item.itemId)
response = json_response(status=200, text='ok')
response['data']['poster'] = item.get_poster()
else:

View file

@ -24,7 +24,7 @@ from ox import stripTags
from ox.normalize import canonicalTitle, canonicalName
def getPersonSort(name):
def get_name_sort(name):
person, created = Person.objects.get_or_create(name=name)
name_sort = unicodedata.normalize('NFKD', person.name_sort)
return name_sort

View file

@ -27,7 +27,7 @@ class Preference(models.Model):
key = models.CharField(blank=True, max_length=255)
value = models.TextField(blank=True)
def getUserJSON(user):
def get_user_json(user):
json = {}
for key in ('username', ):
json[key] = getattr(user, key)
@ -36,11 +36,11 @@ def getUserJSON(user):
json['group'] = 'admin'
elif user.has_perm('0x.vip'): #FIXME: permissions
json['group'] = 'vip'
json['preferences'] = getPreferences(user)
json['ui'] = getUI(user)
json['preferences'] = get_preferences(user)
json['ui'] = get_ui(user)
return json
def getUI(user):
def get_ui(user):
return {
"columns": ["id", "title", "director", "country", "year", "language", "genre"],
"findQuery": {"conditions": [{"key": "", "value": "", "operator": ""}], "operator": ""},
@ -61,14 +61,14 @@ def getUI(user):
"theme": "classic"
}
def getPreferences(user):
def get_preferences(user):
prefs = {}
for p in Preference.objects.filter(user=user):
prefs[p.key] = json.loads(p.value)
prefs['email'] = user.email
return prefs
def getPreference(user, key, value=None):
def get_preference(user, key, value=None):
if key in ('email', ):
value = getattr(user, key)
else:
@ -77,7 +77,7 @@ def getPreference(user, key, value=None):
value = json.loads(q[0].value)
return value
def setPreference(user, key, value):
def set_preference(user, key, value):
if key in ('email', ):
setattr(user, key, value)
user.save()

View file

@ -39,7 +39,7 @@ def api_login(request):
if user is not None:
if user.is_active:
login(request, user)
user_json = models.getUserJSON(user)
user_json = models.get_user_json(user)
response = json_response({'user': user_json},
text='You are logged in.')
else:
@ -227,21 +227,21 @@ def api_preferences(request):
'''
response = json_response()
if 'data' not in request.POST:
response['data']['preferences'] = models.getPreferences(request.user)
response['data']['preferences'] = models.get_preferences(request.user)
else:
data = json.loads(request.POST['data'])
if isinstance(data, basestring):
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):
response['data']['preferences'] = {}
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):
if not data:
response['data']['preferences'] = models.getPreferences(request.user)
response['data']['preferences'] = models.get_preferences(request.user)
else:
del response['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)