-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathdevdata.py
More file actions
300 lines (237 loc) · 8.34 KB
/
devdata.py
File metadata and controls
300 lines (237 loc) · 8.34 KB
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
from wagtail import blocks
from wagtail.rich_text import RichText
import factory
import wagtail_factories
from common.blocks import (
Heading1,
Heading2,
Heading3,
StyledTextBlock,
)
from common.choices import CATEGORY_SYMBOL_CHOICES
from common.models import (
CategoryIncidentFilter,
CategoryPage,
CommonTag,
CustomImage,
OrganizationIndexPage,
OrganizationPage,
PersonPage,
SimplePage,
SiteSettings,
TaxonomyCategoryPage,
TaxonomySettings,
)
from common.tests.utils import StreamfieldProvider, make_html_string
factory.Faker.add_provider(StreamfieldProvider)
class DevelopmentSiteFactory(wagtail_factories.SiteFactory):
class Meta:
django_get_or_create = ("is_default_site",)
site_name = "Press Freedom Tracker (Dev)"
port = 8000
is_default_site = True
root_page = None
class SiteSettingsFactory(factory.django.DjangoModelFactory):
class Meta:
model = SiteSettings
django_get_or_create = ("site",)
site = factory.SubFactory(DevelopmentSiteFactory)
incident_sidebar_note = factory.Faker(
"streamfield",
fields=[
"heading",
"rich_text_line",
],
)
homepage_only = True
banner_content = None
class CategoryIncidentFilterFactory(factory.django.DjangoModelFactory):
class Meta:
model = CategoryIncidentFilter
sort_order = factory.Sequence(lambda n: n)
class TaxonomySettingsFactory(factory.django.DjangoModelFactory):
class Meta:
model = TaxonomySettings
django_get_or_create = ("site",)
site = factory.SubFactory(DevelopmentSiteFactory)
class TaxonomyCategoryPageFactory(factory.django.DjangoModelFactory):
taxonomy_setting = factory.SubFactory(TaxonomySettingsFactory)
sort_order = factory.Sequence(lambda n: n)
class Meta:
model = TaxonomyCategoryPage
class CategoryPageFactory(wagtail_factories.PageFactory):
class Meta:
model = CategoryPage
exclude = ("methodology_text",)
class Params:
arrest = factory.Trait(
title="Arrest/Criminal Charge",
plural_name="Arrests and Criminal Charges",
slug="arrest-criminal-charge",
page_symbol="arrest",
google_sheets_name="Arrest",
)
border_stop = factory.Trait(
title="Border Stop",
plural_name="Border Stops",
slug="border-stop",
page_symbol="border_stop",
google_sheets_name="Border Stop",
)
denial_of_access = factory.Trait(
title="Denial of Access",
plural_name="Denials of Access",
slug="denial-access",
page_symbol="denial_of_access",
google_sheets_name="Denial of Access",
)
equipment_search = factory.Trait(
title="Equipment Search or Seizure",
plural_name="Equipment Searches, Seizures and Damage",
slug="equipment-search-seizure-or-damage",
page_symbol="equipment_search",
google_sheets_name="Equipment Search/Seizure",
)
assault = factory.Trait(
title="Assault",
plural_name="Assaults",
slug="assault",
page_symbol="assault",
google_sheets_name="Assault",
)
leak_case = factory.Trait(
title="Leak Case",
plural_name="Leak Cases",
slug="leak-case",
page_symbol="leak_case",
google_sheets_name="Leak Case",
)
subpoena = factory.Trait(
title="Subpoena/Legal Order",
plural_name="Subpoenas and Legal Orders",
slug="subpoena",
page_symbol="subpoena",
google_sheets_name="Subpoena/Legal Order",
)
equipment_damage = factory.Trait(
title="Equipment Damage",
plural_name="Equipment Damages",
slug="equipment-damage",
page_symbol="equipment_damage",
google_sheets_name="Equipment Damage",
)
other_incident = factory.Trait(
title="Other Incident",
plural_name="Other Incidents",
slug="other-incident",
page_symbol="other_incident",
google_sheets_name="Other",
)
chilling_statement = factory.Trait(
title="Chilling Statement",
plural_name="Chilling Statements",
slug="chilling-statement",
page_symbol="chilling_statement",
google_sheets_name="Chilling Statement",
)
prior_restraint = factory.Trait(
title="Prior Restraint",
plural_name="Prior Restraints",
slug="prior-restraint",
page_symbol="prior_restraint",
google_sheets_name="Prior Restraint",
)
methodology_text = factory.Faker("paragraph", nb_sentences=5)
title = factory.Sequence(lambda n: "Category {n}".format(n=n))
description = factory.LazyAttribute(lambda _: make_html_string())
methodology = factory.LazyAttribute(lambda o: RichText(o.methodology_text))
taxonomy = factory.RelatedFactory(TaxonomyCategoryPageFactory, "category")
page_symbol = factory.Iterator(CATEGORY_SYMBOL_CHOICES, getter=lambda c: c[0])
@factory.post_generation
def incident_filters(self, create, extracted, **kwargs):
if not create:
return
if extracted:
CategoryIncidentFilter.objects.bulk_create(
[
CategoryIncidentFilter(
category=self,
incident_filter=incident_filter,
sort_order=i,
)
for i, incident_filter in enumerate(extracted)
]
)
class CustomImageFactory(wagtail_factories.ImageFactory):
attribution = factory.Faker("name")
class Meta:
model = CustomImage
class PersonPageFactory(wagtail_factories.PageFactory):
class Meta:
model = PersonPage
exclude = ("bio_text",)
bio_text = factory.Faker("paragraph")
title = factory.Faker("name")
bio = factory.LazyAttribute(lambda o: RichText(o.bio_text))
website = factory.Faker("uri")
photo = None
class OrganizationIndexPageFactory(wagtail_factories.PageFactory):
class Meta:
model = OrganizationIndexPage
title = "All Organizations"
class OrganizationPageFactory(wagtail_factories.PageFactory):
class Meta:
model = OrganizationPage
title = factory.Faker("company")
slug = factory.Sequence(lambda n: "organization-{n}".format(n=n))
website = factory.Faker("uri")
description = factory.Faker("catch_phrase")
class SimplePageFactory(wagtail_factories.PageFactory):
class Meta:
model = SimplePage
body = factory.Faker(
"streamfield",
fields=[
"styled_text_paragraphs",
"styled_text",
"info_table_pages",
"info_table_emails",
"info_table_external_links",
"info_table_plain_text",
"raw_html",
],
)
class RichTextBlockFactory(wagtail_factories.blocks.BlockFactory):
class Meta:
model = blocks.RichTextBlock
class RawHTMLBlockFactory(wagtail_factories.blocks.BlockFactory):
class Meta:
model = blocks.RawHTMLBlock
class ChoiceBlockFactory(wagtail_factories.blocks.BlockFactory):
class Meta:
model = blocks.ChoiceBlock
class Heading1Factory(wagtail_factories.StructBlockFactory):
content = wagtail_factories.CharBlockFactory
class Meta:
model = Heading1
class Heading2Factory(wagtail_factories.StructBlockFactory):
content = wagtail_factories.CharBlockFactory
class Meta:
model = Heading2
class Heading3Factory(wagtail_factories.StructBlockFactory):
content = wagtail_factories.CharBlockFactory
class Meta:
model = Heading3
class StyledTextBlockFactory(wagtail_factories.StructBlockFactory):
class Meta:
model = StyledTextBlock
text = RichTextBlockFactory
background_color = ChoiceBlockFactory
text_align = ChoiceBlockFactory
font_size = ChoiceBlockFactory
font_family = ChoiceBlockFactory
class CommonTagFactory(factory.django.DjangoModelFactory):
class Meta:
model = CommonTag
django_get_or_create = ("title",)
title = factory.Faker("word")