From 7b073b2f98adc87aeac84dce2095ab9dcda8b097 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Mon, 5 Sep 2011 15:03:14 +0200 Subject: [PATCH] cablegates --- pandora/app/models.py | 24 +-- pandora/cables.json | 284 +++++++++++++++++++++++++++ pandora/item/models.py | 1 + pandora/item/views.py | 6 +- pandora/load_from_mongodb.py | 22 +++ pandora/urls.py | 2 +- static/js/pandora.js | 4 +- static/js/pandora/ui/cable.js | 19 ++ static/js/pandora/ui/contentPanel.js | 19 +- static/js/pandora/ui/list.js | 11 ++ static/json/pandora.json | 3 +- 11 files changed, 376 insertions(+), 19 deletions(-) create mode 100644 pandora/cables.json create mode 100644 pandora/load_from_mongodb.py create mode 100644 static/js/pandora/ui/cable.js diff --git a/pandora/app/models.py b/pandora/app/models.py index 8cfe979..d7ebb4e 100644 --- a/pandora/app/models.py +++ b/pandora/app/models.py @@ -25,16 +25,16 @@ class SiteSettings(models.Model): def __unicode__(self): return self.key +with open(settings.SITE_CONFIG) as f: + config = json.load(f) + config['site']['id'] = settings.SITEID + config['site']['name'] = settings.SITENAME + config['site']['sectionName'] = settings.SITENAME + config['site']['url'] = settings.URL + + config['keys'] = {} + for key in config['itemKeys']: + config['keys'][key['id']] = key + def site_config(): - with open(settings.SITE_CONFIG) as f: - site_config = json.load(f) - - site_config['site']['id'] = settings.SITEID - site_config['site']['name'] = settings.SITENAME - site_config['site']['sectionName'] = settings.SITENAME - site_config['site']['url'] = settings.URL - - site_config['keys'] = {} - for key in site_config['itemKeys']: - site_config['keys'][key['id']] = key - return site_config + return config.copy() diff --git a/pandora/cables.json b/pandora/cables.json new file mode 100644 index 0000000..1063e85 --- /dev/null +++ b/pandora/cables.json @@ -0,0 +1,284 @@ +{ + "capabilities": { + "canPlayClips": {"guest": 1, "member": 2, "staff": 3, "admin": 4}, + "canPlayVideo": {"guest": 0, "member": 1, "staff": 3, "admin": 4}, + "canSeeItem": {"guest": 2, "member": 2, "staff": 3, "admin": 4}, + "canSeeFiles": {"guest": -1, "member": -1, "staff": 3, "admin": 4} + }, + "clipKeys": [ + {"id": "value", "title": "Text"}, + {"id": "in", "title": "Position"}, + {"id": "duration", "title": "Duration"}, + {"id": "hue", "title": "Hue"}, + {"id": "saturation", "title": "Saturation"}, + {"id": "lightness", "title": "Lightness"}, + {"id": "volume", "title": "Volume"} + ], + "groups": [ + {"id": "origin", "title": "Origin"}, + {"id": "tags", "title": "Tag"}, + {"id": "classification", "title": "Classification"}, + {"id": "created_day", "title": "Created"}, + {"id": "released_day", "title": "Released"} + ], + "itemKeys": [ + { + "id": "all", + "title": "All", + "type": "string", + "find": true + }, + { + "id": "id", + "title": "ID", + "type": "string", + "columnRequired": false, + "columnWidth": 180 + }, + { + "id": "title", + "title": "title", + "type": "string", + "columnRequired": false, + "columnWidth": 180 + }, + { + "id": "director", + "title": "director", + "type": "string", + "columnRequired": false, + "columnWidth": 180 + }, + { + "id": "year", + "title": "Year", + "type": "string", + "columnRequired": false, + "columnWidth": 180 + }, + { + "id": "subject", + "title": "Subject", + "type": "string", + "columnRequired": true, + "columnWidth": 480, + "find": true, + "sort": "string" + }, + { + "id": "header", + "title": "Header", + "type": "text", + "find": true + }, + { + "id": "content", + "title": "Content", + "type": "text", + "find": true + }, + { + "id": "origin", + "title": "Origin", + "type": "string", + "autocomplete": true, + "columnWidth": 140, + "find": true, + "group": true, + "sort": "string" + + }, + { + "id": "created_day", + "title": "Created day", + "autocomplete": true, + "type": "string", + "columnWidth": 60, + "group": true, + "format": {"type": "date", "args": ["%a, %b %e, %Y"]} + + }, + { + "id": "created", + "title": "Created", + "type": "date", + "columnWidth": 60, + "group": true, + "format": {"type": "date", "args": ["%a, %b %e, %Y"]} + + }, + { + "id": "released_day", + "title": "Released day", + "autocomplete": true, + "type": "string", + "columnWidth": 60, + "group": true, + "format": {"type": "date", "args": ["%a, %b %e, %Y"]} + + }, + { + "id": "released", + "title": "Released", + "type": "date", + "columnWidth": 60, + "group": true, + "format": {"type": "date", "args": ["%a, %b %e, %Y"]} + + }, + { + "id": "classification", + "title": "Classification", + "autocomplete": true, + "type": "string", + "columnWidth": 140, + "find": true, + "group": true + }, + { + "id": "tags", + "title": "Tag", + "autocomplete": true, + "type": ["string"], + "columnWidth": 120, + "find": true, + "group": true + } + ], + "itemName": { + "singular": "Cable", + "plural": "Cables" + }, + "itemViews": [ + {"id": "info", "title": "Info"} + ], + "layers": [ + { + "id": "privatenotes", + "title": "Private Notes", + "type": "text", + "overlap": true, + "private": true + }, + { + "id": "publicnotes", + "title": "Public Notes", + "overlap": true, + "type": "text" + }, + { + "id": "subtitles", + "title": "Subtitles", + "type": "text", + "overlay": true, + "sort": [ + {"id": "words", "title": "Words", "type": "words"}, + {"id": "wordsperminute", "title": "Words per Minute", "type": "wordsperminute"} + ] + } + ], + "listViews": [ + {"id": "list", "title": "as List"} + ], + "media": { + "importCablePosters": true, + "importPosterFrames": true + }, + "rightsLevel": {"member": 5, "staff": 4, "admin": 3}, + "rightsLevels": [ + {"name": "Public", "color": [0, 255, 0], "description": "Everyone can see and play."}, + {"name": "Relaxed", "color": [128, 255, 0], "description": "Guests can't play video."}, + {"name": "Regular", "color": [255, 255, 0], "description": "Guests can't play clips, members can't play video."}, + {"name": "Restricted", "color": [255, 128, 0], "description": "Only staff and admin can see and play."}, + {"name": "Private", "color": [255, 0, 0], "description": "Only admins can see and play."} + ], + "site": { + "id": "{{settings.SITEID}}", + "name": "{{settings.SITENAME}}", + "url": "{{settings.URL}}" + }, + "sitePages": [ + {"id": "about", "title": "About"}, + {"id": "news", "title": "News"}, + {"id": "tour", "title": "Take a Tour"}, + {"id": "faq", "title": "Frequently Asked Questions"}, + {"id": "terms", "title": "Terms of Service"} + ], + "totals": [ + {"id": "items"} + ], + "user": { + "level": "guest", + "lists": { + "common": [ + {"id": "all", "title": "All Cables", "query": {}} + ], + "personal": [ + {"user": "foo", "name": "Favorites", "featured": false, "public": true} + ], + "favorite": [ + ], + "featured": [ + ] + }, + "notes": "", + "preferences": {}, + "ui": { + "annotationsSize": 256, + "find": {"index": -1, "key": "", "value": ""}, + "groups": ["origin", "classification", "tags", "created_day", "released_day"], + "groupsSize": 176, + "icons": "posters", + "infoIconSize": 256, + "item": "", + "itemView": "info", + "list": "", + "lists": { + "": { + "columns": ["origin", "subject", "classification", "created", "released", "tags"], + "columnWidth": {}, + "listView": "list", + "selected": [], + "sort": [ + {"key": "created", "operator": ""} + ] + } + }, + "query": {"conditions": [], "operator": ""}, + "section": "items", + "showAnnotations": true, + "showControls": true, + "showGroups": true, + "showHome": true, + "showInfo": false, + "showItems": true, + "showFolder": { + "items": { + "personal": true, + "favorite": true, + "featured": true, + "volumes": true + } + }, + "showSidebar": false, + "sidebarSize": 256, + "sitePage": "home", + "theme": "classic", + "videoPosition": {}, + "videoScale": "fit", + "videoMuted": false, + "videoSize": "small", + "videoView": "player", + "videoVolume": 1 + }, + "username": "", + "volumes": [ + ] + }, + "userLevels": ["guest", "member", "staff", "admin"], + "video": { + "download": false, + "formats": ["webm", "mp4"], + "resolutions": [96] + } +} diff --git a/pandora/item/models.py b/pandora/item/models.py index 17ec255..76ff7d2 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -1103,6 +1103,7 @@ table constructed based on info in site_config['itemKeys'] attrs = { '__module__': 'item.models', 'item': models.OneToOneField('Item', related_name='sort', primary_key=True), + 'duration': models.FloatField(null=True, blank=True, db_index=True), } for key in filter(lambda k: 'columnWidth' in k, config['itemKeys']): name = key['id'] diff --git a/pandora/item/views.py b/pandora/item/views.py index 1912fcf..be0f757 100644 --- a/pandora/item/views.py +++ b/pandora/item/views.py @@ -255,6 +255,7 @@ Positions else: # otherwise stats items = query['qs'] + ''' files = File.objects.filter(item__in=items).filter(size__gt=0) r = files.aggregate( Sum('duration'), @@ -263,13 +264,16 @@ Positions ) response['data']['duration'] = r['duration__sum'] response['data']['files'] = files.count() + ''' response['data']['items'] = items.count() + ''' response['data']['pixels'] = r['pixels__sum'] response['data']['runtime'] = items.aggregate(Sum('sort__runtime'))['sort__runtime__sum'] response['data']['size'] = r['size__sum'] for key in ('runtime', 'duration', 'pixels', 'size'): if response['data'][key] == None: - response['data'][key] = 0 + response['data'][key] = 0 + ''' return render_to_json_response(response) actions.register(find) diff --git a/pandora/load_from_mongodb.py b/pandora/load_from_mongodb.py new file mode 100644 index 0000000..f0c2fbf --- /dev/null +++ b/pandora/load_from_mongodb.py @@ -0,0 +1,22 @@ + +from pymongo import Connection +connection = Connection() + +db = connection.cablegates +cables = db.cables +import item.models + +ids = [c['refid'] for c in cables.find(keys=['refid'])] + +for id in ids: + i, created = item.models.Item.objects.get_or_create(itemId=id) + if not i.data: + cable = cables.find_one({'refid': id}) + i.data = cable + del i.data['_id'] + del i.data['id'] + i.data['created_day'] = i.data['created'].strftime('%Y-%m-%d') + i.data['released_day'] = i.data['released'].strftime('%Y-%m-%d') + print i.data['refid'] + i.public = True + i.save() diff --git a/pandora/urls.py b/pandora/urls.py index e962204..61bffb0 100644 --- a/pandora/urls.py +++ b/pandora/urls.py @@ -28,7 +28,7 @@ urlpatterns = patterns('', (r'^robots.txt$', serve_static_file, {'location': os.path.join(settings.STATIC_ROOT, 'robots.txt'), 'content_type': 'text/plain'}), (r'^favicon.ico$', serve_static_file, {'location': os.path.join(settings.STATIC_ROOT, 'png/icon.16.png'), 'content_type': 'image/x-icon'}), ) -if settings.DEBUG: +if True or settings.DEBUG: urlpatterns += patterns('', (r'^data/(?P.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}), diff --git a/static/js/pandora.js b/static/js/pandora.js index 466fded..c085595 100644 --- a/static/js/pandora.js +++ b/static/js/pandora.js @@ -13,7 +13,7 @@ Ox.load('UI', { hideScreen: false, loadImages: true, showScreen: true, - theme: 'modern' + theme: 'classic' }, function(browserSupported) { // fixme: use Ox.extend() @@ -98,7 +98,7 @@ Ox.load('UI', { Ox.UI.hideLoadingScreen(); - Ox.Theme(pandora.user.ui.theme); + //Ox.Theme(pandora.user.ui.theme); pandora.$ui.appPanel = pandora.ui.appPanel().display(); Ox.Request.requests() && pandora.$ui.loadingIcon.start(); diff --git a/static/js/pandora/ui/cable.js b/static/js/pandora/ui/cable.js new file mode 100644 index 0000000..efe560a --- /dev/null +++ b/static/js/pandora/ui/cable.js @@ -0,0 +1,19 @@ +// vim: et:ts=4:sw=4:sts=4:ft=javascript + +pandora.ui.cable = function(id) { + var that = Ox.Element().addClass('OxSelectable').css({overflow: 'auto'}); + pandora.api.get({id: id, keys: []}, function(result) { + var header = result.data.header, + content = result.data.content; + that.html('') + .append($('
').css('padding', '8px') + .addClass('OxSelectable') + .append($('
').html(header))
+                 .append($('
').html(content)
+            ))
+            .scrollTop(0);
+        
+    });
+    return that;
+};
+
diff --git a/static/js/pandora/ui/contentPanel.js b/static/js/pandora/ui/contentPanel.js
index 28a087e..fe27d15 100644
--- a/static/js/pandora/ui/contentPanel.js
+++ b/static/js/pandora/ui/contentPanel.js
@@ -1,6 +1,6 @@
 // vim: et:ts=4:sw=4:sts=4:ft=javascript
 pandora.ui.contentPanel = function() {
-    var that = Ox.SplitPanel({
+    var that= Ox.SplitPanel({
         elements: !pandora.user.ui.item ? [
             {
                 collapsed: !pandora.user.ui.showGroups,
@@ -12,7 +12,22 @@ pandora.ui.contentPanel = function() {
                 tooltip: 'groups'
             },
             {
-                element: pandora.$ui.list = pandora.ui.list()
+                element: pandora.$ui.mainContent = Ox.SplitPanel({
+                    elements: [
+                        {
+                            element: pandora.$ui.list = pandora.ui.list()
+                        },
+                        {
+                            element:  Ox.Element().addClass('OxSelectable'),
+                            collapsible: true,
+                            collapsed: true,
+                            size: 600,
+                            resizable: true,
+                            resize: [200, 400, 600]
+                        }
+                    ],
+                    orientation: 'horizontal'
+                })
             }
         ] : [
             {
diff --git a/static/js/pandora/ui/list.js b/static/js/pandora/ui/list.js
index 29dddf9..36866c3 100644
--- a/static/js/pandora/ui/list.js
+++ b/static/js/pandora/ui/list.js
@@ -637,6 +637,16 @@ pandora.ui.list = function() { // fixme: remove view argument
             select: function(data) {
                 var $still, $timeline;
                 pandora.UI.set(['lists', pandora.user.ui.list, 'selected'].join('|'), data.ids);
+                if (data.ids.length) {
+                    pandora.$ui.mainContent.replaceElement(1,
+                        pandora.$ui.cable = pandora.ui.cable(data.ids[0]));
+                    if(pandora.$ui.mainContent.isCollapsed(1))
+                        pandora.$ui.mainContent.toggle(1); 
+                } else {
+                    if(!pandora.$ui.mainContent.isCollapsed(1))
+                        pandora.$ui.mainContent.toggle(1); 
+                }
+                /*
                 //pandora.user.ui.lists[pandora.user.ui.list].selected = data.ids;
                 if (data.ids.length) {
                     pandora.$ui.mainMenu.enableItem('copy');
@@ -660,6 +670,7 @@ pandora.ui.list = function() { // fixme: remove view argument
                 }, function(result) {
                     pandora.$ui.selected.html(pandora.ui.status('selected', result.data));
                 });
+                */
             }
         });
         
diff --git a/static/json/pandora.json b/static/json/pandora.json
index 756e9f7..c9f8654 100644
--- a/static/json/pandora.json
+++ b/static/json/pandora.json
@@ -43,5 +43,6 @@
   "js/pandora/ui/mediaView.js",
   "js/pandora/ui/home.js",
   "js/pandora/ui/preferencesDialog.js",
-  "js/pandora/ui/siteDialog.js"
+  "js/pandora/ui/siteDialog.js",
+  "js/pandora/ui/cable.js"
 ]