use django-mptt to ordner the Agenda

http://django-mptt.github.com
you have to run:
pip install django-mptt
This commit is contained in:
Oskar Hahn 2012-02-20 00:14:54 +01:00
parent a404c3fe89
commit 22ef402a50
7 changed files with 47 additions and 74 deletions

View File

@ -11,7 +11,8 @@
"""
from django.contrib import admin
from mptt.admin import MPTTModelAdmin
from openslides.agenda.models import Item
admin.site.register(Item)
admin.site.register(Item, MPTTModelAdmin)

View File

@ -13,14 +13,16 @@
from django.forms import Form, ModelForm, IntegerField, ChoiceField, \
ModelChoiceField, HiddenInput, Select
from django.utils.translation import ugettext as _
from openslides.agenda.models import Item
from mptt.forms import TreeNodeChoiceField
from agenda.models import Item
class ItemFormText(ModelForm):
error_css_class = 'error'
required_css_class = 'required'
items = Item.objects.all().filter(parent=None)
parent = ModelChoiceField(queryset=items, label=_("Parent item"), required=False)
parent = TreeNodeChoiceField(queryset=Item.objects.all(), label=_("Parent item"), required=False)
class Meta:
model = Item
exclude = ('closed', 'weight')

View File

@ -18,6 +18,8 @@ except ImportError:
from django.db import models
from django.utils.translation import ugettext as _
from mptt.models import MPTTModel, TreeForeignKey
from system import config
from projector.models import Slide
@ -26,7 +28,7 @@ from projector.api import register_slidemodel
from agenda.api import is_summary
class Item(models.Model, Slide):
class Item(MPTTModel, Slide):
"""
An Agenda Item
"""
@ -37,7 +39,7 @@ class Item(models.Model, Slide):
transcript = models.TextField(null=True, blank=True, verbose_name=_("Transcript"))
closed = models.BooleanField(default=False, verbose_name=_("Closed"))
weight = models.IntegerField(default=0, verbose_name=_("Weight"))
parent = models.ForeignKey('self', blank=True, null=True)
parent = TreeForeignKey('self', null=True, blank=True, related_name='children')
def slide(self):
@ -72,19 +74,6 @@ class Item(models.Model, Slide):
self.closed = closed
self.save()
@property
def parents(self):
"""
Return the parent of this item, and the parent's partent and so
furth a list.
"""
parents = []
item = self
while item.parent is not None:
parents.append(item.parent)
item = item.parent
return parents
@property
def active_parent(self):
"""
@ -92,18 +81,10 @@ class Item(models.Model, Slide):
"""
sid = get_active_slide(only_sid=True).split()
if len(sid) == 2 and sid[0] == self.prefix:
if sid[1] in [parent.id for parent in self.parents]:
if self.get_ancestors().filter(pk=sid[0]).exists():
return True
return False
@property
def children(self):
"""
Return a list of all childitems from the next generation. The list
is ordert by weight.
"""
return self.item_set.order_by("weight")
@property
def weight_form(self):
"""
@ -145,10 +126,11 @@ class Item(models.Model, Slide):
('can_manage_agenda', "Can manage agenda"),
('can_see_projector', "Can see projector"),
)
ordering = ['weight']
#ordering = ['weight']
class MPTTMeta:
order_insertion_by = ['weight', 'title']
ItemText = Item # ItemText is Depricated
register_slidemodel(Item)

View File

@ -2,6 +2,7 @@
{% load tags %}
{% load i18n %}
{% load mptt_tags %}
{% block title %}{{ block.super }} - {% trans "Agenda" %}{% endblock %}
@ -75,9 +76,6 @@
<th style="width: 1px;">{% trans "Done" %}</th>
{% endif %}
<th>{% trans "Item" %}</th>
{% if perms.agenda.can_manage_agenda %}
<th>{% trans "Type" %}</th>
{% endif %}
<th style="width: 1px;">{% if perms.agenda.can_manage_agenda %}{% trans "Actions" %}{% endif %}</th>
{% if perms.agenda.can_manage_agenda %}
<th class="tabledrag-hide">{% trans "Weight" %}</th>
@ -85,18 +83,15 @@
</tr>
<tr id="item_row_0" class="topline {% if overview %} activeline {% else %}{% if perms.agenda.can_manage_agenda %} inactiveline {% endif %}{% endif %}">
{% if perms.agenda.can_manage_agenda %}
<td class="select">
<a href="{% url item_activate 0 %}" class="activate_link">
<div></div>
</a>
</td>
<td class="select">
<a href="{% url item_activate 0 %}" class="activate_link">
<div></div>
</a>
</td>
{% else %}
<td></td>
<td></td>
{% endif %}
<td><b>{% trans "Agenda" %} ({{ items|length }} {% trans "items" %}<span id="hiddencount"></span>)</b></td>
{% if perms.agenda.can_manage_agenda %}
<td></td>
{% endif %}
<td><span id="action_field" style="width: 1px;white-space: nowrap;">
<span></span>
<a href="{% url print_agenda %}" title="{%trans 'Print agenda' %}"><img src="/static/images/icons/application-pdf.png"></a>
@ -104,27 +99,25 @@
</td>
</tr>
{% for item in items %}
{% if not item.hidden or perms.agenda.can_manage_agenda %}
<tr id="item_row_{{ item.id }}" class="draggable{% cycle ' odd' '' %}
{% if item.active %} activeline{% else %}
{% if item.parent.active and summary %} activesummarychildline{% endif %}
{% if perms.agenda.can_manage_agenda %} inactiveline{% endif %}
{% endif %}">
{% if perms.agenda.can_manage_agenda %}
<td class="select">
<a id="activate_link_{{ item.id }}" class="activate_link" href="{% url item_activate item.id %}">
<div></div>
</a>
</td>
<td class="select">
<a id="activate_link_{{ item.id }}" class="activate_link" href="{% url item_activate item.id %}">
<div></div>
</a>
</td>
{% else %}
<td>
{% if item.closed %}
<img src="/static/images/icons/task-complete.png" title="{% trans 'Item closed' %}">
{% endif %}
</td>
<td>
{% if item.closed %}
<img src="/static/images/icons/task-complete.png" title="{% trans 'Item closed' %}">
{% endif %}
</td>
{% endif %}
<td>
{% for p in item.parents %}
{% for p in item.get_ancestors %}
<div class="indentation">&nbsp;</div>
{% endfor %}
@ -135,24 +128,20 @@
{{ item }}
</td>
{% if perms.agenda.can_manage_agenda %}
<td>
Text
</td>
{% endif %}
<td><span style="width: 1px;white-space: nowrap;">
<span style="width: 1px;white-space: nowrap;">
<a href="{{ item.get_absolute_url }}"><img src="/static/images/icons/document-preview.png" title="{% trans 'Show projector preview' %}"></a>
{% if perms.agenda.can_manage_agenda %}
<a href="{% url item_edit item.id %}"><img src="/static/images/icons/document-edit.png" title="{% trans 'Edit item' %}"></a>
<a href="{% url item_delete item.id %}"><img src="/static/images/icons/edit-delete.png" title="{% trans 'Delete item' %}"></a>
<a class="close_link {% if item.closed %}closed{% else %}open{% endif %}" href="{% if item.closed %}{% url item_open item.id %}{% else %}{% url item_close item.id %}{% endif %}">
<span></span>
</a>
<a href="{% url item_edit item.id %}"><img src="/static/images/icons/document-edit.png" title="{% trans 'Edit item' %}"></a>
<a href="{% url item_delete item.id %}"><img src="/static/images/icons/edit-delete.png" title="{% trans 'Delete item' %}"></a>
<a class="close_link {% if item.closed %}closed{% else %}open{% endif %}" href="{% if item.closed %}{% url item_open item.id %}{% else %}{% url item_close item.id %}{% endif %}">
<span></span>
</a>
{% if item.children.exists %}
<a href="{% url item_activate_summary item.id %}"><img src="/static/images/icons/view-list-tree.png" title="{% trans 'Select item overview' %}"></a>
{% endif %}
{% if item.children.exists %}
<a href="{% url item_activate_summary item.id %}"><img src="/static/images/icons/view-list-tree.png" title="{% trans 'Select item overview' %}"></a>
{% endif %}
{% endif %}
</span>
</td>
@ -166,7 +155,6 @@
</td>
{% endif %}
</tr>
{% endif %}
{% endfor %}
</table>

View File

@ -13,7 +13,7 @@
from django.conf.urls.defaults import *
urlpatterns = patterns('agenda.views',
url(r'^$', 'overview',
url(r'^/$', 'overview',
name='item_overview'),
url(r'^(?P<item_id>\d+)/$', 'view',
@ -35,7 +35,7 @@ urlpatterns = patterns('agenda.views',
url(r'^(?P<item_id>\d+)/edit/$', 'edit',
name='item_edit'),
url(r'^new$', 'edit',
url(r'^new/$', 'edit',
name='item_new'),
url(r'^(?P<item_id>\d+)/del/$', 'delete',

View File

@ -19,8 +19,7 @@ from system import config
from projector.api import get_active_slide, set_active_slide
from agenda.models import Item
from agenda.api import is_summary, children_list, \
del_confirm_form_for_items
from agenda.api import is_summary, del_confirm_form_for_items
from agenda.forms import ItemOrderForm, ItemFormText
from utils.utils import template, permission_required, \
@ -59,7 +58,7 @@ def overview(request):
item.weight = form.cleaned_data['weight']
item.save()
items = children_list(Item.objects.filter(parent=None))
items = Item.objects.all()
if get_active_slide(only_sid=True) == 'agenda_show':
overview = True

View File

@ -100,6 +100,7 @@ INSTALLED_APPS = (
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.admin',
'mptt',
'system',
'utils',
'projector',