Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit e9578232a873a7ea32ea67f8c55e952d970af508 @severb severb committed Oct 5, 2011
@@ -0,0 +1,2 @@
+include README.rst
+recursive-include cms_templates/templates *.html
No changes.
No changes.
@@ -0,0 +1,68 @@
+from django.contrib import admin
+from django.contrib.admin.sites import NotRegistered
+from django.contrib.sites.models import Site
+from django.db.models import Q
+
+from dbtemplates.admin import TemplateAdmin
+from dbtemplates.models import Template
+from cms.models import GlobalPagePermission
+
+
+class RestrictedTemplateAdmin(TemplateAdmin):
+
+ list_filter = ('sites__name', )
+ change_form_template = 'cms_templates/change_form.html'
+
+
+ def formfield_for_manytomany(self, db_field, request, **kwargs):
+ if db_field.name == "sites":
+ kwargs["queryset"] = self._available_sites(request.user)
+ return super(TemplateAdmin, self).formfield_for_manytomany(db_field, request, **kwargs)
+
+ def _available_sites(self, user):
+ q = Site.objects.all()
+ if not user.is_superuser:
+ global_pages = GlobalPagePermission.objects.filter(user=user)
+ q = Site.objects.filter(globalpagepermission__in=global_pages)
+ return q.distinct()
+
+ def queryset(self, request):
+ q = super(TemplateAdmin, self).queryset(request)
+ return q.filter(
+ Q(sites__in=self._available_sites(request.user)) |
+ Q(sites=Site.objects.get(name='PBS'))
+ ).distinct()
+
+ def get_readonly_fields(self, request, obj=None):
+ ro = ['name', 'content', 'sites', 'creation_date', 'last_changed']
+ if not obj or request.user.is_superuser:
+ return []
+ s = Site.objects.get(name='PBS')
+ if s in obj.sites.all():
+ return ro
+ return []
+
+ def has_delete_permission(self, request, obj=None):
+ if not obj or request.user.is_superuser:
+ return True
+ s = Site.objects.get(name='PBS')
+ if s in obj.sites.all():
+ return False
+ return True
+
+ def change_view(self, request, object_id, extra_context=None):
+ extra_context = {}
+ if not request.user.is_superuser:
+ t = Template.objects.get(pk=object_id)
+ s = Site.objects.get(name='PBS')
+ if s in t.sites.all():
+ extra_context = {'read_only': True}
+ return super(RestrictedTemplateAdmin, self).change_view(request,
+ object_id, extra_context=extra_context)
+
+
+try:
+ admin.site.unregister(Template)
+except NotRegistered:
+ pass
+admin.site.register(Template, RestrictedTemplateAdmin)
@@ -0,0 +1,3 @@
+from django.db import models
+
+# Create your models here.
@@ -0,0 +1,77 @@
+{% extends "admin/base_site.html" %}
+{% load i18n admin_modify adminmedia %}
+{% load url from future %}
+
+{% block extrahead %}{{ block.super }}
+{% url 'admin:jsi18n' as jsi18nurl %}
+<script type="text/javascript" src="{{ jsi18nurl|default:"../../../jsi18n/" }}"></script>
+{{ media }}
+{% endblock %}
+
+{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% admin_media_prefix %}css/forms.css" />{% endblock %}
+
+{% block coltype %}{% if ordered_objects %}colMS{% else %}colM{% endif %}{% endblock %}
+
+{% block bodyclass %}{{ opts.app_label }}-{{ opts.object_name.lower }} change-form{% endblock %}
+
+{% block breadcrumbs %}{% if not is_popup %}
+<div class="breadcrumbs">
+ <a href="../../../">{% trans "Home" %}</a> &rsaquo;
+ <a href="../../">{{ app_label|capfirst|escape }}</a> &rsaquo;
+ {% if has_change_permission %}<a href="../">{{ opts.verbose_name_plural|capfirst }}</a>{% else %}{{ opts.verbose_name_plural|capfirst }}{% endif %} &rsaquo;
+ {% if add %}{% trans "Add" %} {{ opts.verbose_name }}{% else %}{{ original|truncatewords:"18" }}{% endif %}
+</div>
+{% endif %}{% endblock %}
+
+{% block content %}<div id="content-main">
+{% block object-tools %}
+{% if change %}{% if not is_popup %}
+ <ul class="object-tools">
+ {% block object-tools-items %}
+ <li><a href="history/" class="historylink">{% trans "History" %}</a></li>
+ {% if has_absolute_url %}<li><a href="../../../r/{{ content_type_id }}/{{ object_id }}/" class="viewsitelink">{% trans "View on site" %}</a></li>{% endif%}
+ {% endblock %}
+ </ul>
+{% endif %}{% endif %}
+{% endblock %}
+<form {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="{{ form_url }}" method="post" id="{{ opts.module_name }}_form">{% csrf_token %}{% block form_top %}{% endblock %}
+<div>
+{% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %}
+{% if save_on_top %}{% submit_row %}{% endif %}
+{% if errors %}
+ <p class="errornote">
+ {% blocktrans count errors|length as counter %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %}
+ </p>
+ {{ adminform.form.non_field_errors }}
+{% endif %}
+
+{% for fieldset in adminform %}
+ {% include "cms_templates/fieldset.html" %}
+{% endfor %}
+
+{% block after_field_sets %}{% endblock %}
+
+{% for inline_admin_formset in inline_admin_formsets %}
+ {% include inline_admin_formset.opts.template %}
+{% endfor %}
+
+{% block after_related_objects %}{% endblock %}
+
+{% if read_only %}
+<div class="submit-row">
+ <a style="float:right; padding:10px" href="../">Back to Templates</a>
+</div>
+{% else %}
+ {% submit_row %}
+{% endif %}
+
+{% if adminform and add %}
+ <script type="text/javascript">document.getElementById("{{ adminform.first_field.id_for_label }}").focus();</script>
+{% endif %}
+
+{# JavaScript for prepopulated fields #}
+{% prepopulated_fields_js %}
+
+</div>
+</form></div>
+{% endblock %}
@@ -0,0 +1,46 @@
+<fieldset class="module aligned {{ fieldset.classes }}">
+ {% if fieldset.name %}<h2>{{ fieldset.name }}</h2>{% endif %}
+ {% if fieldset.description %}
+ <div class="description">{{ fieldset.description|safe }}</div>
+ {% endif %}
+ {% for line in fieldset %}
+ <div class="form-row{% if line.fields|length_is:'1' and line.errors %} errors{% endif %}{% for field in line %} {{ field.field.name }}{% endfor %}">
+ {% if line.fields|length_is:'1' %}{{ line.errors }}{% endif %}
+ {% for field in line %}
+ <div{% if not line.fields|length_is:'1' %} class="field-box{% if not field.is_readonly and field.errors %} errors{% endif %}"{% endif %}>
+ {% if not line.fields|length_is:'1' and not field.is_readonly %}{{ field.errors }}{% endif %}
+ {% if field.is_checkbox %}
+ {{ field.field }}{{ field.label_tag }}
+ {% else %}
+ {{ field.label_tag }}
+ {% if field.is_readonly %}
+ {% if field.field.name == "content" %}
+ <textarea id=template_preview>{{ field.contents }}</textarea>
+ <script type="text/javascript">
+ var editor = CodeMirror.fromTextArea('template_preview', {
+ path: "{{STATIC_URL}}dbtemplates/js/",
+ parserfile: "parsedjango.js",
+ stylesheet: "{{STATIC_URL}}dbtemplates/css/django.css",
+ continuousScanning: 500,
+ height: "40.2em",
+ tabMode: "shift",
+ indentUnit: 4,
+ lineNumbers: true,
+ readOnly: 'nocursor',
+ });
+ </script>
+ {% else %}
+ <p>{{ field.contents }}</p>
+ {% endif %}
+ {% else %}
+ {{ field.field }}
+ {% endif %}
+ {% endif %}
+ {% if field.field.help_text and not field.is_readonly %}
+ <p class="help">{{ field.field.help_text|safe }}</p>
+ {% endif %}
+ </div>
+ {% endfor %}
+ </div>
+ {% endfor %}
+</fieldset>
@@ -0,0 +1,16 @@
+"""
+This file demonstrates writing tests using the unittest module. These will pass
+when you run "manage.py test".
+
+Replace this with more appropriate tests for your application.
+"""
+
+from django.test import TestCase
+
+
+class SimpleTest(TestCase):
+ def test_basic_addition(self):
+ """
+ Tests that 1 + 1 always equals 2.
+ """
+ self.assertEqual(1 + 1, 2)
@@ -0,0 +1 @@
+# Create your views here.
@@ -0,0 +1,28 @@
+#!/usr/bin/env python
+import os
+from setuptools import setup, find_packages
+
+README_PATH = os.path.join(os.path.abspath(os.path.dirname(__file__)),
+ 'README.rst')
+
+dependencies = [
+ 'django-dbtemplates',
+ 'django-cms==2.2',
+]
+
+dependency_links = [
+]
+
+setup(
+ name='django-cms-dbtemplates',
+ version='0.1',
+ description='Integrate django-cms and django-dbtemplates',
+ long_description = open(README_PATH, 'r').read(),
+ author='Sever Banesiu',
+ author_email='banesiu.sever@gmail.com',
+ url='https://github.com/pbs/django-cms-dbtemplates',
+ packages = find_packages(),
+ include_package_data=True,
+ install_requires = dependencies,
+ dependency_links = dependency_links,
+)

0 comments on commit e957823

Please sign in to comment.