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
|
from django.db import models
from django.urls import reverse
CURRICULUM_CHOICES = [
("No curriculum", "No curriculum"),
("English", "English"),
("Scottish", "Scottish"),
]
AGE_RANGE_CHOICES = [
("Preschool (3-4yrs)", "Preschool (3-4yrs)"),
("Nursery (2-5yrs)", "Nursery (2-5yrs)"),
("Reception (4-5yrs)", "Reception (4-5yrs)"),
("Year 1 (5-6yrs)", "Year 1 (5-6yrs)"),
("Year 2 (6-7yrs)", "Year 2 (6-7yrs)"),
("Early Years (0-5yrs)", "Early Years (0-5yrs)"),
("Keystage 1 (5-7yrs)", "Keystage 1 (5-7yrs)"),
("Keystage 2 (7-11yrs)", "Keystage 2 (7-11yrs)"),
("Age not applicable", "Age not applicable"),
]
DESC_HELP_TEXT = """
<strong>Markdown acceptable here!</strong>This is your opportunity to clearly explain what
your resource is all about! It’s worth remembering that you are using the space to
communicate to two different audiences. Firstly, think about what fellow teachers
would like to know, such as exactly what the resource contains and how it could be used in
the classroom. Secondly, the words you include on this page are also talking to internal and
external search engines. External search engines, like Google, show the first 155 characters
of the resource description, so make sure you take advantage
of these characters by using lots of relevant keywords as part of an enticing pitch.
"""
# Create your models here.
class Resource(models.Model):
name = models.CharField(max_length=255, null=False)
thumbnail_filenames = models.JSONField(
null=False,
verbose_name="Thumbnail filenames",
default=list,
)
resource_type = models.ForeignKey("ResourceType", on_delete=models.CASCADE)
main_resource_category = models.ForeignKey(
"ResourceCategory",
on_delete=models.CASCADE,
null=False,
related_name="main_resource_category",
)
subcategories = models.ManyToManyField(
"ResourceSubcategory",
blank=True,
related_name="additional_resource_category",
)
description = models.TextField(
max_length=5000,
null=False,
blank=False,
help_text=DESC_HELP_TEXT,
)
card_description = models.TextField(
max_length=1000,
blank=True,
default="",
help_text=("If you enter text here, it will be used in the 'card' "
"description box on the home page. Max 1000 characters."),
)
age_range = models.CharField(
max_length=20,
null=False,
default="5-7",
blank=False,
choices=AGE_RANGE_CHOICES,
)
curriculum = models.CharField(
max_length=20,
default="English",
blank=True,
null=True,
choices=[
("No curriculum", "No curriculum"),
("English", "English"),
("Scottish", "Scottish"),
],
)
feature_slot = models.IntegerField(
choices=((1, 1), (2, 2), (3, 3)), unique=True, null=True, blank=True, default=0,
)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
def __str__(self):
return self.name
def get_pdf_file_names(self):
return [p.file_name for p in self.pdf_resources.all()]
def get_pdf_snapshot_file_names(self):
rs = self.pdf_resources.all()
sh = [sh for sh in rs.values_list("pdf_page_snapshots__file_name", flat=True)]
return [s for s in sh if s]
def get_absolute_url(self):
return reverse("resources:resource_detail", kwargs={"resource_id": self.pk})
class ResourceType(models.Model):
name = models.CharField(max_length=255, null=False)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
verbose_name_plural = "Resource Types"
def __str__(self):
return self.name
class ResourceSubcategory(models.Model):
name = models.CharField(max_length=255, null=False)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
verbose_name_plural = "Resource Subcategories"
def __str__(self):
return self.name
class ResourceCategory(models.Model):
name = models.CharField(max_length=255, null=False)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
colour_css_class = models.CharField(max_length=56, blank=True, null=True)
badge_foreground_colour = models.CharField(max_length=56, blank=True, null=True)
class Meta:
verbose_name_plural = "Resource Categories"
def __str__(self):
return self.name
class PDFResource(models.Model):
resource = models.ForeignKey(
"Resource",
on_delete=models.CASCADE,
null=False,
related_name="pdf_resources",
)
file_name = models.CharField(max_length=255, null=False)
file_size = models.IntegerField(null=False)
class Meta:
verbose_name_plural = "PDF Resources"
unique_together = ("resource", "file_name")
def __str__(self):
return self.resource.name
def snapshot_file_names(self):
return [f.file_name for f in self.pdf_page_snapshots.all()]
class PDFPageSnapshot(models.Model):
name = models.CharField(max_length=255, null=False)
file_name = models.CharField(max_length=255, null=False)
pdf_file = models.ForeignKey(
"PDFResource",
on_delete=models.CASCADE,
null=False,
related_name="pdf_page_snapshots",
)
class Meta:
verbose_name_plural = "PDF Page Snapshots"
def __str__(self):
return self.name
|