Browse Source

Starting with warnings list. #37

Rafał Pitoń 11 years ago
parent
commit
0cddf1c10f

+ 5 - 2
misago/acl/permissions/warnings.py

@@ -46,8 +46,11 @@ class WarningsACL(BaseACL):
             return False
             return False
 
 
     def can_see_member_warns(self, user, other_user):
     def can_see_member_warns(self, user, other_user):
-        if user.pk == other_user.pk:
-            return Ture
+        try:
+            if user.pk == other_user.pk:
+                return True
+        except AttributeError:
+            pass
         return self.acl['can_see_other_members_warns']
         return self.acl['can_see_other_members_warns']
 
 
     def allow_warning(self):
     def allow_warning(self):

+ 2 - 1
misago/apps/profiles/warnings/profile.py

@@ -1,4 +1,5 @@
 from django.utils.translation import ugettext_lazy as _
 from django.utils.translation import ugettext_lazy as _
 
 
 def register_profile_extension(request, user):
 def register_profile_extension(request, user):
-    return (('user_threads', _('Warnings')),)
+    if request.acl.warnings.can_see_member_warns(request.user, user):
+        return (('user_warnings', _('Warnings')),)

+ 16 - 0
misago/apps/profiles/warnings/urls.py

@@ -0,0 +1,16 @@
+from django.conf.urls import patterns, url
+
+def register_profile_urls(first=False):
+    urlpatterns = []
+    if first:
+        urlpatterns += patterns('misago.apps.profiles.warnings.views',
+            url(r'^$', 'warnings', name="user"),
+            url(r'^$', 'warnings', name="user_warnings"),
+            url(r'^(?P<page>[1-9]([0-9]+)?)/$', 'warnings', name="user_warnings"),
+        )
+    else:
+        urlpatterns += patterns('misago.apps.profiles.warnings.views',
+            url(r'^warnings/$', 'warnings', name="user_warnings"),
+            url(r'^warnings/(?P<page>[1-9]([0-9]+)?)/$', 'warnings', name="user_warnings"),
+        )
+    return urlpatterns

+ 29 - 0
misago/apps/profiles/warnings/views.py

@@ -0,0 +1,29 @@
+from datetime import timedelta
+from django.core.cache import cache
+from django.core.urlresolvers import reverse
+from django.http import Http404
+from django.shortcuts import redirect
+from django.utils import timezone
+from misago.apps.profiles.decorators import profile_view
+from misago.apps.profiles.template import RequestContext
+from misago.models import Forum
+from misago.shortcuts import render_to_response
+from misago.utils.pagination import make_pagination
+
+@profile_view('user_warnings')
+def warnings(request, user, page=0):
+    queryset = user.warning_set
+    count = queryset.count()
+    try:
+        pagination = make_pagination(page, count, 12)
+    except Http404:
+        return redirect(reverse('user_warnings', kwargs={'user': user.id, 'username': user.username_slug}))
+
+    return render_to_response('profiles/warnings.html',
+                              context_instance=RequestContext(request, {
+                                  'profile': user,
+                                  'tab': 'warnings',
+                                  'items_total': count,
+                                  'items': queryset.order_by('-id')[pagination['start']:pagination['stop']],
+                                  'pagination': pagination,
+                                  }));

+ 1 - 1
misago/models/warnmodel.py

@@ -2,7 +2,7 @@ from django.db import models
 from misago.signals import rename_user
 from misago.signals import rename_user
 
 
 class Warn(models.Model):
 class Warn(models.Model):
-    user = models.ForeignKey('User')
+    user = models.ForeignKey('User', related_name="warning_set")
     giver = models.ForeignKey('User', null=True, blank=True,
     giver = models.ForeignKey('User', null=True, blank=True,
         on_delete=models.SET_NULL, related_name="warnings_given_set")
         on_delete=models.SET_NULL, related_name="warnings_given_set")
     giver_name = models.CharField(max_length=255)
     giver_name = models.CharField(max_length=255)

+ 1 - 0
misago/settings_base.py

@@ -165,6 +165,7 @@ PROFILE_EXTENSIONS = (
     'misago.apps.profiles.threads',
     'misago.apps.profiles.threads',
     'misago.apps.profiles.follows',
     'misago.apps.profiles.follows',
     'misago.apps.profiles.followers',
     'misago.apps.profiles.followers',
+    'misago.apps.profiles.warnings',
     'misago.apps.profiles.details',
     'misago.apps.profiles.details',
 )
 )
 
 

+ 3 - 3
templates/cranefly/profiles/threads.html

@@ -44,9 +44,9 @@
 <div class="pagination">
 <div class="pagination">
   <ul>
   <ul>
     <li class="count">{{ macros.pager_label(pagination) }}</li>
     <li class="count">{{ macros.pager_label(pagination) }}</li>
-    {%- if pagination['prev'] > 1 %}<li><a href="{{ url('user_threads', user=profile.id, username=profile.username_slug) }}" class="tooltip-top" title="{% trans %}Lastest Posts{% endtrans %}"><i class="icon-chevron-left"></i> {% trans %}Latest{% endtrans %}</a></li>{% endif -%}
-    {%- if pagination['prev'] > 0 %}<li><a href="{%- if pagination['prev'] > 1 %}{{ url('user_threads', user=profile.id, username=profile.username_slug, page=pagination['prev']) }}{% else %}{{ url('user_threads', user=profile.id, username=profile.username_slug) }}{% endif %}" class="tooltip-top" title="{% trans %}Newer Posts{% endtrans %}"><i class="icon-chevron-left"></i></a></li>{% endif -%}
-    {%- if pagination['next'] > 0 %}<li><a href="{{ url('user_threads', user=profile.id, username=profile.username_slug, page=pagination['next']) }}" class="tooltip-top" title="{% trans %}Older Posts{% endtrans %}"><i class="icon-chevron-right"></i></a></li>{% endif -%}
+    {%- if pagination['prev'] > 1 %}<li><a href="{{ url('user_threads', user=profile.id, username=profile.username_slug) }}" class="tooltip-top" title="{% trans %}Lastest Threads{% endtrans %}"><i class="icon-chevron-left"></i> {% trans %}Latest{% endtrans %}</a></li>{% endif -%}
+    {%- if pagination['prev'] > 0 %}<li><a href="{%- if pagination['prev'] > 1 %}{{ url('user_threads', user=profile.id, username=profile.username_slug, page=pagination['prev']) }}{% else %}{{ url('user_threads', user=profile.id, username=profile.username_slug) }}{% endif %}" class="tooltip-top" title="{% trans %}Newer Threads{% endtrans %}"><i class="icon-chevron-left"></i></a></li>{% endif -%}
+    {%- if pagination['next'] > 0 %}<li><a href="{{ url('user_threads', user=profile.id, username=profile.username_slug, page=pagination['next']) }}" class="tooltip-top" title="{% trans %}Older Threads{% endtrans %}"><i class="icon-chevron-right"></i></a></li>{% endif -%}
   </ul>
   </ul>
 </div>
 </div>
 {% endif %}
 {% endif %}

+ 41 - 0
templates/cranefly/profiles/warnings.html

@@ -0,0 +1,41 @@
+{% extends "cranefly/profiles/profile.html" %}
+{% import "cranefly/macros.html" as macros with context %}
+
+{% block title %}{{ macros.page_title(_('Warnings'), profile.username) }}{% endblock %}
+
+{% block tab %}
+<div class="stat-header">
+  <h2>{% if items_total -%}
+      {%- trans count=items_total, total=items_total|intcomma, username=profile.username -%}
+      {{ username }} received one warning
+      {%- pluralize -%}
+      {{ username }} received {{ total }} warnings
+      {%- endtrans -%}
+      {%- else -%}
+      {% trans username=profile.username %}{{ username }} received no warnings{% endtrans %}
+      {%- endif %}</h2>
+</div>
+
+{% if items_total %}
+<div class="content-list user-threads">
+  {% for item in items %}
+  {{ item.reason }}
+  <hr>
+  {% endfor %}
+  {{ pager() }}
+</div>
+{% endif %}
+{% endblock %}
+
+{% macro pager() -%}
+{% if pagination['total'] > 1 %}
+<div class="pagination">
+  <ul>
+    <li class="count">{{ macros.pager_label(pagination) }}</li>
+    {%- if pagination['prev'] > 1 %}<li><a href="{{ url('user_warnings', user=profile.id, username=profile.username_slug) }}" class="tooltip-top" title="{% trans %}Lastest Warnings{% endtrans %}"><i class="icon-chevron-left"></i> {% trans %}Latest{% endtrans %}</a></li>{% endif -%}
+    {%- if pagination['prev'] > 0 %}<li><a href="{%- if pagination['prev'] > 1 %}{{ url('user_warnings', user=profile.id, username=profile.username_slug, page=pagination['prev']) }}{% else %}{{ url('user_warnings', user=profile.id, username=profile.username_slug) }}{% endif %}" class="tooltip-top" title="{% trans %}Newer Warnings{% endtrans %}"><i class="icon-chevron-left"></i></a></li>{% endif -%}
+    {%- if pagination['next'] > 0 %}<li><a href="{{ url('user_warnings', user=profile.id, username=profile.username_slug, page=pagination['next']) }}" class="tooltip-top" title="{% trans %}Older Warnings{% endtrans %}"><i class="icon-chevron-right"></i></a></li>{% endif -%}
+  </ul>
+</div>
+{% endif %}
+{%- endmacro %}