This repository has been archived by the owner on Mar 15, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 236
/
models.py
86 lines (64 loc) · 2.65 KB
/
models.py
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
from django.db import models
import caching.base
import amo.models
from addons.models import Addon
from applications.models import Application, AppVersion
from translations.fields import TranslatedField, PurifiedField
from users.models import UserProfile
class Version(amo.models.ModelBase):
addon = models.ForeignKey(Addon, related_name='versions')
license = models.ForeignKey('License', null=True)
releasenotes = PurifiedField()
approvalnotes = models.TextField(default="")
version = models.CharField(max_length=255, default=0)
class Meta(amo.models.ModelBase.Meta):
db_table = 'versions'
ordering = ['-created']
def __unicode__(self):
return self.version
@amo.cached_property
def compatible_apps(self):
"""Get a mapping of {APP: ApplicationVersion}."""
apps = {}
for av in self.applicationsversions_set.select_related(depth=1):
app_id = av.application.id
if app_id in amo.APP_IDS:
apps[amo.APP_IDS[app_id]] = av
return apps
# TODO(jbalogh): Do we want names or Platforms?
@amo.cached_property
def supported_platforms(self):
"""Get a list of supported platform names."""
return list(set(f.platform.name for f in self.files.all()))
class License(amo.models.ModelBase):
text = TranslatedField()
class Meta(amo.models.ModelBase.Meta):
db_table = 'licenses'
class VersionComment(amo.models.ModelBase):
"""Editor comments for version discussion threads."""
version = models.ForeignKey(Version)
user = models.ForeignKey(UserProfile)
reply_to = models.ForeignKey(Version, related_name="reply_to", null=True)
subject = models.CharField(max_length=1000)
comment = models.TextField()
class Meta(amo.models.ModelBase.Meta):
db_table = 'versioncomments'
class VersionSummary(amo.models.ModelBase):
addon = models.ForeignKey(Addon)
version = models.ForeignKey(Version)
application = models.ForeignKey(Application)
min = models.IntegerField(null=True)
max = models.IntegerField(null=True)
class Meta(amo.models.ModelBase.Meta):
db_table = 'versions_summary'
class ApplicationsVersions(caching.base.CachingMixin, models.Model):
application = models.ForeignKey(Application)
version = models.ForeignKey(Version)
min = models.ForeignKey(AppVersion, db_column='min',
related_name='min_set')
max = models.ForeignKey(AppVersion, db_column='max',
related_name='max_set')
objects = caching.base.CachingManager()
class Meta:
db_table = u'applications_versions'
unique_together = (("application", "version"),)