Skip to content
This repository has been archived by the owner on Mar 5, 2021. It is now read-only.

Commit

Permalink
Merge branch 'treeadmin' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
evildmp committed Mar 21, 2013
2 parents 2c8bddb + 47d382b commit 165a37e
Show file tree
Hide file tree
Showing 23 changed files with 146 additions and 689 deletions.
1 change: 1 addition & 0 deletions REQUIREMENTS.txt
Expand Up @@ -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

This comment has been minimized.

Copy link
@darbula

darbula Mar 25, 2013

Contributor

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
2 changes: 1 addition & 1 deletion arkestra_utilities/generic_models.py
Expand Up @@ -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")
Expand Down
130 changes: 75 additions & 55 deletions contacts_and_people/admin.py
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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',]
Expand Down Expand Up @@ -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',)
Expand Down Expand Up @@ -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"]:
Expand All @@ -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'),}),)
Expand Down Expand Up @@ -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)
Expand Down
36 changes: 25 additions & 11 deletions contacts_and_people/models.py
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -88,14 +87,24 @@ 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
elif self.street:
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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):
"""
Expand Down

0 comments on commit 165a37e

Please sign in to comment.