fix a number of issues and start adding resources
This commit is contained in:
+38
-3
@@ -23,6 +23,7 @@ from atlas.models import (
|
||||
CidReportAnswer,
|
||||
Differential,
|
||||
Finding,
|
||||
Resource,
|
||||
SelfReview,
|
||||
Series,
|
||||
SeriesImage,
|
||||
@@ -74,7 +75,7 @@ class ConditionForm(ModelForm):
|
||||
class CaseCollectionForm(ModelForm):
|
||||
class Meta:
|
||||
model = CaseCollection
|
||||
exclude = ["cases", "valid_cid_users"]
|
||||
exclude = ["cases", "valid_cid_users", "author"]
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.user = kwargs.pop(
|
||||
@@ -92,6 +93,18 @@ class CaseCollectionForm(ModelForm):
|
||||
|
||||
super(CaseCollectionForm, self).__init__(*args, **kwargs)
|
||||
|
||||
def save(self, commit=True):
|
||||
# Get the unsaved Case instance
|
||||
instance = ModelForm.save(self, False)
|
||||
|
||||
|
||||
# Do we need to save all changes now?
|
||||
# if commit:
|
||||
instance.save()
|
||||
self.save_m2m()
|
||||
|
||||
return instance
|
||||
|
||||
|
||||
class FindingForm(ModelForm):
|
||||
class Meta:
|
||||
@@ -343,8 +356,6 @@ class CaseForm(ModelForm):
|
||||
instance = ModelForm.save(self, False)
|
||||
|
||||
|
||||
|
||||
|
||||
# Prepare a 'save_m2m' method for the form,
|
||||
old_save_m2m = self.save_m2m
|
||||
|
||||
@@ -390,6 +401,21 @@ CaseDifferentialFormSet = inlineformset_factory(
|
||||
},
|
||||
)
|
||||
|
||||
class CaseResourceForm(ModelForm):
|
||||
|
||||
def __init__(self, *args, user, **kwargs):
|
||||
super(CaseResourceForm, self).__init__(*args, **kwargs)
|
||||
|
||||
if not user.groups.filter(name="atlas_editor").exists():
|
||||
queryset = Resource.objects.filter(author__id=user.id)
|
||||
else:
|
||||
queryset = Resource.objects.all()
|
||||
|
||||
self.fields["resource"] = ModelChoiceField(
|
||||
required=False,
|
||||
queryset=queryset,
|
||||
# widget=Select(verbose_name="Series", is_stacked=False),
|
||||
)
|
||||
|
||||
class CaseSeriesForm(ModelForm):
|
||||
|
||||
@@ -446,6 +472,15 @@ CaseCollectionCaseFormSet = inlineformset_factory(
|
||||
max_num=50,
|
||||
)
|
||||
|
||||
CaseResourceFormSet = inlineformset_factory(
|
||||
Case,
|
||||
Resource.case_set.through,
|
||||
form=CaseResourceForm,
|
||||
exclude=[],
|
||||
can_delete=True,
|
||||
extra=0,
|
||||
max_num=10,
|
||||
)
|
||||
|
||||
SeriesImageFormSet = inlineformset_factory(
|
||||
Series,
|
||||
|
||||
Reference in New Issue
Block a user