Skip to content

Commit fb3f227

Browse files
Prepare 0.19.1. Add dashboard class based view and permissions
1 parent ff44238 commit fb3f227

File tree

7 files changed

+97
-4
lines changed

7 files changed

+97
-4
lines changed

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ are used for versioning (schema follows below):
1515
0.3.4 to 0.4).
1616
- All backwards incompatible changes are mentioned in this document.
1717

18+
0.19.1
19+
------
20+
2022-07-12
21+
22+
- Added class-based view for Dashboard.
23+
1824
0.19
1925
----
2026
2022-07-11

docs/changelog.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ are used for versioning (schema follows below):
1515
0.3.4 to 0.4).
1616
- All backwards incompatible changes are mentioned in this document.
1717

18+
0.19.1
19+
------
20+
2022-07-12
21+
22+
- Added class-based view for Dashboard.
23+
1824
0.19
1925
----
2026
2022-07-11

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from distutils.version import LooseVersion
44
from setuptools import setup, find_packages
55

6-
version = '0.19'
6+
version = '0.19.1'
77

88
# ***************************************************************************
99
# ************************** Django version *********************************

src/fobi/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__title__ = 'django-fobi'
2-
__version__ = '0.19'
2+
__version__ = '0.19.1'
33
__author__ = 'Artur Barseghyan <[email protected]>'
44
__copyright__ = '2014-2022 Artur Barseghyan'
55
__license__ = 'GPL 2.0/LGPL 2.1'

src/fobi/permissions/default.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
edit_form_wizard_handler_entry_permission,
2020
wizards_dashboard_permissions,
2121
)
22-
from .generic import AllowAnyPermission, BasePermission
22+
from .generic import AllowAnyPermission, BasePermission, IsAuthenticatedPermission
2323
from .helpers import (
2424
all_permissions_required_func,
2525
any_permission_required_func,
@@ -42,6 +42,7 @@
4242
"EditFormHandlerEntryPermission",
4343
"DeleteFormHandlerEntryPermission",
4444
"ViewFormEntryPermission",
45+
"ViewDashboardPermission",
4546
)
4647

4748

@@ -191,3 +192,7 @@ def has_object_permission(self, request, view, obj) -> bool:
191192

192193
class ViewFormEntryPermission(AllowAnyPermission):
193194
"""Permission to view form entries."""
195+
196+
197+
class ViewDashboardPermission(IsAuthenticatedPermission):
198+
"""Permission to view the dashboard."""

src/fobi/urls/class_based/edit.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
EditFormElementEntryView,
3838
EditFormEntryView,
3939
EditFormHandlerEntryView,
40+
DashboardView,
4041
)
4142

4243
__title__ = "fobi.urls.class_based.edit"
@@ -230,7 +231,12 @@
230231
# ****************************** Dashboard ******************************
231232
# ***********************************************************************
232233
# Forms dashboard
233-
url(_(r"^$"), view=dashboard, name="fobi.dashboard"),
234+
url(
235+
_(r"^$"),
236+
# view=dashboard,
237+
view=DashboardView.as_view(),
238+
name="fobi.dashboard"
239+
),
234240
# Form wizards dashboard
235241
url(
236242
_(r"^wizards/$"),

src/fobi/views/class_based.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from django.views import View
1414
from django.views.generic import CreateView, DeleteView, DetailView, UpdateView
1515
from django.views.generic.edit import DeletionMixin
16+
from django.views.generic.list import ListView
1617

1718
from ..base import ( # get_registered_form_handler_plugins
1819
fire_form_callbacks,
@@ -40,6 +41,10 @@
4041
ImportFormEntryForm,
4142
ImportFormWizardEntryForm,
4243
)
44+
from ..form_importers import (
45+
ensure_autodiscover as ensure_importers_autodiscover,
46+
form_importer_plugin_registry, get_form_importer_plugin_urls
47+
)
4348
from ..models import (
4449
FormElementEntry,
4550
FormEntry,
@@ -59,6 +64,7 @@
5964
EditFormEntryPermission,
6065
EditFormHandlerEntryPermission,
6166
ViewFormEntryPermission,
67+
ViewDashboardPermission,
6268
)
6369
from ..settings import DEBUG, GET_PARAM_INITIAL_DATA, SORT_PLUGINS_BY_VALUE
6470
from ..utils import (
@@ -88,6 +94,7 @@
8894
"DeleteFormHandlerEntryView",
8995
"ViewFormEntryView",
9096
"ViewFormEntrySubmittedView",
97+
"DashboardView",
9198
)
9299

93100
logger = logging.getLogger(__name__)
@@ -219,6 +226,69 @@ def _run_after_plugin_entry_delete(self, request, form_entry_id):
219226
def run_after_plugin_entry_delete(self, request, form_entry_id):
220227
"""Run after plugin entry has been deleted."""
221228

229+
# *****************************************************************************
230+
# *****************************************************************************
231+
# ******************************** Dashboards *********************************
232+
# *****************************************************************************
233+
# *****************************************************************************
234+
235+
# *****************************************************************************
236+
# ********************************** Forms ************************************
237+
# *****************************************************************************
238+
239+
240+
class DashboardView(ListView):
241+
"""Dashboard view."""
242+
243+
template_name = None
244+
theme = None
245+
permission_classes = (ViewDashboardPermission,)
246+
247+
def get_queryset(self):
248+
"""
249+
Return the list of items for this view.
250+
251+
The return value must be an iterable and may be an instance of
252+
`QuerySet` in which case `QuerySet` specific behavior will be enabled.
253+
"""
254+
queryset = FormEntry._default_manager.filter(
255+
user__pk=self.request.user.pk
256+
)
257+
ordering = self.get_ordering()
258+
if ordering:
259+
if isinstance(ordering, str):
260+
ordering = (ordering,)
261+
queryset = queryset.order_by(*ordering)
262+
263+
return queryset
264+
265+
def get_context_data(self, **kwargs):
266+
"""Get context data."""
267+
context = super(DashboardView, self).get_context_data(**kwargs)
268+
context.update({
269+
"form_entries": self.get_queryset(),
270+
'form_importers': get_form_importer_plugin_urls(),
271+
})
272+
if not self.theme:
273+
theme = get_theme(request=self.request, as_instance=True)
274+
else:
275+
theme = self.theme
276+
277+
if theme:
278+
context.update({"fobi_theme": theme})
279+
return context
280+
281+
def get_template_names(self):
282+
"""Get template names."""
283+
template_name = self.template_name
284+
if not template_name:
285+
if not self.theme:
286+
theme = get_theme(request=self.request, as_instance=True)
287+
else:
288+
theme = self.theme
289+
template_name = theme.dashboard_template
290+
return [template_name]
291+
222292

223293
# *****************************************************************************
224294
# *****************************************************************************

0 commit comments

Comments
 (0)