diff options
author | Leif Johansson <leifj@sunet.se> | 2012-10-16 17:57:45 +0200 |
---|---|---|
committer | Leif Johansson <leifj@sunet.se> | 2012-10-16 17:57:45 +0200 |
commit | 8f6f63c87128906be86fdfdf53aba48570677e87 (patch) | |
tree | 443ae2807ace7ed11306699c69cd4f209352874e /meetingtools/apps/archive | |
parent | a15a4d81d5520adbfbbc5509202e32b1b56f826a (diff) |
- normalize sco objects to separate tablesco
- add archive object for "published" archives
- configurable return from form edits
- tagging for archives
- reset south
Diffstat (limited to 'meetingtools/apps/archive')
-rw-r--r-- | meetingtools/apps/archive/__init__.py | 1 | ||||
-rw-r--r-- | meetingtools/apps/archive/admin.py | 10 | ||||
-rw-r--r-- | meetingtools/apps/archive/forms.py | 6 | ||||
-rw-r--r-- | meetingtools/apps/archive/management/__init__.py | 1 | ||||
-rw-r--r-- | meetingtools/apps/archive/management/commands/__init__.py | 1 | ||||
-rw-r--r-- | meetingtools/apps/archive/management/commands/update_recordings.py | 19 | ||||
-rw-r--r-- | meetingtools/apps/archive/models.py | 50 | ||||
-rw-r--r-- | meetingtools/apps/archive/views.py | 63 |
8 files changed, 151 insertions, 0 deletions
diff --git a/meetingtools/apps/archive/__init__.py b/meetingtools/apps/archive/__init__.py new file mode 100644 index 0000000..3929ed7 --- /dev/null +++ b/meetingtools/apps/archive/__init__.py @@ -0,0 +1 @@ +__author__ = 'leifj' diff --git a/meetingtools/apps/archive/admin.py b/meetingtools/apps/archive/admin.py new file mode 100644 index 0000000..3ace40d --- /dev/null +++ b/meetingtools/apps/archive/admin.py @@ -0,0 +1,10 @@ +''' +Created on Jan 31, 2011 + +@author: leifj +''' + +from django.contrib import admin +from meetingtools.apps.archive.models import Archive + +admin.site.register(Archive)
\ No newline at end of file diff --git a/meetingtools/apps/archive/forms.py b/meetingtools/apps/archive/forms.py new file mode 100644 index 0000000..55086b8 --- /dev/null +++ b/meetingtools/apps/archive/forms.py @@ -0,0 +1,6 @@ +from django.forms import Form, CharField + +__author__ = 'leifj' + +class TagArchiveForm(Form): + tag = CharField(max_length=256)
\ No newline at end of file diff --git a/meetingtools/apps/archive/management/__init__.py b/meetingtools/apps/archive/management/__init__.py new file mode 100644 index 0000000..3929ed7 --- /dev/null +++ b/meetingtools/apps/archive/management/__init__.py @@ -0,0 +1 @@ +__author__ = 'leifj' diff --git a/meetingtools/apps/archive/management/commands/__init__.py b/meetingtools/apps/archive/management/commands/__init__.py new file mode 100644 index 0000000..3929ed7 --- /dev/null +++ b/meetingtools/apps/archive/management/commands/__init__.py @@ -0,0 +1 @@ +__author__ = 'leifj' diff --git a/meetingtools/apps/archive/management/commands/update_recordings.py b/meetingtools/apps/archive/management/commands/update_recordings.py new file mode 100644 index 0000000..8aad747 --- /dev/null +++ b/meetingtools/apps/archive/management/commands/update_recordings.py @@ -0,0 +1,19 @@ +from django.core.management import BaseCommand +from meetingtools.apps.archive.models import Archive +from meetingtools.apps.cluster.models import ACCluster + +__author__ = 'leifj' + +class Command(BaseCommand): + + def handle(self, *args, **options): + for ar in Archive.objects.all(): + info = ar.sco.info() + if info is None: + continue + print info + if info.has_key('name'): + ar.name = info['name'] + if info.has_key('description'): + ar.description = info['description'] + ar.save() diff --git a/meetingtools/apps/archive/models.py b/meetingtools/apps/archive/models.py new file mode 100644 index 0000000..3bacec1 --- /dev/null +++ b/meetingtools/apps/archive/models.py @@ -0,0 +1,50 @@ +from datetime import datetime +from iso8601 import iso8601 +from tagging.models import Tag +from meetingtools.ac import ac_api_client +from meetingtools.apps.room.models import Room +from meetingtools.apps.sco.models import ACObject, get_sco, sco_mkdir + +__author__ = 'leifj' + +from django.db import models +from django.db.models import ForeignKey, TextField, CharField + +class Archive(models.Model): + sco = ForeignKey(ACObject,editable=False,unique=True) + folder_sco = ForeignKey(ACObject,editable=False,related_name='archive_folder') + room = ForeignKey(Room,editable=False,related_name='archives') + description = TextField(blank=True,null=True) + name = CharField(max_length=128,blank=True,null=True) + urlpath = CharField(max_length=128) + timecreated = models.DateTimeField(auto_now_add=True) + lastupdated = models.DateTimeField(auto_now=True) + + def __unicode__(self): + return "archive %s, sco %s, in folder %s" % (self.name,self.sco,self.folder_sco) + +def publish_archive(room,sco_id,tags=None): + acc = room.sco.acc + sco = get_sco(acc,sco_id) + + info = sco.info(True) + dt = info['timecreated'] + folder_sco = sco_mkdir(acc,"content/%d/%s/%s" % (dt.year,dt.month,dt.day)) + with ac_api_client(acc) as api: + ar,create = Archive.objects.get_or_create(sco=sco,folder_sco=folder_sco,room=room) + ar.timecreated=info['timecreated'] + if info['description']: + ar.description = info['description'] + if info['name']: + ar.name = info['name'] + ar.save() + try: + r = api.request('sco-move',{'sco-id':sco_id,'folder-id':folder_sco.sco_id},True) + except Exception,ex: + ar.delete() + raise ex + + if tags is not None: + Tag.objects.update_tags(ar, ' '.join(tags)) + + return ar
\ No newline at end of file diff --git a/meetingtools/apps/archive/views.py b/meetingtools/apps/archive/views.py new file mode 100644 index 0000000..2c8086d --- /dev/null +++ b/meetingtools/apps/archive/views.py @@ -0,0 +1,63 @@ +import re +from django.contrib.auth.decorators import login_required +from django.shortcuts import get_object_or_404 +from django.views.decorators.cache import never_cache +from tagging.models import Tag +from meetingtools.apps.archive.forms import TagArchiveForm +from meetingtools.apps.archive.models import publish_archive, Archive +from meetingtools.apps.room.models import Room +from meetingtools.multiresponse import redirect_to, respond_to + +__author__ = 'leifj' + +class HttpRedirect(object): + pass + +@login_required +def publish_sco(request,rid,sco_id): + room = get_object_or_404(Room,pk=rid) + acc = room.sco.sco_id + ar = publish_archive(room,sco_id) + return redirect_to("/room/%d/recordings#%d" % (rid,ar.sco.sco_id)) + +def _can_tag(request,tag): + if tag in ('selfcleaning','cleaning','public','private'): + return False,"'%s' is reserved" % tag + # XXX implement access model for tags here soon + return True,"" + +@never_cache +@login_required +def untag(request,rid,tag): + ar = get_object_or_404(Archive,pk=rid) + new_tags = [] + for t in Tag.objects.get_for_object(ar): + if t.name != tag: + new_tags.append(t.name) + + Tag.objects.update_tags(ar, ' '.join(new_tags)) + return redirect_to("/archive/%d/tag" % ar.id) + +@never_cache +@login_required +def tag(request,rid): + archive = get_object_or_404(Archive,pk=rid) + if request.method == 'POST': + form = TagArchiveForm(request.POST) + if form.is_valid(): + for tag in re.split('[,\s]+',form.cleaned_data['tag']): + tag = tag.strip() + if tag: + ok,reason = _can_tag(request,tag) + if ok: + Tag.objects.add_tag(archive, tag) + else: + form._errors['tag'] = form.error_class([u'%s ... please choose another tag!' % reason]) + else: + form = TagArchiveForm() + + tags = Tag.objects.get_for_object(archive) + tn = "+".join([t.name for t in tags]) + return respond_to(request, + {'text/html': "apps/archive/tag.html"}, + {'form': form,'formtitle': 'Add Tag','cancelname':'Done','submitname': 'Add Tag','archive': archive, 'tagstring': tn,'tags': tags}) |