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
|
return self.category.camp
|
||||||
|
|
||||||
def clean(self):
|
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)
|
# 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'})
|
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 %}
|
{% else %}
|
||||||
Create Info item
|
Create Info item
|
||||||
{% endif %}
|
{% endif %}
|
||||||
for in {{ form.instance.category.headline }}
|
in {{ form.instance.category.headline }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
@ -20,7 +20,7 @@ for in {{ form.instance.category.headline }}
|
||||||
{% else %}
|
{% else %}
|
||||||
Create Info Item
|
Create Info Item
|
||||||
{% endif %}
|
{% endif %}
|
||||||
for in {{ form.instance.category.headline }}
|
in {{ form.instance.category.headline }}
|
||||||
</h4>
|
</h4>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
|
|
|
@ -137,7 +137,7 @@ Team: {{ team.name }} | {{ block.super }}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ item.headline }}</td>
|
<td>{{ item.headline }}</td>
|
||||||
<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">
|
class="btn btn-primary btn-sm">
|
||||||
<i class="fa fa-edit"></i> Edit Task
|
<i class="fa fa-edit"></i> Edit Task
|
||||||
</a>
|
</a>
|
||||||
|
@ -147,8 +147,11 @@ Team: {{ team.name }} | {{ block.super }}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</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 %}
|
{% endfor %}
|
||||||
|
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -10,7 +10,7 @@ from teams.views.base import (
|
||||||
TeamManageView,
|
TeamManageView,
|
||||||
FixIrcAclView,
|
FixIrcAclView,
|
||||||
)
|
)
|
||||||
from teams.views.info import InfoItemUpdateView
|
from teams.views.info import InfoItemUpdateView, InfoItemCreateView
|
||||||
|
|
||||||
from teams.views.tasks import (
|
from teams.views.tasks import (
|
||||||
TaskCreateView,
|
TaskCreateView,
|
||||||
|
@ -92,14 +92,14 @@ urlpatterns = [
|
||||||
]),
|
]),
|
||||||
),
|
),
|
||||||
url(
|
url(
|
||||||
r'^info_items/', include([
|
r'^info_items/(?P<category_anchor>[-_\w+]+)/', include([
|
||||||
url(
|
url(
|
||||||
r'^(?P<anchor>[-_\w+]+)/', include([
|
r'^create/$',
|
||||||
# url(
|
InfoItemCreateView.as_view(),
|
||||||
# r'^$',
|
name='info_item_create',
|
||||||
# TaskDetailView.as_view(),
|
),
|
||||||
# name='task_detail',
|
url(
|
||||||
# ),
|
r'^(?P<item_anchor>[-_\w+]+)/', include([
|
||||||
url(
|
url(
|
||||||
r'^update/$',
|
r'^update/$',
|
||||||
InfoItemUpdateView.as_view(),
|
InfoItemUpdateView.as_view(),
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
|
from django.http import HttpResponseRedirect
|
||||||
from django.views.generic import CreateView, UpdateView
|
from django.views.generic import CreateView, UpdateView
|
||||||
from reversion.views import RevisionMixin
|
from reversion.views import RevisionMixin
|
||||||
|
|
||||||
from camps.mixins import CampViewMixin
|
from camps.mixins import CampViewMixin
|
||||||
from info.models import InfoItem
|
from info.models import InfoItem, InfoCategory
|
||||||
from teams.views.mixins import EnsureTeamResponsibleMixin
|
from teams.views.mixins import EnsureTeamResponsibleMixin
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,11 +16,18 @@ class InfoItemCreateView(LoginRequiredMixin, CampViewMixin, EnsureTeamResponsibl
|
||||||
|
|
||||||
def get_context_data(self, *args, **kwargs):
|
def get_context_data(self, *args, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
context['team'] = self.object.category.team
|
context['team'] = self.team
|
||||||
return context
|
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):
|
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):
|
class InfoItemUpdateView(LoginRequiredMixin, CampViewMixin, EnsureTeamResponsibleMixin, RevisionMixin, UpdateView):
|
||||||
|
@ -31,9 +39,9 @@ class InfoItemUpdateView(LoginRequiredMixin, CampViewMixin, EnsureTeamResponsibl
|
||||||
|
|
||||||
def get_context_data(self, *args, **kwargs):
|
def get_context_data(self, *args, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
context['team'] = self.object.category.team
|
context['team'] = self.team
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def get_success_url(self):
|
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