Coverage for cookbook/views/lists.py: 60%
68 statements
« prev ^ index » next coverage.py v7.4.0, created at 2023-12-29 00:47 +0100
« prev ^ index » next coverage.py v7.4.0, created at 2023-12-29 00:47 +0100
1from datetime import datetime
3from django.db.models import Sum
4from django.shortcuts import render
5from django.utils.translation import gettext as _
6from django_tables2 import RequestConfig
8from cookbook.helper.permission_helper import group_required
9from cookbook.models import InviteLink, RecipeImport, Storage, SyncLog, UserFile
10from cookbook.tables import ImportLogTable, InviteLinkTable, RecipeImportTable, StorageTable
13@group_required('admin')
14def sync_log(request):
15 table = ImportLogTable(
16 SyncLog.objects.filter(sync__space=request.space).all().order_by('-created_at')
17 )
18 RequestConfig(request, paginate={'per_page': 25}).configure(table)
20 return render(
21 request,
22 'generic/list_template.html',
23 {'title': _("Import Log"), 'table': table}
24 )
27@group_required('user')
28def recipe_import(request):
29 table = RecipeImportTable(RecipeImport.objects.filter(space=request.space).all())
31 RequestConfig(request, paginate={'per_page': 25}).configure(table)
33 return render(
34 request,
35 'generic/list_template.html',
36 {'title': _("Discovery"), 'table': table, 'import_btn': True}
37 )
40@group_required('user')
41def shopping_list(request):
42 return render(
43 request,
44 'shoppinglist_template.html',
45 {
46 "title": _("Shopping List"),
48 }
49 )
52@group_required('admin')
53def storage(request):
54 table = StorageTable(Storage.objects.filter(space=request.space).all())
55 RequestConfig(request, paginate={'per_page': 25}).configure(table)
57 return render(
58 request,
59 'generic/list_template.html',
60 {
61 'title': _("Storage Backend"),
62 'table': table,
63 'create_url': 'new_storage'
64 }
65 )
68@group_required('admin')
69def invite_link(request):
70 table = InviteLinkTable(
71 InviteLink.objects.filter(valid_until__gte=datetime.today(), used_by=None, space=request.space).all())
72 RequestConfig(request, paginate={'per_page': 25}).configure(table)
74 return render(request, 'generic/list_template.html', {
75 'title': _("Invite Links"),
76 'table': table,
77 'create_url': 'new_invite_link'
78 })
81@group_required('user')
82def keyword(request):
83 return render(
84 request,
85 'generic/model_template.html',
86 {
87 "title": _("Keywords"),
88 "config": {
89 'model': "KEYWORD",
90 'recipe_param': 'keywords'
91 }
92 }
93 )
96@group_required('user')
97def food(request):
98 # recipe-param is the name of the parameters used when filtering recipes by this attribute
99 # model-name is the models.js name of the model, probably ALL-CAPS
100 return render(
101 request,
102 'generic/model_template.html',
103 {
104 "title": _("Foods"),
105 "config": {
106 'model': "FOOD", # *REQUIRED* name of the model in models.js
107 'recipe_param': 'foods' # *OPTIONAL* name of the listRecipes parameter if filtering on this attribute
108 }
109 }
110 )
113@group_required('user')
114def unit(request):
115 # recipe-param is the name of the parameters used when filtering recipes by this attribute
116 # model-name is the models.js name of the model, probably ALL-CAPS
117 return render(
118 request,
119 'generic/model_template.html',
120 {
121 "title": _("Units"),
122 "config": {
123 'model': "UNIT", # *REQUIRED* name of the model in models.js
124 'recipe_param': 'units', # *OPTIONAL* name of the listRecipes parameter if filtering on this attribute
125 }
126 }
127 )
130@group_required('user')
131def supermarket(request):
132 # recipe-param is the name of the parameters used when filtering recipes by this attribute
133 # model-name is the models.js name of the model, probably ALL-CAPS
134 return render(
135 request,
136 'generic/model_template.html',
137 {
138 "title": _("Supermarkets"),
139 "config": {
140 'model': "SUPERMARKET", # *REQUIRED* name of the model in models.js
141 }
142 }
143 )
146@group_required('user')
147def supermarket_category(request):
148 # recipe-param is the name of the parameters used when filtering recipes by this attribute
149 # model-name is the models.js name of the model, probably ALL-CAPS
150 return render(
151 request,
152 'generic/model_template.html',
153 {
154 "title": _("Shopping Categories"),
155 "config": {
156 'model': "SHOPPING_CATEGORY", # *REQUIRED* name of the model in models.js
157 }
158 }
159 )
162@group_required('user')
163def automation(request):
164 # recipe-param is the name of the parameters used when filtering recipes by this attribute
165 # model-name is the models.js name of the model, probably ALL-CAPS
166 return render(
167 request,
168 'generic/model_template.html',
169 {
170 "title": _("Automations"),
171 "config": {
172 'model': "AUTOMATION", # *REQUIRED* name of the model in models.js
173 }
174 }
175 )
178@group_required('user')
179def custom_filter(request):
180 # recipe-param is the name of the parameters used when filtering recipes by this attribute
181 # model-name is the models.js name of the model, probably ALL-CAPS
182 return render(
183 request,
184 'generic/model_template.html',
185 {
186 "title": _("Custom Filters"),
187 "config": {
188 'model': "CUSTOM_FILTER", # *REQUIRED* name of the model in models.js
189 }
190 }
191 )
194@group_required('user')
195def user_file(request):
196 try:
197 current_file_size_mb = UserFile.objects.filter(space=request.space).aggregate(Sum('file_size_kb'))[
198 'file_size_kb__sum'] / 1000
199 except TypeError:
200 current_file_size_mb = 0
202 return render(
203 request,
204 'generic/model_template.html',
205 {
206 "title": _("Files"),
207 "config": {
208 'model': "USERFILE", # *REQUIRED* name of the model in models.js
209 },
210 'current_file_size_mb': current_file_size_mb, 'max_file_size_mb': request.space.max_file_storage_mb
211 }
212 )
215@group_required('user')
216def step(request):
217 # recipe-param is the name of the parameters used when filtering recipes by this attribute
218 # model-name is the models.js name of the model, probably ALL-CAPS
219 return render(
220 request,
221 'generic/model_template.html',
222 {
223 "title": _("Steps"),
224 "config": {
225 'model': "STEP", # *REQUIRED* name of the model in models.js
226 'recipe_param': 'steps',
227 }
228 }
229 )
232@group_required('user')
233def unit_conversion(request):
234 # model-name is the models.js name of the model, probably ALL-CAPS
235 return render(
236 request,
237 'generic/model_template.html',
238 {
239 "title": _("Unit Conversions"),
240 "config": {
241 'model': "UNIT_CONVERSION", # *REQUIRED* name of the model in models.js
242 }
243 }
244 )
247@group_required('user')
248def property_type(request):
249 # model-name is the models.js name of the model, probably ALL-CAPS
250 return render(
251 request,
252 'generic/model_template.html',
253 {
254 "title": _("Property Types"),
255 "config": {
256 'model': "PROPERTY_TYPE", # *REQUIRED* name of the model in models.js
257 }
258 }
259 )