Add creation of info items.
This commit is contained in:
parent
b668ac0694
commit
92e394cce9
|
@ -92,7 +92,7 @@ class InfoItem(CampRelatedModel):
|
|||
return self.category.camp
|
||||
|
||||
def clean(self):
|
||||
if InfoCategory.objects.filter(camp=self.category.camp, anchor=self.anchor).exists():
|
||||
if hasattr(self, 'category') and InfoCategory.objects.filter(camp=self.category.camp, anchor=self.anchor).exists():
|
||||
# this anchor is already in use on a category, so it cannot be used here (they must be unique on the entire page)
|
||||
raise ValidationError({'anchor': 'Anchor is already in use on an info category for this camp'})
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ Edit Info Item: {{ form.instance.headline }}
|
|||
{% else %}
|
||||
Create Info item
|
||||
{% endif %}
|
||||
for in {{ form.instance.category.headline }}
|
||||
in {{ form.instance.category.headline }}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
@ -20,7 +20,7 @@ for in {{ form.instance.category.headline }}
|
|||
{% else %}
|
||||
Create Info Item
|
||||
{% endif %}
|
||||
for in {{ form.instance.category.headline }}
|
||||
in {{ form.instance.category.headline }}
|
||||
</h4>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
|
|
|
@ -137,7 +137,7 @@ Team: {{ team.name }} | {{ block.super }}
|
|||
<tr>
|
||||
<td>{{ item.headline }}</td>
|
||||
<td>
|
||||
<a href="{% url 'teams:info_item_update' camp_slug=camp.slug team_slug=team.slug anchor=item.anchor %}"
|
||||
<a href="{% url 'teams:info_item_update' camp_slug=camp.slug team_slug=team.slug category_anchor=info_category.anchor item_anchor=item.anchor %}"
|
||||
class="btn btn-primary btn-sm">
|
||||
<i class="fa fa-edit"></i> Edit Task
|
||||
</a>
|
||||
|
@ -147,8 +147,11 @@ Team: {{ team.name }} | {{ block.super }}
|
|||
</tbody>
|
||||
</table>
|
||||
|
||||
<a href="{% url 'teams:info_item_create' camp_slug=camp.slug team_slug=team.slug category_anchor=info_category.anchor %}" class="btn btn-primary"><i class="fa fa-plus"></i> Create Info Item</a>
|
||||
|
||||
{% endfor %}
|
||||
|
||||
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -10,7 +10,7 @@ from teams.views.base import (
|
|||
TeamManageView,
|
||||
FixIrcAclView,
|
||||
)
|
||||
from teams.views.info import InfoItemUpdateView
|
||||
from teams.views.info import InfoItemUpdateView, InfoItemCreateView
|
||||
|
||||
from teams.views.tasks import (
|
||||
TaskCreateView,
|
||||
|
@ -92,14 +92,14 @@ urlpatterns = [
|
|||
]),
|
||||
),
|
||||
url(
|
||||
r'^info_items/', include([
|
||||
r'^info_items/(?P<category_anchor>[-_\w+]+)/', include([
|
||||
url(
|
||||
r'^(?P<anchor>[-_\w+]+)/', include([
|
||||
# url(
|
||||
# r'^$',
|
||||
# TaskDetailView.as_view(),
|
||||
# name='task_detail',
|
||||
# ),
|
||||
r'^create/$',
|
||||
InfoItemCreateView.as_view(),
|
||||
name='info_item_create',
|
||||
),
|
||||
url(
|
||||
r'^(?P<item_anchor>[-_\w+]+)/', include([
|
||||
url(
|
||||
r'^update/$',
|
||||
InfoItemUpdateView.as_view(),
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.views.generic import CreateView, UpdateView
|
||||
from reversion.views import RevisionMixin
|
||||
|
||||
from camps.mixins import CampViewMixin
|
||||
from info.models import InfoItem
|
||||
from info.models import InfoItem, InfoCategory
|
||||
from teams.views.mixins import EnsureTeamResponsibleMixin
|
||||
|
||||
|
||||
|
@ -15,11 +16,18 @@ class InfoItemCreateView(LoginRequiredMixin, CampViewMixin, EnsureTeamResponsibl
|
|||
|
||||
def get_context_data(self, *args, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['team'] = self.object.category.team
|
||||
context['team'] = self.team
|
||||
return context
|
||||
|
||||
def form_valid(self, form):
|
||||
info_item = form.save(commit=False)
|
||||
category = InfoCategory.objects.get(camp=self.camp, anchor=self.kwargs.get('category_anchor'))
|
||||
info_item.category = category
|
||||
info_item.save()
|
||||
return HttpResponseRedirect(self.get_success_url())
|
||||
|
||||
def get_success_url(self):
|
||||
return self.object.category.team.get_absolute_url()
|
||||
return self.team.get_absolute_url()
|
||||
|
||||
|
||||
class InfoItemUpdateView(LoginRequiredMixin, CampViewMixin, EnsureTeamResponsibleMixin, RevisionMixin, UpdateView):
|
||||
|
@ -31,9 +39,9 @@ class InfoItemUpdateView(LoginRequiredMixin, CampViewMixin, EnsureTeamResponsibl
|
|||
|
||||
def get_context_data(self, *args, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['team'] = self.object.category.team
|
||||
context['team'] = self.team
|
||||
return context
|
||||
|
||||
def get_success_url(self):
|
||||
return self.object.category.team.get_absolute_url()
|
||||
return self.team.get_absolute_url()
|
||||
|
||||
|
|
Loading…
Reference in a new issue