Commits

Igor Katson  committed d4a3916

Moved everything to "aloha" dir

  • Participants
  • Parent commits b0cf8c6

Comments (0)

Files changed (16)

File __init__.py

-

File aloha/__init__.py

+

File aloha/templates/aloha/includes/css.html

+{% if request.user.is_staff %}
+  <link rel="stylesheet" href="{{ MEDIA_URL }}js/aloha/css/aloha.css"/>
+{% endif %}

File aloha/templates/aloha/includes/js.html

+{% block aloha %}
+  {% if request.user.is_staff %}
+  <script type="text/javascript">
+    Aloha = {}; Aloha.settings = {};
+    Aloha.settings.baseUrl = '{{ MEDIA_URL }}js/aloha/lib/';
+    Aloha.settings.locale = 'en';
+  </script>
+
+  <script type="text/javascript" src="{{ MEDIA_URL }}js/aloha/lib/aloha.js" data-aloha-plugins="common/format,common/link,common/image,common/list,common/undo,common/paste"></script>
+  <script type="text/javascript">
+    Aloha.ready(function () {
+        Aloha.jQuery('.aloha-editable').aloha();
+	$('form.aloha').click(function() {
+	    $(this).find('input[name="save-content"]').show();
+	});
+        $('form.aloha input[name="save-content"]').click(function () {
+	    var form = $(this).parent();
+	    var hidden_content = $('<input type="hidden" name="content"/>');
+	    hidden_content.val(form.find('.aloha-editable').html());
+	    form.append(hidden_content);
+	    form.submit();
+	});
+    })
+  </script>
+  {% endif %}
+{% endblock %}

File aloha/templates/aloha/postform.html

+{% load i18n %}
+
+<form class="aloha" method="post" action="{% url aloha_save_content %}">
+  <div class="aloha-editable">
+    {{ content|safe }}
+  </div>
+  {% csrf_token %}
+  <input type="hidden" name="field_name" value="{{ field_name }}"/>
+  <input type="hidden" name="object_name" value="{{ object_name }}"/>
+  <input type="hidden" name="object_pk" value="{{ object_pk }}"/>
+  <input type="hidden" name="next" value="{{ request.path }}"/>
+  <input type="submit" style="display:none" value=""/>
+  <input type="button" name="save-content" style="display: none;" value="{% trans 'Save' %}" />
+</form>

File aloha/templatetags/__init__.py

Empty file added.

File aloha/templatetags/aloha_tags.py

+from django import template
+from django.template.loader import render_to_string
+from django.db import models
+
+register = template.Library()
+
+class AlohaNode(template.Node):
+
+    def __init__(self, nodelist, obj, field_name):
+        self.obj = template.Variable(obj)
+        self.field_name = template.Variable(field_name)
+        self.nodelist = nodelist
+
+    def render(self, context):
+        inner_content = self.nodelist.render(context)
+        if not context['request'].user.is_staff:
+            return inner_content
+
+        obj = self.obj.resolve(context)
+        assert isinstance(obj, models.Model), 'The object passed to aloha tag should be a django model'
+        field_name = self.field_name.resolve(context)
+        assert isinstance(field_name, basestring), 'The field name passed to aloha tag should be a string'
+
+        object_name = '%s.%s' % (obj._meta.app_label, obj._meta.object_name)
+
+        assert hasattr(obj, 'pk') and obj.pk, 'The model "%s" doesn\'t have a primary key, it cannot be used with aloha tag'
+        context.update({
+            'object_name': object_name,
+            'object_pk': obj.pk,
+            'field_name': field_name,
+            'content': inner_content,
+        })
+        result = render_to_string('aloha/postform.html', context_instance=context)
+        context.pop()
+        return result
+ 
+
+@register.tag('aloha')
+def aloha(parser, token):
+    try:
+        tag_name, obj, field_name = token.split_contents()
+    except ValueError:
+        raise template.TemplateSyntaxError("Aloha tag requires 2 arguments: a django object, and a field name")
+    nodelist = parser.parse(('endaloha',))
+    parser.delete_first_token()
+    return AlohaNode(nodelist, obj, field_name)

File aloha/urls.py

+from django.conf.urls.defaults import *
+
+urlpatterns = patterns('aloha.views',
+    url('^save/$', 'save', name='aloha_save_content'),
+)

File aloha/views.py

+# coding: utf-8
+
+from django.contrib.auth.decorators import login_required
+from django.db.models import get_model
+from django.http import HttpResponseBadRequest, HttpResponseForbidden, HttpResponseRedirect
+from django.views.decorators.http import require_POST
+from django.shortcuts import get_object_or_404
+from django.utils.translation import ugettext as _
+from django.contrib import messages
+
+
+@login_required
+@require_POST
+def save(request):
+    """Save the field contents for the object"""
+
+    def show_message(msg, level=messages.ERROR):
+        messages.add_message(request, level, msg)
+        return HttpResponseRedirect(request.POST.get('next', '/'))
+
+    # TODO: check permissions better
+    if not request.user.is_staff:
+        return HttpResponseForbidden()
+    try:
+        app_label, model_name = request.POST['object_name'].split('.')
+    except ValueError, e:
+        return show_message(_('Cannot find the model'))
+
+    model = get_model(app_label, model_name)
+    if not model:
+        return show_message(_('Cannot find the model'))
+
+    field_name = request.POST.get('field_name')
+    if (field_name and hasattr(model, field_name)):
+        return show_message(_('No field_name parameter'))
+
+    try:
+        contents = request.POST['content']
+    except KeyError:
+        return show_message(_('No contents parameter provided'))
+
+    try:
+        obj = model.objects.get(pk=request.POST['object_pk'])
+    except KeyError:
+        return show_message(_('object_pk not provided'))
+    except model.DoesNotExist:
+        return show_message(_('Cannot find the object with this primary key'))
+
+    setattr(obj, field_name, contents)
+    obj.save()
+
+    return show_message(_('Object saved'), messages.SUCCESS)

File templates/aloha/includes/css.html

-{% if request.user.is_staff %}
-  <link rel="stylesheet" href="{{ MEDIA_URL }}js/aloha/css/aloha.css"/>
-{% endif %}

File templates/aloha/includes/js.html

-{% block aloha %}
-  {% if request.user.is_staff %}
-  <script type="text/javascript">
-    Aloha = {}; Aloha.settings = {};
-    Aloha.settings.baseUrl = '{{ MEDIA_URL }}js/aloha/lib/';
-    Aloha.settings.locale = 'en';
-  </script>
-
-  <script type="text/javascript" src="{{ MEDIA_URL }}js/aloha/lib/aloha.js" data-aloha-plugins="common/format,common/link,common/image,common/list,common/undo,common/paste"></script>
-  <script type="text/javascript">
-    Aloha.ready(function () {
-        Aloha.jQuery('.aloha-editable').aloha();
-	$('form.aloha').click(function() {
-	    $(this).find('input[name="save-content"]').show();
-	});
-        $('form.aloha input[name="save-content"]').click(function () {
-	    var form = $(this).parent();
-	    var hidden_content = $('<input type="hidden" name="content"/>');
-	    hidden_content.val(form.find('.aloha-editable').html());
-	    form.append(hidden_content);
-	    form.submit();
-	});
-    })
-  </script>
-  {% endif %}
-{% endblock %}

File templates/aloha/postform.html

-{% load i18n %}
-
-<form class="aloha" method="post" action="{% url aloha_save_content %}">
-  <div class="aloha-editable">
-    {{ content|safe }}
-  </div>
-  {% csrf_token %}
-  <input type="hidden" name="field_name" value="{{ field_name }}"/>
-  <input type="hidden" name="object_name" value="{{ object_name }}"/>
-  <input type="hidden" name="object_pk" value="{{ object_pk }}"/>
-  <input type="hidden" name="next" value="{{ request.path }}"/>
-  <input type="submit" style="display:none" value=""/>
-  <input type="button" name="save-content" style="display: none;" value="{% trans 'Save' %}" />
-</form>

File templatetags/__init__.py

Empty file removed.

File templatetags/aloha_tags.py

-from django import template
-from django.template.loader import render_to_string
-from django.db import models
-
-register = template.Library()
-
-class AlohaNode(template.Node):
-
-    def __init__(self, nodelist, obj, field_name):
-        self.obj = template.Variable(obj)
-        self.field_name = template.Variable(field_name)
-        self.nodelist = nodelist
-
-    def render(self, context):
-        inner_content = self.nodelist.render(context)
-        if not context['request'].user.is_staff:
-            return inner_content
-
-        obj = self.obj.resolve(context)
-        assert isinstance(obj, models.Model), 'The object passed to aloha tag should be a django model'
-        field_name = self.field_name.resolve(context)
-        assert isinstance(field_name, basestring), 'The field name passed to aloha tag should be a string'
-
-        object_name = '%s.%s' % (obj._meta.app_label, obj._meta.object_name)
-
-        assert hasattr(obj, 'pk') and obj.pk, 'The model "%s" doesn\'t have a primary key, it cannot be used with aloha tag'
-        context.update({
-            'object_name': object_name,
-            'object_pk': obj.pk,
-            'field_name': field_name,
-            'content': inner_content,
-        })
-        result = render_to_string('aloha/postform.html', context_instance=context)
-        context.pop()
-        return result
- 
-
-@register.tag('aloha')
-def aloha(parser, token):
-    try:
-        tag_name, obj, field_name = token.split_contents()
-    except ValueError:
-        raise template.TemplateSyntaxError("Aloha tag requires 2 arguments: a django object, and a field name")
-    nodelist = parser.parse(('endaloha',))
-    parser.delete_first_token()
-    return AlohaNode(nodelist, obj, field_name)

File urls.py

-from django.conf.urls.defaults import *
-
-urlpatterns = patterns('aloha.views',
-    url('^save/$', 'save', name='aloha_save_content'),
-)

File views.py

-# coding: utf-8
-
-from django.contrib.auth.decorators import login_required
-from django.db.models import get_model
-from django.http import HttpResponseBadRequest, HttpResponseForbidden, HttpResponseRedirect
-from django.views.decorators.http import require_POST
-from django.shortcuts import get_object_or_404
-from django.utils.translation import ugettext as _
-from django.contrib import messages
-
-
-@login_required
-@require_POST
-def save(request):
-    """Save the field contents for the object"""
-
-    def show_message(msg, level=messages.ERROR):
-        messages.add_message(request, level, msg)
-        return HttpResponseRedirect(request.POST.get('next', '/'))
-
-    # TODO: check permissions better
-    if not request.user.is_staff:
-        return HttpResponseForbidden()
-    try:
-        app_label, model_name = request.POST['object_name'].split('.')
-    except ValueError, e:
-        return show_message(_('Cannot find the model'))
-
-    model = get_model(app_label, model_name)
-    if not model:
-        return show_message(_('Cannot find the model'))
-
-    field_name = request.POST.get('field_name')
-    if (field_name and hasattr(model, field_name)):
-        return show_message(_('No field_name parameter'))
-
-    try:
-        contents = request.POST['content']
-    except KeyError:
-        return show_message(_('No contents parameter provided'))
-
-    try:
-        obj = model.objects.get(pk=request.POST['object_pk'])
-    except KeyError:
-        return show_message(_('object_pk not provided'))
-    except model.DoesNotExist:
-        return show_message(_('Cannot find the object with this primary key'))
-
-    setattr(obj, field_name, contents)
-    obj.save()
-
-    return show_message(_('Object saved'), messages.SUCCESS)