Rajeesh Nair avatar Rajeesh Nair committed 1ea885c

Included post_moderation signal

Comments (0)

Files changed (13)

 Django-monitor: CHANGE LOG
 ==========================
 
+0.1.2
+=====
+* Django-monitor now generates a ``post_moderation`` signal whenever an object
+  is moderated. Developers can make use of this if they want to invoke some
+  function right after moderation. See ``docs/dev_howto.rst`` for details.
+
+0.1.1
+======
+
 * monitor now contains one more utility function, ``get_monitor_entry``.
   It will return the monitor_entry that corresponds to the given object.
   **Example**: ::
Add a comment to this file

docs/build/doctrees/dev_howto.doctree

Binary file modified.

Add a comment to this file

docs/build/doctrees/environment.pickle

Binary file modified.

Add a comment to this file

docs/build/html/_images/custom_changelist.jpg

Removed
Old image
Add a comment to this file

docs/build/html/_images/custom_changelist1.jpg

Removed
Old image

docs/build/html/_sources/dev_howto.txt

      >>> me.is_approved()
      ... True
 
+Post-moderation hook
+=====================
+
+If you want to perform something after an object is moderated, you can make use
+of the ``post_moderation`` signal as in the below **example**: ::
+
+    from monitor import post_moderation
+
+    # handler_func: The function to handle your post moderation activities.
+    def handler_func(sender, instance, **kwargs):
+        # sender: MyModel
+        # instance: my_model instance that was just moderated
+        # do whatever you want..
+        pass
+
+    # MyModel: The model whose moderation you are watching.
+    class MyModel(models.Model):
+        pass
+
+    post_moderation.connect(handler_func, sender = MyModel)
+
+Note that the object moderated will be passed as the ``instance`` and its model
+as the ``sender``. This will help you to write separate handlers for each model.
+

docs/build/html/dev_howto.html

 </pre></div>
 </div>
 </div>
+<div class="section" id="post-moderation-hook">
+<h2>Post-moderation hook<a class="headerlink" href="#post-moderation-hook" title="Permalink to this headline">¶</a></h2>
+<p>If you want to perform something after an object is moderated, you can make use
+of the <tt class="docutils literal"><span class="pre">post_moderation</span></tt> signal as in the below <strong>example</strong>:</p>
+<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">monitor</span> <span class="kn">import</span> <span class="n">post_moderation</span>
+
+<span class="c"># handler_func: The function to handle your post moderation activities.</span>
+<span class="k">def</span> <span class="nf">handler_func</span><span class="p">(</span><span class="n">sender</span><span class="p">,</span> <span class="n">instance</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
+    <span class="c"># sender: MyModel</span>
+    <span class="c"># instance: my_model instance that was just moderated</span>
+    <span class="c"># do whatever you want..</span>
+    <span class="k">pass</span>
+
+<span class="c"># MyModel: The model whose moderation you are watching.</span>
+<span class="k">class</span> <span class="nc">MyModel</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
+    <span class="k">pass</span>
+
+<span class="n">post_moderation</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="n">handler_func</span><span class="p">,</span> <span class="n">sender</span> <span class="o">=</span> <span class="n">MyModel</span><span class="p">)</span>
+</pre></div>
+</div>
+<p>Note that the object moderated will be passed as the <tt class="docutils literal"><span class="pre">instance</span></tt> and its model
+as the <tt class="docutils literal"><span class="pre">sender</span></tt>. This will help you to write separate handlers for each model.</p>
+</div>
 </div>
 
 
 <li><a class="reference internal" href="#special-model-admin-class">Special model-admin class</a></li>
 <li><a class="reference internal" href="#data-protection">Data-protection</a></li>
 <li><a class="reference internal" href="#creation-of-objects-by-code">Creation of objects by code</a></li>
+<li><a class="reference internal" href="#post-moderation-hook">Post-moderation hook</a></li>
 </ul>
 </li>
 </ul>

docs/build/html/index.html

 <li class="toctree-l2"><a class="reference internal" href="dev_howto.html#special-model-admin-class">Special model-admin class</a></li>
 <li class="toctree-l2"><a class="reference internal" href="dev_howto.html#data-protection">Data-protection</a></li>
 <li class="toctree-l2"><a class="reference internal" href="dev_howto.html#creation-of-objects-by-code">Creation of objects by code</a></li>
+<li class="toctree-l2"><a class="reference internal" href="dev_howto.html#post-moderation-hook">Post-moderation hook</a></li>
 </ul>
 </li>
 <li class="toctree-l1"><a class="reference internal" href="admin_howto.html">How to use (for admin-users)</a><ul>

docs/build/html/searchindex.js

-Search.setIndex({objects:{},terms:{all:[0,2,3],code:[0,1,3],shot:2,help:[1,3],just:3,show:3,tip:0,yourmodeladmin:0,approv:[0,2,3],model_nam:3,supplement:0,through:2,permiss:[2,3],follow:0,yet:3,paramet:0,current:[2,3],onli:[0,2,3],monitoradmin:0,monitor:[0,1,2,3],how:[0,1,2],field2:0,copi:3,field1:0,activ:2,written:0,should:3,add:[2,3],pend:[0,2,3],might:0,app:3,is_challeng:0,meant:3,applic:0,them:[2,3],sourc:3,everi:3,thei:[0,2],get:[0,2,3],python:3,reset_to_pend:0,repo:3,know:[0,1,2,3],"import":0,press:[2,3],now:[],requir:2,introduct:[1,3],term:3,like:[0,2],specif:3,edit:3,list:[0,1,2],"public":0,"default":[0,2],maintain:3,integr:3,contain:[],found:2,grab:3,get_monitor_entri:0,where:3,page:[1,3],view:[2,3],prevent:0,set:3,replac:0,creation:[0,1],some:[0,2,3],gatekeep:3,moderate_:3,is_approv:0,see:[0,2],search:1,pass:0,download:3,further:3,todo:[1,3],special:[0,1,2],index:1,statu:[0,1,2,3],appear:2,facil:3,section:0,abl:3,invok:0,content:1,delet:3,enough:[],version:3,leav:0,got:3,row:2,method:0,modeladmin:0,refer:[0,2],signatur:0,full:0,deriv:0,kei:0,screen:2,each:[0,2,3],usag:0,differ:[0,3],here:[0,3],job:3,arg1:0,let:0,distinguish:3,org:3,along:[0,3],after:[2,3],addit:3,box:2,protect:[0,1,3],is_pend:0,lock:3,admin:[0,1,2,3],manag:[0,2,3],filter:[2,3],related_nam:0,place:3,monitorentri:0,fals:0,charfield:0,chang:[0,1,2,3],mean:3,actviti:3,commonli:2,origin:[0,3],routin:3,own:3,onc:2,modul:1,within:[2,3],prefer:0,automat:3,right:2,non:2,path:3,instal:[1,3],installed_app:3,assum:0,your:[0,3],select:[2,3],given:2,rajeesh:3,modif:3,wai:3,area:3,associ:[0,3],support:0,regist:0,three:[0,3],dure:[0,3],name:[0,2,3],avail:0,few:2,max_length:0,includ:3,similarli:2,start:3,too:[0,2,3],from:[0,2,3],assign:2,option:[2,3],form:3,offer:3,club:3,notif:3,about:[0,1,3],specifi:[0,3],ani:[2,3],particular:[0,2],moder:[0,1,2,3],inlin:0,"true":0,former:0,those:[0,2,3],must:2,count:3,also:[2,3],none:0,bookadmin:0,my_inst:0,instanc:0,provid:[2,3],wish:0,monitor_entri:0,monitor_nam:0,displai:[2,3],project:3,column:[2,3],below:2,can:[0,1,2,3],abov:[0,2],foreignkei:0,your_model:0,more:[0,2],instead:0,would:2,want:[0,3],creat:[0,2,3],look:2,process:3,certain:0,challeng:[0,2,3],registr:[0,1,3],share:0,argument:0,indic:[1,2],repres:3,itself:[2,3],exist:[2,3],have:[0,3],tabl:1,need:3,seem:3,foreign:0,featur:[1,3],check:[0,2,3],everywher:3,again:2,readonly_field:[0,3],built:0,perform:[2,3],anoth:3,make:2,manager_nam:0,when:[0,3],same:3,reset:[2,3],note:0,field:[0,3],other:[0,2,3],build:0,which:[0,3],auto:3,verifi:[0,2],you:[0,2,3],prepar:0,rel_field:0,runtim:0,protected_field:[0,3],relat:[0,3],http:3,book:0,status_nam:0,clone:3,who:[1,2],correct:2,what:0,superus:2,action:[2,3],user:[0,1,2,3],mai:[0,2,3],develop:[0,1,3],custom:0,data:[0,1,3],"class":[0,1],bitbucket:3,appropri:[2,3],base_manag:0,choos:[2,3],directori:3,entri:[2,3],mymodel:0,well:3,object:[0,1,2,3],django:[0,1,2,3],changelist:[2,3],exampl:0,supplementinlin:0,thi:0,titl:[],model:[0,1,2,3],self:1,latest:3},objtypes:{},titles:["How to use (for developers)","Django-monitor self-help","How to use (for admin-users)","Introduction"],objnames:{},filenames:["dev_howto","index","admin_howto","intro"]})
+Search.setIndex({objects:{},terms:{all:[0,2,3],code:[0,1,3],shot:2,help:[0,1,3],just:[0,3],from:[0,2,3],when:[0,3],yourmodeladmin:0,approv:[0,2,3],model_nam:3,supplement:0,through:2,permiss:[2,3],follow:0,yet:3,row:2,whose:0,onli:[0,2,3],inlin:0,monitor:[0,1,2,3],field:[0,3],field2:0,copi:3,field1:0,activ:[0,2],should:3,add:[2,3],pend:[0,2,3],certain:0,must:2,might:0,modul:1,is_challeng:0,meant:3,reset:[2,3],non:2,sourc:3,everi:3,thei:[0,2],get:[0,2,3],fals:0,prefer:0,watch:0,repo:3,know:[0,1,2,3],got:3,press:[2,3],requir:2,introduct:[1,3],term:3,name:[0,2,3],specif:3,edit:3,signal:0,list:[0,1,2],method:0,separ:0,provid:[2,3],integr:3,each:[0,2,3],found:2,grab:3,get_monitor_entri:0,where:3,manag:[0,2,3],other:[0,2,3],view:[2,3],few:2,prevent:0,right:2,mai:[0,2,3],replac:0,creation:[0,1],some:[0,2,3],moderate_:3,is_approv:0,similarli:2,see:[0,2],connect:0,pass:0,download:3,further:3,todo:[1,3],special:[0,1,2],python:3,index:1,statu:[0,1,2,3],appear:2,assum:0,section:0,abl:3,below:[0,2],your:[0,3],content:1,delet:3,written:0,version:3,leav:0,directori:3,django:[0,1,2,3],"import":0,paramet:0,"public":0,modeladmin:0,refer:[0,2],signatur:0,full:0,deriv:0,kei:0,screen:2,usag:0,given:2,here:[0,3],like:[0,2],job:3,let:0,your_model:0,distinguish:3,org:3,gatekeep:3,handl:0,after:[0,2,3],addit:3,box:2,search:1,is_pend:0,column:[2,3],someth:0,current:[2,3],page:[1,3],filter:[2,3],related_nam:0,place:3,monitorentri:0,correct:2,charfield:0,chang:[0,1,2,3],mean:3,handler_func:0,commonli:2,origin:[0,3],readonly_field:[0,3],own:3,can:[0,1,2,3],onc:2,app:3,within:[2,3],reset_to_pend:0,automat:3,hook:[0,1],set:3,path:3,instal:[1,3],installed_app:3,facil:3,post:[0,1],select:[2,3],differ:[0,3],rajeesh:3,modif:3,would:2,area:3,data:[0,1,3],support:0,regist:0,three:[0,3],custom:0,avail:0,start:3,max_length:0,includ:3,arg1:0,show:3,challeng:[0,2,3],too:[0,2,3],"function":0,verifi:[0,2],assign:2,option:[2,3],form:3,manager_nam:0,club:3,handler:0,notif:3,protect:[0,1,3],specifi:[0,3],argument:0,indic:[1,2],particular:[0,2],rel_field:0,moder:[0,1,2,3],monitoradmin:0,"true":0,former:0,those:[0,2,3],sender:0,count:3,also:[2,3],none:0,bookadmin:0,my_inst:0,instanc:0,"default":[0,2],wish:0,monitor_entri:0,monitor_nam:0,displai:[2,3],exampl:0,project:3,admin:[0,1,2,3],invok:0,itself:[2,3],whatev:0,abov:[0,2],foreignkei:0,about:[0,1,3],more:[0,2],def:0,note:0,featur:[1,3],have:[0,3],creat:[0,2,3],look:2,process:3,lock:3,dure:[0,3],registr:[0,1,3],share:0,them:[2,3],changelist:[2,3],repres:3,wai:3,kwarg:0,exist:[2,3],want:[0,3],tabl:1,need:3,seem:3,foreign:0,routin:3,check:[0,2,3],everywher:3,again:2,develop:[0,1,3],built:0,perform:[0,2,3],anoth:3,self:1,offer:3,tip:0,same:3,write:0,how:[0,1,2],book:0,build:0,which:[0,3],auto:3,instead:0,you:[0,2,3],prepar:0,protected_field:[0,3],relat:[0,3],http:3,status_nam:0,clone:3,who:[1,2],my_model:0,what:0,superus:2,action:[2,3],user:[0,1,2,3],applic:0,along:[0,3],supplementinlin:0,associ:[0,3],"class":[0,1],bitbucket:3,appropri:[2,3],base_manag:0,ani:[2,3],entri:[2,3],mymodel:0,well:3,object:[0,1,2,3],actviti:3,post_moder:0,maintain:3,runtim:0,thi:0,choos:[2,3],model:[0,1,2,3],make:[0,2],latest:3},objtypes:{},titles:["How to use (for developers)","Django-monitor self-help","How to use (for admin-users)","Introduction"],objnames:{},filenames:["dev_howto","index","admin_howto","intro"]})

docs/source/dev_howto.rst

      >>> me.is_approved()
      ... True
 
+Post-moderation hook
+=====================
+
+If you want to perform something after an object is moderated, you can make use
+of the ``post_moderation`` signal as in the below **example**: ::
+
+    from monitor import post_moderation
+
+    # handler_func: The function to handle your post moderation activities.
+    def handler_func(sender, instance, **kwargs):
+        # sender: MyModel
+        # instance: my_model instance that was just moderated
+        # do whatever you want..
+        pass
+
+    # MyModel: The model whose moderation you are watching.
+    class MyModel(models.Model):
+        pass
+
+    post_moderation.connect(handler_func, sender = MyModel)
+
+Note that the object moderated will be passed as the ``instance`` and its model
+as the ``sender``. This will help you to write separate handlers for each model.
+

monitor/__init__.py

 __copyright__ = "Copyright (c) 2011 Rajeesh"
 __license__ = "BSD"
 
+from django.dispatch import Signal
 from django.db.models import signals
 
 from monitor.util import create_moderate_perms, add_fields, save_handler
             'monitor_name': monitor_name
         }
 
+post_moderation = Signal(providing_args = ["instance"])
+
 signals.post_syncdb.connect(
     create_moderate_perms,
     dispatch_uid = "django-monitor.create_moderate_perms"

monitor/models.py

             return self.content_object.get_absolute_url()
 
     def _moderate(self, status, user, notes = ''):
+        from monitor import post_moderation
         self.status = status
         self.status_by = user
         self.status_date = datetime.datetime.now()
         self.notes = notes
         self.save()
+        # post_moderation signal will be generated now with the associated
+        # object as the ``instance`` and its model as the ``sender``.
+        sender_model = self.content_type.model_class()
+        instance = self.content_object
+        post_moderation.send(sender = sender_model, instance = instance)
 
     def approve(self, user = None, notes = ''):
         """ Approve the object"""
 from setuptools import setup, find_packages
 import os
 
-version = '0.1.1'
+version = '0.1.2'
 
 setup(
     name = 'django-monitor',
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.