Commits

David Jean Louis  committed 3387d67

implemented filter by content_types in RecentActionsDashboardModule

  • Participants
  • Parent commits 1cbc1b1

Comments (0)

Files changed (3)

File admin_tools/dashboard/models.py

         self.limit = kwargs.get('limit', 10)
 
     def render(self, request):
+        from django.db.models import Q
         from django.contrib.admin.models import LogEntry
+
+        def get_qset(list):
+            qset = None
+            for contenttype in list:
+                try:
+                    app_label, model = contenttype.split('.')
+                except:
+                    raise ValueError('Invalid contenttype: "%s"' % contenttype)
+                current_qset = Q(
+                    content_type__app_label=app_label,
+                    content_type__model=model
+                )
+                if qset is None:
+                    qset = current_qset
+                else:
+                    qset = qset | current_qset
+            return qset
+
         if request.user is None:
             qs = LogEntry.objects.all()
         else:
             qs = LogEntry.objects.filter(user__id__exact=request.user.id)
-        # todo: RecentActionsDashboardModule: filter by contenttype
+
         if self.include_list:
-            pass
+            qs = qs.filter(get_qset(self.include_list))
         if self.exclude_list:
-            pass
+            qs = qs.exclude(get_qset(self.exclude_list))
+
         self.entries = qs.select_related('content_type', 'user')[:self.limit]
+        if not len(self.entries):
+            self.pre_content = _('No recent actions.')
 
 
 class FeedDashboardModule(DashboardModule):

File admin_tools/dashboard/templates/dashboard/module.html

         <div class="dashboard-module-content">
             {% spaceless %}
             {% if module.pre_content %}
-            {{ module.pre_content }}
+            <p>{{ module.pre_content }}</p>
             {% endif %}
             {% block module_content %}
             {% for entry in module.entries %}
             {% endfor %}
             {% endblock %}
             {% if module.post_content %}
-            {{ module.post_content }}
+            <p>{{ module.post_content }}</p>
             {% endif %}
             {% endspaceless %}
         </div>

File admin_tools/media/admin_tools/css/dashboard.css

     border-top: 1px solid #ececec;
 }
 
+.dashboard-module-content p {
+    margin: 10px;
+}
+
 .dashboard-module ul li {
     vertical-align: top;
     padding: 5px 8px;