-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmodels.py
236 lines (188 loc) · 7.21 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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
import uuid
from django.db import models
from multiselectfield import MultiSelectField
from ordered_model.models import OrderedModel
from versionfield import VersionField
from conreq.utils.models import UUIDFilePath
class DevelopmentStage(models.TextChoices):
PLANNING = "1 - Planning", "Planning"
PREALPHA = "2 - Pre-Alpha", "Pre-Alpha"
ALPHA = "3 - Alpha", "Alpha"
BETA = "4 - Beta", "Beta"
STABLE = "5 - Production/Stable", "Stable"
MATURE = "6 - Mature", "Mature"
INACTIVE = "7 - Inactive", "Inactive"
class AsyncCompatibility(models.TextChoices):
NONE = "NONE", "No Async"
SEMI = "SEMI", "Semi Async"
FULL = "FULL", "Fully Async"
class SysPlatform(models.TextChoices):
ANY = "ANY", "Any"
AIX = "AIX", "Aix"
LINUX = "LINUX", "Linux"
WINDOWS = "WINDOWS", "Windows"
CYGWIN = "CYGWIN", "Cygwin"
MACOS = "MACOS", "Darwin"
class DescriptionType(models.TextChoices):
TXT = "text/plain", "Plain Text (.txt)"
RST = "text/x-rst", "reStructuredText (.rst)"
MD = "text/markdown", "Markdown (.md)"
class Category(models.Model):
def __str__(self):
return str(self.name)
class Meta:
verbose_name_plural = "Categories"
uuid = models.UUIDField(
primary_key=True, default=uuid.uuid4, editable=False, unique=True
)
# Basic Info
name = models.CharField(max_length=50, unique=True)
class Subcategory(models.Model):
def __str__(self):
return str(self.name)
class Meta:
verbose_name = "Subcategory"
verbose_name_plural = "Subcategories"
unique_together = ["name", "category"]
uuid = models.UUIDField(
primary_key=True, default=uuid.uuid4, editable=False, unique=True
)
# Basic Info
name = models.CharField(max_length=50)
category = models.ForeignKey(Category, on_delete=models.CASCADE)
class PackageVersion(models.Model):
def __str__(self):
return str(self.version)
version = VersionField(unique=True)
class AppPackage(models.Model):
def __str__(self):
return str(self.name)
uuid = models.UUIDField(
primary_key=True, default=uuid.uuid4, editable=False, unique=True
)
# General Info
name = models.CharField(max_length=100)
pkg_name = models.CharField(
max_length=100,
help_text="Must be snake_case. Used for PyPI package installation, or folder naming on Git installations.",
unique=True,
)
logo = models.ImageField(
upload_to=UUIDFilePath("serve/app_store/logos/"),
blank=True,
)
background = models.ImageField(
upload_to=UUIDFilePath("serve/app_store/backgrounds/"),
blank=True,
)
special = models.BooleanField(
default=False,
help_text="If enabled, this app's cards will be visually highlighted. Reserved for donations.",
)
short_description = models.CharField(max_length=255, blank=True)
long_description = models.TextField(blank=True)
long_description_type = models.CharField(
max_length=20,
choices=DescriptionType.choices,
default=DescriptionType.TXT,
)
subcategories = models.ManyToManyField(Subcategory)
development_stage = models.CharField(
max_length=21,
choices=DevelopmentStage.choices,
default=DevelopmentStage.PLANNING,
blank=True,
)
min_version = VersionField(
default="0.0.0",
help_text="Minimum PyPI version or Git tag for this package that is compatible with Conreq.",
)
banner_message = models.TextField(
blank=True,
help_text="Optional text message banner shown on the app info page.",
max_length=1000,
)
sync_with_pypi = models.BooleanField(
default=False,
help_text="Will automatically sync relevant information with the latest PyPI version.",
verbose_name="Sync with PyPI",
)
created_at = models.DateTimeField(auto_now_add=True)
modified_at = models.DateTimeField(auto_now=True)
versions = models.ManyToManyField(PackageVersion, blank=True)
# Ownership Info
author = models.CharField(max_length=50)
author_email = models.EmailField(blank=True)
pypi_url = models.URLField(blank=True)
repository_url = models.URLField(
blank=True,
help_text="Must be a Git repository if not using PyPI.",
)
homepage_url = models.URLField(blank=True)
support_url = models.URLField(blank=True)
donation_url = models.URLField(blank=True)
license_type = models.CharField(max_length=100, default="GPLv3")
# Environment
sys_platforms = MultiSelectField(
choices=SysPlatform.choices,
max_length=40,
verbose_name="Supported Platforms",
default=SysPlatform.ANY,
)
# Compatibility
touch_compatible = models.BooleanField()
mobile_compatible = models.BooleanField()
conreq_min_version = VersionField(default="0.0.0")
conreq_tested_version = VersionField(blank=True, null=True)
conreq_max_version = VersionField(blank=True, null=True)
asynchronous = models.CharField(
max_length=20,
choices=AsyncCompatibility.choices,
default=AsyncCompatibility.NONE,
)
# App Dependencies
required_apps = models.ManyToManyField("self", blank=True)
optional_apps = models.ManyToManyField("self", blank=True)
incompatible_apps = models.ManyToManyField("self", blank=True)
incompatible_subcategories = models.ManyToManyField(
Subcategory, related_name="incompatible_subcategories", blank=True
)
class SpotlightCategory(OrderedModel):
def __str__(self):
return str(self.name)
class Meta:
verbose_name = "Spotlight category"
verbose_name_plural = "Spotlight categories"
uuid = models.UUIDField(
primary_key=True, default=uuid.uuid4, editable=False, unique=True
)
name = models.CharField(max_length=50, unique=True)
description = models.TextField(blank=True)
apps = models.ManyToManyField(AppPackage, through="SpotlightApp")
class SpotlightApp(OrderedModel):
"""This model is used to create a many-to-many relationship between SpotlightCategory and AppPackage.
This allows for the ordering of apps within a spotlight category."""
category = models.ForeignKey(SpotlightCategory, on_delete=models.CASCADE)
app = models.ForeignKey(AppPackage, on_delete=models.CASCADE)
order_with_respect_to = "category"
class Meta:
ordering = ("category", "order")
class Screenshot(models.Model):
def __str__(self):
return str(self.title)
uuid = models.UUIDField(
primary_key=True, default=uuid.uuid4, editable=False, unique=True
)
title = models.CharField(max_length=100)
description = models.CharField(max_length=255, blank=True)
image = models.ImageField(upload_to=UUIDFilePath("serve/app_store/screenshot/"))
app_package = models.ForeignKey(AppPackage, on_delete=models.CASCADE)
class NoticeMessage(models.Model):
def __str__(self):
return str(self.title)
uuid = models.UUIDField(
primary_key=True, default=uuid.uuid4, editable=False, unique=True
)
title = models.CharField(max_length=100)
description = models.TextField(blank=True)
app_package = models.ForeignKey(AppPackage, on_delete=models.CASCADE)