def post(self, request, *args, **kwargs): customer = get_object_or_404(EmailUser, pk=args[0]) form = CommunicationsLogEntryForm(data=request.POST, files=request.FILES) if form.is_valid(): communications_log_entry = form.save(commit=False) communications_log_entry.customer = customer communications_log_entry.staff = request.user communications_log_entry.save() if request.FILES and 'attachment' in request.FILES: communications_log_entry.documents.add( Document.objects.create(file=request.FILES['attachment'])) return JsonResponse('ok', safe=False, encoder=WildlifeLicensingJSONEncoder) else: return JsonResponse( { "errors": [{ 'status': "422", 'title': 'Data not valid', 'detail': form.errors }] }, safe=False, encoder=WildlifeLicensingJSONEncoder, status_code=422)
def post(self, request, *args, **kwargs): customer = get_object_or_404(EmailUser, pk=args[0]) form = CommunicationsLogEntryForm(data=request.POST, files=request.FILES) if form.is_valid(): communications_log_entry = form.save(commit=False) communications_log_entry.customer = customer communications_log_entry.officer = request.user if request.FILES and 'attachment' in request.FILES: communications_log_entry.document = Document.objects.create(file=request.FILES['attachment']) communications_log_entry.save() return JsonResponse('ok', safe=False, encoder=WildlifeLicensingJSONEncoder) else: return JsonResponse( { "errors": [ { 'status': "422", 'title': 'Data not valid', 'detail': form.errors } ] }, safe=False, encoder=WildlifeLicensingJSONEncoder, status_code=422)
def post(self, request, *args, **kwargs): form = CommunicationsLogEntryForm(data=request.POST, files=request.FILES) if form.is_valid(): ret = get_object_or_404(Return, pk=args[0]) customer = ret.licence.holder officer = request.user document = None if request.FILES and 'attachment' in request.FILES: document = Document.objects.create(file=request.FILES['attachment']) kwargs = { 'document': document, 'officer': officer, 'customer': customer, 'ret': ret, 'type': form.cleaned_data['type'], 'text': form.cleaned_data['text'], 'subject': form.cleaned_data['subject'], 'to': form.cleaned_data['to'], 'fromm': form.cleaned_data['fromm'] } ReturnLogEntry.objects.create(**kwargs) return JsonResponse('ok', safe=False, encoder=WildlifeLicensingJSONEncoder) else: return JsonResponse( { "errors": [ { 'status': "422", 'title': 'Data not valid', 'detail': form.errors } ] }, safe=False, encoder=WildlifeLicensingJSONEncoder, status_code=422)
def post(self, request, *args, **kwargs): form = CommunicationsLogEntryForm(data=request.POST, files=request.FILES) if form.is_valid(): application = get_object_or_404(Application, pk=args[0]) customer = application.applicant_profile.user officer = request.user document = None if request.FILES and "attachment" in request.FILES: document = Document.objects.create(file=request.FILES["attachment"]) kwargs = { "document": document, "officer": officer, "customer": customer, "application": application, "type": form.cleaned_data["type"], "text": form.cleaned_data["text"], "subject": form.cleaned_data["subject"], "to": form.cleaned_data["to"], "fromm": form.cleaned_data["fromm"], } ApplicationLogEntry.objects.create(**kwargs) return JsonResponse("ok", safe=False, encoder=WildlifeLicensingJSONEncoder) else: return JsonResponse( {"errors": [{"status": "422", "title": "Data not valid", "detail": form.errors}]}, safe=False, encoder=WildlifeLicensingJSONEncoder, status_code=422, )
def get(self, request, *args, **kwargs): if 'customer' in self.request.GET: customer = get_object_or_404(EmailUser, pk=self.request.GET.get('customer')) return redirect('wl_customer_management:customer_lookup', customer.pk) context = {} if len(self.args) > 0: customer = get_object_or_404(EmailUser, pk=self.args[0]) kwargs['customer'] = customer kwargs['log_entry_form'] = CommunicationsLogEntryForm(to=customer.get_full_name(), fromm=self.request.user.get_full_name()) context = super(CustomerLookupView, self).get_context_data(**kwargs) return render(request, self.template_name, context)