def view_free_timeslot(request, id_hash): """Mark the CalendarEvent attribute 'is_timeslot_free' as True""" # is id_hash specified if id_hash is None: raise Http404('Reservation not found.') lu = get_common_lookup(request) # get event try: cal_event = CalendarEvent.objects.get(id_hash=id_hash, is_visible=True) selected_date = cal_event.start_datetime.date() lu.update({ 'selected_date' : selected_date}) except CalendarEvent.DoesNotExist: raise Http404('CalendarEvent not found.') cal_user = lu.get('calendar_user', None) # admin check if not cal_user.is_calendar_admin: lu.update({ 'ERR_found' : True, 'ERR_no_permission_to_free_timeslot' : True }) return render_to_response('admin_signup/reservation_signup_page.html', lu, context_instance=RequestContext(request)) # free timeslot cal_event.is_timeslot_free = True cal_event.save() signup_url = reverse('view_admin_signup_page'\ , kwargs={ 'selected_date' : selected_date.strftime('%Y-%m-%d') }) return HttpResponseRedirect(signup_url) # Redirect after POST
def view_admin_signup_page_success(request, id_hash): if id_hash is None: raise Http404('Reservation not found.') lu = get_common_lookup(request) lu.update({ 'admin_signup' : True }) if not request.user.is_authenticated(): lu.update({ 'ERR_found' : True, 'ERR_not_authenticated' : True }) return render_to_response('admin_signup/admin_signup_success.html', lu, context_instance=RequestContext(request)) cal_user = lu.get('calendar_user', None) if cal_user is None or not cal_user.is_calendar_admin: lu.update({ 'ERR_found' : True, 'ERR_no_permission_to_reserve_as_admin' : True }) return render_to_response('admin_signup/admin_signup_success.html', lu, context_instance=RequestContext(request)) try: reservation = Reservation.objects.get(id_hash=id_hash, is_visible=True) except Reservation.DoesNotExist: raise Http404('Reservation not found.') lu.update({'reservation' : reservation , 'selected_date' : reservation.start_datetime.date() }) timeslot_checker = TimeSlotChecker(selected_date=reservation.start_datetime.date()) lu.update({ 'calendar_events' : timeslot_checker.calendar_events , 'is_last_minute_reservation' : timeslot_checker.is_last_minute_reservation(reservation) }) return render_to_response('admin_signup/admin_signup_success.html', lu, context_instance=RequestContext(request))
def view_blackout_days_signup_success(request, id_hash): if id_hash is None: raise Http404('CalendarMessage not found.') lu = get_common_lookup(request) lu.update({ 'admin_blackout' : True }) if not request.user.is_authenticated(): lu.update({ 'ERR_found' : True, 'ERR_not_authenticated' : True }) return render_to_response('admin_signup/blackout_days_signup_success.html', lu, context_instance=RequestContext(request)) cal_user = lu.get('calendar_user', None) if cal_user is None or not cal_user.is_calendar_admin: lu.update({ 'ERR_found' : True, 'ERR_no_permission_to_reserve_as_admin' : True }) return render_to_response('admin_signup/blackout_days_signup_success.html', lu, context_instance=RequestContext(request)) try: calendar_message = CalendarFullDayMessage.objects.get(id_hash=id_hash, is_visible=True) except CalendarFullDayMessage.DoesNotExist: raise Http404('CalendarFullDayMessage not found.') try: message_group = calendar_message.message_group except: message_group = None lu.update({'calendar_message' : calendar_message , 'message_group' : message_group , 'selected_date' : calendar_message.start_datetime.date() }) timeslot_checker = TimeSlotChecker(selected_date=calendar_message.start_datetime.date()) lu.update({ 'calendar_events' : timeslot_checker.calendar_events }) return render_to_response('admin_signup/blackout_days_signup_success.html', lu, context_instance=RequestContext(request))
def view_signup_page_success(request, id_hash): if id_hash is None: raise Http404('Reservation not found.') if not request.user.is_authenticated(): lu.update({ 'ERR_found' : True, 'ERR_not_authenticated' : True }) return render_to_response('reservation_signup/signup_success.html', lu, context_instance=RequestContext(request)) try: reservation = Reservation.objects.get(id_hash=id_hash, is_visible=True) except Reservation.DoesNotExist: raise Http404('Reservation not found.') lu = get_common_lookup(request) lu.update({'reservation' : reservation , 'selected_date' : reservation.start_datetime.date() }) timeslot_checker = TimeSlotChecker(selected_date=reservation.start_datetime.date()) is_last_minute_reservation = timeslot_checker.is_last_minute_reservation(reservation) #print if is_last_minute_reservation: notify_staff_of_last_minute_reservation(reservation) lu.update({ 'calendar_events' : timeslot_checker.calendar_events\ , 'is_last_minute_reservation' : is_last_minute_reservation }) return render_to_response('reservation_signup/signup_success.html', lu, context_instance=RequestContext(request))
def view_admin_signup_page(request, selected_date): if selected_date is None: raise Http404('Signup date not found.') lu = get_common_lookup(request) lu.update({ 'admin_signup' : True }) try: selected_datetime = datetime.strptime(selected_date, '%Y-%m-%d') except: raise Http404('Signup date not found.') selected_date = selected_datetime.date() lu.update({ 'selected_date' : selected_date}) cal_user = lu.get('calendar_user', None) if cal_user is None or not cal_user.is_calendar_admin: lu.update({ 'ERR_found' : True, 'ERR_no_permission_to_reserve_as_admin' : True }) return render_to_response('admin_signup/reservation_signup_page.html', lu, context_instance=RequestContext(request)) if not request.user.is_authenticated(): lu.update({ 'ERR_found' : True, 'ERR_not_authenticated' : True }) return render_to_response('admin_signup/reservation_signup_page.html', lu, context_instance=RequestContext(request)) timeslot_checker = TimeSlotChecker(selected_date=selected_date) if timeslot_checker.err_found(): lu.update({ 'ERR_found' : True }) lu.update(timeslot_checker.get_lookup_for_template()) return render_to_response('admin_signup/reservation_signup_page.html', lu, context_instance=RequestContext(request)) lu.update(timeslot_checker.get_lookup_for_template()) if request.method == 'POST': # If the form has been submitted... signup_form = AdminSignupForm(request.POST) # A form bound to the POST data if signup_form.is_valid(): # All validation rules pass # Process the data in form.cleaned_data # ... new_signup = signup_form.get_reservation() success_url = reverse('view_admin_signup_page_success'\ , kwargs={ 'id_hash' : new_signup.id_hash }\ ) return HttpResponseRedirect(success_url) # Redirect after POST else: signup_form.init(timeslot_checker.get_timeslot_choices_for_form()\ , timeslot_checker.get_reservation_time_block() , cal_user ) else: signup_form = AdminSignupForm() signup_form.init(timeslot_checker.get_timeslot_choices_for_form()\ , timeslot_checker.get_reservation_time_block() , cal_user) lu.update({ 'signup_form' : signup_form , 'poster_tube_types' : PosterTubeType.objects.filter(available=True) , 'show_open_slot_links' : True}) return render_to_response('admin_signup/reservation_signup_page.html', lu, context_instance=RequestContext(request))
def view_logout_success_page(request): lu = get_common_lookup(request) cal_user = lu.get('calendar_user', None) lu.update({ 'logout_success' : True}) return render_to_response('login/logout_page.html', lu, context_instance=RequestContext(request))
def view_logout_page(request): lu = get_common_lookup(request) cal_user = lu.get('calendar_user', None) if not request.user.is_authenticated(): lu.update({ 'ERR_found' : True, 'ERR_already_logged_out' : True }) return render_to_response('login/logout_page.html', lu, context_instance=RequestContext(request))
def view_adjust_reservation_type(request, selected_date, new_reservation_time_set=False): if selected_date is None: raise Http404('selected_date is None.') lu = get_common_lookup(request) lu.update({'success_new_reservation_time_set' : new_reservation_time_set}) try: selected_date = datetime.datetime.strptime(selected_date, '%Y-%m-%d').date() lu.update({'selected_date' : selected_date }) except: raise Http404('selected_date date not found.') lu.update({ 'change_hours' : True }) if not request.user.is_authenticated(): lu.update({ 'ERR_found' : True, 'ERR_not_authenticated' : True }) return render_to_response('admin_signup/change_time_page.html', lu, context_instance=RequestContext(request)) cal_user = lu.get('calendar_user', None) if not cal_user.is_calendar_admin: lu.update({ 'ERR_found' : True, 'ERR_no_permission_to_change_time' : True }) return render_to_response('admin_signup/change_time_page.html', lu, context_instance=RequestContext(request)) timeslot_checker = TimeSlotChecker(selected_date=selected_date) lu.update(timeslot_checker.get_lookup_for_template()) if request.method == 'POST': # If the form has been submitted... change_time_form = AvailableHoursForm(request.POST) # A form bound to the POST data if change_time_form.is_valid(): # All validation rules pass if change_time_form.make_new_reservation_type(): success_url = reverse('view_adjust_reservation_type_success'\ , kwargs={ 'selected_date' : selected_date.strftime('%Y-%m-%d') }) return HttpResponseRedirect(success_url) # Redirect after POST else: change_time_form.init(selected_date) else: change_time_form = AvailableHoursForm() change_time_form.init(selected_date) lu.update({ 'change_time_form' : change_time_form}) return render_to_response('admin_signup/change_time_page.html', lu, context_instance=RequestContext(request))
def view_blackout_signup_page(request, selected_date): if selected_date is None: raise Http404('Signup date not found.') lu = get_common_lookup(request) lu.update({ 'admin_blackout' : True }) try: selected_datetime = datetime.strptime(selected_date, '%Y-%m-%d') except: selected_datetime = datetime.now() #return HttpResponse('Sign up date is not valid') selected_date = selected_datetime.date() lu.update({ 'selected_date' : selected_date}) cal_user = lu.get('calendar_user', None) if cal_user is None or not cal_user.is_calendar_admin: lu.update({ 'ERR_found' : True, 'ERR_no_permission_to_reserve_as_admin' : True }) return render_to_response('admin_signup/blackout_signup_page.html', lu, context_instance=RequestContext(request)) if not request.user.is_authenticated(): lu.update({ 'ERR_found' : True, 'ERR_not_authenticated' : True }) return render_to_response('admin_signup/blackout_signup_page.html', lu, context_instance=RequestContext(request)) timeslot_checker = TimeSlotChecker(selected_date=selected_date) if timeslot_checker.err_found(): lu.update({ 'ERR_found' : True }) lu.update(timeslot_checker.get_lookup_for_template()) return render_to_response('admin_signup/blackout_signup_page.html', lu, context_instance=RequestContext(request)) lu.update(timeslot_checker.get_lookup_for_template()) if request.method == 'POST': # If the form has been submitted... signup_form = AdminBlackoutForm(request.POST) # A form bound to the POST data if signup_form.is_valid(): # All validation rules pass new_signup = signup_form.get_calendar_event() success_url = reverse('view_blackout_signup_success'\ , kwargs={ 'id_hash' : new_signup.id_hash }\ ) return HttpResponseRedirect(success_url) # Redirect after POST else: signup_form.init(timeslot_checker.get_start_time_choices_for_form()\ , timeslot_checker.get_end_time_choices_for_form() ) else: signup_form = AdminBlackoutForm() signup_form.init(timeslot_checker.get_start_time_choices_for_form()\ , timeslot_checker.get_end_time_choices_for_form() ) lu.update({ 'signup_form' : signup_form}) return render_to_response('admin_signup/blackout_signup_page.html', lu, context_instance=RequestContext(request))
def view_cancel_signup(request, id_hash): import logging log = logging.getLogger(__name__) log.info("HERE") if id_hash is None: raise Http404("Reservation not found.") if not request.user.is_authenticated(): lu.update({"ERR_found": True, "ERR_not_authenticated": True}) return render_to_response("reservation_signup/cancel_signup.html", lu, context_instance=RequestContext(request)) try: reservation = Reservation.objects.get(id_hash=id_hash, is_visible=True) except Reservation.DoesNotExist: raise Http404("Reservation not found.") lu = get_common_lookup(request) cal_user = lu.get("calendar_user", None) if cal_user.is_calendar_admin or (cal_user == reservation.user): pass else: lu.update({"ERR_found": True, "ERR_no_permission_to_cancel": True}) return render_to_response("reservation_signup/cancel_signup.html", lu, context_instance=RequestContext(request)) if reservation.is_cancelled: # should never happen b/c shouldn't be visible lu.update({"ERR_found": True, "ERR_reservation_already_cancelled": True}) return render_to_response("reservation_signup/cancel_signup.html", lu, context_instance=RequestContext(request)) lu.update({"reservation": reservation, "selected_date": reservation.start_datetime.date()}) timeslot_checker = TimeSlotChecker(selected_date=reservation.start_datetime.date()) lu.update({"calendar_events": timeslot_checker.calendar_events}) cal_user = lu.get("calendar_user") if request.method == "POST": # If the form has been submitted... cancel_form = ReservationCancellationForm(request.POST) # A form bound to the POST data if cancel_form.is_valid(): # All validation rules pass res = cancel_form.cancel_reservation() success_url = reverse("view_cancel_success", kwargs={"id_hash": res.id_hash}) return HttpResponseRedirect(success_url) # Redirect after POST else: pass else: cancel_form = ReservationCancellationForm() cancel_form.init(id_hash) lu.update({"cancel_form": cancel_form}) return render_to_response("reservation_signup/cancel_signup.html", lu, context_instance=RequestContext(request))
def view_mark_status(request, res_id, status): if res_id is None: raise Http404('Reservation not found.') if not request.user.is_authenticated(): lu.update({ 'ERR_found' : True, 'ERR_not_authenticated' : True }) return render_to_response('reservation_history/view_user_history.html', lu, context_instance=RequestContext(request)) lu = get_common_lookup(request) cal_user = lu.get('calendar_user', None) if cal_user.is_calendar_admin: pass else: lu.update({ 'ERR_found' : True, 'ERR_no_permission_to_view_history' : True }) return render_to_response('reservation_history/view_user_history.html', lu, context_instance=RequestContext(request)) try: reservation = Reservation.objects.get(pk=res_id) except Reservation.DoesNotExist: raise Http404('Reservation not found.') try: reservation.status = Status.objects.get(name=status) reservation.save() except: raise Http404('Problem setting reservation status') cal_admin = cal_user cal_user = reservation.user lu.update({'cal_event': reservation.calendarevent_ptr, 'cal_user': cal_user, 'cal_admin': cal_admin, 'hostname': request.get_host(), 'static_url': STATIC_URL}) plaintext = get_template('email/%s.txt' % status) htmly = get_template('email/%s.html' % status) d = Context(lu) if status == 'received': subject = 'Your image file has been received.' if status == 'finished': subject = 'Your Poster has been printed' from_email, to = MCB_GRAPHICS_EMAIL, cal_user.get_email() text_content = plaintext.render(d) html_content = htmly.render(d) msg = EmailMultiAlternatives(subject, text_content, from_email, [to]) msg.attach_alternative(html_content, "text/html") msg.send() #filename = "/vagrant/MCB-Graphics-Printer-Scheduler/email_log/email%s.txt" % datetime.now().strftime("%y%m%d_%H%M%S") #filename = "/vagrant/MCB-Graphics-Printer-Scheduler/email_log/email%s.html" % datetime.now().strftime("%y%m%d_%H%M%S") #with open(filename, "w") as f: # f.write(html_content) return redirect(reverse('view_reservation_history', kwargs={'id_hash': reservation.user.id_hash}))
def view_logout_page(request): lu = get_common_lookup(request) cal_user = lu.get('calendar_user', None) if not request.user.is_authenticated(): lu.update({ 'ERR_found' : True, 'ERR_already_logged_out' : True }) return render_to_response('hu_authz_handler/view_authz_logout.html', lu, context_instance=RequestContext(request)) try: logout(request) return view_logout_success_page(request) except: return render_to_response('hu_authz_handler/view_authz_logout.html', lu, context_instance=RequestContext(request))
def view_faqs(request): lu = get_common_lookup(request) if not request.user.is_authenticated(): lu.update({ 'ERR_found' : True\ , 'ERR_not_authenticated' : True\ , 'next_link_if_not_logged_in' : reverse('view_faqs', kwargs={}) }) return render_to_response('faqs/faq_listing.html', lu, context_instance=RequestContext(request)) lu.update({ 'faqs' : FrequentlyAskedQuestion.objects.filter(is_visible=True) }) return render_to_response('faqs/faq_listing.html', lu, context_instance=RequestContext(request))
def view_reservation_history(request, id_hash): if id_hash is None: raise Http404('History not found.') if not request.user.is_authenticated(): lu.update({ 'ERR_found' : True, 'ERR_not_authenticated' : True }) return render_to_response('reservation_history/view_user_history.html', lu, context_instance=RequestContext(request)) try: cal_user_to_check = CalendarUser.objects.get(id_hash=id_hash) except CalendarUser.DoesNotExist: raise Http404('Reservation history not found for this user.') lu = get_common_lookup(request) cal_user = lu.get('calendar_user', None) if cal_user.is_calendar_admin or cal_user == cal_user_to_check: pass else: lu.update({ 'ERR_found' : True, 'ERR_no_permission_to_view_history' : True }) return render_to_response('reservation_history/view_user_history.html', lu, context_instance=RequestContext(request)) reservations = Reservation.objects.select_related(\ 'user', 'print_media'\ ).filter(user=cal_user_to_check\ # , is_cancelled=False\ ) cancellations = Reservation.objects.select_related(\ 'user', 'print_media'\ ).filter(user=cal_user_to_check\ , is_cancelled=True\ ) stati = Status.objects.all().order_by('sort_order') lu.update({ 'reservations' : reservations, 'cancellations_count' :cancellations.count(), 'cal_user_to_check' : cal_user_to_check, 'stati': stati }) return render_to_response('reservation_history/view_user_history.html', lu, context_instance=RequestContext(request))
def view_logo_listing(request): lu = get_common_lookup(request) if not request.user.is_authenticated(): lu.update({ 'ERR_found' : True\ , 'ERR_not_authenticated' : True , 'next_link_if_not_logged_in' : reverse('view_logo_listing', kwargs={}) }) return render_to_response('design_links/logo_listing.html', lu, context_instance=RequestContext(request)) base_qs = Organization.objects.filter(is_visible=True) lu.update({ 'primary_organizations' : base_qs.filter(is_primary=True)\ , 'other_organizations' : base_qs.filter(is_primary=False)\ }) return render_to_response('design_links/logo_listing.html', lu, context_instance=RequestContext(request))
def view_cancel_calendar_message(request, id_hash): if id_hash is None: raise Http404("Reservation not found.") if not request.user.is_authenticated(): lu.update({"ERR_found": True, "ERR_not_authenticated": True}) return render_to_response("admin_cancel/cancel_signup.html", lu, context_instance=RequestContext(request)) try: calendar_message = CalendarEvent.objects.get(id_hash=id_hash, is_visible=True) except CalendarEvent.DoesNotExist: raise Http404("CalendarEvent not found.") lu = get_common_lookup(request) cal_user = lu.get("calendar_user", None) if not cal_user.is_calendar_admin: lu.update({"ERR_found": True, "ERR_no_permission_to_cancel": True}) return render_to_response("admin_cancel/cancel_signup.html", lu, context_instance=RequestContext(request)) selected_date = calendar_message.start_datetime.date() lu.update({"calendar_message": calendar_message, "selected_date": selected_date, "admin_blackout_cancel": True}) timeslot_checker = TimeSlotChecker(selected_date=selected_date) lu.update({"calendar_events": timeslot_checker.calendar_events}) if request.method == "POST": # If the form has been submitted... cancel_form = CalendarEventCancellationForm(request.POST) # A form bound to the POST data if cancel_form.is_valid(): # All validation rules pass res = cancel_form.cancel_reservation() success_url = reverse( "view_cancel_calendar_message_success", kwargs={"id_hash": id_hash, "selected_date": selected_date.strftime("%Y-%m-%d")}, ) return HttpResponseRedirect(success_url) # Redirect after POST else: pass else: cancel_form = CalendarEventCancellationForm() cancel_form.init(id_hash) lu.update({"cancel_form": cancel_form}) return render_to_response("admin_cancel/cancel_signup.html", lu, context_instance=RequestContext(request))
def view_cancel_success(request, id_hash): if id_hash is None: raise Http404("Reservation not found.") if not request.user.is_authenticated(): lu.update({"ERR_found": True, "ERR_not_authenticated": True}) return render_to_response( "reservation_signup/cancel_signup_success.html", lu, context_instance=RequestContext(request) ) try: reservation = Reservation.objects.get(id_hash=id_hash) except Reservation.DoesNotExist: raise Http404("Reservation not found.") lu = get_common_lookup(request) cal_user = lu.get("calendar_user", None) if cal_user.is_calendar_admin or (cal_user == reservation.user): pass else: lu.update({"ERR_found": True, "ERR_no_permission_to_cancel": True}) return render_to_response( "reservation_signup/cancel_signup_success.html", lu, context_instance=RequestContext(request) ) lu.update({"reservation": reservation, "selected_date": reservation.start_datetime.date()}) timeslot_checker = TimeSlotChecker(selected_date=reservation.start_datetime.date()) lu.update({"calendar_events": timeslot_checker.calendar_events}) if not reservation.is_cancelled: lu.update({"ERR_found": True, "ERR_reservation_not_cancelled": True}) return render_to_response( "reservation_signup/cancel_signup_success.html", lu, context_instance=RequestContext(request) ) lu.update({"cancel_success": True}) return render_to_response( "reservation_signup/cancel_signup_success.html", lu, context_instance=RequestContext(request) )
def view_cancel_calendar_message_success(request, id_hash, selected_date): if id_hash is None or selected_date is None: raise Http404("id_hash or date not found.") lu = get_common_lookup(request) try: selected_date = datetime.datetime.strptime(selected_date, "%Y-%m-%d").date() lu.update({"selected_date": selected_date}) except: raise Http404("selected_date date not found.") lu.update({"admin_blackout_cancel": True}) if not request.user.is_authenticated(): lu.update({"ERR_found": True, "ERR_not_authenticated": True}) return render_to_response( "admin_cancel/cancel_signup_success.html", lu, context_instance=RequestContext(request) ) cal_user = lu.get("calendar_user", None) if not cal_user.is_calendar_admin: lu.update({"ERR_found": True, "ERR_no_permission_to_cancel": True}) return render_to_response( "admin_cancel/cancel_signup_success.html", lu, context_instance=RequestContext(request) ) if CalendarEvent.objects.filter(id_hash=id_hash).count() > 0: lu.update({"ERR_found": True, "ERR_calendar_event_not_cancelled": True}) return render_to_response( "admin_cancel/cancel_signup_success.html", lu, context_instance=RequestContext(request) ) timeslot_checker = TimeSlotChecker(selected_date=selected_date) lu.update({"calendar_events": timeslot_checker.calendar_events}) lu.update({"cancel_success": True}) return render_to_response("admin_cancel/cancel_signup_success.html", lu, context_instance=RequestContext(request))
def view_mark_timeslot_free(request, res_id, status): if res_id is None: raise Http404('Reservation not found.') if not request.user.is_authenticated(): lu.update({ 'ERR_found' : True, 'ERR_not_authenticated' : True }) return render_to_response('reservation_history/view_user_history.html', lu, context_instance=RequestContext(request)) lu = get_common_lookup(request) cal_user = lu.get('calendar_user', None) if cal_user.is_calendar_admin: pass else: lu.update({ 'ERR_found' : True, 'ERR_no_permission_to_view_history' : True }) return render_to_response('reservation_history/view_user_history.html', lu, context_instance=RequestContext(request)) try: cal_event = CalendarEvent.objects.get(pk=res_id) except CalendarEvent.DoesNotExist: raise Http404('Cal Event not found.') #only make boolean true if the string "True" is passed if status == 'True': status = True else: status = False try: cal_event.is_timeslot_free = status cal_event.save() except: raise Http404('Problem setting calendar event') return redirect(reverse('view_reservation_history', kwargs={'id_hash': cal_event.reservation.user.id_hash}))
def view_code_reminder(request, id_hash): import logging log = logging.getLogger(__name__) if id_hash is None: raise Http404("Reservation not found.") if not request.user.is_authenticated(): lu.update({"ERR_found": True, "ERR_not_authenticated": True}) return render_to_response("reservation_signup/cancel_signup.html", lu, context_instance=RequestContext(request)) try: reservation = Reservation.objects.get(id_hash=id_hash, is_visible=True) except Reservation.DoesNotExist: raise Http404("Reservation not found.") lu = get_common_lookup(request) cal_user = lu.get("calendar_user", None) log.info("USER %s" % cal_user) log.info("USER %s" % cal_user.contact_email) lu.update( { "reservation": reservation, "email": cal_user.contact_email, "selected_date": reservation.start_datetime.date(), } ) cal_user = lu.get("calendar_user") mail_billing_code_reminder(reservation, cal_user.contact_email) return render_to_response("reservation_signup/code_reminder.html", lu, context_instance=RequestContext(request))
def view_create_invoice(request, res_id): if res_id is None: raise Http404('Reservation not found.') if not request.user.is_authenticated(): lu.update({ 'ERR_found' : True, 'ERR_not_authenticated' : True }) return render_to_response('reservation_history/view_user_history.html', lu, context_instance=RequestContext(request)) lu = get_common_lookup(request) cal_user = lu.get('calendar_user', None) if cal_user.is_calendar_admin: pass else: lu.update({ 'ERR_found' : True, 'ERR_no_permission_to_view_history' : True }) return render_to_response('reservation_history/view_user_history.html', lu, context_instance=RequestContext(request)) try: reservation = Reservation.objects.get(pk=res_id) except Reservation.DoesNotExist: raise Http404('Reservation not found.') bill_date = date.today().strftime("%B %d, %Y") m = hashlib.md5() m.update(datetime.now().__str__()) invoice_no = m.hexdigest()[0:10] invoice_datestring = reservation.start_datetime.strftime("%Y%m%d_%H%M") invoice_code = "%s_%s" % (invoice_datestring, reservation.user.get_user_initials()) print_media = PrintMediaType.objects.all() poster_tube_details = reservation.poster_tube_details poster_tube_types = PosterTubeType.objects.all().order_by('name') selected_poster_tube_id = None selected_poster_tube = None for ptype in poster_tube_types: if ptype.name in poster_tube_details: selected_poster_tube = ptype selected_poster_tube_id = ptype.id lu.update({'reservation': reservation\ , 'bill_date': bill_date\ , 'invoice_no': invoice_no\ , 'invoice_code': invoice_code\ , 'cal_user': cal_user\ , 'user_fullname': reservation.user.get_fullname() , 'print_media': print_media , 'poster_tube_id': selected_poster_tube_id , 'poster_tube': selected_poster_tube , 'print_proofing_cost': Decimal(PRINT_PROOFING_COST) , 'tax_rate': Decimal(TAX_RATE) , 'mcb_graphics_email': MCB_GRAPHICS_EMAIL }) if request.method == 'POST': frm = CreateInvoiceForm(request.POST) lu.update({'form': frm }) if frm.is_valid(): frm_data = frm.cleaned_data frm_data['note'] = mark_safe(frm_data['note'].replace('\n', '<br />\n')) frm_data['note'] = mark_safe("%s<br />\n" % frm_data['note']) frm_data['extra'] = mark_safe(frm_data['extra'].replace('\n', '<br />\n')) prod_cost = frm_data['print_media'].name billing_code = frm_data['billing_code'] try: poster_tube = PosterTubeType.objects.get(pk=frm_data['poster_tube']) except: try: poster_tube = PosterTubeType.objects.get(name='No Tube') except: raise cc = frm_data['cc'] if frm_data['payment_method'] == 'cash': billing_code = 'paid with cash' lu.update({'fd': frm_data, 'cc': cc, 'billing_code': billing_code, 'prod_cost': prod_cost, 'poster_tube': poster_tube }) if frm_data['download_pdf'] == "True": return view_save_invoice(request, lu) return view_preview_invoice(request, lu) return render_to_response('reservation_history/view_form_create_invoice.html', lu, context_instance=RequestContext(request)) else: note_array = [reservation.note] note_array = filter(None, note_array) note_string = '\n'.join(note_array) initial_form_data = {'note': note_string, 'billing_date': datetime.now(), 'completed_date': reservation.last_update, 'print_proofing_cost': PRINT_PROOFING_COST, 'sq_feet': 0.0} if reservation.print_media != None: initial_form_data.update({'print_media': reservation.print_media}) if reservation.poster_tube_details != None: initial_form_data.update({'poster_tube': selected_poster_tube_id}) if reservation.billing_code != None: initial_form_data.update({'billing_code': reservation.billing_code}) frm = CreateInvoiceForm(instance=reservation, initial=initial_form_data) lu.update({ 'form': frm }) return render_to_response('reservation_history/view_form_create_invoice.html', lu, context_instance=RequestContext(request))