Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'treeadmin' into develop

  • Loading branch information...
commit 165a37e9bd32d85483ab2efd61f36ff899d19240 2 parents 2c8bddb + 47d382b
@evildmp authored
Showing with 146 additions and 689 deletions.
  1. +1 −0  REQUIREMENTS.txt
  2. +1 −1  arkestra_utilities/generic_models.py
  3. +75 −55 contacts_and_people/admin.py
  4. +25 −11 contacts_and_people/models.py
  5. +0 −133 contacts_and_people/templates/admin/contacts_and_people/entity/change_list.html
  6. +0 −20 contacts_and_people/templates/admin/contacts_and_people/entity/change_list_tree.html
  7. +0 −26 contacts_and_people/templates/admin/contacts_and_people/entity/change_list_tree_item.html
  8. +0 −9 contacts_and_people/templates/admin/contacts_and_people/entity/change_list_tree_items.html
  9. +0 −14 contacts_and_people/templates/xpeople.html
  10. +0 −16 contacts_and_people/templatetags/entity_tags.py
  11. +1 −1  contacts_and_people/views.py
  12. +3 −2 example_14/example_14/settings.py
  13. +4 −11 links/admin.py
  14. +11 −3 links/models.py
  15. +0 −133 links/templates/admin/links/externalsite/change_list.html
  16. +0 −20 links/templates/admin/links/externalsite/change_list_tree.html
  17. +0 −10 links/templates/admin/links/externalsite/change_list_tree_item.html
  18. +0 −9 links/templates/admin/links/externalsite/change_list_tree_items.html
  19. +25 −44 news_and_events/admin.py
  20. +0 −131 news_and_events/templates/admin/news_and_events/event/change_list.html
  21. +0 −20 news_and_events/templates/admin/news_and_events/event/change_list_tree.html
  22. +0 −11 news_and_events/templates/admin/news_and_events/event/change_list_tree_item.html
  23. +0 −9 news_and_events/templates/admin/news_and_events/event/change_list_tree_items.html
View
1  REQUIREMENTS.txt
@@ -8,3 +8,4 @@
-e git+https://github.com/stefanfoulis/django-filer.git@81c7304b8240279a5fe13bf769d7839fed72fba9#egg=django_filer-0.9a1-py2.6-feature/issue-213
+-e git+git@github.com:evildmp/django-treeadmin.git#egg=django_treeadmin-dev
@darbula
darbula added a note

There is a username present (evildmp) in this line and using a git protocol did not work for me but this one did:

-e git+https://github.com/evildmp/django-treeadmin.git#egg=django_treeadmin-dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
View
2  arkestra_utilities/generic_models.py
@@ -53,7 +53,7 @@ class Meta:
(0, u"Normal"),
(1, u"More important"),
(10, u"Most important"),
- )
+ )
importance = models.PositiveIntegerField(null=True, blank=False,
default=0, choices=IMPORTANCES,
help_text=u"Important items will be featured in lists")
View
130 contacts_and_people/admin.py
@@ -5,14 +5,18 @@
from django.conf import settings
from django.contrib import admin, messages
+from django.contrib.admin import SimpleListFilter
from django.contrib.contenttypes import generic
from django.contrib.auth.models import User
from django import forms
-from django.utils.safestring import mark_safe
from django.http import HttpResponseRedirect, HttpResponse
+from django.utils.safestring import mark_safe
+from django.utils.translation import ugettext_lazy as _
+
+from treeadmin.admin import TreeAdmin
from arkestra_utilities.widgets.combobox import ComboboxField
from widgetry.tabs.placeholderadmin import ModelAdminWithTabsAndCMSPlaceholder
@@ -46,10 +50,12 @@ class MembershipInline(AutocompleteMixin, admin.TabularInline):
class MembershipForEntityInline(MembershipInline): # for Entity admin
exclude = ('display_role',)
extra = 3
+ ordering = ['-importance_to_entity',]
class MembershipForPersonInline(MembershipInline): # for Person admin
exclude = ('display_role',)
+ ordering = ['-importance_to_person',]
class MembershipAdmin(admin.ModelAdmin):
@@ -166,11 +172,44 @@ def action(modeladmin,request,queryset):
return (name, (action, name,"Add selected Person to %s as 'Member'" % (entity,)))
+class HasHomeRole(SimpleListFilter):
+ title = _('Has home role')
+ parameter_name = 'homerole'
+
+ def lookups(self, request, model_admin):
+ return (
+ ('ok', _('OK')),
+ ('missing', _('Missing')),
+ )
+
+ def queryset(self, request, queryset):
+ if self.value() == 'ok':
+ return queryset.filter(member_of__importance_to_person=5)
+ if self.value() == 'missing':
+ return queryset.exclude(member_of__importance_to_person=5)
+
+class PersonIsExternal(SimpleListFilter):
+ title = _('Profile is hosted')
+ parameter_name = 'hosted'
+
+ def lookups(self, request, model_admin):
+ return (
+ ('external', _('Externally')),
+ ('internal', _('In Arkestra')),
+ )
+
+ def queryset(self, request, queryset):
+ if self.value() == 'external':
+ return queryset.exclude(external_url=None)
+ if self.value() == 'internal':
+ return queryset.filter(external_url=None)
+
+
class PersonAdmin(PersonAndEntityAdmin):
search_fields = ['given_name','surname','institutional_username',]
form = PersonForm
- list_display = ('surname', 'given_name', 'title', 'get_entity', 'slug', 'active')
- list_editable = ('title',)
+ list_filter = (HasHomeRole, PersonIsExternal, 'active')
+ list_display = ('surname', 'given_name','get_entity_short_name', 'active')
filter_horizontal = ('entities',)
prepopulated_fields = {'slug': ('title', 'given_name', 'middle_names', 'surname',)}
readonly_fields = ['address_report',]
@@ -284,13 +323,34 @@ def clean(self):
return self.cleaned_data
-class EntityAdmin(PersonAndEntityAdmin):
- search_fields = ['name']
- # inlines = (MembershipForEntityInline,PhoneContactInline)
+class EntityIsExternal(SimpleListFilter):
+ title = _('website hosted')
+ parameter_name = 'hosted'
+
+ def lookups(self, request, model_admin):
+ return (
+ ('external', _('Externally')),
+ ('internal', _('In Arkestra')),
+ ('nowebsite', _('No website')),
+ )
+
+ def queryset(self, request, queryset):
+ if self.value() == 'external':
+ return queryset.exclude(external_url=None)
+ if self.value() == 'internal':
+ return queryset.exclude(website=None)
+ if self.value() == 'nowebsite':
+ return queryset.filter(website=None, external_url=None)
+
+
+class EntityAdmin(PersonAndEntityAdmin, TreeAdmin):
+ filter_include_ancestors = False
+ search_fields = ['name',]
form = EntityForm
- list_display = ('name', 'parent', 'building', 'abstract_entity','website', )
- list_editable = ('website', )
- change_list_template = "admin/contacts_and_people/entity/change_list.html"
+ list_display = ('name',)
+ list_filter = (EntityIsExternal, 'abstract_entity')
+ list_max_show_all = 400
+ list_per_page = 400
related_search_fields = ['parent', 'building', 'website', 'external_url',]
prepopulated_fields = {
'slug': ('name',)
@@ -363,58 +423,15 @@ def address_report(self, instance):
('Publications', {'fieldsets': publications_fieldset})
)
- def changelist_view(self, request, extra_context=None):
- extra_context = extra_context or {}
- extra_context.update({
- 'root_entities':models.Entity.objects.filter(level=0),
- 'has_add_permission': request.user.has_perm('contacts_and_people.add_entity'),
- 'has_change_permission': request.user.has_perm('contacts_and_people.change_entity'),
- 'has_delete_permission': request.user.has_perm('contacts_and_people.delete_entity'),
- })
- return super(EntityAdmin, self).changelist_view(request, extra_context)
-
- def get_urls(self):
- urls = super(EntityAdmin, self).get_urls()
-
- # helper for url pattern generation
- info = "%sadmin_%s_%s" % (self.admin_site.name, self.model._meta.app_label, self.model._meta.module_name)
- #pat = lambda regex, fn: url(regex, self.admin_site.admin_view(fn), name='%s_%s' % (info, fn.__name__))
-
- url_patterns = patterns('',
- url(r'^([0-9]+)/move-page/$', self.admin_site.admin_view(self.move_entity), name='%s_%s' % (info, 'move_page') ),
- #pat(r'^([0-9]+)/move-page/$', self.move_entity),
- )
- url_patterns.extend(urls)
- return url_patterns
-
- def move_entity(self, request, entity_id, extra_context=None):
- target = request.POST.get('target', None)
- position = request.POST.get('position', None)
- if target is None or position is None:
- return HttpResponseRedirect('../../')
- try:
- entity = self.model.objects.get(pk=entity_id)
- target = self.model.objects.get(pk=target)
- except self.model.DoesNotExist:
- return HttpResponse("error")
-
- # does he haves permissions to do this...?
- if not request.user.has_perm('contacts_and_people.change_entity'):
- return HttpResponse("Denied")
- # move page
- entity.move_to(target, position)
- entity.save()
- return HttpResponse("ok")
# ------------------------- Building and site admin -------------------------
class BuildingAdminForm(forms.ModelForm):
- # getting_here = forms.CharField(widget=WYMEditor, required = False)
- # access_and_parking = forms.CharField(widget=WYMEditor, required = False)
-
+
class Meta:
model = models.Building
+
def clean(self):
super(BuildingAdminForm, self).clean()
if self.cleaned_data["number"] and not self.cleaned_data["street"]:
@@ -433,10 +450,12 @@ class BuildingInline(admin.StackedInline):
class SiteAdmin(admin.ModelAdmin):
- list_display = ('site_name', 'post_town', 'country',)
+ list_display = ('site_name', 'post_town', 'country', 'buildings')
class BuildingAdmin(ModelAdminWithTabsAndCMSPlaceholder):
+ list_filter = ('site',)
+ list_display = ('building_identifier', 'site', 'has_map')
search_fields = ['name','number','street','postcode','site__site_name']
form = BuildingAdminForm
address_fieldsets = (('', {'fields': ('name', 'number', 'street', 'additional_street_address', 'postcode', 'site'),}),)
@@ -467,6 +486,7 @@ class BuildingAdmin(ModelAdminWithTabsAndCMSPlaceholder):
admin.site.register(models.Person, PersonAdmin)
except admin.sites.AlreadyRegistered:
pass
+
admin.site.register(models.Building,BuildingAdmin)
admin.site.register(models.Entity,EntityAdmin)
View
36 contacts_and_people/models.py
@@ -14,13 +14,9 @@
from mptt.models import MPTTModel, TreeForeignKey
from mptt.managers import TreeManager
-# import mptt
from filer.fields.image import FilerImageField
-# from news_and_events.models import NewsAndEventsPlugin
-# from news_and_events.cms_plugins import CMSNewsAndEventsPlugin
-
from arkestra_utilities.mixins import URLModelMixin
from arkestra_utilities.settings import MULTIPLE_ENTITY_MODE, ARKESTRA_BASE_ENTITY, DEFAULT_NEWS_PAGE_TITLE, DEFAULT_CONTACTS_PAGE_TITLE, DEFAULT_VACANCIES_PAGE_TITLE, DEFAULT_PUBLICATIONS_PAGE_TITLE
from links.models import ExternalLink
@@ -45,9 +41,12 @@ class Meta:
def __unicode__(self):
return self.site_name
+ def buildings(self):
+ return self.place.all().count()
+
@property
def maps(self):
- return [building for building in self.place.all() if building.has_map]
+ return [building for building in self.place.all() if building.has_map()]
class BuildingManager(models.Manager):
def get_by_natural_key(self, slug):
@@ -88,6 +87,14 @@ class Meta:
# def natural_key(self):
# return (self.slug)
+ def building_identifier(self):
+ if self.name:
+ return self.name
+ elif self.street:
+ return self.number + " " + self.street
+ else:
+ return self.postcode
+
def __unicode__(self):
if self.name:
building_identifier = unicode(self.site) + ": " + self.name
@@ -95,7 +102,9 @@ def __unicode__(self):
building_identifier = unicode(self.site) + ": " + self.number + " " + self.street
else:
building_identifier = unicode(self.site) + ": " + self.postcode
- return building_identifier
+
+ return u"%s (%s)" %(self.building_identifier(), unicode(self.site))
+
def get_absolute_url(self):
return "/place/%s/" % self.slug
@@ -138,9 +147,9 @@ def get_postal_address(self):
address.append(self.postcode)
return address
- @property
def has_map(self):
- return self.map and self.latitude and self.longitude and self.zoom
+ return (self.latitude and self.longitude and self.zoom and self.map)==True
+ has_map.boolean = True
def events(self):
# invoke the plugin to find out more
@@ -242,14 +251,12 @@ def default_entity_id(self):
if self.base_entity and not MULTIPLE_ENTITY_MODE:
return base_entity_id
- def some_thing(self):
- print "*********"
class Entity(MPTTModel, EntityLite, CommonFields):
objects=EntityManager()
short_name = models.CharField(blank=True, help_text="e.g. Haematology",
max_length=100, null=True, verbose_name="Short name for menus")
- abstract_entity = models.BooleanField("Abstract entity", default=False,
+ abstract_entity = models.BooleanField("abstract", default=False,
help_text=u"Select if this <em>group</em> of entities, but not an entity itself, or if it's just a grouping of people",)
parent = TreeForeignKey('self', null=True, blank=True, related_name='children')
display_parent = models.BooleanField(u"Include parent entity's name in address", default=True, help_text=u"Deselect if this entity recapitulates its parent's name")
@@ -631,6 +638,13 @@ def get_entity(self):
return self.get_role.entity
return None
+ def get_entity_short_name(self):
+ if self.get_entity:
+ return self.get_entity.short_name
+ else:
+ return u""
+ get_entity_short_name.short_description = "Entity"
+
@property
def get_building(self):
"""
View
133 contacts_and_people/templates/admin/contacts_and_people/entity/change_list.html
@@ -1,133 +0,0 @@
-{% extends "admin/change_list.html" %}
-{% load adminmedia admin_list i18n cms_admin cms_js_tags %}
-{% block title %}List of entities{% endblock %}
-{% block bodyclass %}change-list{% endblock %}
-
-{% if not is_popup %}{% block breadcrumbs %}
- <div class="breadcrumbs">
- <a href="../../">{% trans "Home" %}</a> &rsaquo;
- <a href="../">{{ app_label|capfirst|escape }}</a> &rsaquo; {{ opts.verbose_name_plural|capfirst|escape }}
- </div>
-{% endblock %}{% endif %}
-
-{% block coltype %}flex{% endblock %}
-{% block extrahead %}
-<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}cms/css/pages.css"/>
-<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}cms/jstree/tree_component.css" />
-<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}cms/css/jquery.dialog.css" />
-
-{{ block.super }}
-<script type="text/javascript" src="{% admin_static_url %}js/jquery.min.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/csrf.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/libs/jquery.livequery.js"></script>
-
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/libs/jquery.ui.core.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/libs/jquery.bind.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/libs/jquery.ui.checkbox.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/libs/jquery.ui.effects.core.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/libs/jquery.ui.effects.highlight.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/libs/jquery.form.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/jstree/_lib/_all.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/jstree/tree_component.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/libs/jquery.ui.dialog.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/libs/jquery.functional.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/libs/classy.min.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/plugins/cms.setup.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/plugins/cms.base.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/change_list.js"></script>
-
-
-{% if cl.is_filtered %}
-<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}cms/jstree/themes/default/style.css" />
-{% endif %}
-{% endblock %}
-
-{% block content %}
-<script type="text/javascript">
-//<![CDATA[
-(function namespacing($) {
- $(document).ready(function() {
- {% if not cl.is_filtered %}
- initTree();
- {% endif %}
- });
-
- showchangelistfilter = function(){
- $("#changelist-filter").toggle();
- }
- moveSuccess = function(node){
- var msg = $({% javascript_string %}<span class="success">{% trans "Successfully moved" %}</span>{% end_javascript_string %});
- node.append(msg);
- msg.fadeOut(3000);
- }
- moveError = function(node,message){
- if(message && message!="error") {
- var msg = $({% javascript_string %}<span class="success">{% end_javascript_string %}+message+{% javascript_string %}</span>{% end_javascript_string %});
- }
- else {
- var msg = $({% javascript_string %}<span class="success">{% trans "An error occured. Please reload the page" %}</span>{% end_javascript_string %});
- }
- node.append(msg);
- }
-
-})(jQuery);
-//]]>
-</script>
-
-
-<div id="content-main"{% if cl.is_filtered %} class="activ-filter"{% endif %}>
-
-{% block object-tools %}
-
- <ul class="object-tools">
- {% if has_recover_permission %}
- <li><a href="recover/" class="recoverlink">{% blocktrans with cl.opts.verbose_name_plural|escape as name %}Recover deleted {{name}}{% endblocktrans %}</a></li>
- {% endif %}
- {% if has_add_permission %}
- <li><a href="add/{% if is_popup %}?_popup=1{% endif %}" class="addlink">{% blocktrans with cl.opts.verbose_name as name %}Add {{ name }}{% endblocktrans %}</a></li>
- {% endif %}
- </ul>
-
- {% include "admin/cms/page/loading.html" %}
-
-{% endblock %}
-<div class="module{% if cl.has_filters %} filtered{% endif %}" id="changelist">
-{% block search %}
-
-
-{% if cl.has_access_to_multiple_sites %}
- <div id="site-selector">{% trans "Entities on:" %}
- <select id="site-select">{% for site in cl.sites %}
- <option {% ifequal site.pk cl.current_site.pk %}selected {% endifequal %}value="{{ site.pk }}">{{ site.name }}</option>{% endfor %}
- </select>
- </div>
-{% else %}
- <input type="hidden" id="site-select" value="{{ cl.sites.0.pk }}">
-{% endif %}
-
-{% search_form cl %}
-{% endblock %}
-{% block date_hierarchy %}{% date_hierarchy cl %}{% endblock %}
-
-{% block filters %}
-{% if cl.has_filters %}
-
-
-<a href="javascript:showchangelistfilter();" id="changelist-filter-button">{% trans "Filter:" %} {% if cl.is_filtered %}{% trans "on" %}{% else %}{% trans "off" %}{% endif %}</a>
-<div id="changelist-filter" style="display:none;">
-<h2>{% trans 'Filter' %}</h2>
-{% for spec in cl.filter_specs %}
- {% clean_admin_list_filter cl spec %}
-{% endfor %}
-</div>
-{% endif %}
-{% endblock %}
-
-{% include "admin/contacts_and_people/entity/change_list_tree.html" %}
-
-</div>
-</div>
-
-<div id="dialogs"></div>
-
-{% endblock %}
View
20 contacts_and_people/templates/admin/contacts_and_people/entity/change_list_tree.html
@@ -1,20 +0,0 @@
-{% load i18n entity_admin_tags cms_admin %}
-<div id="sitemap" style="display:none">
-<ul class="header">
- <li>
- <div class="cont">
- <div class="col1">{% trans "title" %}</div>
- <div class="col2">
- <div class="col-actions">{% trans "actions" %}</div>
- </div>
- </div>
- </li>
-</ul>
-<div class="tree root_allow_children">
- <ul class="tree-default">
- {% for entity in root_entities %}
- {% show_entity_tree_item entity %}
- {% endfor %}
- </ul>
-</div>
-</div>
View
26 contacts_and_people/templates/admin/contacts_and_people/entity/change_list_tree_item.html
@@ -1,26 +0,0 @@
-{% load i18n adminmedia %}
-<div class="cont">
- <div class="col1">
- <a href="{{ url }}{{ entity.id }}" class="title" title="edit">{{ entity.name }}</a>
- <a href="{{ url }}{{ entity.id }}" class="changelink" title="edit">edit</a>
- </div>
- <div class="col2">
- <span id="move-target-{{ entity.id }}" class="move-target-container" >
- {% if has_add_permission %}
- <a href="#" class="move-target left" title="{% trans "insert above" %}"><img alt="" src="{% admin_media_prefix %}img/admin/arrow-up.gif"/></a><span class="line first"> |</span>
- <a href="#" class="move-target right" title="{% trans "insert below" %}"><img alt="" src="{% admin_media_prefix %}img/admin/arrow-down.gif"/></a><span class="line second"> |</span>
- <a href="#" class="move-target first-child" title="{% trans "insert inside" %}">↘</a>
- {% endif %}
- </span>
-
- <div class="col-actions">{% if not filtered %}
- {% if has_change_permission %}<a href="#" class="move" title="{% trans "Cut" %}" id="move-link-{{ entity.id }}"><span>{% trans "cut" %}</span></a>{% endif %}{% endif %}
- {# {% if has_change_permission %}<a href="#" class="copy" title="{% trans "Copy" %}" id="copy-link-{{ entity.id }}"><span>{% trans "copy" %}</span></a>{% endif %} #}
-
- {% if has_add_permission %}
- <a href="add/?parent={{ entity.id }}" class="addlink" title="{% trans "Add Child" %}" id="add-link-{{ entity.id }}"><span>{% trans "add" %}</span></a>
- {% endif %}
- {% if has_delete_permission %}<a href="{{ entity.id }}/delete/" title="{% trans "Delete" %}" class="deletelink"><span>{% trans "delete" %}</span></a>{% endif %}
- </div>
- </div>
-</div>
View
9 contacts_and_people/templates/admin/contacts_and_people/entity/change_list_tree_items.html
@@ -1,9 +0,0 @@
-{% load i18n entity_admin_tags %}
-<li id="page_{{entity.pk}}" class="{% if cl.is_filtered %}leaf{% endif %} moveable"{% if metadata %} mdata="{{ metadata }}{% endif %}" rel="{% ifequal entity.level 0 %}topnode{% else %}node{% endifequal %}">
- {% include 'admin/contacts_and_people/entity/change_list_tree_item.html' %}
- {% with entity.children.all as children %}
- {% if children%}<ul>{% for child in children %}
- {% show_entity_tree_item child %}{% endfor %}
- </ul>{% endif %}
- {% endwith %}
-</li>
View
14 contacts_and_people/templates/xpeople.html
@@ -1,14 +0,0 @@
-{% comment %}
-
-No longer used by anything, as far as I can tell
-
-{% endcomment %}
-{% if membership_list %}
-{% regroup membership_list by person as person_list %}
- <dl>
- {% for person in person_list %}
- <dt><a href="{{ person.grouper.get_absolute_url }}">{{ person.grouper }}</a></dt>
- {% for role in person.list %}<dd>{{role.role}}</dd>{% endfor %}
- {% endfor %}
- </dl>
-{% endif %}
View
16 contacts_and_people/templatetags/entity_tags.py
@@ -10,22 +10,6 @@ def directory(context, entity = None):
# print entity.get_descendants()
return { "entities": entity.get_descendants()}
-@register.inclusion_tag('people.html', takes_context=True)
-def key_people(context, entity = None):
- """
- Publishes an ordered list of memberships, grouped by people
- """
- entity = work_out_entity(context, entity)
- memberships = Membership.objects.filter(entity = entity, importance_to_entity_gte = 3).order_by('importance_to_entity',)
- duplicates = set()
- membership_list = []
- for membership in memberships:
- if membership not in duplicates:
- duplicates.add(membership)
- membership_list.append(membership)
- # returns a list of memberships, in the right order - we use a regroup tag to group them by person in the template
- # this doesn't list people's non-key-roles - should it?
- return {'membership_list': membership_list}
@register.inclusion_tag('includes/people_with_roles.html', takes_context=True)
def people_with_roles(context, letter = None):
View
2  contacts_and_people/views.py
@@ -282,7 +282,7 @@ def place(request, slug, active_tab=""):
tabs = []
if place.postcode or place.street or place.description.cmsplugin_set.all():
tabs.append(tabs_dict["about"])
- if place.has_map:
+ if place.has_map():
tabs.append(tabs_dict["map"])
if (place.getting_here and place.getting_here.cmsplugin_set.all()) \
or (place.access_and_parking and place.access_and_parking.cmsplugin_set.all()):
View
5 example_14/example_14/settings.py
@@ -189,8 +189,8 @@
'typogrify',
'filer',
'widgetry',
- # 'south',
- # 'adminsortable',
+ # 'south', # don't leave this disabled
+ 'treeadmin',
# core Django applications
# these should be last, so we can override their templates
@@ -204,6 +204,7 @@
'django.contrib.admin',
'django.contrib.admindocs',
'django.contrib.humanize',
+ 'django.contrib.markup'
)
# A sample logging configuration. The only tangible logging
View
15 links/admin.py
@@ -9,6 +9,8 @@
from widgetry import fk_lookup
from widgetry.views import search
+from treeadmin.admin import TreeAdmin
+
from arkestra_utilities.admin_mixins import AutocompleteMixin, SupplyRequestMixin, InputURLMixin
from links.models import ObjectLink, ExternalLink, ExternalSite, LinkType
@@ -114,20 +116,11 @@ def clean(self):
return self.cleaned_data
-class ExternalSiteAdmin(admin.ModelAdmin):
+class ExternalSiteAdmin(TreeAdmin):
readonly_fields = ('parent',)
form = ExternalSiteForm
+ list_display = ('domain', 'site',)
- def changelist_view(self, request, extra_context=None):
- extra_context = extra_context or {}
- extra_context.update({
- 'root_domains': ExternalSite.objects.filter(level = 0),
- # 'has_add_permission': request.user.has_perm('links.add_link'),
- # 'has_change_permission': request.user.has_perm('links.change_link'),
- # 'has_delete_permission': request.user.has_perm('links.delete_link'),
- })
- return super(ExternalSiteAdmin, self).changelist_view(request, extra_context)
-
admin.site.register(ExternalLink, ExternalLinkAdmin)
admin.site.register(ExternalSite, ExternalSiteAdmin)
View
14 links/models.py
@@ -175,6 +175,10 @@ class Meta:
def __unicode__(self):
return self.title or self.url
+
+ def get_absolute_url(self):
+ return self.url
+
def save(self, *args, **kwargs):
# here we either find the ExternalSite to attach to, or create it if it doesn't exist
# split url into component parts
@@ -211,13 +215,17 @@ def __unicode__(self):
class ExternalSite(models.Model):
- site = models.CharField(max_length=50,help_text = u"e.g. 'BBC News', 'Welsh Assembly Goverment', etc", null = True)
+ site = models.CharField(
+ max_length=50,
+ help_text = u"e.g. 'BBC News', 'Welsh Assembly Goverment', etc",
+ null = True
+ )
domain = models.CharField(max_length=256, null = True, blank = True,)
- parent = models.ForeignKey('self', blank=True, null = True, related_name='children') # for tree version of ExternalLinks
+ parent = models.ForeignKey('self', blank=True, null = True, related_name='children')
class Meta:
ordering = ['domain',]
-
+
def __unicode__(self):
# if this site is unnamed, let's see if it has a named ancestor
if self.site == self.domain:
View
133 links/templates/admin/links/externalsite/change_list.html
@@ -1,133 +0,0 @@
-{% extends "admin/change_list.html" %}
-{% load adminmedia admin_list i18n cms_admin cms_js_tags %}
-{% block title %}List of domains{% endblock %}
-{% block bodyclass %}change-list{% endblock %}
-
-{% if not is_popup %}{% block breadcrumbs %}
- <div class="breadcrumbs">
- <a href="../../">{% trans "Home" %}</a> &rsaquo;
- <a href="../">{{ app_label|capfirst|escape }}</a> &rsaquo; {{ opts.verbose_name_plural|capfirst|escape }}
- </div>
-{% endblock %}{% endif %}
-
-{% block coltype %}flex{% endblock %}
-{% block extrahead %}
-<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}cms/css/pages.css"/>
-<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}cms/jstree/tree_component.css" />
-<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}cms/css/jquery.dialog.css" />
-
-{{ block.super }}
-<script type="text/javascript" src="{% admin_static_url %}js/jquery.min.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/csrf.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/libs/jquery.livequery.js"></script>
-
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/libs/jquery.ui.core.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/libs/jquery.bind.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/libs/jquery.ui.checkbox.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/libs/jquery.ui.effects.core.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/libs/jquery.ui.effects.highlight.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/libs/jquery.form.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/jstree/_lib/_all.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/jstree/tree_component.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/libs/jquery.ui.dialog.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/libs/jquery.functional.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/libs/classy.min.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/plugins/cms.setup.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/plugins/cms.base.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/change_list.js"></script>
-
-
-{% if cl.is_filtered %}
-<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}cms/jstree/themes/default/style.css" />
-{% endif %}
-{% endblock %}
-
-{% block content %}
-<script type="text/javascript">
-//<![CDATA[
-(function namespacing($) {
- $(document).ready(function() {
- {% if not cl.is_filtered %}
- initTree();
- {% endif %}
- });
-
- showchangelistfilter = function(){
- $("#changelist-filter").toggle();
- }
- moveSuccess = function(node){
- var msg = $({% javascript_string %}<span class="success">{% trans "Successfully moved" %}</span>{% end_javascript_string %});
- node.append(msg);
- msg.fadeOut(3000);
- }
- moveError = function(node,message){
- if(message && message!="error") {
- var msg = $({% javascript_string %}<span class="success">{% end_javascript_string %}+message+{% javascript_string %}</span>{% end_javascript_string %});
- }
- else {
- var msg = $({% javascript_string %}<span class="success">{% trans "An error occured. Please reload the page" %}</span>{% end_javascript_string %});
- }
- node.append(msg);
- }
-
-})(jQuery);
-//]]>
-</script>
-
-
-<div id="content-main"{% if cl.is_filtered %} class="activ-filter"{% endif %}>
-
-{% block object-tools %}
-
- <ul class="object-tools">
- {% if has_recover_permission %}
- <li><a href="recover/" class="recoverlink">{% blocktrans with cl.opts.verbose_name_plural|escape as name %}Recover deleted {{name}}{% endblocktrans %}</a></li>
- {% endif %}
- {% if has_add_permission %}
- <li><a href="add/{% if is_popup %}?_popup=1{% endif %}" class="addlink">{% blocktrans with cl.opts.verbose_name as name %}Add {{ name }}{% endblocktrans %}</a></li>
- {% endif %}
- </ul>
-
- {% include "admin/cms/page/loading.html" %}
-
-{% endblock %}
-<div class="module{% if cl.has_filters %} filtered{% endif %}" id="changelist">
-{% block search %}
-
-
-{% if cl.has_access_to_multiple_sites %}
- <div id="site-selector">{% trans "Entities on:" %}
- <select id="site-select">{% for site in cl.sites %}
- <option {% ifequal site.pk cl.current_site.pk %}selected {% endifequal %}value="{{ site.pk }}">{{ site.name }}</option>{% endfor %}
- </select>
- </div>
-{% else %}
- <input type="hidden" id="site-select" value="{{ cl.sites.0.pk }}">
-{% endif %}
-
-{% search_form cl %}
-{% endblock %}
-{% block date_hierarchy %}{% date_hierarchy cl %}{% endblock %}
-
-{% block filters %}
-{% if cl.has_filters %}
-
-
-<a href="javascript:showchangelistfilter();" id="changelist-filter-button">{% trans "Filter:" %} {% if cl.is_filtered %}{% trans "on" %}{% else %}{% trans "off" %}{% endif %}</a>
-<div id="changelist-filter" style="display:none;">
-<h2>{% trans 'Filter' %}</h2>
-{% for spec in cl.filter_specs %}
- {% clean_admin_list_filter cl spec %}
-{% endfor %}
-</div>
-{% endif %}
-{% endblock %}
-
-{% include "admin/links/externalsite/change_list_tree.html" %}
-
-</div>
-</div>
-
-<div id="dialogs"></div>
-
-{% endblock %}
View
20 links/templates/admin/links/externalsite/change_list_tree.html
@@ -1,20 +0,0 @@
-{% load i18n externalsite_admin_tags %}
-<div id="sitemap" style="display:none">
-<ul class="header">
- <li>
- <div class="cont">
- <div class="col1">{% trans "title" %}</div>
- <div class="col2">
- <div class="col-actions">{% trans "actions" %}</div>
- </div>
- </div>
- </li>
-</ul>
-<div class="tree root_allow_children">
- <ul class="tree-default">
- {% for domain in root_domains %}
- {% show_externalsite_tree_item domain %}
- {% endfor %}
- </ul>
-</div>
-</div>
View
10 links/templates/admin/links/externalsite/change_list_tree_item.html
@@ -1,10 +0,0 @@
-{% load i18n adminmedia arkestra_filters %}
-<div class="cont">
- <div class="col1">
- <a href="{{ url }}{{ externalsite.id }}" class="title" title="edit">
- {{ externalsite.domain }}
- {% ifnotequal externalsite.domain externalsite.site %} <strong>{{ externalsite.site }}</strong>{% endifnotequal %}
- </a>
- <a href="{{ url }}{{ externalsite.id }}" class="changelink" title="edit">edit</a>
- </div>
-</div>
View
9 links/templates/admin/links/externalsite/change_list_tree_items.html
@@ -1,9 +0,0 @@
-{% load i18n externalsite_admin_tags %}
-<li id="page_{{externalsite.pk}}" class="{% if cl.is_filtered %}leaf{% endif %} moveable"{% if metadata %} mdata="{{ metadata }}{% endif %}" rel="{% ifequal externalsite.level 0 %}topnode{% else %}node{% endifequal %}">
- {% include 'admin/links/externalsite/change_list_tree_item.html' %}
- {% with externalsite.children.all as children %}
- {% if children%}<ul>{% for child in children %}
- {% show_externalsite_tree_item child %}{% endfor %}
- </ul>{% endif %}
- {% endwith %}
-</li>
View
69 news_and_events/admin.py
@@ -2,11 +2,15 @@
from django import forms
from django.contrib import admin, messages
+from django.contrib.admin import SimpleListFilter
from django.db.models import ForeignKey
from django.http import HttpResponseRedirect, HttpResponse
+from django.utils.translation import ugettext_lazy as _
from widgetry.tabs.placeholderadmin import ModelAdminWithTabsAndCMSPlaceholder
+from treeadmin.admin import TreeAdmin
+
from arkestra_utilities.admin_mixins import GenericModelAdmin, GenericModelForm, fieldsets
from links.admin import ExternalLinkForm, ObjectLinkInline
@@ -174,7 +178,23 @@ def clean_enquiries(self):
return data
'''
-class EventAdmin(NewsAndEventsAdmin):
+class EventIsSeries(SimpleListFilter):
+ title = _('actual/series')
+ parameter_name = 'series'
+
+ def lookups(self, request, model_admin):
+ return (
+ ('actual', _('Actual')),
+ ('series', _('Series')),
+ )
+
+ def queryset(self, request, queryset):
+ if self.value() == 'actual':
+ return queryset.filter(series=False)
+ if self.value() == 'series':
+ return queryset.filter(series=True)
+
+class EventAdmin(NewsAndEventsAdmin, TreeAdmin):
# some general settings
form = EventForm
filter_horizontal = (
@@ -184,11 +204,10 @@ class EventAdmin(NewsAndEventsAdmin):
'featuring',
)
ordering = ['type',]
- change_list_template = "admin/news_and_events/event/change_list.html"
- list_display = ('short_title','parent', 'start_date', 'series', 'slug',)
- list_editable = ('parent', 'start_date', 'series', 'slug',)
- search_fields = ['title',]
- list_filter = ('start_date',)
+ list_display = ('short_title', 'hosted_by', 'start_date')
+ list_editable = ()
+ search_fields = ['title']
+ list_filter = (EventIsSeries,)
save_as = True
# autocomplete fields
related_search_fields = ['hosted_by','parent','building', 'external_url']
@@ -224,44 +243,6 @@ class EventAdmin(NewsAndEventsAdmin):
('Advanced Options', {'fieldsets': (fieldsets["url"], fieldsets["slug"],)}),
)
- def changelist_view(self, request, extra_context=None):
- extra_context = extra_context or {}
- extra_context.update({
- 'root_events': Event.objects.filter(level=0),
- 'has_add_permission': request.user.has_perm('news_and_events.add_event'),
- 'has_change_permission': request.user.has_perm('news_and_events.change_event'),
- 'has_delete_permission': request.user.has_perm('news_and_events.delete_event'),
- })
- return super(EventAdmin, self).changelist_view(request, extra_context)
- def get_urls(self):
- from django.conf.urls.defaults import patterns, url
- urls = super(EventAdmin, self).get_urls()
- # helper for url pattern generation
- info = "%sadmin_%s_%s" % (self.admin_site.name, self.model._meta.app_label, self.model._meta.module_name)
- #pat = lambda regex, fn: url(regex, self.admin_site.admin_view(fn), name='%s_%s' % (info, fn.__name__))
- url_patterns = patterns('',
- url(r'^([0-9]+)/move-page/$', self.admin_site.admin_view(self.move_event), name='%s_%s' % (info, 'move_page') ),
- #pat(r'^([0-9]+)/move-page/$', self.move_entity),
- )
- url_patterns.extend(urls)
- return url_patterns
- def move_event(self, request, event_id, extra_context=None):
- target = request.POST.get('target', None)
- position = request.POST.get('position', None)
- if target is None or position is None:
- return HttpResponseRedirect('../../')
- try:
- event = self.model.objects.get(pk=event_id)
- target = self.model.objects.get(pk=target)
- except self.model.DoesNotExist:
- return HttpResponse("error")
- # does he haves permissions to do this...?
- if not request.user.has_perm('news_and_events.change_event'):
- return HttpResponse("Denied")
- # move page
- event.move_to(target, position)
- event.save()
- return HttpResponse("ok")
class EventTypeAdmin(admin.ModelAdmin):
pass
View
131 news_and_events/templates/admin/news_and_events/event/change_list.html
@@ -1,131 +0,0 @@
-{% extends "admin/change_list.html" %}
-{% load adminmedia admin_list i18n cms_admin cms_js_tags %}
-{% block title %}List of events{% endblock %}
-{% block bodyclass %}change-list{% endblock %}
-
-{% if not is_popup %}{% block breadcrumbs %}
- <div class="breadcrumbs">
- <a href="../../">{% trans "Home" %}</a> &rsaquo;
- <a href="../">{{ app_label|capfirst|escape }}</a> &rsaquo; {{ opts.verbose_name_plural|capfirst|escape }}
- </div>
-{% endblock %}{% endif %}
-
-{% block coltype %}flex{% endblock %}
-{% block extrahead %}
-<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}cms/css/pages.css"/>
-<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}cms/jstree/tree_component.css" />
-<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}cms/css/jquery.dialog.css" />
-
-{{ block.super }}
-<script type="text/javascript" src="{% admin_static_url %}js/jquery.min.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/csrf.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/libs/jquery.livequery.js"></script>
-
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/libs/jquery.ui.core.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/libs/jquery.bind.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/libs/jquery.ui.checkbox.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/libs/jquery.ui.effects.core.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/libs/jquery.ui.effects.highlight.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/libs/jquery.form.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/jstree/_lib/_all.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/jstree/tree_component.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/libs/jquery.ui.dialog.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/libs/jquery.functional.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/libs/classy.min.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/plugins/cms.setup.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/plugins/cms.base.js"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}cms/js/change_list.js"></script>
-
-
-{% if cl.is_filtered %}
-<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}cms/jstree/themes/default/style.css" />
-{% endif %}
-{% endblock %}
-
-{% block content %}
-<script type="text/javascript">
-//<![CDATA[
-(function namespacing($) {
- $(document).ready(function() {
- {% if not cl.is_filtered %}
- initTree();
- {% endif %}
- });
-
- showchangelistfilter = function(){
- $("#changelist-filter").toggle();
- }
- moveSuccess = function(node){
- var msg = $({% javascript_string %}<span class="success">{% trans "Successfully moved" %}</span>{% end_javascript_string %});
- node.append(msg);
- msg.fadeOut(3000);
- }
- moveError = function(node,message){
- if(message && message!="error") {
- var msg = $({% javascript_string %}<span class="success">{% end_javascript_string %}+message+{% javascript_string %}</span>{% end_javascript_string %});
- }
- else {
- var msg = $({% javascript_string %}<span class="success">{% trans "An error occured. Please reload the page" %}</span>{% end_javascript_string %});
- }
- node.append(msg);
- }
-
-})(jQuery);
-//]]>
-</script>
-
-
-<div id="content-main"{% if cl.is_filtered %} class="activ-filter"{% endif %}>
-
-{% block object-tools %}
-
- <ul class="object-tools">
- {% if has_recover_permission %}
- <li><a href="recover/" class="recoverlink">{% blocktrans with cl.opts.verbose_name_plural|escape as name %}Recover deleted {{name}}{% endblocktrans %}</a></li>
- {% endif %}
- {% if has_add_permission %}
- <li><a href="add/{% if is_popup %}?_popup=1{% endif %}" class="addlink">{% blocktrans with cl.opts.verbose_name as name %}Add {{ name }}{% endblocktrans %}</a></li>
- {% endif %}
- </ul>
-
- {% include "admin/cms/page/loading.html" %}
-
-{% endblock %}
-<div class="module{% if cl.has_filters %} filtered{% endif %}" id="changelist">
-{% block search %}
-
-
-{% if cl.has_access_to_multiple_sites %}
- <div id="site-selector">{% trans "Events on:" %}
- <select id="site-select">{% for site in cl.sites %}
- <option {% ifequal site.pk cl.current_site.pk %}selected {% endifequal %}value="{{ site.pk }}">{{ site.name }}</option>{% endfor %}
- </select>
- </div>
-{% else %}
- <input type="hidden" id="site-select" value="{{ cl.sites.0.pk }}">
-{% endif %}
-
-{% search_form cl %}
-{% endblock %}
-{% block date_hierarchy %}{% date_hierarchy cl %}{% endblock %}
-
-{% block filters %}
-{% if cl.has_filters %}
-
-
-<a href="javascript:showchangelistfilter();" id="changelist-filter-button">{% trans "Filter:" %} {% if cl.is_filtered %}{% trans "on" %}{% else %}{% trans "off" %}{% endif %}</a>
-<div id="changelist-filter" style="display:none;">
-<h2>{% trans 'Filter' %}</h2>
-{% for spec in cl.filter_specs %}
- {% clean_admin_list_filter cl spec %}
-{% endfor %}
-</div>
-{% endif %}
-{% endblock %}
-
-{% include "admin/news_and_events/event/change_list_tree.html" %}
-
-</div>
-</div>
-
-{% endblock %}
View
20 news_and_events/templates/admin/news_and_events/event/change_list_tree.html
@@ -1,20 +0,0 @@
-{% load i18n event_admin_tags %}
-<div id="sitemap" style="display:none">
-<ul class="header">
- <li>
- <div class="cont">
- <div class="col1">{% trans "title" %}</div>
- <div class="col2">
- <div class="col-actions">{% trans "actions" %}</div>
- </div>
- </div>
- </li>
-</ul>
-<div class="tree root_allow_children">
- <ul class="tree-default">
- {% for event in root_events %}
- {% show_event_tree_item event %}
- {% endfor %}
- </ul>
-</div>
-</div>
View
11 news_and_events/templates/admin/news_and_events/event/change_list_tree_item.html
@@ -1,11 +0,0 @@
-{% load i18n adminmedia arkestra_filters %}
-<div class="cont">
- <div class="col1">
- <a href="{{ url }}{{ event.id }}" class="title" title="edit">{{ event.title }} ({% if event.series %}Series{% else %}{{ event.type }}{% endif %})</a>
- <a href="{{ url }}{{ event.id }}" class="changelink" title="edit">edit</a>
- </div>
- <div class="col2">
- <div class="col-actions">{{ event.hosted_by.short_name }}</div>
- <div class="col-actions">{{ event.get_dates }}{% if event.get_times %}, {{ event.get_times|safe }}{% endif %}{% if event.building %}, {{ event.building }}{% endif %}</div>
- </div>
-</div>
View
9 news_and_events/templates/admin/news_and_events/event/change_list_tree_items.html
@@ -1,9 +0,0 @@
-{% load i18n event_admin_tags %}
-<li id="page_{{event.pk}}" class="{% if cl.is_filtered %}leaf{% endif %} moveable"{% if metadata %} mdata="{{ metadata }}{% endif %}" rel="{% ifequal event.level 0 %}topnode{% else %}node{% endifequal %}">
- {% include 'admin/news_and_events/event/change_list_tree_item.html' %}
- {% with event.children.all as children %}
- {% if children%}<ul>{% for child in children %}
- {% show_event_tree_item child %}{% endfor %}
- </ul>{% endif %}
- {% endwith %}
-</li>
Please sign in to comment.
Something went wrong with that request. Please try again.