Skip to content

Commit

Permalink
Merge pull request #347 from maykinmedia/feature/901-action-status-to…
Browse files Browse the repository at this point in the history
…ggle

[#901, #902, #903 ] Implemented Action-status toggle and added HTMX to backend
  • Loading branch information
alextreme authored Dec 7, 2022
2 parents bedb511 + 58816f2 commit 32f04c3
Show file tree
Hide file tree
Showing 41 changed files with 1,008 additions and 54 deletions.
1 change: 1 addition & 0 deletions requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ django-csp
django-csp-reports
mozilla-django-oidc-db
django-open-forms-client
django-htmx

# API libraries
djangorestframework
Expand Down
3 changes: 3 additions & 0 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ django==3.2.15
# django-filter
# django-formtools
# django-hijack
# django-htmx
# django-import-export
# django-localflavor
# django-open-forms-client
Expand Down Expand Up @@ -134,6 +135,8 @@ django-formtools==2.3
# via maykin-django-two-factor-auth
django-hijack==3.0.4
# via -r requirements/base.in
django-htmx==1.13.0
# via -r requirements/base.in
django-import-export==2.6.1
# via -r requirements/base.in
django-ipware==4.0.0
Expand Down
8 changes: 8 additions & 0 deletions requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ django==3.2.15
# django-filter
# django-formtools
# django-hijack
# django-htmx
# django-import-export
# django-localflavor
# django-open-forms-client
Expand All @@ -127,6 +128,7 @@ django==3.2.15
# django-relativedelta
# django-rich
# django-rosetta
# django-selenium-login
# django-sendfile2
# django-simple-certmanager
# django-sniplates
Expand Down Expand Up @@ -221,6 +223,10 @@ django-hijack==3.0.4
# via
# -c requirements/base.txt
# -r requirements/base.txt
django-htmx==1.13.0
# via
# -c requirements/base.txt
# -r requirements/base.txt
django-import-export==2.6.1
# via
# -c requirements/base.txt
Expand Down Expand Up @@ -295,6 +301,8 @@ django-rosetta==0.9.7
# via
# -c requirements/base.txt
# -r requirements/base.txt
django-selenium-login==2.0.0
# via -r requirements/test-tools.in
django-sendfile2==0.7.0
# via
# -c requirements/base.txt
Expand Down
10 changes: 10 additions & 0 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ django==3.2.15
# django-filter
# django-formtools
# django-hijack
# django-htmx
# django-import-export
# django-localflavor
# django-open-forms-client
Expand All @@ -156,6 +157,7 @@ django==3.2.15
# django-relativedelta
# django-rich
# django-rosetta
# django-selenium-login
# django-sendfile2
# django-simple-certmanager
# django-sniplates
Expand Down Expand Up @@ -254,6 +256,10 @@ django-hijack==3.0.4
# via
# -c requirements/ci.txt
# -r requirements/ci.txt
django-htmx==1.13.0
# via
# -c requirements/ci.txt
# -r requirements/ci.txt
django-import-export==2.6.1
# via
# -c requirements/ci.txt
Expand Down Expand Up @@ -328,6 +334,10 @@ django-rosetta==0.9.7
# via
# -c requirements/ci.txt
# -r requirements/ci.txt
django-selenium-login==2.0.0
# via
# -c requirements/ci.txt
# -r requirements/ci.txt
django-sendfile2==0.7.0
# via
# -c requirements/ci.txt
Expand Down
1 change: 1 addition & 0 deletions requirements/test-tools.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pyquery # integrates with webtest
requests-mock
tblib
selenium
django-selenium-login

# DigidLocal
pyopenssl
5 changes: 4 additions & 1 deletion src/open_inwoner/accounts/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class _UserAdmin(UserAdmin):
@admin.register(Action)
class ActionAdmin(UUIDAdminFirstInOrder, PrivateMediaMixin, admin.ModelAdmin):
readonly_fields = ("uuid",)
list_display = ("name", "created_on", "created_by", "is_deleted")
list_display = ("name", "status", "plan", "created_on", "created_by", "is_deleted")
list_filter = (
"is_deleted",
"created_by",
Expand All @@ -103,6 +103,9 @@ class ActionAdmin(UUIDAdminFirstInOrder, PrivateMediaMixin, admin.ModelAdmin):
"mark_not_deleted",
"mark_deleted",
]
raw_id_fields = [
"plan",
]

@admin.action(description=_("Mark selected actions as soft-deleted by user."))
def mark_deleted(self, request, queryset):
Expand Down
18 changes: 16 additions & 2 deletions src/open_inwoner/accounts/choices.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,22 @@ class StatusEmptyChoice(DjangoChoices):


class StatusChoices(DjangoChoices):
open = ChoiceItem("open", _("Open"))
closed = ChoiceItem("closed", _("Afgerond"))
open = ChoiceItem("open", _("Open"), icon="format_list_bulleted")
approval = ChoiceItem("approval", _("Accordering"), icon="question_mark")
closed = ChoiceItem("closed", _("Afgerond"), icon="check")

# note the icons are names from Material Symbols and Icons - Google Fonts

@classmethod
def get_icon(cls, status, default="label"):
if status in cls.values:
return cls.get_choice(status).icon
else:
return default

@classmethod
def choices_with_icons(cls):
return [(value, label, cls.get_icon(value)) for value, label in cls.choices]


class EmptyStatusChoices(StatusEmptyChoice, StatusChoices):
Expand Down
28 changes: 28 additions & 0 deletions src/open_inwoner/accounts/migrations/0048_alter_action_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 3.2.15 on 2022-12-06 13:52

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("accounts", "0047_action_is_deleted"),
]

operations = [
migrations.AlterField(
model_name="action",
name="status",
field=models.CharField(
choices=[
("open", "Open"),
("approval", "Accordering"),
("closed", "Afgerond"),
],
default="open",
help_text="The current status of the action",
max_length=200,
verbose_name="Status",
),
),
]
13 changes: 13 additions & 0 deletions src/open_inwoner/accounts/migrations/0051_merge_20221207_0918.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Generated by Django 3.2.15 on 2022-12-07 08:18

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("accounts", "0048_alter_action_status"),
("accounts", "0050_auto_20221205_0924"),
]

operations = []
5 changes: 4 additions & 1 deletion src/open_inwoner/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def save(self, *args, **kwargs):
return super().save(*args, **kwargs)

def is_connected(self, user):
return Action.objects.filter(pk=self.pk).connected(user=user).exists()
return Action.objects.visible().filter(pk=self.pk).connected(user=user).exists()

def send(self, plan, message, receivers, request=None):
plan_url = plan.get_absolute_url()
Expand All @@ -472,6 +472,9 @@ def send(self, plan, message, receivers, request=None):

return template.send_email(to_emails, context)

def get_status_icon(self):
return StatusChoices.get_icon(self.status)


class Message(models.Model):
uuid = models.UUIDField(
Expand Down
Loading

0 comments on commit 32f04c3

Please sign in to comment.