def new_report(request): if request.method == 'POST': reportform = ReportForm(request.POST) if reportform.is_valid(): report = reportform.save() report.created_by = request.user report.save() action.send(request.user, verb='created lot number', action_object=report, target=report) return HttpResponseRedirect(report.get_absolute_url()) else: copy = request.GET.get('copy', None) if copy: report = Report.objects.get(lot_number=copy) reportform = ReportForm(instance=report) else: reportform = ReportForm( initial={'receiving_date': time.strftime("%Y-%m-%d")}) return render_to_response('reports/new_report.html', { 'reportform': reportform, }, context_instance=RequestContext(request))
def report(request): if request.method == "POST": form = ReportForm(request.POST) if form.is_valid(): model_instance = form.save(commit=False) model_instance.save() return redirect(reverse("reportdone")) else: form = ReportForm() return render(request, 'reports/report.html', {'form': form})
def view_reports(request): formset = ReportForm() if request.method == 'POST': if request.POST.get('report'): report = get_object_or_404(Report, pk=request.POST.get('report')) form = ReportForm(request.POST, instance=report) if form.is_valid(): report = form.save() report.save() return render_to_response('reports/reports.html',{ 'success': "success", 'form': formset, 'reports': Report.objects.all()}, context_instance=RequestContext(request)) else: return render_to_response('reports/reports.html',{ 'error': form.errors, 'form': formset, 'reports': Report.objects.all()}, context_instance=RequestContext(request)) else: form = ReportForm(request.POST) if form.is_valid(): new_report= form.save() return render_to_response('reports/reports.html',{ 'success': "success", 'form': formset, 'reports': Report.objects.all()}, context_instance=RequestContext(request)) else: return render_to_response('reports/reports.html',{ 'error': form.errors, 'form': formset, 'reports': Report.objects.all()}, context_instance=RequestContext(request)) else: return render_to_response('reports/reports.html',{ 'form': formset, 'reports': Report.objects.all()}, context_instance=RequestContext(request))
def edit_report(request, lot_number): report = Report.objects.get(lot_number=lot_number) if request.method == 'POST': reportform = ReportForm(request.POST, instance=report) if reportform.is_valid(): report = reportform.save() action.send(request.user, verb='edited lot number', target=report) return HttpResponseRedirect(report.get_absolute_url()) else: reportform = ReportForm(instance=report) return render_to_response('reports/new_report.html', {'reportform': reportform,}, context_instance=RequestContext(request))
def edit_report(request, lot_number): report = Report.objects.get(lot_number=lot_number) if request.method == 'POST': reportform = ReportForm(request.POST, instance=report) if reportform.is_valid(): report = reportform.save() action.send(request.user, verb='edited lot number', target=report) return HttpResponseRedirect(report.get_absolute_url()) else: reportform = ReportForm(instance=report) return render_to_response('reports/new_report.html', { 'reportform': reportform, }, context_instance=RequestContext(request))
def create_report_view(request): form = ReportForm(request.POST or None) if request.is_ajax(): image = request.POST.get('image') img = get_report_image(image) author_profile = Profile.objects.get(user=request.user) if form.is_valid(): instance = form.save(commit=False) instance.image = img instance.author = author_profile instance.save() return JsonResponse({'msg': 'success'}) return JsonResponse({})
def report(request, id): try: reported_elem = Node.objects.get(id=id) except: reported_elem = Edge.objects.get(id=id) if request.method == "POST": form = ReportForm(request.POST) if form.is_valid(): model_instance = form.save(commit=False) model_instance.save() return redirect(reverse("reportdone")) else: form = ReportForm() return render(request, 'reports/report.html', { 'form': form, "element": reported_elem })
def index(request): if request.user.is_authenticated: if request.method == 'GET': form = ReportForm(data=request.POST, user_from=request.user.username) context = {'form': form} return render(request, 'reports/report.html', context) if request.method == 'POST': form = ReportForm(data=request.POST, user_from=request.user.username) if form.is_valid(): instance = form.save() report_reverse = instance.pk return redirect( reverse('reports:status', kwargs={'report_id': str(report_reverse)})) else: return redirect(reverse('user:login'))
def list_file(request): ''' :param request: :return:a response ''' report_form = ReportForm(request.POST or None) file_form = FileForm(request.POST or None, request.FILES or None) if file_form.is_valid(): collection_name = create_collection(request, file_form) instance = file_form.save(commit=False) instance.collection = collection_name instance.save() collection_obj = get_collection(request, collection_name) field_list, _ = get_fields_and_data_from_collection(collection_obj) field_instance_list = [] for turn in field_list: field_instance_list.append( Field.objects.create(name=turn[0], type=turn[1], file=instance)) print(Field.objects.all()) return redirect(reverse('files:list')) elif report_form.is_valid(): instance = report_form.save() narrative_instance = Narrative.objects.create(report=instance) narrative_instance.segments.create(index=0) print(instance.name, instance.file) return redirect(reverse('reports:editor', kwargs={'id': instance.id})) else: file_qs = File.objects.all() collection_list = [] for turn in file_qs: collection_list.append(get_summary_of_collection(request, turn)) context = { 'collection_list': collection_list, 'file_form': file_form, 'report_form': report_form, } return render(request, 'files/list.html', context)
def new_report(request): if request.method == 'POST': reportform = ReportForm(request.POST) if reportform.is_valid(): report = reportform.save() report.created_by = request.user report.save() action.send(request.user, verb='created lot number', action_object=report, target=report) return HttpResponseRedirect(report.get_absolute_url()) else: copy = request.GET.get('copy', None) if copy: report = Report.objects.get(lot_number=copy) reportform = ReportForm(instance=report) else: reportform = ReportForm(initial={'receiving_date': time.strftime("%Y-%m-%d")}) return render_to_response('reports/new_report.html', {'reportform': reportform,}, context_instance=RequestContext(request))