import amo.models to avoid circular imports, move constants to __init__

This commit is contained in:
Jeff Balogh 2010-01-28 17:59:26 -08:00
Родитель 60c9111e9a
Коммит 5e3052ddbe
21 изменённых файлов: 180 добавлений и 184 удалений

Просмотреть файл

@ -1,9 +1,9 @@
from django.db import models
import amo
import amo.models
class Group(amo.ModelBase):
class Group(amo.models.ModelBase):
name = models.CharField(max_length=255, default='')
rules = models.TextField()

Просмотреть файл

@ -1,12 +1,12 @@
from django.conf import settings
from django.db import models
import amo
import amo.models
from amo.urlresolvers import reverse
from translations.fields import TranslatedField, translations_with_fallback
class Addon(amo.ModelBase):
class Addon(amo.models.ModelBase):
STATUS_CHOICES = amo.STATUS_CHOICES.items()
CONTRIBUTIONS_CHOICES = (
@ -104,7 +104,7 @@ class AddonCategory(models.Model):
db_table = 'addons_categories'
class AddonPledge(amo.ModelBase):
class AddonPledge(amo.models.ModelBase):
addon = models.ForeignKey(Addon)
target = models.PositiveIntegerField() # Only $ for now
what_ima_gonna_do = TranslatedField()
@ -127,7 +127,7 @@ class AddonRecommendation(models.Model):
db_table = 'addon_recommendations'
class AddonType(amo.ModelBase):
class AddonType(amo.models.ModelBase):
name = TranslatedField()
name_plural = TranslatedField()
description = TranslatedField()
@ -152,7 +152,7 @@ class AddonUser(models.Model):
db_table = 'addons_users'
class BlacklistedGuid(amo.ModelBase):
class BlacklistedGuid(amo.models.ModelBase):
guid = models.CharField(max_length=255, unique=True)
class Meta:
@ -162,7 +162,7 @@ class BlacklistedGuid(amo.ModelBase):
return self.guid
class Category(amo.ModelBase):
class Category(amo.models.ModelBase):
name = TranslatedField()
description = TranslatedField()
addontype = models.ForeignKey(AddonType)
@ -198,7 +198,7 @@ class CompatibilityReport(models.Model):
db_table = 'compatibility_reports'
class Feature(amo.ModelBase):
class Feature(amo.models.ModelBase):
addon = models.ForeignKey(Addon)
start = models.DateTimeField()
end = models.DateTimeField()
@ -213,7 +213,7 @@ class Feature(amo.ModelBase):
self.locale)
class Preview(amo.ModelBase):
class Preview(amo.models.ModelBase):
addon = models.ForeignKey(Addon)
filetype = models.CharField(max_length=25)
thumbtype = models.CharField(max_length=25)

Просмотреть файл

@ -4,7 +4,7 @@ from django.shortcuts import redirect
import jingo
import amo
import amo.models
from addons.models import Addon
from files.models import Approval
from versions.models import Version

Просмотреть файл

@ -1,5 +1,100 @@
"""
Miscellaneous helpers that make Django compatible with AMO.
"""
from .models import ModelBase
from .constants import *
from django.utils.translation import ugettext as _
# Add-on and File statuses.
STATUS_NULL = 0
STATUS_SANDBOX = 1
STATUS_PENDING = 2
STATUS_NOMINATED = 3
STATUS_PUBLIC = 4
STATUS_DISABLED = 5
STATUS_LISTED = 6
STATUS_BETA = 7
STATUS_CHOICES = {
STATUS_NULL: 'Null',
STATUS_SANDBOX: 'In the sandbox',
STATUS_PENDING: 'Pending approval',
STATUS_NOMINATED: 'Nominated to be public',
STATUS_PUBLIC: 'Public',
STATUS_DISABLED: 'Disabled',
STATUS_LISTED: 'Listed',
STATUS_BETA: 'Beta',
}
# Add-on author roles.
AUTHOR_ROLE_NONE = 0
AUTHOR_ROLE_VIEWER = 1
AUTHOR_ROLE_DEV = 4
AUTHOR_ROLE_OWNER = 5
AUTHOR_ROLE_ADMIN = 6
AUTHOR_ROLE_ADMINOWNER = 7
AUTHOR_CHOICES = {
AUTHOR_ROLE_NONE: 'None',
AUTHOR_ROLE_VIEWER: 'Viewer',
AUTHOR_ROLE_DEV: 'Developer',
AUTHOR_ROLE_OWNER: 'Owner',
AUTHOR_ROLE_ADMIN: 'Admin',
AUTHOR_ROLE_ADMINOWNER: 'Admin & Owner',
}
# Collection author roles.
COLLECTION_ROLE_PUBLISHER = 0
COLLECTION_ROLE_ADMIN = 1
COLLECTION_AUTHOR_CHOICES = {
COLLECTION_ROLE_PUBLISHER: 'Publisher',
COLLECTION_ROLE_ADMIN: 'Admin',
}
# Addon types
ADDON_ANY = -1
ADDON_EXTENSION = 1
ADDON_THEME = 2
ADDON_DICT = 3
ADDON_SEARCH = 4
ADDON_LPAPP = 5
ADDON_LPADDON = 6
ADDON_PLUGIN = 7
ADDON_API = 8 # not actually a type but used to identify extensions + themes
ADDON_PERSONA = 9
# Applications
class FIREFOX:
id = 1
short = 'firefox'
pretty = _('Firefox')
browser = True
class THUNDERBIRD:
id = 18
short = 'thunderbird'
pretty = _('Thunderbird')
browser = True
class SEAMONKEY:
id = 59
short = 'seamonkey'
pretty = _('SeaMonkey')
browser = True
class SUNBIRD:
id = 52
short = 'sunbird'
pretty = _('Sunbird')
class MOBILE:
id = 60
short = 'mobile'
pretty = _('Mobile')
browser = True
_apps = (FIREFOX, THUNDERBIRD, SEAMONKEY, SUNBIRD, MOBILE)
APPS = dict((app.short, app) for app in _apps)
APP_IDS = dict((app.id, app) for app in _apps)
APP_SUPPORTS_PERSONAS = (FIREFOX, THUNDERBIRD)

Просмотреть файл

@ -1,97 +0,0 @@
from django.utils.translation import ugettext as _
# Add-on and File statuses.
STATUS_NULL = 0
STATUS_SANDBOX = 1
STATUS_PENDING = 2
STATUS_NOMINATED = 3
STATUS_PUBLIC = 4
STATUS_DISABLED = 5
STATUS_LISTED = 6
STATUS_BETA = 7
STATUS_CHOICES = {
STATUS_NULL: 'Null',
STATUS_SANDBOX: 'In the sandbox',
STATUS_PENDING: 'Pending approval',
STATUS_NOMINATED: 'Nominated to be public',
STATUS_PUBLIC: 'Public',
STATUS_DISABLED: 'Disabled',
STATUS_LISTED: 'Listed',
STATUS_BETA: 'Beta',
}
# Add-on author roles.
AUTHOR_ROLE_NONE = 0
AUTHOR_ROLE_VIEWER = 1
AUTHOR_ROLE_DEV = 4
AUTHOR_ROLE_OWNER = 5
AUTHOR_ROLE_ADMIN = 6
AUTHOR_ROLE_ADMINOWNER = 7
AUTHOR_CHOICES = {
AUTHOR_ROLE_NONE: 'None',
AUTHOR_ROLE_VIEWER: 'Viewer',
AUTHOR_ROLE_DEV: 'Developer',
AUTHOR_ROLE_OWNER: 'Owner',
AUTHOR_ROLE_ADMIN: 'Admin',
AUTHOR_ROLE_ADMINOWNER: 'Admin & Owner',
}
# Collection author roles.
COLLECTION_ROLE_PUBLISHER = 0
COLLECTION_ROLE_ADMIN = 1
COLLECTION_AUTHOR_CHOICES = {
COLLECTION_ROLE_PUBLISHER: 'Publisher',
COLLECTION_ROLE_ADMIN: 'Admin',
}
# Addon types
ADDON_ANY = -1
ADDON_EXTENSION = 1
ADDON_THEME = 2
ADDON_DICT = 3
ADDON_SEARCH = 4
ADDON_LPAPP = 5
ADDON_LPADDON = 6
ADDON_PLUGIN = 7
ADDON_API = 8 # not actually a type but used to identify extensions + themes
ADDON_PERSONA = 9
# Applications
class FIREFOX:
id = 1
short = 'firefox'
pretty = _('Firefox')
browser = True
class THUNDERBIRD:
id = 18
short = 'thunderbird'
pretty = _('Thunderbird')
browser = True
class SEAMONKEY:
id = 59
short = 'seamonkey'
pretty = _('SeaMonkey')
browser = True
class SUNBIRD:
id = 52
short = 'sunbird'
pretty = _('Sunbird')
class MOBILE:
id = 60
short = 'mobile'
pretty = _('Mobile')
browser = True
_apps = (FIREFOX, THUNDERBIRD, SEAMONKEY, SUNBIRD, MOBILE)
APPS = dict((app.short, app) for app in _apps)
APP_IDS = dict((app.id, app) for app in _apps)
APP_SUPPORTS_PERSONAS = (FIREFOX, THUNDERBIRD)

Просмотреть файл

@ -6,7 +6,7 @@ Note: didn't make sense to use localeurl since we need to capture app as well
from django.http import HttpResponseRedirect
from django.utils import translation
import amo
import amo.models
from . import urlresolvers

Просмотреть файл

@ -2,7 +2,7 @@ from django.conf import settings
from django.core.urlresolvers import reverse as django_reverse
from django.utils.thread_support import currentThread
import amo
import amo.models
# Thread-local storage for URL prefixes. Access with {get,set}_url_prefix.

Просмотреть файл

@ -1,10 +1,10 @@
from django.db import models
import amo
import amo.models
from translations.fields import TranslatedField
class Application(amo.ModelBase):
class Application(amo.models.ModelBase):
guid = models.CharField(max_length=255, default='')
name = TranslatedField()
@ -19,7 +19,7 @@ class Application(amo.ModelBase):
return unicode(self.name)
class AppVersion(amo.ModelBase):
class AppVersion(amo.models.ModelBase):
application = models.ForeignKey(Application)
version = models.CharField(max_length=255, default='')

Просмотреть файл

@ -1,13 +1,13 @@
from django.db import models
import amo
import amo.models
from addons.models import Addon, AddonCategory
from applications.models import Application
from users.models import User
from translations.fields import TranslatedField
class Collection(amo.ModelBase):
class Collection(amo.models.ModelBase):
uuid = models.CharField(max_length=36, blank=True, unique=True)
name = TranslatedField()
nickname = models.CharField(max_length=30, blank=True, unique=True)
@ -31,7 +31,7 @@ class Collection(amo.ModelBase):
downvotes = models.PositiveIntegerField(default=0)
rating = models.FloatField(default=0)
class Meta(amo.ModelBase.Meta):
class Meta(amo.models.ModelBase.Meta):
db_table = 'collections'
@ -44,40 +44,40 @@ class CollectionAddonRecommendation(models.Model):
db_table = 'collection_addon_recommendations'
class CollectionCategory(amo.ModelBase):
class CollectionCategory(amo.models.ModelBase):
collection = models.ForeignKey(Collection)
category = models.ForeignKey(AddonCategory)
class Meta(amo.ModelBase.Meta):
class Meta(amo.models.ModelBase.Meta):
db_table = 'collection_categories'
class CollectionFeature(amo.ModelBase):
class CollectionFeature(amo.models.ModelBase):
title = TranslatedField()
tagline = TranslatedField()
class Meta(amo.ModelBase.Meta):
class Meta(amo.models.ModelBase.Meta):
db_table = 'collection_features'
class CollectionPromo(amo.ModelBase):
class CollectionPromo(amo.models.ModelBase):
collection = models.ForeignKey(Collection, null=True)
locale = models.CharField(max_length=10, null=True)
collection_feature = models.ForeignKey(CollectionFeature)
class Meta(amo.ModelBase.Meta):
class Meta(amo.models.ModelBase.Meta):
db_table = 'collection_promos'
unique_together = ('collection', 'locale', 'collection_feature')
class CollectionRecommendation(amo.ModelBase):
class CollectionRecommendation(amo.models.ModelBase):
collection = models.ForeignKey(Collection, null=True,
related_name="collection_one")
other_collection = models.ForeignKey(Collection, null=True,
related_name="collection_two")
score = models.FloatField(blank=True)
class Meta(amo.ModelBase.Meta):
class Meta(amo.models.ModelBase.Meta):
db_table = 'collection_recommendations'
@ -99,11 +99,11 @@ class CollectionSummary(models.Model):
db_table = 'collection_search_summary'
class CollectionSubscription(amo.ModelBase):
class CollectionSubscription(amo.models.ModelBase):
collection = models.ForeignKey(Collection)
user = models.ForeignKey(User)
class Meta(amo.ModelBase.Meta):
class Meta(amo.models.ModelBase.Meta):
db_table = 'collection_subscriptions'

Просмотреть файл

@ -1,36 +1,36 @@
from django.db import models
import amo
import amo.models
class BlocklistApp(amo.ModelBase):
class BlocklistApp(amo.models.ModelBase):
blitem = models.ForeignKey('BlocklistItem')
guid = models.CharField(max_length=255, blank=True, db_index=True)
min = models.CharField(max_length=255, blank=True)
max = models.CharField(max_length=255, blank=True)
class Meta(amo.ModelBase.Meta):
class Meta(amo.models.ModelBase.Meta):
db_table = 'blapps'
def __unicode__(self):
return '%s: %s - %s' % (self.guid, self.min, self.max)
class BlocklistItem(amo.ModelBase):
class BlocklistItem(amo.models.ModelBase):
guid = models.CharField(max_length=255, blank=True)
min = models.CharField(max_length=255, blank=True)
max = models.CharField(max_length=255, blank=True)
os = models.CharField(max_length=255, blank=True)
severity = models.SmallIntegerField(null=True)
class Meta(amo.ModelBase.Meta):
class Meta(amo.models.ModelBase.Meta):
db_table = 'blitems'
def __unicode__(self):
return '%s: %s - %s' % (self.guid, self.min, self.max)
class BlocklistPlugin(amo.ModelBase):
class BlocklistPlugin(amo.models.ModelBase):
name = models.CharField(max_length=255, blank=True)
guid = models.CharField(max_length=255, blank=True)
min = models.CharField(max_length=255, blank=True)
@ -41,7 +41,7 @@ class BlocklistPlugin(amo.ModelBase):
filename = models.CharField(max_length=255, blank=True)
severity = models.SmallIntegerField(null=True)
class Meta(amo.ModelBase.Meta):
class Meta(amo.models.ModelBase.Meta):
db_table = 'blplugins'
def __unicode__(self):

Просмотреть файл

@ -2,7 +2,7 @@ from datetime import datetime
from django.db import models
import amo
import amo.models
from translations.fields import TranslatedField
@ -57,7 +57,7 @@ LOG = {
}
class HubPromo(amo.ModelBase):
class HubPromo(amo.models.ModelBase):
VISIBILITY_CHOICES = (
(0, 'Nobody'),
(1, 'Visitors'),
@ -76,7 +76,7 @@ class HubPromo(amo.ModelBase):
return unicode(self.heading)
class HubEvent(amo.ModelBase):
class HubEvent(amo.models.ModelBase):
name = models.CharField(max_length=255, default='')
url = models.URLField(max_length=255, default='')
location = models.CharField(max_length=255, default='')
@ -89,7 +89,7 @@ class HubEvent(amo.ModelBase):
return self.name
class AddonLog(amo.ModelBase):
class AddonLog(amo.models.ModelBase):
TYPES = [(value, key) for key, value in LOG.items()]
addon = models.ForeignKey('addons.Addon', null=True, blank=True)

Просмотреть файл

@ -1,10 +1,8 @@
from django.db import models
import amo
import amo.models
from translations.fields import TranslatedField
class CannedResponse(amo.ModelBase):
class CannedResponse(amo.models.ModelBase):
name = TranslatedField()
response = TranslatedField()

Просмотреть файл

@ -1,11 +1,11 @@
from django.db import models
import amo
import amo.models
from versions.models import Version
from translations.fields import TranslatedField
class File(amo.ModelBase):
class File(amo.models.ModelBase):
STATUS_CHOICES = amo.STATUS_CHOICES.items()
version = models.ForeignKey(Version)
@ -18,11 +18,11 @@ class File(amo.ModelBase):
default=0)
datestatuschanged = models.DateTimeField(null=True)
class Meta(amo.ModelBase.Meta):
class Meta(amo.models.ModelBase.Meta):
db_table = 'files'
class Approval(amo.ModelBase):
class Approval(amo.models.ModelBase):
reviewtype = models.CharField(max_length=10, default='pending')
action = models.IntegerField(default=0)
@ -35,21 +35,21 @@ class Approval(amo.ModelBase):
file = models.ForeignKey(File)
reply_to = models.ForeignKey('self', null=True, db_column='reply_to')
class Meta(amo.ModelBase.Meta):
class Meta(amo.models.ModelBase.Meta):
db_table = 'approvals'
class Platform(amo.ModelBase):
class Platform(amo.models.ModelBase):
name = TranslatedField()
shortname = TranslatedField()
# icondata => mysql blob
icontype = models.CharField(max_length=25, default='')
class Meta(amo.ModelBase.Meta):
class Meta(amo.models.ModelBase.Meta):
db_table = 'platforms'
class TestCase(amo.ModelBase):
class TestCase(amo.models.ModelBase):
test_group = models.ForeignKey('TestGroup')
platform = models.ForeignKey('Platform')
help_link = models.CharField(max_length=255, blank=True,
@ -57,11 +57,11 @@ class TestCase(amo.ModelBase):
function = models.CharField(max_length=255,
help_text='Name of the function to call')
class Meta(amo.ModelBase.Meta):
class Meta(amo.models.ModelBase.Meta):
db_table = 'test_cases'
class TestGroup(amo.ModelBase):
class TestGroup(amo.models.ModelBase):
category = models.CharField(max_length=255, blank=True)
tier = models.PositiveSmallIntegerField(default=2,
help_text="Run in order. Tier 1 runs before Tier 2, etc.")
@ -70,11 +70,11 @@ class TestGroup(amo.ModelBase):
types = models.PositiveIntegerField(default=0,
help_text="Pretty sure it involves binary math... KHAN!!!")
class Meta(amo.ModelBase.Meta):
class Meta(amo.models.ModelBase.Meta):
db_table = 'test_groups'
class TestResult(amo.ModelBase):
class TestResult(amo.models.ModelBase):
file = models.ForeignKey(File)
test_case = models.ForeignKey(TestCase)
result = models.PositiveSmallIntegerField(default=0)
@ -82,11 +82,11 @@ class TestResult(amo.ModelBase):
filename = models.CharField(max_length=255, blank=True)
message = models.TextField(blank=True)
class Meta(amo.ModelBase.Meta):
class Meta(amo.models.ModelBase.Meta):
db_table = 'test_results'
class TestResultCache(amo.ModelBase):
class TestResultCache(amo.models.ModelBase):
"""When a file is checked the results are stored here in JSON. This is
temporary storage and removed with the garbage cleanup cron."""
date = models.DateTimeField()
@ -94,5 +94,5 @@ class TestResultCache(amo.ModelBase):
test_case = models.ForeignKey(TestCase)
message = models.TextField(blank=True)
class Meta(amo.ModelBase.Meta):
class Meta(amo.models.ModelBase.Meta):
db_table = 'test_results_cache'

Просмотреть файл

@ -2,12 +2,12 @@ import itertools
from django.db import models
import amo
import amo.models
from translations.fields import TranslatedField
from translations.models import Translation
class Review(amo.ModelBase):
class Review(amo.models.ModelBase):
version = models.ForeignKey('versions.Version')
user = models.ForeignKey('users.UserProfile')

Просмотреть файл

@ -3,7 +3,7 @@ import re
from django.conf import settings
from django.utils import translation
import amo
import amo.models
from .sphinxapi import SphinxClient
import sphinxapi as sphinx
from .utils import convert_version, crc32

Просмотреть файл

@ -1,9 +1,9 @@
from django.db import models
import amo
import amo.models
class Tag(amo.ModelBase):
class Tag(amo.models.ModelBase):
tag_text = models.CharField(max_length=128)
blacklisted = models.BooleanField(default=False)
addons = models.ManyToManyField('addons.Addon', through='AddonTag')
@ -16,7 +16,7 @@ class Tag(amo.ModelBase):
return self.tagstat.num_addons
class TagStat(amo.ModelBase):
class TagStat(amo.models.ModelBase):
tag = models.OneToOneField(Tag, primary_key=True)
num_addons = models.IntegerField()
@ -24,7 +24,7 @@ class TagStat(amo.ModelBase):
db_table = 'tag_stat'
class AddonTag(amo.ModelBase):
class AddonTag(amo.models.ModelBase):
addon = models.ForeignKey('addons.Addon')
tag = models.ForeignKey(Tag)
user = models.ForeignKey('users.UserProfile')

Просмотреть файл

@ -16,8 +16,8 @@ class Translation(caching.CachingMixin, models.Model):
locale = models.CharField(max_length=10)
localized_string = models.TextField(null=True)
# These are normally from amo.ModelBase, but we don't want to have weird
# circular dependencies between ModelBase and Translations.
# These are normally from amo.models.ModelBase, but we don't want to have
# weird circular dependencies between ModelBase and Translations.
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)

Просмотреть файл

@ -1,14 +1,14 @@
from django.db import models
import amo
import amo.models
from translations.fields import TranslatedField
class TranslatedModel(amo.ModelBase):
class TranslatedModel(amo.models.ModelBase):
name = TranslatedField()
description = TranslatedField()
class UntranslatedModel(amo.ModelBase):
class UntranslatedModel(amo.models.ModelBase):
"""Make sure nothing is broken when a model doesn't have translations."""
number = models.IntegerField()

Просмотреть файл

@ -6,7 +6,7 @@ import string
from django.db import models
from django.contrib.auth.models import User as DjangoUser
import amo
import amo.models
from translations.fields import TranslatedField
@ -24,7 +24,7 @@ def create_password(algorithm, raw_password):
return '$'.join([algorithm, salt, hsh])
class UserProfile(amo.ModelBase):
class UserProfile(amo.models.ModelBase):
nickname = models.CharField(max_length=255, unique=True, default='')
firstname = models.CharField(max_length=255, default='')

Просмотреть файл

@ -1,6 +1,6 @@
from django.db import models
import amo
import amo.models
from addons.models import Addon
from users.models import UserProfile
@ -9,26 +9,26 @@ from applications.models import Application, AppVersion
from translations.fields import TranslatedField
class Version(amo.ModelBase):
class Version(amo.models.ModelBase):
addon = models.ForeignKey(Addon)
license = models.ForeignKey('License', null=True)
releasenotes = TranslatedField()
approvalnotes = models.TextField()
version = models.CharField(max_length=255, default=0)
class Meta(amo.ModelBase.Meta):
class Meta(amo.models.ModelBase.Meta):
db_table = 'versions'
class License(amo.ModelBase):
class License(amo.models.ModelBase):
rating = models.SmallIntegerField(default=-1)
text = TranslatedField()
class Meta(amo.ModelBase.Meta):
class Meta(amo.models.ModelBase.Meta):
db_table = 'licenses'
class VersionComment(amo.ModelBase):
class VersionComment(amo.models.ModelBase):
"""Editor comments for version discussion threads."""
version = models.ForeignKey(Version)
user = models.ForeignKey(UserProfile)
@ -36,18 +36,18 @@ class VersionComment(amo.ModelBase):
subject = models.CharField(max_length=1000)
comment = models.TextField()
class Meta(amo.ModelBase.Meta):
class Meta(amo.models.ModelBase.Meta):
db_table = 'versioncomments'
class VersionSummary(amo.ModelBase):
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.ModelBase.Meta):
class Meta(amo.models.ModelBase.Meta):
db_table = 'versions_summary'

Просмотреть файл

@ -13,14 +13,14 @@ of translation rows.
A minimal Addon model looks like this::
import amo
import amo.models
from translations.fields import TranslatedField
class Addon(amo.ModelBase):
class Addon(amo.models.ModelBase):
name = TranslatedField()
description = TranslatedField()
:class:`amo.ModelBase` inherits from
:class:`amo.models.ModelBase` inherits from
:class:`translations.fields.TranslatedFieldMixin`, which fetches all of a
model's translations during initialization. It first tries to fetch strings for
the current locale, and then looks for any missing strings in the default