remove unnecessary imports
[mygpo.git] / mygpo / web / models.py
blob1dcc73249fac2dd13d064df7d798c368f3a330f9
2 # This file is part of my.gpodder.org.
4 # my.gpodder.org is free software: you can redistribute it and/or modify it
5 # under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or (at your
7 # option) any later version.
9 # my.gpodder.org is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
12 # License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with my.gpodder.org. If not, see <http://www.gnu.org/licenses/>.
18 from django.db import models
19 from django.contrib.auth.models import User
20 from mygpo.api.models import Podcast
21 from datetime import datetime
22 import random
23 import string
26 class Rating(models.Model):
27 target = models.CharField(max_length=15)
28 user = models.ForeignKey(User)
29 rating = models.IntegerField()
30 timestamp = models.DateTimeField(default=datetime.now)
32 class Meta:
33 db_table = 'ratings'
35 def __unicode__(self):
36 return '%s rates %s as %s on %s' % (self.user, self.target, self.rating, self.timestamp)
39 class SecurityToken(models.Model):
40 user = models.ForeignKey(User)
41 token = models.CharField(max_length=32, blank=True, default=lambda: "".join(random.sample(string.letters+string.digits, 32)))
42 object = models.CharField(max_length=64)
43 action = models.CharField(max_length=10)
45 class Meta:
46 db_table = 'security_tokens'
48 def __unicode__(self):
49 return '%s %s %s: %s' % (self.user, self.object, self.action, self.token[:5])
51 def random_token(self, length=32):
52 self.token = "".join(random.sample(string.letters+string.digits, length))
54 def check(self, token):
55 if self.token == '':
56 return True
57 return self.token == token
60 class Advertisement(models.Model):
61 podcast = models.ForeignKey(Podcast)
62 title = models.CharField(max_length=100)
63 text = models.TextField()
64 start = models.DateTimeField()
65 end = models.DateTimeField()
67 class Meta:
68 db_table = 'advertisements'
70 def __unicode__(self):
71 return '%s (%s - %s)' % (self.podcast, self.start, self.end)