tum vor 1 Jahr
Ursprung
Commit
93c19cf273
3 geänderte Dateien mit 73 neuen und 55 gelöschten Zeilen
  1. 49 36
      app/legacy/templates/legacy/datacrud_list.html
  2. 6 3
      app/legacy/views.py
  3. 18 16
      app/templates/base.html

+ 49 - 36
app/legacy/templates/legacy/datacrud_list.html

@@ -26,43 +26,43 @@
26 26
 
27 27
     <!-- Data Table -->
28 28
     <div class="clear-both bg-white shadow rounded-lg overflow-x-auto">
29
-        <table class="w-full border-collapse border border-gray-200 table-fixed">
30
-            <thead>
31
-                <tr class="bg-gray-100 text-left text-sm uppercase">
32
-                    {% for field in fields %}
33
-                      <th class="border border-gray-200 px-4 py-2 text-left">{{ field.verbose_name }}</th>
34
-                    {% endfor %}
35
-                    <th class="py-2 px-4 border-b">Actions</th>
36
-                </tr>
37
-            </thead>
38
-            <tbody>
39
-                {% for obj in page_obj %}
40
-                    <tr class="hover:bg-gray-50">
41
-                        {% for field in fields %}
42
-                        <td class="border border-gray-200 px-4 py-2 whitespace-nowrap">
43
-                           {% if field.name == 'id' %}
44
-                              <a href="{% url  update_url obj.pk %}" class="text-blue-500 hover:underline">
45
-                                  {{ obj|attr:field.name }}
46
-                              </a>
47
-                          {% else %}
48
-                             {{ obj|attr:field.name}}
49
-                          {% endif %}
50
-                        </td>
51
-                        {% endfor %}
52
-                        <td class="py-2 px-4 border-b whitespace-nowrap">
53
-                            <a href="{% url  update_url obj.pk %}" 
54
-                              class="bg-blue-500 text-white px-3 py-2 rounded hover:bg-blue-600">Edit</a>
55
-                            <a href="{% url delete_url obj.pk %}" 
56
-                              class="bg-red-500 text-white px-3 py-2 rounded hover:bg-red-600">Delete</a>
57
-                        </td>
58
-                    </tr>
59
-                {% empty %}
60
-                    <tr>
61
-                        <td colspan="5" class="py-4 px-4 text-center text-gray-600">No data available.</td>
62
-                    </tr>
29
+<table class="w-full border-collapse border border-gray-200">
30
+    <thead>
31
+        <tr class="bg-gray-100 text-left text-sm uppercase">
32
+            {% for field in fields %}
33
+                <th class="border border-gray-200 px-4 py-2 text-left">{{ field.verbose_name }}</th>
34
+            {% endfor %}
35
+            <th class="py-2 px-4 border-b">Actions</th>
36
+        </tr>
37
+    </thead>
38
+    <tbody>
39
+        {% for obj in page_obj %}
40
+            <tr class="hover:bg-gray-50">
41
+                {% for field in fields %}
42
+                <td class="border border-gray-200 px-4 py-2">
43
+                    {% if field.name == 'id' %}
44
+                        <a href="{% url update_url obj.pk %}" class="text-blue-500 hover:underline">
45
+                            {{ obj|attr:field.name }}
46
+                        </a>
47
+                    {% else %}
48
+                        {{ obj|attr:field.name }}
49
+                    {% endif %}
50
+                </td>
63 51
                 {% endfor %}
64
-            </tbody>
65
-        </table>
52
+                <td class="py-2 px-4 border-b">
53
+                    <a href="{% url update_url obj.pk %}" 
54
+                       class="bg-blue-500 text-white px-3 py-2 rounded hover:bg-blue-600">Edit</a>
55
+                    <a href="{% url delete_url obj.pk %}" 
56
+                       class="bg-red-500 text-white px-3 py-2 rounded hover:bg-red-600">Delete</a>
57
+                </td>
58
+            </tr>
59
+        {% empty %}
60
+            <tr>
61
+                <td colspan="5" class="py-4 px-4 text-center text-gray-600">No data available.</td>
62
+            </tr>
63
+        {% endfor %}
64
+    </tbody>
65
+</table>
66 66
     </div>
67 67
 
68 68
     <!-- Pagination -->
@@ -88,4 +88,17 @@
88 88
         </div>
89 89
     </div>
90 90
 </div>
91
+<style>
92
+/* Remove fixed layout and allow columns to grow dynamically */
93
+table {
94
+    table-layout: auto; /* Default is auto, can be explicitly set */
95
+    width: 100%; /* Ensures table spans available space */
96
+}
97
+
98
+th, td {
99
+    white-space: nowrap; /* Prevents text wrapping */
100
+    text-overflow: ellipsis; /* Adds ellipsis for overflowed content if combined with max-width */
101
+    vertical-align: top; /* Aligns content to the top */
102
+}
103
+</style>
91 104
 {% endblock %}

+ 6 - 3
app/legacy/views.py

@@ -133,6 +133,7 @@ class ConfigurableCRUDView:
133 133
     config_readonly_fields = []  # Fields that should be read-only in update view
134 134
 
135 135
     config_edit_fields = "__all__"  # "all" or a list of field names to display
136
+    ordering = None
136 137
 
137 138
 
138 139
 
@@ -151,8 +152,8 @@ class ConfigurableCRUDView:
151 152
             fields = [model_fields[f] for f in self.config_fields if f in model_fields]
152 153
         else:
153 154
             fields = list(model_fields.values())
154
-        pprint("------------------------")
155
-        pprint(f"fields = {fields}")
155
+        # pprint("------------------------")
156
+        # pprint(f"fields = {fields}")
156 157
 
157 158
         # Exclude fields specified in `config_excludes`
158 159
         fields = [f for f in fields if f.name not in self.config_excludes]
@@ -197,6 +198,7 @@ class ConfigurableCRUDView:
197 198
             template_name = self.list_template_name
198 199
             paginate_by = self.paginate_by
199 200
             filterset_class = self.filterset_class
201
+            ordering = self.ordering
200 202
 
201 203
             def get_context_data(inner_self, **kwargs):
202 204
                 context = super().get_context_data(**kwargs)
@@ -364,5 +366,6 @@ class LotSummaryCRUDView(ConfigurableCRUDView):
364 366
     config_fields = ["id", "lot_no", "code", "avg", "start_time", "end_time", "grade", "created_at"]  # Display these fields first
365 367
     config_field_orders = ["id", "lot_no", "code", "avg", "start_time", "end_time", "grade", "created_at"]  # Display these fields first
366 368
     config_readonly_fields = ["lot_no"]
367
-    config_edit_fields = ["lot_no", "code"]
369
+    # config_edit_fields = ["lot_no", "code"]
370
+    ordering = ["-created_at", "-id",]
368 371
     

+ 18 - 16
app/templates/base.html

@@ -100,24 +100,26 @@
100 100
     {% endif %}
101 101
 
102 102
     <!-- Main Content -->
103
-    <div class="p-4 sm:ml-64">
104
-        <div class="mt-14">
105
-        {% if messages %}
103
+    <div class="flex flex-col min-h-screen">
104
+    <!-- Content Area -->
105
+       <div class="flex-grow p-4 sm:ml-64">
106
+          <div class="mt-14">
107
+          {% if messages %}
106 108
 
107
-            <div class="container mx-auto px-4 py-4">
108
-                {% for message in messages %}
109
-                <div id="message-alert" 
110
-                     class="p-4 mb-4 text-white rounded-lg bg-green-500 transition-opacity duration-500"
111
-                     style="opacity: 1;">
112
-                  {{ message }}
113
-                </div>
114
-                {% endfor %}
115
-            </div>
116
-        {% endif %}
109
+              <div class="container mx-auto px-4 py-4">
110
+                  {% for message in messages %}
111
+                  <div id="message-alert" 
112
+                       class="p-4 mb-4 text-white rounded-lg bg-green-500 transition-opacity duration-500"
113
+                       style="opacity: 1;">
114
+                    {{ message }}
115
+                  </div>
116
+                  {% endfor %}
117
+              </div>
118
+          {% endif %}
117 119
 
118
-          {% render_breadcrumbs bs %}
119
-          {% block content %}{% endblock %}
120
-        </div>
120
+            {% render_breadcrumbs bs %}
121
+            {% block content %}{% endblock %}
122
+          </div>
121 123
     </div>
122 124
 
123 125
     <!-- Footer -->