summaryrefslogtreecommitdiff
path: root/src/meetingtools/apps/room/feeds.py
blob: 3dff05e0b05933c45b1b61be5f87cb9246aab717 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
'''
Created on May 13, 2011

@author: leifj
'''

from django.contrib.syndication.views import Feed
from meetingtools.apps.room.models import Room
from tagging.models import TaggedItem
from meetingtools.settings import BASE_URL
from django.utils.feedgenerator import Atom1Feed, Rss201rev2Feed
from meetingtools.apps.room.views import room_recordings
from django.shortcuts import get_object_or_404

class TagsWrapper(object):
    
    def __init__(self,tn):
        self.tags = tn.split('+')
        self.rooms = TaggedItem.objects.get_by_model(Room, tn.split('+'))
        
    def title(self):
        return "Rooms tagged with %s" % " and ".join(self.tags)

    def description(self):
        return self.title()
    
    def link(self,ext):
        return "%s/room/+%s.%s" % (BASE_URL,"+".join(self.tags),ext)

class MeetingToolsFeed(Feed):
    
    item_author_name = 'SUNET e-meeting tools'
    
    def ext(self):
        if self.feed_type == Atom1Feed:
            return "atom"
        
        if self.feed_type == Rss201rev2Feed:
            return "rss"
        
        return "rss"


class RoomTagFeed(MeetingToolsFeed):
    
    def get_object(self,request,tn):
        return TagsWrapper(tn)
    
    def title(self,t):
        return t.title()
    
    def link(self,t):
        return t.link(self.ext())
    
    def description(self,t):
        return t.description()
    
    def items(self,t):
        return t.rooms
    
    def item_title(self,room):
        return room.name
    
    def item_description(self,room):
        return room.description
    
    def item_link(self,room):
        return room.go_url()
    
    def item_guid(self,room):
        return room.permalink()
    
    def item_pubdate(self,room):
        return room.lastupdated
    
    
class RoomAtomTagFeed(RoomTagFeed):
    feed_type = Atom1Feed
    
class RoomRSSTagField(RoomTagFeed):
    feed_type = Rss201rev2Feed
    
class RecordingsWrapper(object):
    def __init__(self,room,request):
        self.room = room
        self.items = room_recordings(request, room)
    
class RecordingFeed(MeetingToolsFeed):
    
    def get_object(self,request,rid):
        room = get_object_or_404(Room,pk=rid)
        return RecordingsWrapper(room,request)
    
    def title(self,recordings):
        return "Recordings in room '%s'" % recordings.room.name
    
    def link(self,recordings):
        return recordings.room.recordings_url()
    
    def items(self,recordings):
        return recordings.items
    
    def item_title(self,recording):
        return recording['name']
    
    def item_description(self,recording):
        return recording['description']
    
    def item_link(self,recording):
        return recording['url']
    
    def item_pubdate(self,recording):
        return recording['date_created']
    
class AtomRecordingFeed(RecordingFeed):
    feed_type = Atom1Feed
    
class RSSRecordingField(RecordingFeed):
    feed_type = Rss201rev2Feed