.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
data-annotations='{{question.image_annotations}}' data-edit_annotation=true></div>-->
|
||||
<div class="question">
|
||||
<a href="{% url 'anatomy:anatomy_question_update' question.id %}" title="Edit the Question">Edit</a>
|
||||
<a href="{% url 'anatomy:question_clone' question.id %}" title="Clone the Question">Clone</a>
|
||||
<a href="{% url 'admin:anatomy_anatomyquestion_change' question.id %}" title="Edit the Question using the admin interface">Admin Edit</a>
|
||||
<div class="date">
|
||||
Created: {{ question.created_date }}
|
||||
|
||||
@@ -873,6 +873,36 @@ class AnatomyQuestionCreateBase(LoginRequiredMixin, CreateView):
|
||||
else:
|
||||
return super().form_invalid(form)
|
||||
|
||||
@login_required
|
||||
def question_clone(request, pk):
|
||||
new_item = get_object_or_404(AnatomyQuestion, pk=pk)
|
||||
new_item.pk = None #autogen a new pk (item_id)
|
||||
#new_item.name = "Copy of " + new_item.name #need to change uniques
|
||||
|
||||
form = AnatomyQuestion(request.POST or None, instance=new_item)
|
||||
|
||||
formset = AnswerFormSet()
|
||||
|
||||
if form.is_valid():
|
||||
form.instance.author.add(request.user.id)
|
||||
|
||||
#logger.debug(formset.is_valid())
|
||||
if formset.is_valid():
|
||||
response = super().form_valid(form)
|
||||
formset.instance = obj
|
||||
formset.save()
|
||||
return response
|
||||
else:
|
||||
return super().form_invalid(form)
|
||||
|
||||
context = {
|
||||
"form": form,
|
||||
"answer_formset": formset
|
||||
#other context
|
||||
}
|
||||
|
||||
return render(request, "anatomy/anatomyquestion_form.html", context)
|
||||
|
||||
|
||||
# @login_required
|
||||
class AnatomyQuestionCreate(AnatomyQuestionCreateBase):
|
||||
|
||||
Reference in New Issue
Block a user