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 %} + +
+ {% trans "No records found." %} +
+|
+
+
+
+ |
+ {% endif %}
+ {% for cell in columns %}
+ {% with cell_attr=header_attrs|get_item:cell.1 %}
+
+
+ {{cell.0}}
+
+ |
+ {% endwith %}
+ {% endfor %}
+ {% if options or option_method%}
+ + {% trans "Options" %} + | + {% endif %} + {% if actions or action_method %} ++ {% trans "Actions" %} + | + {% endif %} +
|---|---|---|---|
|
+
+
+
+ |
+ {% endif %}
+ {% for cell in columns %}
+ {% with attribute=cell.1 index=forloop.counter %}
+
+ {% if not cell.2 %}
+ {{instance|getattribute:attribute|selected_format:request.user.employee_get.employee_work_info.company_id|safe}}
+ {% else %}
+
+
+ {% endif %}
+
+
+
+ {{instance|getattribute:attribute}}
+
+ |
+ {% endwith %}
+ {% endfor %}
+ {% if options or option_method %}
+
+ {% if not option_method %}
+
+ {% for option in options %}
+ {% if option.accessibility|accessibility:instance %}
+
+
+ {% else %} {{instance|getattribute:option_method|safe}} {% endif %}
+ |
+ {% endif %}
+ {% if actions or action_method %}
+
+ {% if not action_method %}
+
+ {% for action in actions %}
+ {% if action.accessibility|accessibility:instance %}
+
+
+ {% else %} {{instance|getattribute:action_method|safe}} {% endif %}
+ |
+ {% endif %}
+
+ {% trans "No records found." %} +
+