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 django.contrib import admin
from mptt.admin import MPTTModelAdmin
from openslides.agenda.models import Item 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, \ from django.forms import Form, ModelForm, IntegerField, ChoiceField, \
ModelChoiceField, HiddenInput, Select ModelChoiceField, HiddenInput, Select
from django.utils.translation import ugettext as _ 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): class ItemFormText(ModelForm):
error_css_class = 'error' error_css_class = 'error'
required_css_class = 'required' required_css_class = 'required'
items = Item.objects.all().filter(parent=None) parent = TreeNodeChoiceField(queryset=Item.objects.all(), label=_("Parent item"), required=False)
parent = ModelChoiceField(queryset=items, label=_("Parent item"), required=False)
class Meta: class Meta:
model = Item model = Item
exclude = ('closed', 'weight') exclude = ('closed', 'weight')

View File

@ -18,6 +18,8 @@ except ImportError:
from django.db import models from django.db import models
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from mptt.models import MPTTModel, TreeForeignKey
from system import config from system import config
from projector.models import Slide from projector.models import Slide
@ -26,7 +28,7 @@ from projector.api import register_slidemodel
from agenda.api import is_summary from agenda.api import is_summary
class Item(models.Model, Slide): class Item(MPTTModel, Slide):
""" """
An Agenda Item An Agenda Item
""" """
@ -37,7 +39,7 @@ class Item(models.Model, Slide):
transcript = models.TextField(null=True, blank=True, verbose_name=_("Transcript")) transcript = models.TextField(null=True, blank=True, verbose_name=_("Transcript"))
closed = models.BooleanField(default=False, verbose_name=_("Closed")) closed = models.BooleanField(default=False, verbose_name=_("Closed"))
weight = models.IntegerField(default=0, verbose_name=_("Weight")) 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): def slide(self):
@ -72,19 +74,6 @@ class Item(models.Model, Slide):
self.closed = closed self.closed = closed
self.save() 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 @property
def active_parent(self): def active_parent(self):
""" """
@ -92,18 +81,10 @@ class Item(models.Model, Slide):
""" """
sid = get_active_slide(only_sid=True).split() sid = get_active_slide(only_sid=True).split()
if len(sid) == 2 and sid[0] == self.prefix: 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 True
return False 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 @property
def weight_form(self): def weight_form(self):
""" """
@ -145,10 +126,11 @@ class Item(models.Model, Slide):
('can_manage_agenda', "Can manage agenda"), ('can_manage_agenda', "Can manage agenda"),
('can_see_projector', "Can see projector"), ('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) register_slidemodel(Item)

View File

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

View File

@ -13,7 +13,7 @@
from django.conf.urls.defaults import * from django.conf.urls.defaults import *
urlpatterns = patterns('agenda.views', urlpatterns = patterns('agenda.views',
url(r'^$', 'overview', url(r'^/$', 'overview',
name='item_overview'), name='item_overview'),
url(r'^(?P<item_id>\d+)/$', 'view', url(r'^(?P<item_id>\d+)/$', 'view',
@ -35,7 +35,7 @@ urlpatterns = patterns('agenda.views',
url(r'^(?P<item_id>\d+)/edit/$', 'edit', url(r'^(?P<item_id>\d+)/edit/$', 'edit',
name='item_edit'), name='item_edit'),
url(r'^new$', 'edit', url(r'^new/$', 'edit',
name='item_new'), name='item_new'),
url(r'^(?P<item_id>\d+)/del/$', 'delete', 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 projector.api import get_active_slide, set_active_slide
from agenda.models import Item from agenda.models import Item
from agenda.api import is_summary, children_list, \ from agenda.api import is_summary, del_confirm_form_for_items
del_confirm_form_for_items
from agenda.forms import ItemOrderForm, ItemFormText from agenda.forms import ItemOrderForm, ItemFormText
from utils.utils import template, permission_required, \ from utils.utils import template, permission_required, \
@ -59,7 +58,7 @@ def overview(request):
item.weight = form.cleaned_data['weight'] item.weight = form.cleaned_data['weight']
item.save() item.save()
items = children_list(Item.objects.filter(parent=None)) items = Item.objects.all()
if get_active_slide(only_sid=True) == 'agenda_show': if get_active_slide(only_sid=True) == 'agenda_show':
overview = True overview = True

View File

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