summaryrefslogtreecommitdiff
path: root/apps/blog/signals.py
diff options
context:
space:
mode:
Diffstat (limited to 'apps/blog/signals.py')
-rw-r--r--apps/blog/signals.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/apps/blog/signals.py b/apps/blog/signals.py
new file mode 100644
index 0000000..0f3c9c4
--- /dev/null
+++ b/apps/blog/signals.py
@@ -0,0 +1,34 @@
+from django.template.loader import render_to_string
+from django.conf import settings
+from django.template import Context
+from django.db.models import get_model
+
+from locations.models import Region,Country
+
+def update_recent(sender, instance, signal, *args, **kwargs):
+ # Update recent entries static file
+ model = get_model('blog', 'entry')
+ qs = {'object_list': model.objects.filter(status__exact=1).order_by('-pub_date')[1:6]}
+ c = Context(qs)
+ t = render_to_string('includes/recent_entries_template.html',c)
+ fpath = '%s%s' %(settings.PROJ_ROOT,'templates/includes/recent_entries.html')
+ file = open(fpath, 'w')
+ file.write(t)
+ file.close()
+ # Update map template
+ import codecs
+ qs = model.objects.filter(status__exact=1)
+ cl = Country.objects.filter(visited=True).exclude(name='default')
+ rl = Region.objects.all()
+ c = Context({'object_list':qs, 'country_list':cl,'region_list':rl})
+ t = render_to_string('includes/map_entry_list_template.html',c)
+ fpath = '%s%s' %(settings.PROJ_ROOT,'templates/includes/map_entry_list.html')
+ file = codecs.open(fpath, 'w','utf8')
+ file.write(t)
+ file.close()
+ c = Context({'country_list':cl,'region_list':rl})
+ t = render_to_string('includes/map_sidebar_template.html',c)
+ fpath = '%s%s' %(settings.PROJ_ROOT,'templates/includes/map_sidebar.html')
+ file = codecs.open(fpath, 'w','utf8')
+ file.write(t)
+ file.close() \ No newline at end of file