def client_order_update(request, pk): context = {} order = ClientOrder.objects.select_related().get(pk=int(pk)) client = order.client area_list = client.city.area_set.all() success_msg = u'' error_msg = u'' release_date = order.date_end if request.method == 'POST': form = ClientOrderForm(request.POST, instance=order) if form.is_valid(): order_instance = form.save() if order_instance.date_end != release_date: for cos in order_instance.clientordersurface_set.all(): surface = cos.surface surface.release_date = order_instance.date_end surface.save() else: form = ClientOrderForm(instance=order) try: request.session['client_filtered_list'] except: request.session['client_filtered_list'] = reverse('client:list') context.update({ 'success': success_msg, 'error': error_msg, 'order_form': form, 'object': order, 'client': client, 'area_list': area_list, 'back_to_list': request.session['client_filtered_list'] }) return render(request, 'client/client_order_update.html', context)
def client_order(request, pk): context = {} client = Client.objects.get(pk=int(pk)) success_msg = u'' error_msg = u'' order_list_qs = client.clientorder_set.all() paginator = Paginator(order_list_qs, 25) page = request.GET.get('page') try: order_list = paginator.page(page) except PageNotAnInteger: order_list = paginator.page(1) except EmptyPage: order_list = paginator.page(paginator.num_pages) if request.method == 'POST': form = ClientOrderForm(request.POST) if form.is_valid(): order = form.save() return HttpResponseRedirect(reverse('client:order-update', args=(order.id,))) else: form = ClientOrderForm(initial={ 'client': client }) try: request.session['client_filtered_list'] except: request.session['client_filtered_list'] = reverse('client:list') context.update({ 'success': success_msg, 'error': error_msg, 'client_order_form': form, 'object': client, 'client': client, 'order_list': order_list, 'back_to_list': request.session['client_filtered_list'] }) return render(request, 'client/client_order.html', context)