Changeset 402 in main


Ignore:
Timestamp:
10/18/11 09:10:28 (8 years ago)
Author:
pcosquer
Message:

controllers: add stuff to block mails sending

Location:
trunk/openPLM/plmapp/controllers
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/openPLM/plmapp/controllers/base.py

    r379 r402  
    2828import re 
    2929from functools import wraps 
     30from collections import deque 
    3031 
    3132from django.db.models.fields import FieldDoesNotExist 
     
    129130 
    130131    def __init__(self, obj, user): 
     132        self._mail_blocked = False 
     133        self._pending_mails = deque() 
    131134        self._user = user 
    132135        # variable to store attribute changes 
     
    178181                                     details=details, user=self._user) 
    179182        roles = [models.ROLE_OWNER] + list(roles) 
    180         send_histories_mail(self, roles, action, [h], self._user, blacklist, 
    181                 users) 
     183        self._send_mail(send_histories_mail, self, roles, action, [h], 
     184                self._user, blacklist, users) 
    182185 
    183186    def get_verbose_name(self, attr_name): 
     
    263266        return True 
    264267 
     268    def block_mails(self): 
     269        """ 
     270        Blocks mails sending. Call :meth:`unblock_mails` to send blocked mails. 
     271        """ 
     272        self._mail_blocked = True 
     273 
     274    def unblock_mails(self): 
     275        """ 
     276        Unblock mails sending. This sends all previously blocked mails. 
     277        """ 
     278        while self._pending_mails: 
     279            mail = self._pending_mails.popleft() 
     280            mail[0](*mail[1:]) 
     281        self._mail_blocked = False 
     282 
     283    def _send_mail(self, func, *args): 
     284        if self._mail_blocked: 
     285            mail = (func,) + args 
     286            self._pending_mails.append(mail) 
     287        else: 
     288             func(*args) 
     289 
  • trunk/openPLM/plmapp/controllers/group.py

    r376 r402  
    157157                } 
    158158        subject = "[PLM] Invitation to join the group %s" % self.name  
    159         send_mail(subject, [user], ctx, "mails/invitation1") 
     159        self._send_mail(send_mail, subject, [user], ctx, "mails/invitation1") 
    160160 
    161161    def ask_to_join(self): 
     
    172172                } 
    173173        subject = "[PLM] %s ask you to join the group %s" % (self._user, self.name)  
    174         send_mail(subject, [self.owner], ctx, "mails/invitation2") 
    175  
     174        self._send_mail(send_mail, subject, [self.owner], ctx, "mails/invitation2") 
    176175 
    177176    def accept_invitation(self, invitation): 
  • trunk/openPLM/plmapp/controllers/plmobject.py

    r396 r402  
    6060     
    6161    @classmethod 
    62     def create(cls, reference, type, revision, user, data={}): 
     62    def create(cls, reference, type, revision, user, data={}, block_mails=False): 
    6363        u""" 
    6464        This method builds a new :class:`.PLMObject` of 
     
    9898        obj.save() 
    9999        res = cls(obj, user) 
     100        if block_mails: 
     101            res.block_mails() 
    100102        # record creation in history 
    101103        infos = {"type" : type, "reference" : reference, "revision" : revision} 
     
    119121         
    120122    @classmethod 
    121     def create_from_form(cls, form, user): 
     123    def create_from_form(cls, form, user, block_mails=False): 
    122124        u""" 
    123125        Creates a :class:`PLMObjectController` from *form* and associates *user* 
     
    134136            type = form.Meta.model.__name__ 
    135137            rev = form.cleaned_data["revision"] 
    136             obj = cls.create(ref, type, rev, user, form.cleaned_data) 
     138            obj = cls.create(ref, type, rev, user, form.cleaned_data, block_mails) 
    137139            return obj 
    138140        else: 
  • trunk/openPLM/plmapp/controllers/user.py

    r377 r402  
    251251                "password" : password, 
    252252               } 
    253         send_mail("New account on openPLM", [new_user], ctx, "mails/new_account")  
     253        self._send_mail(send_mail, "New account on openPLM", [new_user], 
     254                ctx, "mails/new_account")  
    254255        models.UserHistory.objects.create(action="Create", user=self._user, 
    255256                plmobject=self._user, details="New user: %s" % new_user.username) 
Note: See TracChangeset for help on using the changeset viewer.