def detail(request, event_id): try: app = KennellingAppointment.objects.get(pk=event_id) except KennellingAppointment.DoesNotExist: try: app = Appointment.objects.get(pk=event_id) except Appointment.DoesNotExist: return HttpResponseNotFound() if inEmpGroup(request.user) or inManGroup(request.user): return render_to_response('appointments/employee_detail.html', {'app': app }) elif inCusGroup(request.user) and app.customer_id == request.user: return render_to_response('appointments/detail.html', {'app': app}) else: return HttpResponseForbidden()
def appointment_list(request): if inCusGroup(request.user): a = Appointment.objects.filter(customer_id=request.user).order_by('-start') apps = [] kennels = [] for app in a: try: k = app.kennellingappointment kennels.append(k) except KennellingAppointment.DoesNotExist: apps.append(app) return render_to_response('appointments/customer_list.html', {'apps': apps, 'kennels' : kennels }) elif inEmpGroup(request.user) or inManGroup(request.user): apps = Appointment.objects.all().order_by('-start') return render_to_response('appointments/employee_list.html', {'apps': apps})
def edit(request, event_id): try: app = KennellingAppointment.objects.get(pk=event_id) except KennellingAppointment.DoesNotExist: try: app = Appointment.objects.get(pk=event_id) except Appointment.DoesNotExist: return HttpResponseNotFound() if inEmpGroup(request.user) or inManGroup(request.user): users = User.objects.filter(groups__name='customer') return render_to_response('appointments/edit_form.html', {'app': app, 'users' : users, 'parent' : 'structure/base_employee.html' }) elif (inCusGroup(request.user) and app.customer_id == request.user): return render_to_response('appointments/edit_form.html', {'app': app, 'parent' : 'structure/base_customer.html' }) else: return HttpResponseForbidden()
def deleteConfirmed(request, event_id): app = get_object_or_404(Appointment, pk=event_id) if inEmpGroup(request.user) or inManGroup(request.user) or (inCusGroup(request.user) and app.customer_id == request.user): app.delete() return redirect('/appointments/')
def delete(request, event_id): app = get_object_or_404(Appointment, pk=event_id) if inEmpGroup(request.user) or inManGroup(request.user): return render_to_response('appointments/delete.html', { 'app' : app, 'parent' : 'structure/base_employee.html' }); elif (inCusGroup(request.user) and app.customer_id == request.user): return render_to_response('appointments/delete.html', { 'app' : app, 'parent' : 'structure/base_customer.html' });
def create(request): if inCusGroup(request.user): return render_to_response('appointments/appointment_form.html', { 'parent' : 'structure/base_customer.html' } ) else: users = User.objects.filter(groups__name='customer') return render_to_response('appointments/appointment_form.html', { 'users' : users, 'parent' : 'structure/base_employee.html', 'employee_view' : True })
from django.contrib.auth.models import User from django.contrib.auth.decorators import login_required, user_passes_test from django.template import RequestContext from appointments.models import Appointment, KennellingAppointment from scheduling.models import ScheduleManager from itertools import chain from users.views import inEmpGroup, inManGroup, inCusGroup from django.forms import ModelForm from django.core.context_processors import csrf from django.views.decorators.csrf import csrf_exempt from datetime import datetime, date, timedelta from django.core.serializers import serialize from random import randint @login_required @user_passes_test(lambda u: inEmpGroup(u) or inManGroup(u) or inCusGroup(u), login_url='/') def appointment_list(request): if inCusGroup(request.user): a = Appointment.objects.filter(customer_id=request.user).order_by('-start') apps = [] kennels = [] for app in a: try: k = app.kennellingappointment kennels.append(k) except KennellingAppointment.DoesNotExist: apps.append(app) return render_to_response('appointments/customer_list.html', {'apps': apps, 'kennels' : kennels }) elif inEmpGroup(request.user) or inManGroup(request.user): apps = Appointment.objects.all().order_by('-start') return render_to_response('appointments/employee_list.html', {'apps': apps})