From 3d36da45af4db24043c11bf8211d7ca65d3c77e3 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Mon, 8 Feb 2010 15:56:25 +0530 Subject: [PATCH] site.js, cleanup stream names again --- oxdb/app/views.py | 5 +++- oxdb/backend/models.py | 62 +++++++++++++++++++-------------------- oxdb/backend/views.py | 10 ++++--- oxdb/oxuser/models.py | 5 ++++ oxdb/settings.py | 17 +++++++---- oxdb/static/js/ui.js | 25 +++++++++++++++- oxdb/templates/index.html | 17 +++++------ oxdb/urls.py | 1 + 8 files changed, 90 insertions(+), 52 deletions(-) diff --git a/oxdb/app/views.py b/oxdb/app/views.py index 9b79fa5..a23851c 100644 --- a/oxdb/app/views.py +++ b/oxdb/app/views.py @@ -6,6 +6,9 @@ from django.conf import settings def index(request): - context = RequestContext(request, {}) + context = RequestContext(request, {'settings':settings}) return render_to_response('index.html', context) +def site_js(request): + context = RequestContext(request, {'settings':settings}) + return render_to_response('site.js', context, mimetype="application/javascript") diff --git a/oxdb/backend/models.py b/oxdb/backend/models.py index 77ffe75..43cc8eb 100644 --- a/oxdb/backend/models.py +++ b/oxdb/backend/models.py @@ -306,9 +306,9 @@ class Movie(models.Model): #stream related fields ''' ''' - stream96p = models.FileField(default=None, blank=True, upload_to=lambda f, x: movie_path(f, '96p')) - stream320 = models.FileField(default=None, blank=True, upload_to=lambda f, x: movie_path(f, '320')) - stream640 = models.FileField(default=None, blank=True, upload_to=lambda f, x: movie_path(f, '640')) + stream_low = models.FileField(default=None, blank=True, upload_to=lambda f, x: movie_path(f, 'low')) + stream_mid = models.FileField(default=None, blank=True, upload_to=lambda f, x: movie_path(f, 'mid')) + stream_high = models.FileField(default=None, blank=True, upload_to=lambda f, x: movie_path(f, 'high')) #FIXME: is this still required? should this not be aspect ratio? depends on stream??? scene_height = models.IntegerField(null=True, blank=True) @@ -612,10 +612,10 @@ class MovieSort(models.Model): resolution = models.IntegerField(blank=True) aspectratio = models.IntegerField('Aspect Ratio', blank=True) bitrate = models.IntegerField(blank=True) - pixels = models.IntegerField(blank=True) + pixels = models.BigIntegerField(blank=True) filename = models.IntegerField(blank=True) files = models.IntegerField(blank=True) - size = models.IntegerField(blank=True) + size = models.BigIntegerField(blank=True) _private_fields = ('id', 'movie') #return available sort fields @@ -923,7 +923,7 @@ class Review(models.Model): if q.count() > 0: o = q[0] else: - o = self.objects.create(movie=movie, url=url) + o = self.objects.create(movie=movie, url=g) o.save() return o get_or_create = classmethod(get_or_create) @@ -1044,17 +1044,17 @@ class File(models.Model): #stream related fields available = models.BooleanField(default=False) - stream96p = models.FileField(default=None, upload_to=lambda f, x: stream_path(f, '96p')) - stream320 = models.FileField(default=None, upload_to=lambda f, x: stream_path(f, '320')) - stream640 = models.FileField(default=None, upload_to=lambda f, x: stream_path(f, '640')) + stream_low = models.FileField(default=None, upload_to=lambda f, x: stream_path(f, 'low')) + stream_mid = models.FileField(default=None, upload_to=lambda f, x: stream_path(f, 'mid')) + stream_high = models.FileField(default=None, upload_to=lambda f, x: stream_path(f, 'high')) def timeline_base_url(self): - return '%s/timeline' % os.path.dirname(self.stream96p.url) + return '%s/timeline' % os.path.dirname(self.stream_low.url) def save_chunk(self, chunk, name='video.ogv'): if not self.available: - #FIXME: this should use stream96p or stream640 depending on configuration - video = getattr(self, 'stream96p') + #FIXME: this should use stream_low or stream_high depending on configuration + video = getattr(self, 'stream_%s'%settings.VIDEO_PROFILE) if not video: video.save(name, chunk) self.save() @@ -1116,12 +1116,12 @@ class File(models.Model): self.save() def extract_timeline(self): - if self.stream640: - video = self.stream640.path - elif stream320: - video = self.stream320.path - elif stream96p: - video = self.stream96p.path + if self.stream_high: + video = self.stream_high.path + elif self.stream_mid: + video = self.stream_mid.path + elif self.stream_low: + video = self.stream_low.path else: return False prefix = os.path.join(os.path.dirname(video), 'timeline') @@ -1132,19 +1132,19 @@ class File(models.Model): def extract_video(self): ogg = Firefogg() - if self.stream640: - #320 stream - self.stream320.name = stream_path(self, '320') - self.stream320.save() - ogg.encode(self.stream640.path, self.stream320.path, settings.VIDEO320) - #96p stream - self.stream96p.name = stream_path(self, '96p') - self.stream96p.save() - ogg.encode(self.stream640.path, self.stream96p.path, settings.VIDEO96P) - elif self.stream320: - self.stream96p.name = stream_path(self, '96p') - self.stream96p.save() - ogg.encode(self.stream320.path, self.stream96p.path, settings.VIDEO96P) + if self.stream_high: + #mid stream + self.stream_mid.name = stream_path(self, 'mid') + self.stream_mid.save() + ogg.encode(self.stream_height.path, self.stream_mid.path, settings.VIDEO_MID) + #low stream + self.stream_low.name = stream_path(self, 'low') + self.stream_low.save() + ogg.encode(self.stream_high.path, self.stream_low.path, settings.VIDEO_LOW) + elif self.stream_mid: + self.stream_low.name = stream_path(self, 'low') + self.stream_low.save() + ogg.encode(self.stream_mid.path, self.stream_low.path, settings.VIDEO_LOW) def extract(self): #FIXME: do stuff, like create timeline or create smaller videos etc diff --git a/oxdb/backend/views.py b/oxdb/backend/views.py index 5970f85..78460f9 100644 --- a/oxdb/backend/views.py +++ b/oxdb/backend/views.py @@ -14,6 +14,7 @@ from django.db.models import Q, Avg, Count from django.http import HttpResponse from django.shortcuts import render_to_response, get_object_or_404, get_list_or_404 from django.template import RequestContext +from django.conf import settings try: import simplejson as json @@ -62,7 +63,7 @@ def api_hello(request): if request.user.is_authenticated(): response['data']['user'] = getUserJSON(request.user) else: - response['data']['user'] = {'name': 'Guest'} + response['data']['user'] = {'name': 'Guest', 'group': 'guest', 'preferences': {}} return render_to_json_response(response) def api_error(request): @@ -463,7 +464,7 @@ def api_encodingSettings(request): 'data': {'options': {'videoQuality':...}}} ''' response = {'status': {'code': 200, 'text': 'ok'}} - response['data'] = {'options': {'preset': 'padma'}} + response['data'] = {'options': settings.VIDEO_ENCODING[settings.VIDEO_PROFILE]} return render_to_json_response(response) class UploadForm(forms.Form): @@ -515,8 +516,9 @@ def firefogg_upload(request): #FIXME: what to do if requested oshash is not in db? #FIXME: should existing data be reset here? or better, should this fail if an upload was there f = get_object_or_404(models.File, oshash=request.POST['oshash']) - if f.stream96p: - f.stream96p.delete() + stream = getattr(f, 'stream_%s'%settings.VIDEO_UPLOAD) + if stream: + stream.delete() f.available = False f.save() response = { diff --git a/oxdb/oxuser/models.py b/oxdb/oxuser/models.py index abd252f..c9e93a9 100644 --- a/oxdb/oxuser/models.py +++ b/oxdb/oxuser/models.py @@ -28,6 +28,11 @@ def getUserJSON(user): json = {} for key in ('username', ): json[key] = getattr(user, key) + json['group'] = 'user' + if user.is_staff: + json['group'] = 'admin' + elif user.has_perm('0x.vip'): #FIXME: permissions + json['group'] = 'vip' json['preferences'] = getPreferences(user) return json diff --git a/oxdb/settings.py b/oxdb/settings.py index 53b26fb..4d04ccc 100644 --- a/oxdb/settings.py +++ b/oxdb/settings.py @@ -4,7 +4,9 @@ import os from os.path import join -SITENAME = 'Pad.ma' +SITENAME = 'Oxdb' +URL = 'Oxdb.org' + PROJECT_ROOT = os.path.normpath(os.path.dirname(__file__)) DEBUG = True @@ -109,11 +111,14 @@ BROKER_PASSWORD = "0xdb" BROKER_VHOST = "/oxdb" #Video encoding settings -VIDEO96P = {'height': 96, 'videoBitrate': 180, 'softTarget': True, - 'samplerate': 44100, 'audioQuality': -1, 'channels': 1, 'noUpscaling': True} -VIDEO320 = {'maxSize': 320, 'videoBitrate': 500, - 'samplerate': 44100, 'audioQuality': 0, 'channels': 1, 'noUpscaling': True} -VIDEO640 = {'profile': 'padma'} +VIDEO_PROFILE = 'low' # possible values low, mid or high +VIDEO_ENCODING = { + 'low': {'height': 96, 'videoBitrate': 180, 'softTarget': True, + 'samplerate': 44100, 'audioQuality': -1, 'channels': 1, 'noUpscaling': True}, + 'mid': {'maxSize': 320, 'videoBitrate': 500, + 'samplerate': 44100, 'audioQuality': 0, 'channels': 1, 'noUpscaling': True}, + 'high': {'profile': 'padma'} +} #overwrite default settings with local settings try: diff --git a/oxdb/static/js/ui.js b/oxdb/static/js/ui.js index 1990a66..3344e09 100644 --- a/oxdb/static/js/ui.js +++ b/oxdb/static/js/ui.js @@ -1,6 +1,29 @@ $(function() { Ox.initLoading(); - oxdb = {}; + var oxdb = new Ox.App({ + requestURL: "/api/" + }), + $dialog = new Ox.Dialog({ + title: "Application Error", + buttons: [ + { + value: "Change Title", + click: function() { + Ox.print("click to change title") + $dialog.options({ + title: "New Title" + }); + $dialog.$buttons[0].toggleDisabled(); + } + }, + { + value: "Close", + click: function() { + $dialog.close(); + } + } + ] + }); var user = { username: "", diff --git a/oxdb/templates/index.html b/oxdb/templates/index.html index 29a3f09..a6e7407 100644 --- a/oxdb/templates/index.html +++ b/oxdb/templates/index.html @@ -1,16 +1,15 @@
-