forked from 0x2620/pandora
merge
This commit is contained in:
commit
7c37c1efde
6 changed files with 87 additions and 56 deletions
|
@ -126,6 +126,12 @@ class Annotation(models.Model):
|
|||
super(Annotation, self).save(*args, **kwargs)
|
||||
if set_public_id:
|
||||
self.set_public_id()
|
||||
|
||||
Clip.objects.filter(**{
|
||||
'id': self.clip.id,
|
||||
self.layer.name: False
|
||||
}).update(**{self.layer.name: True})
|
||||
|
||||
#how expensive is this?
|
||||
#update_matching_events.delay(self.value)
|
||||
#update_matching_places.delay(self.value)
|
||||
|
|
|
@ -165,10 +165,6 @@ class ClipManager(Manager):
|
|||
if conditions:
|
||||
qs = qs.filter(conditions)
|
||||
if 'keys' in data:
|
||||
public_layers = [l['id']
|
||||
for l in filter(lambda l: not l.get('private', False),
|
||||
settings.CONFIG['layers'])]
|
||||
filter_layers = filter(lambda k: k in public_layers, data['keys'])
|
||||
if filter_layers:
|
||||
qs = qs.filter(annotations__layer__name__in=filter_layers)
|
||||
for l in filter(lambda k: k in self.model.layers, data['keys']):
|
||||
qs = qs.filter(**{l: True})
|
||||
return qs
|
||||
|
|
|
@ -9,37 +9,7 @@ from archive import extract
|
|||
import managers
|
||||
|
||||
|
||||
class Clip(models.Model):
|
||||
'''
|
||||
CREATE INDEX clip_clip_title_idx ON clip_clip (title ASC NULLS LAST);
|
||||
CREATE INDEX clip_clip_director_idx ON clip_clip (director ASC NULLS LAST);
|
||||
'''
|
||||
class Meta:
|
||||
unique_together = ("item", "start", "end")
|
||||
|
||||
objects = managers.ClipManager()
|
||||
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
modified = models.DateTimeField(auto_now=True)
|
||||
public_id = models.CharField(max_length=128, unique=True)
|
||||
aspect_ratio = models.FloatField(default=0)
|
||||
|
||||
item = models.ForeignKey('item.Item', related_name='clips')
|
||||
|
||||
#seconds
|
||||
start = models.FloatField(default=-1, db_index=True)
|
||||
end = models.FloatField(default=-1)
|
||||
duration = models.FloatField(default=0, db_index=True)
|
||||
|
||||
#get from annotation
|
||||
hue = models.FloatField(default=0, db_index=True)
|
||||
saturation = models.FloatField(default=0, db_index=True)
|
||||
lightness = models.FloatField(default=0, db_index=True)
|
||||
volume = models.FloatField(default=0, null=True, db_index=True)
|
||||
|
||||
director = models.CharField(max_length=1000, db_index=True)
|
||||
title = models.CharField(max_length=1000, db_index=True)
|
||||
|
||||
class MetaClip:
|
||||
def update_calculated_values(self):
|
||||
self.duration = self.end - self.start
|
||||
if self.duration > 0:
|
||||
|
@ -60,7 +30,9 @@ class Clip(models.Model):
|
|||
streams = self.item.streams()
|
||||
if streams:
|
||||
self.aspect_ratio = streams[0].aspect_ratio
|
||||
super(Clip, self).save(*args, **kwargs)
|
||||
for l in self.layers:
|
||||
setattr(self, l, self.annotations.filter(layer__name=l).count()>0)
|
||||
models.Model.save(self, *args, **kwargs)
|
||||
|
||||
def json(self, keys=None):
|
||||
j = {}
|
||||
|
@ -104,3 +76,40 @@ class Clip(models.Model):
|
|||
def __unicode__(self):
|
||||
return self.public_id
|
||||
|
||||
class Meta:
|
||||
unique_together = ("item", "start", "end")
|
||||
|
||||
attrs = {
|
||||
'__module__': 'clip.models',
|
||||
'Meta': Meta,
|
||||
'objects': managers.ClipManager(),
|
||||
'created': models.DateTimeField(auto_now_add=True),
|
||||
'modified': models.DateTimeField(auto_now=True),
|
||||
'public_id': models.CharField(max_length=128, unique=True),
|
||||
'aspect_ratio': models.FloatField(default=0),
|
||||
|
||||
'item': models.ForeignKey('item.Item', related_name='clips'),
|
||||
|
||||
#seconds
|
||||
'start': models.FloatField(default=-1, db_index=True),
|
||||
'end': models.FloatField(default=-1),
|
||||
'duration': models.FloatField(default=0, db_index=True),
|
||||
|
||||
#get from annotation
|
||||
'hue': models.FloatField(default=0, db_index=True),
|
||||
'saturation': models.FloatField(default=0, db_index=True),
|
||||
'lightness': models.FloatField(default=0, db_index=True),
|
||||
'volume': models.FloatField(default=0, null=True, db_index=True),
|
||||
|
||||
'director': models.CharField(max_length=1000, db_index=True),
|
||||
'title': models.CharField(max_length=1000, db_index=True),
|
||||
}
|
||||
public_layers = [l['id']
|
||||
for l in filter(lambda l: not l.get('private', False),
|
||||
settings.CONFIG['layers'])]
|
||||
for name in public_layers:
|
||||
attrs[name] = models.BooleanField(default=False, db_index=True)
|
||||
|
||||
Clip = type('Clip', (MetaClip,models.Model), attrs)
|
||||
Clip.layers = public_layers
|
||||
|
||||
|
|
|
@ -82,19 +82,21 @@ def findClips(request):
|
|||
if 'keys' in data:
|
||||
qs = order_query(qs, query['sort'])
|
||||
qs = qs[query['range'][0]:query['range'][1]]
|
||||
qs = qs.select_related('item__sort')
|
||||
response['data']['items'] = [p.json(keys=data['keys']) for p in qs]
|
||||
#qs = qs.select_related('item__sort')
|
||||
ids = []
|
||||
keys = filter(lambda k: k not in models.Clip.layers, data['keys'])
|
||||
def add(p):
|
||||
ids.append(p.id)
|
||||
return p.json(keys=keys)
|
||||
response['data']['items'] = [add(p) for p in qs]
|
||||
|
||||
keys = data['keys']
|
||||
public_layers = [l['id']
|
||||
for l in filter(lambda l: not l.get('private', False),
|
||||
settings.CONFIG['layers'])]
|
||||
|
||||
def add_annotations(layer, qs):
|
||||
for a in qs.values('public_id', 'value', 'clip__public_id'):
|
||||
for i in response['data']['items']:
|
||||
if i['id'] == a['clip__public_id']:
|
||||
if not i[layer]:
|
||||
if not layer in i:
|
||||
i[layer] = []
|
||||
i[layer].append({
|
||||
'id': a['public_id'],
|
||||
|
@ -103,10 +105,10 @@ def findClips(request):
|
|||
if response['data']['items']:
|
||||
if 'annotations' in keys:
|
||||
add_annotations('annotations',
|
||||
Annotation.objects.filter(layer__name__in=public_layers, clip__in=qs))
|
||||
for layer in filter(lambda l: l in keys, public_layers):
|
||||
Annotation.objects.filter(layer__name__in=models.Clip.layers, clip__in=ids))
|
||||
for layer in filter(lambda l: l in keys, models.Clip.layers):
|
||||
add_annotations(layer,
|
||||
Annotation.objects.filter(layer__name=layer, clip__in=qs))
|
||||
Annotation.objects.filter(layer__name=layer, clip__in=ids))
|
||||
elif 'position' in query:
|
||||
qs = order_query(qs, query['sort'])
|
||||
ids = [i.public_id for i in qs]
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
Hi {{sitename}} admin,
|
||||
|
||||
someone sent you a message:
|
||||
{{name}} <{{email}}> sent a contact message:
|
||||
{{message}}
|
||||
|
||||
--
|
||||
{{sitename}}
|
||||
|
|
|
@ -534,21 +534,38 @@ def contact(request):
|
|||
}
|
||||
'''
|
||||
data = json.loads(request.POST['data'])
|
||||
if 'email' in data and 'message' in data:
|
||||
email = data['email']
|
||||
name = data.get('name', '')
|
||||
email = data.get('email', '')
|
||||
if request.user.is_authenticated():
|
||||
if not name:
|
||||
name = request.user.username
|
||||
if not email:
|
||||
email = request.user.email
|
||||
if 'message' in data and data['message'].strip():
|
||||
email_from = settings.CONFIG['site']['email']['system']
|
||||
email_to = [settings.CONFIG['site']['email']['contact'], ]
|
||||
template = loader.get_template('contact_email.txt')
|
||||
context = RequestContext(request, {
|
||||
'sitename': settings.SITENAME,
|
||||
'email': email,
|
||||
'message': data['message'],
|
||||
'message': data['message'].strip(),
|
||||
'name': name,
|
||||
'sitename': settings.SITENAME,
|
||||
})
|
||||
message = template.render(context)
|
||||
subject = '%s contact: %s' % (settings.SITENAME, data['subject'])
|
||||
subject = (u'[%s Contact] %s' % (settings.SITENAME, data.get('subject', ''))).strip()
|
||||
response = json_response(text='message sent')
|
||||
try:
|
||||
send_mail(subject, message, email, [settings.DEFAULT_FROM_EMAIL, ])
|
||||
send_mail(subject.strip(), message, email_from, email_to)
|
||||
except BadHeaderError:
|
||||
response = json_response(status=400, text='invalid data')
|
||||
if request.user.is_authenticated() \
|
||||
and 'receipt' in data \
|
||||
and data['receipt']:
|
||||
message = data['message'].strip()
|
||||
try:
|
||||
send_mail(subject.strip(), message, email_from, [email])
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
response = json_response(status=400, text='invalid data')
|
||||
return render_to_json_response(response)
|
||||
|
|
Loading…
Reference in a new issue