1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
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 'description' in info:
ar.description = info['description']
if 'name' in info:
ar.name = info['name']
ar.save()
try:
r = api.request('sco-move',{'sco-id':sco_id,'folder-id':folder_sco.sco_id},True)
r = api.request('permissions-update',{'acl-id':sco_id,'permission-id': 'view','principal-id':'public-access'})
except Exception,ex:
ar.delete()
raise ex
if tags is not None:
Tag.objects.update_tags(ar, ' '.join(tags))
return ar
|