From 416fde56c4a175525760d06510bdc43542d9a53b Mon Sep 17 00:00:00 2001 From: Horilla Date: Wed, 26 Mar 2025 14:02:20 +0530 Subject: [PATCH] [FIX] BASE: #604 --- base/announcement.py | 2 +- base/forms.py | 6 ++- base/signals.py | 3 +- .../announcement_update_form.html | 28 ++++++----- base/templates/announcement/as_p.html | 49 +++++++++++++++++++ .../rotating_work_type_assign_view.html | 1 - base/urls.py | 5 ++ 7 files changed, 77 insertions(+), 17 deletions(-) create mode 100644 base/templates/announcement/as_p.html diff --git a/base/announcement.py b/base/announcement.py index 5b5c9b7c6..97f9c24d9 100644 --- a/base/announcement.py +++ b/base/announcement.py @@ -178,7 +178,7 @@ def update_announcement(request, anoun_id): announcement = Announcement.objects.get(id=anoun_id) form = AnnouncementForm(instance=announcement) - existing_attachments = announcement.attachments.all() + existing_attachments = announcement.attachments.all() instance_ids = request.GET.get("instance_ids") if request.method == "POST": form = AnnouncementForm(request.POST, request.FILES, instance=announcement) diff --git a/base/forms.py b/base/forms.py index 368db58d4..d1bf9f05b 100644 --- a/base/forms.py +++ b/base/forms.py @@ -2371,7 +2371,7 @@ class AnnouncementForm(ModelForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self.fields["attachments"] = MultipleFileField(label="Attachments ") + self.fields["attachments"] = MultipleFileField(label=_("Attachments")) self.fields["attachments"].required = False self.fields["description"].required = False @@ -2394,6 +2394,10 @@ class AnnouncementForm(ModelForm): instance.attachements.add(*multiple_attachment_ids) return instance, multiple_attachment_ids + def as_p(self, *args, **kwargs): + context = {"form": self} + return render_to_string("announcement/as_p.html", context) + class AnnouncementCommentForm(ModelForm): """ diff --git a/base/signals.py b/base/signals.py index 5bd4c855d..3db4b765a 100644 --- a/base/signals.py +++ b/base/signals.py @@ -12,7 +12,8 @@ from horilla.methods import get_horilla_model_class @receiver(post_save, sender=PenaltyAccounts) def create_deduction_cutleave_from_penalty(sender, instance, created, **kwargs): """ - This is post save method, used to create deduction and cut availabl leave days""" + This is post save method, used to create deduction and cut available leave days + """ # only work when creating if created: penalty_amount = instance.penalty_amount diff --git a/base/templates/announcement/announcement_update_form.html b/base/templates/announcement/announcement_update_form.html index 151d5feaa..eb3b19bb5 100644 --- a/base/templates/announcement/announcement_update_form.html +++ b/base/templates/announcement/announcement_update_form.html @@ -1,33 +1,35 @@ {% load i18n %} {% if messages %} - + + + {% endif %} {% if form.errors %} - -
-
- {% for error in form.non_field_errors %} -
- {{ error }} +
+
+ {% for error in form.non_field_errors %} +
+ {{ error }} +
+ {% endfor %}
- {% endfor %}
-
{% endif %}
-
{% trans "Edit Announcement." %} +
{% trans "Update" %} {{form.verbose_name}} +
- -
+ {% csrf_token %} {{form.as_p}}
diff --git a/base/templates/announcement/as_p.html b/base/templates/announcement/as_p.html new file mode 100644 index 000000000..1548bf915 --- /dev/null +++ b/base/templates/announcement/as_p.html @@ -0,0 +1,49 @@ +{% load static %} +{% load i18n %} +{% load widget_tweaks %} +
+
+
{{ form.non_field_errors }}
+ {% for field in form.visible_fields %} +
+
+ + {% if field.help_text != '' %} + + {% endif %} +
+ {% if field.field.widget.input_type == 'checkbox' %} +
{{ field|add_class:'oh-switch__checkbox' }}
+ {% else %} + {{ field|add_class:'form-control' }} + {% endif %} + {{ field.errors }} + {% if field.name == "attachments" and field.field.widget.input_type == "file" and field.field.widget.attrs.multiple %} + {% if form.instance.pk %} +
+ {% for file in form.instance.attachments.all %} + + + + + + {% endfor %} +
+ {% endif %} + {% endif %} +
+ {% endfor %} +
+ {% for field in form.hidden_fields %} + {{ field }} + {% endfor %} +
\ No newline at end of file diff --git a/base/templates/base/rotating_work_type/rotating_work_type_assign_view.html b/base/templates/base/rotating_work_type/rotating_work_type_assign_view.html index 092afbca7..1a93cea06 100644 --- a/base/templates/base/rotating_work_type/rotating_work_type_assign_view.html +++ b/base/templates/base/rotating_work_type/rotating_work_type_assign_view.html @@ -399,5 +399,4 @@ if (!localStorageroratingWorkTypeCells) { $("#roratingWorkTypeCells").find("[type=checkbox]").prop("checked", true); } - $("[type=checkbox]").change(); diff --git a/base/urls.py b/base/urls.py index dadfead58..3bd7fa13a 100644 --- a/base/urls.py +++ b/base/urls.py @@ -946,6 +946,11 @@ urlpatterns = [ announcement.update_announcement, name="update-announcement", ), + path( + "remove-announcement-file//", + announcement.remove_announcement_file, + name="remove-announcement-file", + ), path( "announcement-add-comment//", announcement.create_announcement_comment,