Commit ad9b9baf authored by Patrick Kimber's avatar Patrick Kimber

edit event from detail page #903

parent 86c0095c
# -*- encoding: utf-8 -*-
from __future__ import unicode_literals
from django.contrib import admin
from .models import BookingSettings
......
# -*- encoding: utf-8 -*-
from __future__ import unicode_literals
from django import forms
from base.form_utils import (
......@@ -74,9 +72,9 @@ class BookingForm(RequiredFieldForm):
fields = ('start_date', 'end_date', 'title', 'description')
class BookingNotesForm(RequiredFieldForm):
class BookingNotesStaffForm(RequiredFieldForm):
"""
Notes for logged in users and members of staff.
Notes for members of staff.
This form will only be used if 'booking.BookingSettings.notes_user_staff'
is set to 'True'.
......@@ -84,20 +82,40 @@ class BookingNotesForm(RequiredFieldForm):
"""
def __init__(self, *args, **kwargs):
super(BookingNotesForm, self).__init__(*args, **kwargs)
for name in ('notes_user', 'notes_staff'):
self.fields[name].widget.attrs.update(
{'class': 'pure-input-2-3'}
)
super(BookingNotesStaffForm, self).__init__(*args, **kwargs)
self.fields['notes_staff'].widget.attrs.update(
{'class': 'pure-input-2-3'}
)
class Meta:
model = Booking
fields = (
'notes_user',
'notes_staff',
)
class BookingNotesUserForm(RequiredFieldForm):
"""
Notes for logged in users.
This form will only be used if 'booking.BookingSettings.notes_user_staff'
is set to 'True'.
"""
def __init__(self, *args, **kwargs):
super(BookingNotesUserForm, self).__init__(*args, **kwargs)
self.fields['notes_user'].widget.attrs.update(
{'class': 'pure-input-2-3'}
)
class Meta:
model = Booking
fields = (
'notes_user',
)
class CategoryForm(RequiredFieldForm):
def __init__(self, *args, **kwargs):
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('booking', '0007_auto_20150104_1641'),
]
operations = [
migrations.AddField(
model_name='bookingsettings',
name='edit_from_detail',
field=models.BooleanField(help_text='Edit events from the detail page.', default=False),
preserve_default=True,
),
]
......@@ -52,6 +52,11 @@ class BookingSettings(SingletonModel):
self.notes_user_staff,
)
@property
def edit_from_detail(self):
"""Do we edit events from the detail page?"""
return self.notes_user_staff or self.display_rota
reversion.register(BookingSettings)
......
......@@ -18,8 +18,12 @@
<div class="pure-u-1 pure-u-md-18-24">
{% endif %}
{% if user.is_staff and booking_edit and b.is_current %}
<a href="{% url "booking.update" b.pk %}">
{% if booking_settings.edit_from_detail %}
<a href="{% url 'booking.detail' b.pk %}">
{% else %}
<a href="{% url 'booking.update' b.pk %}">
<i class="fa fa-edit"></i>
{% endif %}
{% include 'booking/_booking_time.html' %}
{% include 'booking/_booking_title.html' %}
</a>
......
......@@ -3,22 +3,7 @@
{% if forloop.first %}
<br />
{% endif %}
{% if booking_edit %}
<a href="{% url 'booking.rota.update' rota.pk %}">
<i class="fa fa-edit"></i>
{{ rota.rota.name }}:
{{ rota.name }}
</a>
{% else %}
<strong>{{ rota.rota.name }}</strong>:
{{ rota.name }}
{% endif %}
{% if booking_edit and user.is_staff %}
&nbsp;
<a href="{% url 'booking.rota.delete' rota.pk %}">
<i class="fa fa-times"></i>
</a>
&nbsp;
{% endif %}
<strong>{{ rota.rota.name }}</strong>:
{{ rota.name }}
{% endfor %}
{% endif %}
......@@ -18,21 +18,8 @@
{% endif %}
<a href="{% url 'booking.delete' b.pk %}">
<i class="fa fa-times"></i>
Booking
Delete
</a>
<br />
{% if booking_settings.display_rota %}
<a href="{% url 'booking.rota.create' b.pk %}">
<i class="fa fa-plus"></i>
Rota
</a>
&nbsp;
{% endif %}
{% if booking_settings.notes_user_staff %}
<a href="{% url 'booking.update.notes' b.pk %}">
<i class="fa fa-edit"></i>
Notes
</a>
{% endif %}
</small>
{% endif %}
{% extends 'booking/base.html' %}
{% load static %}
{% load thumbnail %}
{% block stylesheets_extra %}
<link rel="stylesheet" href="{% static 'booking/css/booking.css' %}">
{% endblock stylesheets_extra %}
{% block title %}
{{ object.title }}
{% endblock title %}
{% block sub_heading %}
{{ object.title }}
{% endblock sub_heading %}
{% block content %}
<div class="pure-g">
<div class="pure-u-1">
<div class="pure-menu pure-menu-horizontal">
<ul class="pure-menu-list">
<li class="pure-menu-item">
<a href="{% url 'booking.list' %}" class="pure-menu-link">
<i class="fa fa-reply"></i>
</a>
</li>
<li class="pure-menu-item">
<a href="{% url 'booking.update' object.pk %}" class="pure-menu-link">
<i class="fa fa-edit"></i>
Edit
</a>
</li>
<li class="pure-menu-item">
<a href="{% url 'booking.delete' object.pk %}" class="pure-menu-link">
<i class="fa fa-times"></i>
Delete
</a>
</li>
</ul>
</div>
</div>
</div>
<div class="pure-g">
<div class="pure-u-1 pure-u-md-1-2">
<table class="pure-table pure-table-bordered">
<tbody>
<tr valign="top">
<td>
Date
</td>
<td>
{% if not object.is_current %}<del>{% endif %}
{% include 'booking/_booking_date.html' with b=object %}
{% if not object.is_current %}</del>{% endif %}
</td>
</tr>
{% if object.start_time or object.end_time %}
<tr valign="top">
<td>
Time
</td>
<td>
{% include 'booking/_booking_time.html' with b=object %}
</td>
</tr>
{% endif %}
<tr>
<td>
Title
</td>
<td>
{% include 'booking/_booking_title.html' with b=object %}
</td>
</tr>
<tr>
<td>
Location
</td>
<td>
{% include 'booking/_booking_location.html' with b=object %}
</td>
</tr>
</tbody>
</table>
</div>
<div class="pure-u-1 pure-u-md-1-2">
<table class="pure-table pure-table-bordered">
<tbody>
<tr>
<td>
Permission
</td>
<td>
{% if object.permission.slug == 'staff' %}
<span class="staff">
<i class="fa fa-lock"></i>
{% elif object.permission.slug == 'user' %}
<span class="user">
<i class="fa fa-user"></i>
{% else %}
<span>
<i class="fa fa-globe"></i>
{% endif %}
{{ object.permission.slug }}
</span>
</td>
<td>
</td>
</tr>
{% if object.picture %}
<tr valign="top">
<td>
Picture
</td>
<td>
<img class="pure-img" src="{% thumbnail object.picture 200x141 crop %}" />
</td>
<td>
</td>
</tr>
{% endif %}
{% for rota in object.rota %}
<tr>
<td>
{% if forloop.first %}
Rota
{% endif %}
</td>
<td>
<a href="{% url 'booking.rota.update' rota.pk %}">
<i class="fa fa-edit"></i>
{{ rota.rota.name }}:
{{ rota.name }}
</a>
</td>
<td>
<a href="{% url 'booking.rota.delete' rota.pk %}">
<i class="fa fa-times"></i>
</a>
</td>
</tr>
{% endfor %}
<tr>
<td>
</td>
<td>
<a href="{% url 'booking.rota.create' object.pk %}">
<i class="fa fa-plus"></i>
Rota
</a>
</td>
<td>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="pure-g">
<div class="pure-u-1 pure-u-md-4-24">
<p>
<strong>Description</strong>
</p>
</div>
<div class="pure-u-1 pure-u-md-20-24">
{% include 'booking/_booking_description.html' with b=object %}
</div>
</div>
{% if booking_settings.notes_user_staff %}
<div class="pure-g">
<div class="pure-u-1 pure-u-md-4-24">
<p>
<a href="{% url 'booking.update.notes.user' object.pk %}">
<i class="fa fa-edit"></i>
User notes
</a>
</p>
</div>
<div class="pure-u-1 pure-u-md-20-24">
{% include 'booking/_booking_notes_user.html' with b=object %}
</div>
</div>
<div class="pure-g">
<div class="pure-u-1 pure-u-md-4-24">
<p>
<a href="{% url 'booking.update.notes.staff' object.pk %}">
<i class="fa fa-edit"></i>
Staff notes
</a>
</p>
</div>
<div class="pure-u-1 pure-u-md-20-24">
{% include 'booking/_booking_notes_staff.html' with b=object %}
</div>
</div>
{% endif %}
{% endblock content %}
......@@ -11,15 +11,15 @@
{% block content %}
<div class="pure-g">
<div class="pure-u-1">
<div class="pure-menu pure-menu-open pure-menu-horizontal">
<ul>
<li>
<a href="{% url 'project.settings' %}">
<div class="pure-menu pure-menu-horizontal">
<ul class="pure-menu-list">
<li class="pure-menu-item">
<a href="{% url 'project.settings' %}" class="pure-menu-link">
<i class="fa fa-reply"></i>
</a>
</li>
<li>
<a href="{% url 'booking.rota.type.create' %}">
<li class="pure-menu-item">
<a href="{% url 'booking.rota.type.create' %}" class="pure-menu-link">
<i class="fa fa-male"></i>
Create rota type
</a>
......
# -*- encoding: utf-8 -*-
from __future__ import unicode_literals
from datetime import date
from django.utils import timezone
......@@ -25,6 +23,14 @@ class TestViewPerm(PermTestCase):
def test_event_create(self):
self.assert_staff_only(reverse('booking.create'))
def test_event_detail(self):
event = BookingFactory(start_date=date(2013, 3, 30))
url = reverse(
'booking.detail',
kwargs=dict(pk=event.pk)
)
self.assert_staff_only(url)
def test_event_list(self):
self.assert_logged_in(reverse('booking.list'))
......
# -*- encoding: utf-8 -*-
from __future__ import unicode_literals
from django.conf.urls import (
patterns,
url,
......@@ -8,9 +6,11 @@ from django.conf.urls import (
from .views import (
BookingDeleteView,
BookingDetailView,
BookingListMonthView,
BookingListView,
BookingUpdateNotesView,
BookingUpdateNotesStaffView,
BookingUpdateNotesUserView,
CategoryCreateView,
CategoryListView,
CategoryUpdateView,
......@@ -34,6 +34,10 @@ urlpatterns = patterns(
view=BookingListView.as_view(),
name='booking.list'
),
url(regex=r'^(?P<pk>\d+)/$',
view=BookingDetailView.as_view(),
name='booking.detail'
),
url(regex=r'^(?P<pk>\d+)/delete/$',
view=BookingDeleteView.as_view(),
name='booking.delete'
......@@ -42,9 +46,13 @@ urlpatterns = patterns(
view=BookingListMonthView.as_view(),
name='booking.list.month'
),
url(regex=r'^(?P<pk>\d+)/update/notes/$',
view=BookingUpdateNotesView.as_view(),
name='booking.update.notes'
url(regex=r'^(?P<pk>\d+)/update/notes/staff/$',
view=BookingUpdateNotesStaffView.as_view(),
name='booking.update.notes.staff'
),
url(regex=r'^(?P<pk>\d+)/update/notes/user/$',
view=BookingUpdateNotesUserView.as_view(),
name='booking.update.notes.user'
),
url(regex=r'^category/$',
view=CategoryListView.as_view(),
......
# -*- encoding: utf-8 -*-
from __future__ import unicode_literals
from datetime import datetime
from dateutil.relativedelta import relativedelta
......@@ -29,7 +27,8 @@ from base.view_utils import BaseMixin
from .forms import (
BookingForm,
BookingNotesForm,
BookingNotesStaffForm,
BookingNotesUserForm,
CategoryForm,
LocationForm,
RotaEmptyForm,
......@@ -47,6 +46,14 @@ from .models import (
from .service import PdfCalendar
def _url_booking(booking):
"""If we are editing from the detail form."""
if BookingSettings.load().edit_from_detail:
return reverse('booking.detail', args=[booking.pk])
else:
return _url_booking_list_month(booking)
def _url_booking_list_month(booking):
return reverse(
'booking.list.month',
......@@ -63,7 +70,7 @@ class BookingCreateView(
model = Booking
def get_success_url(self):
return _url_booking_list_month(self.object)
return _url_booking(self.object)
class BookingDeleteView(
......@@ -92,6 +99,19 @@ class BookingDeleteView(
return reverse('booking.list')
class BookingDetailView(
LoginRequiredMixin, StaffuserRequiredMixin, BaseMixin, DetailView):
model = Booking
def get_context_data(self, **kwargs):
context = super(BookingDetailView, self).get_context_data(**kwargs)
context.update(dict(
booking_settings=BookingSettings.load(),
))
return context
class BookingListMixin(LoginRequiredMixin, BaseMixin, ListView):
def get_context_data(self, **kwargs):
......@@ -173,15 +193,26 @@ class BookingListMonthView(BookingListMonthMixin):
return context
class BookingUpdateNotesView(
class BookingUpdateNotesStaffView(
LoginRequiredMixin, StaffuserRequiredMixin, BaseMixin, UpdateView):
form_class = BookingNotesForm
form_class = BookingNotesStaffForm
model = Booking
template_name = 'booking/booking_notes_form.html'
def get_success_url(self):
return reverse('booking.list')
return _url_booking(self.object)
class BookingUpdateNotesUserView(
LoginRequiredMixin, StaffuserRequiredMixin, BaseMixin, UpdateView):
form_class = BookingNotesUserForm
model = Booking
template_name = 'booking/booking_notes_form.html'
def get_success_url(self):
return _url_booking(self.object)
class BookingUpdateView(
......@@ -190,7 +221,7 @@ class BookingUpdateView(
model = Booking
def get_success_url(self):
return _url_booking_list_month(self.object)
return _url_booking(self.object)
class CategoryCreateView(
......@@ -285,7 +316,7 @@ class RotaCreateView(
return super(RotaCreateView, self).form_valid(form)
def get_success_url(self):
return _url_booking_list_month(self.object.booking)
return _url_booking(self.object.booking)
class RotaDeleteView(
......@@ -301,7 +332,7 @@ class RotaDeleteView(
return super(RotaDeleteView, self).form_valid(form)
def get_success_url(self):
return _url_booking_list_month(self.object.booking)
return _url_booking(self.object.booking)
class RotaUpdateView(
......@@ -316,7 +347,7 @@ class RotaUpdateView(
return context
def get_success_url(self):
return _url_booking_list_month(self.object.booking)
return _url_booking(self.object.booking)
class RotaTypeCreateView(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment