1 from __future__
import unicode_literals
3 from django
.db
import models
5 from couchdbkit
.ext
.django
.schema
import *
7 from mygpo
.podcasts
.models
import Podcast
8 from mygpo
.core
.models
import UpdateInfoModel
11 class SubscriptionError(Exception):
14 class Subscription(Document
):
15 url
= StringProperty(required
=True)
16 verify_token
= StringProperty(required
=True)
17 mode
= StringProperty(required
=True)
18 verified
= BooleanProperty(default
=False)
21 def __unicode__(self
):
23 verified
= u
'verified'
25 verified
= u
'unverified'
26 return u
'<Subscription for %s: %s>' % (self
.url
, verified
)
29 return str(unicode(self
))
32 class HubSubscription(UpdateInfoModel
):
33 """ A client-side PubSubHubbub subscription
35 https://code.google.com/p/pubsubhubbub/ """
37 SUBSCRIBE
= 'subscribe'
38 UNSUBSCRIBE
= 'unsubscribe'
41 (SUBSCRIBE
, 'subscribe'),
42 (UNSUBSCRIBE
, 'unsubscribe'),
45 # podcast to which the subscription belongs
46 podcast
= models
.ForeignKey(Podcast
, on_delete
=models
.PROTECT
)
48 # the topic of the subscription, ie the URL that was subscribed at the hub
49 topic_url
= models
.CharField(max_length
=2048, unique
=True)
52 hub_url
= models
.CharField(max_length
=1000)
54 # a token to verify the authenticity of the hub
55 verify_token
= models
.CharField(max_length
=32)
57 # the last mode that was requested, either subscribe or unsubscribe
58 mode
= models
.CharField(
60 max_length
=max(map(len, [mode
for mode
, name
in MODE_CHOICES
])),
64 # indicates whether the last mode change has already been verified
65 verified
= models
.BooleanField(default
=False)