def documents_document_detail(request, doc_id):
d = Document.objects.get(pk=doc_id)
feedback_form = FeedbackForm()
context = {
'feedback_comment_form': FeedbackCommentForm(),
'doc': d,
'id': doc_id,
'service': d.system,
'form': DocumentForm(model_to_dict(d), None),
'doc_attachments': d.attachments.filter(doc_content=0).all(),
'report_attachments': d.attachments.filter(doc_content=1).all(),
'comment_attachments': d.attachments.filter(doc_content=2).all(),
'feedback_form': feedback_form,
'comment_list': DocumentComment.objects.filter(document=d, user=request.user)
}
if hasattr(d, 'feedback'):
feedback_form = FeedbackForm(initial={
'platform_awareness': d.feedback.platform_awareness,
'main_points': d.feedback.main_points,
'secondary_points': d.feedback.secondary_points,
'guids_and_recommendations': d.feedback.guids_and_recommendations
})
context['feedback_form'] = feedback_form
if request.POST and 'document_form_submit' in request.POST:
document_form = DocumentForm(request.POST, initial={'system': d.system})
document_form.fields.pop('system')
document_form.fields.pop('templateversion')
document_form.fields.pop('doc_type')
document_form.fields.pop('docdate')
if document_form.is_valid():
status = document_form.cleaned_data['status']
d.status = status
d.save()
context['doc'] = d
context['form'] = DocumentForm(model_to_dict(d), None)
context['doc_attachments'] = d.attachments.filter(doc_content=0).all()
context['report_attachments'] = d.attachments.filter(doc_content=1).all()
context['comment_attachments'] = d.attachments.filter(doc_content=2).all()
messages.success(request, '...')
return render(request, "man/documents/document-detail.html", context)
else:
for _, error in document_form.errors.items():
messages.error(request, error)
return render(request, "man/documents/document-detail.html", context)
if request.POST and 'feedback_form_submit' in request.POST:
feedback_form = FeedbackForm(request.POST)
if feedback_form.is_valid():
platform_awareness = feedback_form.cleaned_data['platform_awareness']
main_points = feedback_form.cleaned_data['main_points']
secondary_points = feedback_form.cleaned_data['secondary_points']
guids_and_recommendations = feedback_form.cleaned_data['guids_and_recommendations']
if hasattr(d, 'feedback'):
d.feedback.platform_awareness = platform_awareness
d.feedback.main_points = main_points
d.feedback.secondary_points = secondary_points
d.feedback.guids_and_recommendations = guids_and_recommendations
d.feedback.save()
feedback_form = FeedbackForm(initial={
'platform_awareness': platform_awareness,
'main_points': main_points,
'secondary_points': secondary_points,
'guids_and_recommendations': guids_and_recommendations
})
else:
f = Feedback.objects.create(
document=d,
platform_awareness=platform_awareness,
main_points=main_points,
secondary_points=secondary_points,
guids_and_recommendations=guids_and_recommendations
)
feedback_form = FeedbackForm(initial={
'platform_awareness': f.platform_awareness,
'main_points': f.main_points,
'secondary_points': f.secondary_points,
'guids_and_recommendations': f.guids_and_recommendations
})
context['feedback_form'] = feedback_form
messages.success(request, '...د')
return render(request, "man/documents/document-detail.html", context)
else:
for _, error in feedback_form.errors.items():
messages.error(request, error)
return render(request, "man/documents/document-detail.html", context)
if request.POST and 'comment_form_submit' in request.POST:
feedback_comment_form = FeedbackCommentForm(request.POST)
if feedback_comment_form.is_valid():
body = feedback_comment_form.cleaned_data['body']
DocumentComment.objects.create(
document=d,
user=request.user,
body=body,
comment_datetime=datetime.datetime.now()
)
context['comment_list'] = DocumentComment.objects.filter(document=d, user=request.user)
messages.success(request, '...')
return render(request, "man/documents/document-detail.html", context)
else:
for _, error in feedback_comment_form.errors.items():
messages.error(request, error)
return render(request, "man/documents/document-detail.html", context)
return render(request, "man/documents/document-detail.html", context)