summaryrefslogtreecommitdiff
path: root/meetingtools/apps/archive/views.py
blob: 2c8086d80d6153567b7211f0acf3840b4fc5b4c1 (plain)
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
52
53
54
55
56
57
58
59
60
61
62
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})