Zine

open source content publishing system


Ticket #215: before-comment-created.patch

File before-comment-created.patch, 1.1 KB (added by arteme, 3 years ago)

Prososed patch.

  • zine/forms.py

    diff --git a/zine/forms.py b/zine/forms.py
    a b  
    1010""" 
    1111from copy import copy 
    1212from datetime import datetime 
     13from itertools import chain 
    1314import os 
    1415 
    1516from zine.i18n import _, lazy_gettext, list_languages 
     
    155156        is not a post req or the form is invalid the return value is None, 
    156157        otherwise a redirect response to the new comment. 
    157158        """ 
    158         if req.method != 'POST' or not self.validate(req.form): 
     159        if req.method != 'POST': 
     160            return 
     161 
     162        valid = self.validate(req.form) 
     163 
     164        errors = emit_event('before-comment-created', req) 
     165        errors = filter(lambda x: x is not None, errors) 
     166        errors = list(chain(*errors)) 
     167 
     168        if len(errors) > 0: 
     169            # update the form-wide error list with those added by the 
     170            # event handlers 
     171            error_list = self.errors.get(None, forms.ErrorList()) 
     172            error_list.extend(errors) 
     173            self.errors[None] = error_list 
     174            return 
     175 
     176        if not valid: 
    159177            return 
    160178 
    161179        # if we don't have errors let's save it and emit an