Rafał Pitoń 11 лет назад
Родитель
Сommit
c81db16b7d

+ 22 - 10
misago/apps/profiles/warnings/views.py

@@ -5,11 +5,12 @@ from django.http import Http404
 from django.shortcuts import redirect
 from django.utils import timezone
 from django.utils.translation import ugettext as _
+from misago import messages
 from misago.apps.errors import error404
 from misago.apps.profiles.decorators import profile_view
 from misago.apps.profiles.template import RequestContext
 from misago.apps.profiles.warnings.warningstracker import WarningsTracker
-from misago.decorators import check_csrf
+from misago.decorators import block_guest, check_csrf
 from misago.models import Warn
 from misago.shortcuts import render_to_response
 from misago.utils.pagination import make_pagination
@@ -43,32 +44,43 @@ def warning_decorator(f):
         warning_pk = kwargs['warning']
         try:
             warning = user.warning_set.get(pk=warning_pk)
-            return f(request, user, warning)
+            f(request, user, warning)
+            return redirect('user_warnings', username=user.username_slug, user=user.pk)
         except Warn.DoesNotExist:
             return error404(request, _("Requested warning could not be found."))
     return decorator
 
 
-def todo_decorator(f):
-    def decorator(*args, **kwargs):
-        raise NotImplementedError("TODO: add decrease_warning_level function to user model, then do magic for cancel/delete warning")
-
-
+@block_guest
 @check_csrf
 @profile_view('user_warnings_cancel')
 @warning_decorator
-@todo_decorator
 def cancel_warning(request, user, warning):
     request.acl.warnings.allow_cancel_warning(
         request.user, user, warning)
 
+    user.decrease_warning_level()
+    warning.canceled = True
+    warning.canceled_on = timezone.now()
+    warning.canceler = request.user
+    warning.canceler_username = request.user.username
+    warning.canceler_slug = request.user.username_slug
+    warning.canceler_ip = request.session.get_ip(request)
+    warning.canceler_agent = request.META.get('HTTP_USER_AGENT')
+    warning.save(force_update=True)
 
+    messages.success(request, _("Selected warning has been canceled."))
+
+
+@block_guest
 @check_csrf
 @profile_view('user_warnings_delete')
 @warning_decorator
-@todo_decorator
 def delete_warning(request, user, warning):
     request.acl.warnings.allow_delete_warning()
 
     if user.is_warning_active(warning):
-        pass
+        user.decrease_warning_level()
+    warning.delete()
+
+    messages.success(request, _("Selected warning has been deleted."))

+ 9 - 1
misago/models/usermodel.py

@@ -579,9 +579,17 @@ class User(models.Model):
 
         return self.get_warning_level()
 
+    def expire_current_warning(self):
+        self.warning_level_update_on = tz_util.now() - timedelta(minutes=1)
+
+    def decrease_warning_level(self):
+        if self.get_current_warning_level():
+            self.expire_current_warning()
+            self.save(force_update=True)
+
     def is_warning_active(self, warning):
         warning_level = self.get_warning_level()
-        warnings_tracker = WarningsTracker(warning_level)
+        warnings_tracker = WarningsTracker(self.warning_level)
 
         for db_warning in self.warning_set.order_by('-pk').iterator():
             if warnings_tracker.is_warning_active(db_warning):

+ 2 - 2
static/cranefly/css/cranefly.css

@@ -987,10 +987,10 @@ a.btn-link:hover,a.btn-link:active,a.btn-link:focus{color:#333;text-decoration:n
 .user-profile .content-list .media{overflow:auto}.user-profile .content-list .media .media-object{border-radius:3px;width:52px;height:52px}
 .user-profile .content-list .media .media-body{margin-left:66px}.user-profile .content-list .media .media-body .post-preview:link,.user-profile .content-list .media .media-body .post-preview:active,.user-profile .content-list .media .media-body .post-preview:visited,.user-profile .content-list .media .media-body .post-preview:hover{display:block;margin-top:7px;color:#333;font-size:16.8px;text-decoration:none}
 .user-profile .content-list .media .media-body .media-footer{margin:0;color:#999;font-size:10.5px;font-weight:normal}.user-profile .content-list .media .media-body .media-footer a{color:#555}
-.user-profile .content-list.user-warnings .media{margin-bottom:-6px}.user-profile .content-list.user-warnings .media .warning-icon{width:60px;font-size:35px;text-align:center}.user-profile .content-list.user-warnings .media .warning-icon .warning-active,.user-profile .content-list.user-warnings .media .warning-icon .warning-expired{margin-bottom:-3px;position:relative;top:3px}
+.user-profile .content-list.user-warnings .media{margin-bottom:-6px}.user-profile .content-list.user-warnings .media .warning-icon{width:60px;font-size:35px;text-align:center}.user-profile .content-list.user-warnings .media .warning-icon .warning-active,.user-profile .content-list.user-warnings .media .warning-icon .warning-expired,.user-profile .content-list.user-warnings .media .warning-icon .warning-canceled{margin-bottom:-3px;position:relative;top:3px}
 .user-profile .content-list.user-warnings .media .warning-icon .warning-active{color:#cf402e}
 .user-profile .content-list.user-warnings .media .warning-icon .warning-expired{color:#999}
-.user-profile .content-list.user-warnings .media .warning-icon .warning-canceled{margin-bottom:0;position:relative;bottom:5px;color:#999;font-size:43.75px}
+.user-profile .content-list.user-warnings .media .warning-icon .warning-canceled{color:#999}
 .user-profile .content-list.user-warnings .media .media-body .warning-reason>:first-child{margin-top:0;padding-top:0}
 .user-profile .content-list.user-warnings .media .media-body .warning-reason>:last-child{margin-bottom:0;padding-bottom:0}
 .user-profile .content-list.user-warnings .media .media-footer form,.user-profile .content-list.user-warnings .media .media-footer p{float:left;margin:0}

+ 1 - 7
static/cranefly/css/cranefly/profiles.less

@@ -224,7 +224,7 @@
           font-size: @fontSizeLarge * 2;
           text-align: center;
 
-          .warning-active, .warning-expired {
+          .warning-active, .warning-expired, .warning-canceled {
             margin-bottom: -3px;
             position: relative;
             top: 3px;
@@ -236,16 +236,10 @@
 
           .warning-expired {
             color: @grayLight;
-
           }
 
           .warning-canceled {
-            margin-bottom: 0px;
-            position: relative;
-            bottom: 5px;
-
             color: @grayLight;
-            font-size: @fontSizeLarge * 2.5;
           }
         }
 

+ 2 - 2
templates/cranefly/profiles/warnings.html

@@ -43,7 +43,7 @@
     <div class="pull-left">
       <div class="warning-icon ">
         {% if item.canceled %}
-        <i class="icon-ban warning-canceled tooltip-top" title="{% trans %}This warning has been canceled.{% endtrans %}"></i>
+        <i class="icon-ban-circle warning-canceled tooltip-top" title="{% trans %}This warning has been canceled.{% endtrans %}"></i>
         {% elif warnings_tracker.is_warning_expired(item) %}
         <i class="icon-warning-sign warning-expired tooltip-top" title="{% trans %}This warning has expired.{% endtrans %}"></i>
         {% else %}
@@ -63,7 +63,7 @@
         {% if acl.warnings.can_cancel_warning(user, profile, item) and not warnings_tracker.is_warning_expired(item) %}
         <form action="{{ url('user_warnings_cancel', user=profile.pk, username=profile.username_slug, warning=item.pk) }}" method="post">
           <input type="hidden" name="{{ csrf_id }}" value="{{ csrf_token }}">
-          <button type="submit" class="btn btn-mini"><i class="icon-ban"></i> {% trans %}Cancel{% endtrans %}</button>
+          <button type="submit" class="btn btn-mini"><i class="icon-ban-circle"></i> {% trans %}Cancel{% endtrans %}</button>
         </form>
         {% endif %}
         {% if acl.warnings.can_delete_warnings() %}