diff --git a/horilla_views/cbv_methods.py b/horilla_views/cbv_methods.py index ca0466731..bcc42a254 100644 --- a/horilla_views/cbv_methods.py +++ b/horilla_views/cbv_methods.py @@ -327,9 +327,9 @@ class Reverse: return str(self.reverse) -def getmodelattribute(value, attr: str): +def getmodelattribute(value: models.Model, attr: str): """ - Gets an attribute of a model dynamically from a string name, handling related fields. + Gets an attribute of a model dynamically, handling related fields. """ result = value attrs = attr.split("__") diff --git a/horilla_views/generic/cbv/views.py b/horilla_views/generic/cbv/views.py index bad533456..926da9910 100644 --- a/horilla_views/generic/cbv/views.py +++ b/horilla_views/generic/cbv/views.py @@ -48,7 +48,7 @@ class HorillaListView(ListView): export_file_name: str = None - template_name: str = "generic/horilla_list.html" + template_name: str = "generic/horilla_list_table.html" context_object_name = "queryset" # column = [("Verbose Name","field_name","avatar_mapping")], opt: avatar_mapping columns: list = [] @@ -97,6 +97,8 @@ class HorillaListView(ListView): bulk_update_fields: list = [] bulk_template: str = "generic/bulk_form.html" + header_attrs: dict = {} + def __init__(self, **kwargs: Any) -> None: if not self.view_id: self.view_id = get_short_uuid(4) @@ -246,6 +248,8 @@ class HorillaListView(ListView): context["options"] = self.options context["row_attrs"] = self.row_attrs + context["header_attrs"] = self.header_attrs + context["show_filter_tags"] = self.show_filter_tags context["bulk_select_option"] = self.bulk_select_option context["row_status_class"] = self.row_status_class @@ -329,7 +333,7 @@ class HorillaListView(ListView): if request and self._saved_filters.get("field"): field = self._saved_filters.get("field") - self.template_name = "generic/group_by.html" + self.template_name = "generic/group_by_table.html" if isinstance(queryset, Page): queryset = self.filter_class( request.GET, queryset=queryset.object_list.model.objects.all() @@ -514,6 +518,8 @@ class HorillaDetailedView(DetailView): instance_ids = eval(str(self.request.GET.get(self.ids_key))) pk = context["object"].pk + if instance_ids: + context["object"].ordered_ids = instance_ids context["instance"] = context["object"] url = resolve(self.request.path) @@ -812,6 +818,8 @@ class HorillaFormView(FormView): super().__init__(**kwargs) request = getattr(_thread_locals, "request", None) self.request = request + if not self.success_url: + self.success_url = self.request.path update_initial_cache(request, CACHE, HorillaFormView) if self.form_class: @@ -832,7 +840,7 @@ class HorillaFormView(FormView): response = super().post(request, *args, **kwargs) return response - def init_form(self, *args, data=None, files=None, instance=None, **kwargs): + def init_form(self, *args, data={}, files={}, instance=None, **kwargs): """ method where first the form where initialized """ diff --git a/horilla_views/templates/generic/group_by_table.html b/horilla_views/templates/generic/group_by_table.html new file mode 100644 index 000000000..443c3f07d --- /dev/null +++ b/horilla_views/templates/generic/group_by_table.html @@ -0,0 +1,399 @@ +{% load static i18n generic_template_filters %} + +
+ + {% include "generic/export_fields_modal.html" %} + + {% if bulk_select_option and queryset|length %} + {% include "generic/quick_actions.html" %} + {% endif %} + + {% if show_filter_tags %} {% include "generic/filter_tags.html" %} {% endif %} +
+ {% if not groups.paginator.count %} +
+
+ Page not found. 404. +

{% trans "No Records found" %}

+

+ {% trans "No records found." %} +

+
+
+ {% endif %} + {% for group in groups %} +
+
+
+ + +
+ + {{group.list.paginator.count}} + + {{group.grouper|capfirst}} +
+
+
+
+
+
+ + + + {% if bulk_select_option %} + + {% endif %} + {% for cell in columns %} + {% with cell_attr=header_attrs|get_item:cell.1 %} + + {% endwith %} + {% endfor %} + {% if options or option_method%} + + {% endif %} + {% if actions or action_method %} + + {% endif %} + + + + {% for instance in group.list %} + + {% if bulk_select_option %} + + {% endif %} + {% for cell in columns %} + {% with attribute=cell.1 index=forloop.counter %} + + {% endwith %} + {% endfor %} + {% if options or option_method %} + + {% endif %} + {% if actions or action_method %} + + {% endif %} + + {% endfor %} + +
+
+ +
+
+
+ {{cell.0}} +
+
+ {% trans "Options" %} + + {% trans "Actions" %} +
+
+ +
+
+ {% if not cell.2 %} + {{instance|getattribute:attribute|selected_format:request.user.employee_get.employee_work_info.company_id|safe}} + {% else %} +
+
+ +
+ + {{instance|getattribute:attribute}} + +
+ {% endif %} +
+ {% if not option_method %} +
+ {% for option in options %} + {% if option.accessibility|accessibility:instance %} + + + + {% endif %} + {% endfor %} +
+ {% else %} {{instance|getattribute:option_method|safe}} {% endif %} +
+ {% if not action_method %} +
+ {% for action in actions %} + {% if action.accessibility|accessibility:instance %} + + {% endif %} + {% endfor %} +
+ {% else %} {{instance|getattribute:action_method|safe}} {% endif %} +
+ +
+
+ + {% trans "Page" %} {{ group.list.number }} + {% trans "of" %} {{ group.list.paginator.num_pages }}. + + +
+
+
+
+ {% endfor %} +
+ {% if groups.paginator.count %} +
+ {% trans "Page" %} {{groups.number}} {% trans "of" %} {{groups.paginator.num_pages}} + + +
+ + {% if bulk_select_option %} + + {% endif %} + {% endif %} + + +
diff --git a/horilla_views/templates/generic/horilla_detailed_view.html b/horilla_views/templates/generic/horilla_detailed_view.html index 0966b5763..5f92dfd69 100644 --- a/horilla_views/templates/generic/horilla_detailed_view.html +++ b/horilla_views/templates/generic/horilla_detailed_view.html @@ -94,12 +94,16 @@ {% if actions and not action_method %}
{% for action in actions %} - + {% endfor %}
{% else %} {{object|getattribute:action_method|safe}} {% endif %} {% endif %} + + diff --git a/horilla_views/templates/generic/horilla_list_table.html b/horilla_views/templates/generic/horilla_list_table.html new file mode 100644 index 000000000..0cdce0a60 --- /dev/null +++ b/horilla_views/templates/generic/horilla_list_table.html @@ -0,0 +1,358 @@ +{% load static i18n generic_template_filters %} +
+ + {% include "generic/export_fields_modal.html" %} + + + {% if show_filter_tags %} {% include "generic/filter_tags.html" %} {% endif %} + {% if queryset|length %} + {% if bulk_select_option %} + {% include "generic/quick_actions.html" %} + {% endif %} + + +
+ {% if show_toggle_form %} +
+
+ +
+ {{ toggle_form.as_list }} +
+
+
+ {% endif %} + +
+ + + + {% if bulk_select_option %} + + {% endif %} + {% for cell in columns %} + {% with cell_attr=header_attrs|get_item:cell.1 %} + + {% endwith %} + {% endfor %} + {% if options or option_method%} + + {% endif %} + {% if actions or action_method %} + + {% endif %} + + + + {% for instance in queryset %} + + {% if bulk_select_option %} + + {% endif %} + {% for cell in columns %} + {% with attribute=cell.1 index=forloop.counter %} + + {% endwith %} + {% endfor %} + {% if options or option_method %} + + {% endif %} + {% if actions or action_method %} + + {% endif %} + + {% endfor %} + +
+
+ +
+
+
+ {{cell.0}} +
+
+ {% trans "Options" %} + + {% trans "Actions" %} +
+
+ +
+
+ {% if not cell.2 %} + {{instance|getattribute:attribute|selected_format:request.user.employee_get.employee_work_info.company_id|safe}} + {% else %} +
+
+ +
+ + {{instance|getattribute:attribute}} + +
+ {% endif %} +
+ {% if not option_method %} +
+ {% for option in options %} + {% if option.accessibility|accessibility:instance %} + + + + {% endif %} + {% endfor %} +
+ {% else %} {{instance|getattribute:option_method|safe}} {% endif %} +
+ {% if not action_method %} +
+ {% for action in actions %} + {% if action.accessibility|accessibility:instance %} + + + + {% endif %} + {% endfor %} +
+ {% else %} {{instance|getattribute:action_method|safe}} {% endif %} +
+
+
+ {% if queryset.paginator.count %} +
+ {% trans "Page" %} {{queryset.number}} {% trans "of" %} + {{queryset.paginator.num_pages}} + + +
+ + {% if bulk_select_option %} + + {% endif %} + {% endif %} + + + {% else %} + {% if row_status_indications %} +
+ {% for indication in row_status_indications %} + + + {{indication.1}} + + {% endfor %} +
+ {% endif %} +
+
+ Page not found. 404. +

{% trans "No Records found" %}

+

+ {% trans "No records found." %} +

+
+
+ {% endif %} +
diff --git a/horilla_views/templates/generic/quick_actions.html b/horilla_views/templates/generic/quick_actions.html index ed7cfdf72..e4a04fde8 100644 --- a/horilla_views/templates/generic/quick_actions.html +++ b/horilla_views/templates/generic/quick_actions.html @@ -14,7 +14,7 @@ addToSelectedId({{select_all_ids|safe}},'{{selected_instances_key_id}}'); selectSelected('#{{view_id|safe}}','{{selected_instances_key_id}}'); reloadSelectedCount($('#count_{{view_id|safe}}'),'{{selected_instances_key_id}}'); - reloadSelectedCount($('.count_{{view_id|safe}}')); + reloadSelectedCount($('.count_{{view_id|safe}}'),'{{selected_instances_key_id}}'); " style="cursor: pointer;">