From 8aafc4f0b9cc985ee5796d970e58882bc61e6cd1 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Wed, 5 Feb 2014 11:27:17 +0000 Subject: [PATCH] add smart edit support to backend --- pandora/edit/models.py | 30 +++++++++++++++++++++--------- pandora/edit/views.py | 3 ++- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/pandora/edit/models.py b/pandora/edit/models.py index 82174cde..b5c9eb66 100644 --- a/pandora/edit/models.py +++ b/pandora/edit/models.py @@ -10,7 +10,7 @@ import subprocess from urllib import quote import ox -from ox.django.fields import TupleField +from ox.django.fields import DictField, TupleField from django.conf import settings from django.db import models, transaction from django.db.models import Max @@ -40,6 +40,9 @@ class Edit(models.Model): description = models.TextField(default='') rightslevel = models.IntegerField(db_index=True, default=0) + query = DictField(default={"static": True}) + type = models.CharField(max_length=255, default='static') + icon = models.ImageField(default=None, blank=True, null=True, upload_to=lambda i, x: i.path("icon.jpg")) @@ -164,7 +167,13 @@ class Edit(models.Model): pos.section = 'personal' pos.save() if 'type' in data: - self.type = data['type'] == 'pdf' and 'pdf' or 'html' + if data['type'] == 'static': + self.query = {"static":True} + self.type = 'static' + else: + self.type = 'dynamic' + if self.query.get('static', False): + self.query = {} if 'posterFrames' in data: self.poster_frames = tuple(data['posterFrames']) self.save() @@ -236,22 +245,22 @@ class Edit(models.Model): def json(self, keys=None, user=None): if not keys: keys=[ + 'clips', 'description', + 'duration', 'editable', - 'rightslevel', 'id', 'items', - 'clips', - 'duration', 'name', 'posterFrames', + 'query', + 'rightslevel', 'status', 'subscribed', - 'user' + 'type', + 'user', ] - response = { - 'type': 'static' - } + response = {} _map = { 'posterFrames': 'poster_frames' } @@ -260,6 +269,9 @@ class Edit(models.Model): response[key] = self.get_id() elif key == 'items': response[key] = self.clips.all().count() + elif key == 'query': + if not self.query.get('static', False): + response[key] = self.query elif key == 'clips': response[key] = [c.json(user) for c in self.clips.all().order_by('index')] elif key == 'duration': diff --git a/pandora/edit/views.py b/pandora/edit/views.py index d0eaef70..b1d97334 100644 --- a/pandora/edit/views.py +++ b/pandora/edit/views.py @@ -223,7 +223,8 @@ actions.register(getEdit) def addEdit(request): ''' takes { - name + [name], + [type] } returns { id