Mercurial > public > sg101
annotate weblinks/signals.py @ 693:ad69236e8501
For issue #52, update many 3rd party Javascript libraries.
Updated to jquery 1.10.2, jquery ui 1.10.3.
This broke a lot of stuff.
- Found a newer version of the jquery cycle all plugin (3.0.3).
- Updated JPlayer to 2.4.0.
- Updated to MarkItUp 1.1.14. This also required me to add multiline attributes
set to true on various buttons in the markdown set.
- As per a stackoverflow post, added some code to get multiline titles in
a jQuery UI dialog. They removed that functionality but allow you to put it
back.
Tweaked the MarkItUp preview CSS to show blockquotes in italic.
Did not update TinyMCE at this time. I'm not using the JQuery version and this
version appears to work ok for now.
What I should do is make a repo for MarkItUp and do a vendor branch thing so
I don't have to futz around diffing directories to figure out if I'll lose
changes when I update.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 04 Sep 2013 19:55:20 -0500 |
parents | ee87ea74d46b |
children |
rev | line source |
---|---|
bgneal@202 | 1 """Signals for the weblinks application. |
bgneal@202 | 2 We use signals to compute the denormalized category counts whenever a weblink |
bgneal@202 | 3 is saved.""" |
bgneal@202 | 4 from django.db.models.signals import post_save |
bgneal@202 | 5 from django.db.models.signals import post_delete |
bgneal@202 | 6 |
bgneal@202 | 7 from weblinks.models import Category, Link |
bgneal@202 | 8 |
bgneal@202 | 9 |
bgneal@202 | 10 def on_link_save(sender, **kwargs): |
bgneal@202 | 11 """This function updates the count field for all categories. |
bgneal@202 | 12 It is called whenever a link is saved via a signal. |
bgneal@202 | 13 """ |
bgneal@202 | 14 if kwargs['created']: |
bgneal@202 | 15 # we only have to update the parent category |
bgneal@202 | 16 link = kwargs['instance'] |
bgneal@202 | 17 cat = link.category |
bgneal@202 | 18 cat.count = Link.public_objects.filter(category=cat).count() |
bgneal@202 | 19 cat.save() |
bgneal@202 | 20 else: |
bgneal@202 | 21 # update all categories just to be safe (an existing link could |
bgneal@202 | 22 # have been moved from one category to another |
bgneal@202 | 23 cats = Category.objects.all() |
bgneal@202 | 24 for cat in cats: |
bgneal@202 | 25 cat.count = Link.public_objects.filter(category=cat).count() |
bgneal@202 | 26 cat.save() |
bgneal@202 | 27 |
bgneal@202 | 28 |
bgneal@202 | 29 def on_link_delete(sender, **kwargs): |
bgneal@202 | 30 """This function updates the count field for the link's parent |
bgneal@202 | 31 category. It is called when a link is deleted via a signal. |
bgneal@202 | 32 """ |
bgneal@202 | 33 # update the parent category |
bgneal@202 | 34 link = kwargs['instance'] |
bgneal@202 | 35 cat = link.category |
bgneal@202 | 36 cat.count = Link.public_objects.filter(category=cat).count() |
bgneal@202 | 37 cat.save() |
bgneal@202 | 38 |
bgneal@202 | 39 |
bgneal@260 | 40 post_save.connect(on_link_save, sender=Link, dispatch_uid='weblinks.signals') |
bgneal@260 | 41 post_delete.connect(on_link_delete, sender=Link, dispatch_uid='weblinks.signals') |