def print_obituary2(request, obituary_id=None): ''' Coding Horror: Pretty much copied line-for-line from manage_obituary(request, obituary_id=None), ~ Line 241, above. ''' if obituary_id: obit = Obituary.objects.get(pk=obituary_id) tm = loader.get_template('obituary_list_unix_include2.txt') ct = RequestContext(request, {'object_list': [obit]}) dt = tm.render(ct) dt = output_cleanup_hack(dt) dt = adobe_to_web(dt) response_dict = { 'obit_string': dt, 'obit': obit, } return render_to_response('print_obituary2.html', response_dict, context_instance=RequestContext(request))
def manage_obituary2(request, obituary_id=None): if obituary_id: # Editing existing record ... obituary = get_object_or_404(Obituary, pk=obituary_id) else: # Creating new record ... obituary = Obituary() if request.method == 'POST': if request.POST.has_key('delete') and obituary_id: try: current_obit = Obituary.objects.filter(user=request.user).get( pk=obituary_id) except Obituary.DoesNotExist: current_obit = Obituary.objects.filter( death_notice__funeral_home__username=request.user.username ).get(pk=obituary_id) first_name = current_obit.death_notice.first_name last_name = current_obit.death_notice.last_name current_obit.delete() msg = ugettext('The %(verbose_name)s for %(first)s %(last)s was deleted.') % \ { 'verbose_name': Obituary._meta.verbose_name, 'first': first_name, 'last': last_name, } messages.success(request, msg, fail_silently=False) return HttpResponseRedirect(reverse('death_notice_index2')) if obituary_id: # try looking up obituary as if created by internal RG user ... try: current_obit = Obituary.objects.filter(user=request.user).get( pk=obituary_id) # ... if that fails, lookup obituary with requester as creating FH except Obituary.DoesNotExist: current_obit = Obituary.objects.filter( death_notice__funeral_home__username=request.user.username ).get(pk=obituary_id) form = ObituaryForm(request, request.POST, request.FILES, instance=obituary) if form.is_valid(): obituary = form.save(commit=False) obituary.user = request.user obituary.save() msg = ugettext('The %(verbose_name)s for %(first)s %(last)s was updated.') % \ { 'verbose_name': Obituary._meta.verbose_name, 'first': obituary.death_notice.first_name, 'last': obituary.death_notice.last_name, } messages.success(request, msg, fail_silently=False) if request.POST.has_key('submit'): return HttpResponseRedirect(reverse('death_notice_index2')) elif request.POST.has_key('submit_add'): return HttpResponseRedirect(reverse('add_obituary2')) else: return HttpResponseRedirect( reverse('django_obit_desk2.views.manage_obituary2', args=(obituary.pk, ))) else: if obituary_id: current_obit = Obituary.objects.get(pk=obituary_id) form = ObituaryForm(request, instance=obituary) else: form = ObituaryForm(request) ob_response_dict = { 'form': form, 'obituary_id': obituary_id, } # To be used for Preview if obituary_id: tm = loader.get_template('obituary_list_unix_include2.txt') ct = RequestContext(request, {'object_list': [current_obit]}) # ct = RequestContext(request) # ct['object_list'] = [current_obit] dt = tm.render(ct) dt = output_cleanup_hack(dt) dt = adobe_to_web(dt) ob_response_dict['obit_preview'] = dt ob_response_dict['current_obit'] = current_obit return render_to_response('manage_obituary2.html', ob_response_dict, context_instance=RequestContext(request))
def manage_obituary2(request, obituary_id=None): if obituary_id: # Editing existing record ... obituary = get_object_or_404(Obituary, pk=obituary_id) else: # Creating new record ... obituary = Obituary() if request.method == 'POST': if request.POST.has_key('delete') and obituary_id: try: current_obit = Obituary.objects.filter(user=request.user).get(pk=obituary_id) except Obituary.DoesNotExist: current_obit = Obituary.objects.filter(death_notice__funeral_home__username=request.user.username).get(pk=obituary_id) first_name = current_obit.death_notice.first_name last_name = current_obit.death_notice.last_name current_obit.delete() msg = ugettext('The %(verbose_name)s for %(first)s %(last)s was deleted.') % \ { 'verbose_name': Obituary._meta.verbose_name, 'first': first_name, 'last': last_name, } messages.success(request, msg, fail_silently=False) return HttpResponseRedirect(reverse('death_notice_index2')) if obituary_id: # try looking up obituary as if created by internal RG user ... try: current_obit = Obituary.objects.filter(user=request.user).get(pk=obituary_id) # ... if that fails, lookup obituary with requester as creating FH except Obituary.DoesNotExist: current_obit = Obituary.objects.filter(death_notice__funeral_home__username=request.user.username).get(pk=obituary_id) form = ObituaryForm(request, request.POST, request.FILES, instance=obituary) if form.is_valid(): obituary = form.save(commit=False) obituary.user = request.user obituary.save() msg = ugettext('The %(verbose_name)s for %(first)s %(last)s was updated.') % \ { 'verbose_name': Obituary._meta.verbose_name, 'first': obituary.death_notice.first_name, 'last': obituary.death_notice.last_name, } messages.success(request, msg, fail_silently=False) if request.POST.has_key('submit'): return HttpResponseRedirect(reverse('death_notice_index2')) elif request.POST.has_key('submit_add'): return HttpResponseRedirect(reverse('add_obituary2')) else: return HttpResponseRedirect(reverse('django_obit_desk2.views.manage_obituary2', args=(obituary.pk,))) else: if obituary_id: current_obit = Obituary.objects.get(pk=obituary_id) form = ObituaryForm(request, instance=obituary) else: form = ObituaryForm(request) ob_response_dict = { 'form': form, 'obituary_id': obituary_id, } # To be used for Preview if obituary_id: tm = loader.get_template('obituary_list_unix_include2.txt') ct = RequestContext(request, {'object_list': [current_obit]}) # ct = RequestContext(request) # ct['object_list'] = [current_obit] dt = tm.render(ct) dt = output_cleanup_hack(dt) dt = adobe_to_web(dt) ob_response_dict['obit_preview'] = dt ob_response_dict['current_obit'] = current_obit return render_to_response('manage_obituary2.html', ob_response_dict, context_instance=RequestContext(request))