i should break these commits up
This commit is contained in:
+31
-7
@@ -2,6 +2,7 @@ from django import forms
|
||||
from django.contrib.admin import widgets
|
||||
from django.forms import (
|
||||
BaseInlineFormSet,
|
||||
BooleanField,
|
||||
Form,
|
||||
HiddenInput,
|
||||
ModelForm,
|
||||
@@ -54,6 +55,11 @@ import logging
|
||||
|
||||
from generic.forms import ExamAuthorFormMixin
|
||||
|
||||
from crispy_forms.helper import FormHelper
|
||||
|
||||
from atlas.helpers import get_cases_available_to_user
|
||||
|
||||
|
||||
class ConditionForm(ModelForm):
|
||||
class Meta:
|
||||
model = Condition
|
||||
@@ -75,7 +81,7 @@ class ConditionForm(ModelForm):
|
||||
class CaseCollectionForm(ModelForm):
|
||||
class Meta:
|
||||
model = CaseCollection
|
||||
exclude = ["cases", "valid_cid_users", "author"]
|
||||
exclude = ["cases", "valid_cid_users", "valid_user_users", "author"]
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.user = kwargs.pop(
|
||||
@@ -261,6 +267,7 @@ class CaseForm(ModelForm):
|
||||
|
||||
# exams = ModelMultipleChoiceField(required=False, queryset=Exam.objects.all(),widget=FilteredSelectMultiple(verbose_name="Exams", is_stacked=False))
|
||||
|
||||
|
||||
class Media:
|
||||
# Django also includes a few javascript files necessary
|
||||
# for the operation of this form element. You need to
|
||||
@@ -296,12 +303,18 @@ class CaseForm(ModelForm):
|
||||
# initial["exams"] = [t.pk for t in kwargs["instance"].exams.all()]
|
||||
|
||||
|
||||
|
||||
ModelForm.__init__(self, *args, **kwargs)
|
||||
|
||||
super(CaseForm, self).__init__(*args, **kwargs)
|
||||
|
||||
# self.fields["series"].queryset =
|
||||
|
||||
if self.user.groups.filter(name="atlas_editor").exists():
|
||||
case_queryset = Case.objects.all()
|
||||
else:
|
||||
case_queryset = get_cases_available_to_user(self.user)
|
||||
self.fields["previous_case"].queryset=case_queryset
|
||||
|
||||
def get_queryset(self, request):
|
||||
return (
|
||||
super()
|
||||
@@ -401,6 +414,17 @@ CaseDifferentialFormSet = inlineformset_factory(
|
||||
},
|
||||
)
|
||||
|
||||
class ResourceForm(ModelForm):
|
||||
class Meta:
|
||||
model = Resource
|
||||
exclude = ["author"]
|
||||
|
||||
widgets = {
|
||||
"description": Textarea(attrs={"cols": 80, "rows": 5}),
|
||||
"url": TextInput(attrs={"cols": 80, "rows": 1}),
|
||||
}
|
||||
|
||||
|
||||
class CaseResourceForm(ModelForm):
|
||||
|
||||
def __init__(self, *args, user, **kwargs):
|
||||
@@ -417,6 +441,9 @@ class CaseResourceForm(ModelForm):
|
||||
# widget=Select(verbose_name="Series", is_stacked=False),
|
||||
)
|
||||
|
||||
self.fields["pre_review"] = BooleanField(required=False)
|
||||
|
||||
|
||||
class CaseSeriesForm(ModelForm):
|
||||
|
||||
def __init__(self, *args, user, **kwargs):
|
||||
@@ -440,10 +467,7 @@ class CaseCollectionCaseForm(ModelForm):
|
||||
def __init__(self, *args, user, **kwargs):
|
||||
super(CaseCollectionCaseForm, self).__init__(*args, **kwargs)
|
||||
|
||||
if not user.groups.filter(name="atlas_editor").exists():
|
||||
queryset = Case.objects.filter(author__id=user.id)
|
||||
else:
|
||||
queryset = Case.objects.all()
|
||||
queryset = get_cases_available_to_user(user)
|
||||
|
||||
self.fields["case"] = ModelChoiceField(
|
||||
required=False,
|
||||
@@ -478,7 +502,7 @@ CaseResourceFormSet = inlineformset_factory(
|
||||
form=CaseResourceForm,
|
||||
exclude=[],
|
||||
can_delete=True,
|
||||
extra=0,
|
||||
extra=1,
|
||||
max_num=10,
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user