From e61beac58ae010a71bc014744e569a652c627657 Mon Sep 17 00:00:00 2001 From: Daniele Procida Date: Tue, 19 Mar 2013 15:41:55 +0000 Subject: [PATCH 1/4] now use django-treeadmin for MPTT --- REQUIREMENTS.txt | 1 + contacts_and_people/admin.py | 128 +++++++++-------- contacts_and_people/models.py | 30 +++- .../entity/change_list.html | 133 ------------------ .../entity/change_list_tree.html | 20 --- .../entity/change_list_tree_item.html | 26 ---- .../entity/change_list_tree_items.html | 9 -- contacts_and_people/templates/xpeople.html | 14 -- .../templatetags/entity_tags.py | 16 --- contacts_and_people/views.py | 2 +- example_14/example_14/settings.py | 5 +- links/admin.py | 15 +- links/models.py | 10 +- .../admin/links/externalsite/change_list.html | 133 ------------------ .../links/externalsite/change_list_tree.html | 20 --- .../externalsite/change_list_tree_item.html | 10 -- .../externalsite/change_list_tree_items.html | 9 -- news_and_events/admin.py | 69 ++++----- .../news_and_events/event/change_list.html | 131 ----------------- .../event/change_list_tree.html | 20 --- .../event/change_list_tree_item.html | 11 -- .../event/change_list_tree_items.html | 9 -- 22 files changed, 139 insertions(+), 682 deletions(-) delete mode 100644 contacts_and_people/templates/admin/contacts_and_people/entity/change_list.html delete mode 100644 contacts_and_people/templates/admin/contacts_and_people/entity/change_list_tree.html delete mode 100644 contacts_and_people/templates/admin/contacts_and_people/entity/change_list_tree_item.html delete mode 100644 contacts_and_people/templates/admin/contacts_and_people/entity/change_list_tree_items.html delete mode 100644 contacts_and_people/templates/xpeople.html delete mode 100644 links/templates/admin/links/externalsite/change_list.html delete mode 100644 links/templates/admin/links/externalsite/change_list_tree.html delete mode 100644 links/templates/admin/links/externalsite/change_list_tree_item.html delete mode 100644 links/templates/admin/links/externalsite/change_list_tree_items.html delete mode 100644 news_and_events/templates/admin/news_and_events/event/change_list.html delete mode 100644 news_and_events/templates/admin/news_and_events/event/change_list_tree.html delete mode 100644 news_and_events/templates/admin/news_and_events/event/change_list_tree_item.html delete mode 100644 news_and_events/templates/admin/news_and_events/event/change_list_tree_items.html diff --git a/REQUIREMENTS.txt b/REQUIREMENTS.txt index dfe029c6..a49ac421 100644 --- a/REQUIREMENTS.txt +++ b/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 \ No newline at end of file diff --git a/contacts_and_people/admin.py b/contacts_and_people/admin.py index bf39db4c..98fe8f26 100755 --- a/contacts_and_people/admin.py +++ b/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,32 @@ 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') related_search_fields = ['parent', 'building', 'website', 'external_url',] prepopulated_fields = { 'slug': ('name',) @@ -363,58 +421,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 +448,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 +484,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) diff --git a/contacts_and_people/models.py b/contacts_and_people/models.py index e99d854c..f3e58ad1 100755 --- a/contacts_and_people/models.py +++ b/contacts_and_people/models.py @@ -45,9 +45,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 +91,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 +106,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 +151,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 @@ -249,7 +262,7 @@ 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 group 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 +644,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): """ diff --git a/contacts_and_people/templates/admin/contacts_and_people/entity/change_list.html b/contacts_and_people/templates/admin/contacts_and_people/entity/change_list.html deleted file mode 100644 index 831a019c..00000000 --- a/contacts_and_people/templates/admin/contacts_and_people/entity/change_list.html +++ /dev/null @@ -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 %} - -{% endblock %}{% endif %} - -{% block coltype %}flex{% endblock %} -{% block extrahead %} - - - - -{{ block.super }} - - - - - - - - - - - - - - - - - - - - -{% if cl.is_filtered %} - -{% endif %} -{% endblock %} - -{% block content %} - - - -
- -{% block object-tools %} - - - - {% include "admin/cms/page/loading.html" %} - -{% endblock %} -
-{% block search %} - - -{% if cl.has_access_to_multiple_sites %} -
{% trans "Entities on:" %} - -
-{% else %} - -{% endif %} - -{% search_form cl %} -{% endblock %} -{% block date_hierarchy %}{% date_hierarchy cl %}{% endblock %} - -{% block filters %} -{% if cl.has_filters %} - - -{% trans "Filter:" %} {% if cl.is_filtered %}{% trans "on" %}{% else %}{% trans "off" %}{% endif %} - -{% endif %} -{% endblock %} - -{% include "admin/contacts_and_people/entity/change_list_tree.html" %} - -
-
- -
- -{% endblock %} diff --git a/contacts_and_people/templates/admin/contacts_and_people/entity/change_list_tree.html b/contacts_and_people/templates/admin/contacts_and_people/entity/change_list_tree.html deleted file mode 100644 index 4151a381..00000000 --- a/contacts_and_people/templates/admin/contacts_and_people/entity/change_list_tree.html +++ /dev/null @@ -1,20 +0,0 @@ -{% load i18n entity_admin_tags cms_admin %} - \ No newline at end of file diff --git a/contacts_and_people/templates/admin/contacts_and_people/entity/change_list_tree_item.html b/contacts_and_people/templates/admin/contacts_and_people/entity/change_list_tree_item.html deleted file mode 100644 index 9b569ae1..00000000 --- a/contacts_and_people/templates/admin/contacts_and_people/entity/change_list_tree_item.html +++ /dev/null @@ -1,26 +0,0 @@ -{% load i18n adminmedia %} -
- -
- - {% if has_add_permission %} - | - | - - {% endif %} - - -
{% if not filtered %} - {% if has_change_permission %}{% trans "cut" %}{% endif %}{% endif %} - {# {% if has_change_permission %}{% trans "copy" %}{% endif %} #} - - {% if has_add_permission %} - {% trans "add" %} - {% endif %} - {% if has_delete_permission %}{% trans "delete" %}{% endif %} -
-
-
diff --git a/contacts_and_people/templates/admin/contacts_and_people/entity/change_list_tree_items.html b/contacts_and_people/templates/admin/contacts_and_people/entity/change_list_tree_items.html deleted file mode 100644 index 5de696ff..00000000 --- a/contacts_and_people/templates/admin/contacts_and_people/entity/change_list_tree_items.html +++ /dev/null @@ -1,9 +0,0 @@ -{% load i18n entity_admin_tags %} -
  • - {% include 'admin/contacts_and_people/entity/change_list_tree_item.html' %} - {% with entity.children.all as children %} - {% if children%}{% endif %} - {% endwith %} -
  • \ No newline at end of file diff --git a/contacts_and_people/templates/xpeople.html b/contacts_and_people/templates/xpeople.html deleted file mode 100644 index 3648012e..00000000 --- a/contacts_and_people/templates/xpeople.html +++ /dev/null @@ -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 %} -
    - {% for person in person_list %} -
    {{ person.grouper }}
    - {% for role in person.list %}
    {{role.role}}
    {% endfor %} - {% endfor %} -
    -{% endif %} \ No newline at end of file diff --git a/contacts_and_people/templatetags/entity_tags.py b/contacts_and_people/templatetags/entity_tags.py index 1e97590d..629c665e 100644 --- a/contacts_and_people/templatetags/entity_tags.py +++ b/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): diff --git a/contacts_and_people/views.py b/contacts_and_people/views.py index 94d2fcf9..4220595f 100755 --- a/contacts_and_people/views.py +++ b/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()): diff --git a/example_14/example_14/settings.py b/example_14/example_14/settings.py index c90e01e1..4593a451 100644 --- a/example_14/example_14/settings.py +++ b/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 diff --git a/links/admin.py b/links/admin.py index a260f856..cad8105c 100644 --- a/links/admin.py +++ b/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) diff --git a/links/models.py b/links/models.py index 8e8e64c7..1ed059e6 100644 --- a/links/models.py +++ b/links/models.py @@ -211,13 +211,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: diff --git a/links/templates/admin/links/externalsite/change_list.html b/links/templates/admin/links/externalsite/change_list.html deleted file mode 100644 index 3e974a3e..00000000 --- a/links/templates/admin/links/externalsite/change_list.html +++ /dev/null @@ -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 %} - -{% endblock %}{% endif %} - -{% block coltype %}flex{% endblock %} -{% block extrahead %} - - - - -{{ block.super }} - - - - - - - - - - - - - - - - - - - - -{% if cl.is_filtered %} - -{% endif %} -{% endblock %} - -{% block content %} - - - -
    - -{% block object-tools %} - - - - {% include "admin/cms/page/loading.html" %} - -{% endblock %} -
    -{% block search %} - - -{% if cl.has_access_to_multiple_sites %} -
    {% trans "Entities on:" %} - -
    -{% else %} - -{% endif %} - -{% search_form cl %} -{% endblock %} -{% block date_hierarchy %}{% date_hierarchy cl %}{% endblock %} - -{% block filters %} -{% if cl.has_filters %} - - -{% trans "Filter:" %} {% if cl.is_filtered %}{% trans "on" %}{% else %}{% trans "off" %}{% endif %} - -{% endif %} -{% endblock %} - -{% include "admin/links/externalsite/change_list_tree.html" %} - -
    -
    - -
    - -{% endblock %} diff --git a/links/templates/admin/links/externalsite/change_list_tree.html b/links/templates/admin/links/externalsite/change_list_tree.html deleted file mode 100644 index b6274c44..00000000 --- a/links/templates/admin/links/externalsite/change_list_tree.html +++ /dev/null @@ -1,20 +0,0 @@ -{% load i18n externalsite_admin_tags %} - \ No newline at end of file diff --git a/links/templates/admin/links/externalsite/change_list_tree_item.html b/links/templates/admin/links/externalsite/change_list_tree_item.html deleted file mode 100644 index 270f0390..00000000 --- a/links/templates/admin/links/externalsite/change_list_tree_item.html +++ /dev/null @@ -1,10 +0,0 @@ -{% load i18n adminmedia arkestra_filters %} -
    - -
    diff --git a/links/templates/admin/links/externalsite/change_list_tree_items.html b/links/templates/admin/links/externalsite/change_list_tree_items.html deleted file mode 100644 index b0ef31f7..00000000 --- a/links/templates/admin/links/externalsite/change_list_tree_items.html +++ /dev/null @@ -1,9 +0,0 @@ -{% load i18n externalsite_admin_tags %} -
  • - {% include 'admin/links/externalsite/change_list_tree_item.html' %} - {% with externalsite.children.all as children %} - {% if children%}{% endif %} - {% endwith %} -
  • \ No newline at end of file diff --git a/news_and_events/admin.py b/news_and_events/admin.py index 2ee23dd4..e86c0b6d 100644 --- a/news_and_events/admin.py +++ b/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 diff --git a/news_and_events/templates/admin/news_and_events/event/change_list.html b/news_and_events/templates/admin/news_and_events/event/change_list.html deleted file mode 100644 index 931317f8..00000000 --- a/news_and_events/templates/admin/news_and_events/event/change_list.html +++ /dev/null @@ -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 %} - -{% endblock %}{% endif %} - -{% block coltype %}flex{% endblock %} -{% block extrahead %} - - - - -{{ block.super }} - - - - - - - - - - - - - - - - - - - - -{% if cl.is_filtered %} - -{% endif %} -{% endblock %} - -{% block content %} - - - -
    - -{% block object-tools %} - - - - {% include "admin/cms/page/loading.html" %} - -{% endblock %} -
    -{% block search %} - - -{% if cl.has_access_to_multiple_sites %} -
    {% trans "Events on:" %} - -
    -{% else %} - -{% endif %} - -{% search_form cl %} -{% endblock %} -{% block date_hierarchy %}{% date_hierarchy cl %}{% endblock %} - -{% block filters %} -{% if cl.has_filters %} - - -{% trans "Filter:" %} {% if cl.is_filtered %}{% trans "on" %}{% else %}{% trans "off" %}{% endif %} - -{% endif %} -{% endblock %} - -{% include "admin/news_and_events/event/change_list_tree.html" %} - -
    -
    - -{% endblock %} diff --git a/news_and_events/templates/admin/news_and_events/event/change_list_tree.html b/news_and_events/templates/admin/news_and_events/event/change_list_tree.html deleted file mode 100644 index a12b61c9..00000000 --- a/news_and_events/templates/admin/news_and_events/event/change_list_tree.html +++ /dev/null @@ -1,20 +0,0 @@ -{% load i18n event_admin_tags %} - \ No newline at end of file diff --git a/news_and_events/templates/admin/news_and_events/event/change_list_tree_item.html b/news_and_events/templates/admin/news_and_events/event/change_list_tree_item.html deleted file mode 100644 index 379f2384..00000000 --- a/news_and_events/templates/admin/news_and_events/event/change_list_tree_item.html +++ /dev/null @@ -1,11 +0,0 @@ -{% load i18n adminmedia arkestra_filters %} -
    - -
    -
    {{ event.hosted_by.short_name }}
    -
    {{ event.get_dates }}{% if event.get_times %}, {{ event.get_times|safe }}{% endif %}{% if event.building %}, {{ event.building }}{% endif %}
    -
    -
    diff --git a/news_and_events/templates/admin/news_and_events/event/change_list_tree_items.html b/news_and_events/templates/admin/news_and_events/event/change_list_tree_items.html deleted file mode 100644 index 877819b2..00000000 --- a/news_and_events/templates/admin/news_and_events/event/change_list_tree_items.html +++ /dev/null @@ -1,9 +0,0 @@ -{% load i18n event_admin_tags %} -
  • - {% include 'admin/news_and_events/event/change_list_tree_item.html' %} - {% with event.children.all as children %} - {% if children%}{% endif %} - {% endwith %} -
  • \ No newline at end of file From d6f9da6fa37962018acc071105cbddad665d0979 Mon Sep 17 00:00:00 2001 From: Daniele Procida Date: Thu, 21 Mar 2013 12:52:15 +0000 Subject: [PATCH 2/4] tidy code --- arkestra_utilities/generic_models.py | 2 +- contacts_and_people/models.py | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/arkestra_utilities/generic_models.py b/arkestra_utilities/generic_models.py index 680ae5c2..a3afca03 100644 --- a/arkestra_utilities/generic_models.py +++ b/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") diff --git a/contacts_and_people/models.py b/contacts_and_people/models.py index f3e58ad1..02c016f9 100755 --- a/contacts_and_people/models.py +++ b/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 @@ -255,8 +251,6 @@ 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() From 77942a7b75530b27d64cb4153d3ca94f4c3f4be3 Mon Sep 17 00:00:00 2001 From: Daniele Procida Date: Thu, 21 Mar 2013 19:30:52 +0000 Subject: [PATCH 3/4] Entity tree list improvement --- contacts_and_people/admin.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contacts_and_people/admin.py b/contacts_and_people/admin.py index 98fe8f26..94e3ede2 100755 --- a/contacts_and_people/admin.py +++ b/contacts_and_people/admin.py @@ -348,7 +348,9 @@ class EntityAdmin(PersonAndEntityAdmin, TreeAdmin): search_fields = ['name',] form = EntityForm list_display = ('name',) - list_filter = (EntityIsExternal, 'abstract_entity') + 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',) From 47d382b28347ebfb03cd3043107b24db3f118fe0 Mon Sep 17 00:00:00 2001 From: Daniele Procida Date: Thu, 21 Mar 2013 19:31:18 +0000 Subject: [PATCH 4/4] ExternalLink needed get_absolute_url() --- links/models.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/links/models.py b/links/models.py index 1ed059e6..f3b251dd 100644 --- a/links/models.py +++ b/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