.
This commit is contained in:
@@ -81,6 +81,17 @@ class LongSeriesForm(ModelForm):
|
||||
js = ["jsi18n.js", "tesseract.min.js"]
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.user = kwargs.pop(
|
||||
"user"
|
||||
) # To get request.user. Do not use kwargs.pop('user', None) due to potential security hole
|
||||
if kwargs.get("instance"):
|
||||
# We get the 'initial' keyword argument or initialize it
|
||||
# as a dict if it didn't exist.
|
||||
initial = kwargs.setdefault("initial", {})
|
||||
# The widget for a ModelMultipleChoiceField expects
|
||||
# a list of primary key for the selected data.
|
||||
initial["long"] = [t.pk for t in kwargs["instance"].exams.all()]
|
||||
|
||||
super(LongSeriesForm, self).__init__(*args, **kwargs)
|
||||
# self.fields["examination"] = ModelChoiceField(
|
||||
# queryset=Examination.objects.all(),
|
||||
|
||||
@@ -310,6 +310,12 @@ class LongSeriesCreate(RevisionMixin, LoginRequiredMixin, CreateView):
|
||||
|
||||
return initial
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super(LongSeriesCreate, self).get_form_kwargs()
|
||||
kwargs.update({"user": self.request.user})
|
||||
return kwargs
|
||||
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(LongSeriesCreate, self).get_context_data(**kwargs)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user