def part_edit(request, play_id, play, production_id, part_id): production = check_parameters(play_id, play, production_id) part = get_object_or_404(Part, id=part_id) if part.production != production: raise Http404() part_form = PartForm( data = request.POST or None, editing = True, instance = part, initial = { 'person': part.person } # To make form have name rather than ID ) if request.method == 'POST': if request.POST.get('disregard'): messages.success(request, u"All right, we\u2019ve ignored any changes you made.") return HttpResponseRedirect(production.get_edit_cast_url()) if part_form.is_valid(): part_form.save() messages.success(request, "Your changes have been stored; thank you.") return HttpResponseRedirect(production.get_edit_cast_url()) return render(request, 'productions/edit-part.html', { 'id': part_id, 'form': part_form, 'production': production, 'places': production.place_set.order_by('start_date', 'press_date'), })
def check_in_or_update_part(request): errlst=[] c = {} c.update(csrf(request)) if request.method == 'POST': # Testing if Part() object exists try: # Setting the part to pass as instance to form part = Part.objects.get(bar_code=request.POST.get('bar_code')) except Part.DoesNotExist: # Creating form with POST data & new row in part table myPart = Part(type=PartType(1), bar_code='') #Blank Part entry form = PartForm(request.POST, instance=myPart) else: # Create form with part instance # Updating part row with POST data-->most likely new status form = PartForm(request.POST, instance=part) if form.is_valid() and form.instance.check_in() == False: form.save(commit=True) sn = form.cleaned_data['bar_code'] status = form.cleaned_data['status'] messages.success(request,"bar code %s has been successfully %s!" % (sn,status)) else: messages.ERROR(request,"Part is already checked in!") return http.HttpResponseRedirect('') else: form = PartForm(initial={'status': Status(3),'type':PartType(1)}) return render(request,'add_part.html',{ 'title':'Add Item', 'form': form, 'errlist': errlst })
}) @login_required def production_edit_cast(request, play_id, play, production_id): """For picking someone to edit, or adding a new Part""" try: production = check_parameters(play_id, play, production_id) except UnmatchingSlugException, e: return HttpResponsePermanentRedirect(e.args[0].get_edit_cast_url()) initial = { 'production': production } if request.GET.get('person'): initial['person'] = Person.objects.get(id=base32_to_int(request.GET.get('person'))) part_form = PartForm(data=request.POST or None, editing=False, initial=initial) if request.method == 'POST': if part_form.is_valid(): part_form.instance.production = production part_form.save() messages.success(request, "Your new part has been added; thank you.") return HttpResponseRedirect(production.get_edit_cast_url()) return render(request, 'productions/edit-parts.html', { 'production': production, 'places': production.place_set.order_by('start_date', 'press_date'), 'form': part_form, 'parts': production.part_set.order_by('-cast', 'order', 'role', 'person__last_name', 'person__first_name'), }) @login_required def production_add(request, play=None, place=None, company=None):