# HG changeset patch # User Brian Neal # Date 1257714931 0 # Node ID 3ae999b0c53bb559bda773c1d9e89a0cc3378772 # Parent b28d30848c57256ea8cbd75578c04f7737b35eaa Forums: added a jquery ui dialog of extra smileys. diff -r b28d30848c57 -r 3ae999b0c53b gpp/forums/forms.py --- a/gpp/forums/forms.py Tue Oct 27 02:56:16 2009 +0000 +++ b/gpp/forums/forms.py Sun Nov 08 21:15:31 2009 +0000 @@ -17,10 +17,12 @@ class Media: css = { - 'all': settings.GPP_THIRD_PARTY_CSS['markitup'], + 'all': (settings.GPP_THIRD_PARTY_CSS['markitup'] + + settings.GPP_THIRD_PARTY_CSS['jquery-ui']), } - js = settings.GPP_THIRD_PARTY_JS['markitup'] + \ - ('js/forums.js', ) + js = (settings.GPP_THIRD_PARTY_JS['markitup'] + + settings.GPP_THIRD_PARTY_JS['jquery-ui'] + + ('js/forums.js', )) def clean_topic_id(self): id = self.cleaned_data['topic_id'] @@ -55,10 +57,12 @@ class Media: css = { - 'all': settings.GPP_THIRD_PARTY_CSS['markitup'], + 'all': (settings.GPP_THIRD_PARTY_CSS['markitup'] + + settings.GPP_THIRD_PARTY_CSS['jquery-ui']), } - js = settings.GPP_THIRD_PARTY_JS['markitup'] + \ - ('js/forums.js', ) + js = (settings.GPP_THIRD_PARTY_JS['markitup'] + + settings.GPP_THIRD_PARTY_JS['jquery-ui'] + + ('js/forums.js', )) def __init__(self, user, forum, *args, **kwargs): super(NewTopicForm, self).__init__(*args, **kwargs) @@ -102,10 +106,12 @@ class Media: css = { - 'all': settings.GPP_THIRD_PARTY_CSS['markitup'], + 'all': (settings.GPP_THIRD_PARTY_CSS['markitup'] + + settings.GPP_THIRD_PARTY_CSS['jquery-ui']), } - js = settings.GPP_THIRD_PARTY_JS['markitup'] + \ - ('js/forums.js', ) + js = (settings.GPP_THIRD_PARTY_JS['markitup'] + + settings.GPP_THIRD_PARTY_JS['jquery-ui'] + + ('js/forums.js', )) class MoveTopicForm(forms.Form): diff -r b28d30848c57 -r 3ae999b0c53b gpp/forums/views.py --- a/gpp/forums/views.py Tue Oct 27 02:56:16 2009 +0000 +++ b/gpp/forums/views.py Sun Nov 08 21:15:31 2009 +0000 @@ -292,6 +292,8 @@ else: form = PostForm(instance=post) + post.user_profile = request.user.get_profile() + return render_to_response('forums/edit_post.html', { 'forum': post.topic.forum, 'topic': post.topic, diff -r b28d30848c57 -r 3ae999b0c53b gpp/smiley/admin.py --- a/gpp/smiley/admin.py Tue Oct 27 02:56:16 2009 +0000 +++ b/gpp/smiley/admin.py Sun Nov 08 21:15:31 2009 +0000 @@ -6,6 +6,6 @@ from smiley.models import Smiley class SmileyAdmin(admin.ModelAdmin): - list_display = ('title', 'code', 'html') + list_display = ('title', 'code', 'html', 'is_extra') admin.site.register(Smiley, SmileyAdmin) diff -r b28d30848c57 -r 3ae999b0c53b gpp/smiley/models.py --- a/gpp/smiley/models.py Tue Oct 27 02:56:16 2009 +0000 +++ b/gpp/smiley/models.py Sun Nov 08 21:15:31 2009 +0000 @@ -2,34 +2,38 @@ Models for the smiley application. """ from django.db import models +from django.core.cache import cache + +CACHE_TIMEOUT = 60 * 5 # seconds class SmileyManager(models.Manager): - smiley_map = None - smilies = None def get_smiley_map(self): - if self.smiley_map is None: - smilies = self.all() - self.smiley_map = {} - for s in smilies: - self.smiley_map[s.code] = s.html() - return self.smiley_map + map = cache.get('smiley_map') + if map: + return map - def get_smilies(self): - if self.smilies is None: - self.smilies = self.all() - return self.smilies + map = dict((s.code, s.html()) for s in self.all()) + cache.set('smiley_map', map, CACHE_TIMEOUT) + return map - def clear_cache(self): - self.smiley_map = None - self.smilies = None + def get_smilies(self, extra=False): + key = 'smileys' if not extra else 'smileys_extra' + smilies = cache.get(key) + if smilies: + return smilies + + smilies = self.filter(is_extra=extra) + cache.set(key, smilies, CACHE_TIMEOUT) + return smilies class Smiley(models.Model): image = models.ImageField(upload_to='smiley/images/') title = models.CharField(max_length=32) code = models.CharField(max_length=32) + is_extra = models.BooleanField() objects = SmileyManager() @@ -45,8 +49,8 @@ def html(self): if self.image: - return u'%s' % \ - (self.get_absolute_url(), self.title, self.title) + return (u'%s' % + (self.get_absolute_url(), self.title, self.title)) return u'' html.allow_tags = True diff -r b28d30848c57 -r 3ae999b0c53b gpp/smiley/urls.py --- a/gpp/smiley/urls.py Tue Oct 27 02:56:16 2009 +0000 +++ b/gpp/smiley/urls.py Sun Nov 08 21:15:31 2009 +0000 @@ -6,4 +6,5 @@ urlpatterns = patterns('smiley.views', url(r'^farm/$', 'farm', name='smiley-farm'), + url(r'^farm/extra/$', 'farm', kwargs={'extra': True}, name='smiley-farm_extra'), ) diff -r b28d30848c57 -r 3ae999b0c53b gpp/smiley/views.py --- a/gpp/smiley/views.py Tue Oct 27 02:56:16 2009 +0000 +++ b/gpp/smiley/views.py Sun Nov 08 21:15:31 2009 +0000 @@ -10,10 +10,9 @@ @login_required @require_GET -def farm(request): +def farm(request, extra=False): return render_to_response('smiley/smiley_farm.html', { - 'smilies': Smiley.objects.get_smilies(), + 'smilies': Smiley.objects.get_smilies(extra), }, context_instance = RequestContext(request)) -# vim: ts=4 sw=4 diff -r b28d30848c57 -r 3ae999b0c53b gpp/templates/forums/edit_post.html --- a/gpp/templates/forums/edit_post.html Tue Oct 27 02:56:16 2009 +0000 +++ b/gpp/templates/forums/edit_post.html Sun Nov 08 21:15:31 2009 +0000 @@ -20,8 +20,13 @@
Edit Post {{ form.as_p }} + +More smileys
+
+Loading +
{% endblock %} diff -r b28d30848c57 -r 3ae999b0c53b gpp/templates/forums/new_post.html --- a/gpp/templates/forums/new_post.html Tue Oct 27 02:56:16 2009 +0000 +++ b/gpp/templates/forums/new_post.html Sun Nov 08 21:15:31 2009 +0000 @@ -17,10 +17,15 @@
New Post {{ form.as_p }} + +More smileys
+
+Loading +
{% else %} {% if topic.locked %}

This topic is locked.

diff -r b28d30848c57 -r 3ae999b0c53b gpp/templates/forums/new_topic.html --- a/gpp/templates/forums/new_topic.html Tue Oct 27 02:56:16 2009 +0000 +++ b/gpp/templates/forums/new_topic.html Sun Nov 08 21:15:31 2009 +0000 @@ -11,7 +11,13 @@
{{ form.as_p }} + +More smileys
+
+Loading +
+ {% endblock %} diff -r b28d30848c57 -r 3ae999b0c53b gpp/templates/forums/topic.html --- a/gpp/templates/forums/topic.html Tue Oct 27 02:56:16 2009 +0000 +++ b/gpp/templates/forums/topic.html Sun Nov 08 21:15:31 2009 +0000 @@ -58,9 +58,14 @@
Reply to "{{ topic.name }}" {{ form.as_p }} + +More smileys
+
+Loading +
{% endif %} {% endblock %} diff -r b28d30848c57 -r 3ae999b0c53b gpp/templates/smiley/smiley_farm.html --- a/gpp/templates/smiley/smiley_farm.html Tue Oct 27 02:56:16 2009 +0000 +++ b/gpp/templates/smiley/smiley_farm.html Sun Nov 08 21:15:31 2009 +0000 @@ -1,6 +1,5 @@
{% for s in smilies %} - {{ s.code }} +{{ s.code }} {% endfor %}
diff -r b28d30848c57 -r 3ae999b0c53b media/icons/emoticon_smile.png Binary file media/icons/emoticon_smile.png has changed diff -r b28d30848c57 -r 3ae999b0c53b media/js/forums.js --- a/media/js/forums.js Tue Oct 27 02:56:16 2009 +0000 +++ b/media/js/forums.js Sun Nov 08 21:15:31 2009 +0000 @@ -83,4 +83,31 @@ 'WARNING: all posts will be lost.'); }); $('#id_body').markItUp(mySettings); + $('#smileys_dialog').dialog({autoOpen:false}); + var firstTime = true; + $('#more_smileys').click(function () { + $('#smileys_dialog').dialog('open'); + var postBox = $('#id_body')[0]; + if (firstTime) { + $.ajax({ + url: '/smiley/farm/extra/', + type: 'GET', + dataType: 'html', + success: function(data, textStatus) { + var img = $('#smiley_busy'); + img.hide(); + img.after(data); + $('#smileys_dialog .smiley_farm img').click(function() { + postBox.value += ' ' + this.alt + ' '; + postBox.focus(); + }); + firstTime = false; + }, + error: function (xhr, textStatus, ex) { + alert('Oops, an error occurred: ' + xhr.statusText + ' - ' + xhr.responseText); + } + }); + } + return false; + }); }); diff -r b28d30848c57 -r 3ae999b0c53b media/js/shoutbox.js --- a/media/js/shoutbox.js Tue Oct 27 02:56:16 2009 +0000 +++ b/media/js/shoutbox.js Sun Nov 08 21:15:31 2009 +0000 @@ -28,15 +28,13 @@ if (!smilies_loaded) { smiley_frame.load('/smiley/farm/', function () { $('#shoutbox-busy-icon').hide(); + var txt = $("#shoutbox-smiley-input")[0]; + $('#shoutbox-smiley-frame img').click(function() { + txt.value += ' ' + this.alt + ' '; + txt.focus(); + }); smilies_loaded = true; }); } }); }); - -function sb_smiley_click(code) -{ - var txt = document.getElementById("shoutbox-smiley-input"); - txt.value += code; - txt.focus(); -}