now it is possible to create a item, witch is realted to another object, for example an application.

This commit is contained in:
Oskar Hahn 2012-04-19 12:46:04 +02:00
parent e23c195388
commit 4e904c7356
11 changed files with 65 additions and 35 deletions

View File

@ -25,7 +25,7 @@ class ItemForm(ModelForm, CssClassMixin):
parent = TreeNodeChoiceField(queryset=Item.objects.all(), label=_("Parent item"), required=False)
class Meta:
model = Item
exclude = ('closed', 'weight')
exclude = ('closed', 'weight', 'releated_sid')
def genweightchoices():

View File

@ -22,7 +22,7 @@ from mptt.models import MPTTModel, TreeForeignKey
from config.models import config
from projector.projector import SlideMixin
from projector.api import register_slidemodel
from projector.api import register_slidemodel, get_slide_from_sid
from utils.translation_ext import ugettext as _
@ -35,12 +35,26 @@ class Item(MPTTModel, SlideMixin):
"""
prefix = 'item'
title = models.CharField(max_length=100, verbose_name=_("Title"))
title = models.CharField(null=True, max_length=100, verbose_name=_("Title"))
text = models.TextField(null=True, blank=True, verbose_name=_("Text"))
comment = models.TextField(null=True, blank=True, verbose_name=_("Comment"))
closed = models.BooleanField(default=False, verbose_name=_("Closed"))
weight = models.IntegerField(default=0, verbose_name=_("Weight"))
parent = TreeForeignKey('self', null=True, blank=True, related_name='children')
releated_sid = models.CharField(null=True, blank=True, max_length=64)
def get_releated_slide(self):
return get_slide_from_sid(self.releated_sid, True)
def get_title(self):
if self.releated_sid is None:
return self.title
return self.get_releated_slide().get_agenda_title()
def get_text(self):
if self.releated_sid is None:
return self.text
return self.get_releated_slide().get_agenda_text()
def slide(self):
@ -49,7 +63,7 @@ class Item(MPTTModel, SlideMixin):
"""
data = {
'item': self,
'title': self.title,
'title': self.get_title(),
'template': 'projector/AgendaText.html',
}
return data
@ -105,7 +119,7 @@ class Item(MPTTModel, SlideMixin):
return ('item_delete', [str(self.id)])
def __unicode__(self):
return self.title
return self.get_title()
class Meta:
permissions = (
@ -114,7 +128,7 @@ class Item(MPTTModel, SlideMixin):
)
class MPTTMeta:
order_insertion_by = ['weight', 'title']
order_insertion_by = ['weight']
register_slidemodel(Item, control_template='agenda/control_item.html')

View File

@ -5,8 +5,8 @@
{% block title %}{{ block.super }} {{ item.title }}{% endblock %}
{% block content %}
<h1>{{ item.title }}</h1>
<p>{{ item.text|safe|linebreaks }}</p>
<h1>{{ item }}</h1>
<p>{{ item.get_text|safe|linebreaks }}</p>
{% if perms.agenda.can_manage_agenda and item.comment %}
<h2>{% trans "Comment" %}</h2>

View File

@ -2,13 +2,13 @@
{% load i18n %}
{% block title %}{{ block.super }} - {{ item.title }}{% endblock %}
{% block title %}{{ block.super }} - {{ item }}{% endblock %}
{% block content %}
{% if item.text %}
<h1>{{ item.title }}</h1>
{{ item.text|safe|linebreaks }}
{% if item.get_text %}
<h1>{{ item }}</h1>
{{ item.get_text|safe|linebreaks }}
{% else %}
<div class="item_fullscreen">{{ item.title }}</div>
<div class="item_fullscreen">{{ item }}</div>
{% endif %}
{% endblock %}

View File

@ -162,9 +162,9 @@ class AgendaPDF(PDFView):
ancestors = item.get_ancestors()
if ancestors:
space = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" * ancestors.count()
story.append(Paragraph("%s%s" % (space, item.title), stylesheet['Subitem']))
story.append(Paragraph("%s%s" % (space, item.get_title()), stylesheet['Subitem']))
else:
story.append(Paragraph(item.title, stylesheet['Item']))
story.append(Paragraph(item.get_title(), stylesheet['Item']))
class Config(FormView):

View File

@ -399,6 +399,12 @@ class Application(models.Model, SlideMixin):
self.log += "\n"
self.save()
def get_agenda_title(self):
return self.title
def get_agenda_text(self):
return 'TODO'
def __getattr__(self, name):
"""
if name is title, text, reason or time,

View File

@ -26,7 +26,10 @@
<li><a href="{% url application_delete application.id %}">{%trans 'Delete Application' %}</a></li>
{% endif %}
{% if perms.projector.can_manage_projector %}
<li><a href="{% url application_activate_item application.id %}"><img src="{% static 'images/icons/video-projector.png' %}"> {%trans 'Show Application' %}</a></li>
<li><a href="{% url projector_activate_slide application.sid %}"><img src="{% static 'images/icons/video-projector.png' %}">{%trans 'Show Application' %}</a></li>
{% endif %}
{% if perms.agenda.can_manage_agenda %}
<li><a href="{% url application_create_agenda application.id %}">{%trans 'Create Agendaitem for this application' %}</a></li>
{% endif %}
<li><a href="{% url print_application application.id %}"><img src="{% static 'images/icons/application-pdf.png' %}"> {%trans 'Application as PDF' %}</a></li>
</ul>

View File

@ -10,10 +10,10 @@
:license: GNU GPL, see LICENSE for more details.
"""
from django.conf.urls.defaults import *
from django.conf.urls.defaults import url, patterns
from django.utils.translation import ugettext as _
from application.views import ViewPoll, ApplicationPDF, ApplicationPollPDF
from application.views import ViewPoll, ApplicationPDF, ApplicationPollPDF, CreateAgendaItem
urlpatterns = patterns('application.views',
url(r'^$',
@ -26,6 +26,11 @@ urlpatterns = patterns('application.views',
name='application_view',
),
url(r'^(?P<application_id>\d+)/agenda/$',
CreateAgendaItem.as_view(),
name='application_create_agenda',
),
url(r'^(?P<application_id>\d+)/newest/$',
'view',
{'newest': True},
@ -97,11 +102,6 @@ urlpatterns = patterns('application.views',
name='application_unsupport',
),
url(r'^(?P<application_id>\d+)/set_active/$',
'set_active',
name='application_activate_item',
),
url(r'^(?P<application_id>\d+)/gen_poll/$',
'gen_poll',
name='application_gen_poll',

View File

@ -29,7 +29,6 @@ from django.core.urlresolvers import reverse
from django.utils.translation import ugettext as _
from django.utils.translation import ungettext
from django.db import transaction
from django.views.generic.base import RedirectView
from reportlab.lib import colors
from reportlab.lib.units import cm
@ -38,7 +37,7 @@ from reportlab.platypus import PageBreak, Paragraph, Spacer, Table, TableStyle
from config.models import config
from settings import SITE_ROOT
from utils.pdf import stylesheet
from utils.views import PDFView
from utils.views import PDFView, RedirectView
from agenda.models import Item
@ -377,13 +376,6 @@ def unsupport(request, application_id):
return redirect(reverse('application_view', args=[application_id]))
@permission_required('application.can_manage_application')
def set_active(request, application_id):
application = Application.objects.get(pk=application_id)
application.set_active()
return redirect(reverse('application_view', args=[application_id]))
@permission_required('application.can_manage_application')
@template('application/view.html')
def gen_poll(request, application_id):
@ -577,6 +569,18 @@ def application_import(request):
}
class CreateAgendaItem(RedirectView):
permission_required = 'agenda.can_manage_agenda'
def pre_redirect(self, request, *args, **kwargs):
self.application = Application.objects.get(pk=kwargs['application_id'])
self.item = Item(releated_sid=self.application.sid)
self.item.save()
def get_redirect_url(self, **kwargs):
return reverse('item_view', args=[self.item.id])
class ApplicationPDF(PDFView):
permission_required = 'application.can_manage_application'
top_space = 0

View File

@ -20,14 +20,17 @@ def split_sid(sid):
return None
def get_slide_from_sid(sid):
def get_slide_from_sid(sid, element=False):
try:
key, id = split_sid(sid)
except TypeError:
return None
if id is not None:
return SLIDE[key].model.objects.get(pk=id).slide()
object = SLIDE[key].model.objects.get(pk=id)
if element:
return object
return object.slide()
try:
return SLIDE[key].func()
except KeyError:

View File

@ -127,7 +127,7 @@ class RedirectView(PermissionMixin, _RedirectView):
def get(self, request, *args, **kwargs):
if request.method == 'GET':
self.pre_redirect( request, *args, **kwargs)
self.pre_redirect(request, *args, **kwargs)
elif request.method == 'POST':
self.pre_post_redirect(request, *args, **kwargs)