Skip to content

Commit

Permalink
new_fields added but not saving the m2m
Browse files Browse the repository at this point in the history
  • Loading branch information
silvadealmeida committed Aug 20, 2024
1 parent 83884b8 commit 0c9caeb
Show file tree
Hide file tree
Showing 21 changed files with 4,132 additions and 2,018 deletions.
4 changes: 3 additions & 1 deletion geonode/api/resourcebase_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ class CommonModelApi(ModelResource):
"edition",
"purpose",
"maintenance_frequency",
"restriction_code_type",
"use_constraint_restrictions",
"use_constrains",
"restriction_other",
"constraints_other",
"license",
"language",
Expand Down
10 changes: 7 additions & 3 deletions geonode/base/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,12 +710,15 @@ def __init__(self, *args, **kwargs):
self.fields["tkeywords"] = ComplexDynamicRelationField(SimpleThesaurusKeywordSerializer, embed=False, many=True)
self.fields["regions"] = DynamicRelationField(SimpleRegionSerializer, embed=True, many=True, read_only=True)
self.fields["category"] = ComplexDynamicRelationField(SimpleTopicCategorySerializer, embed=True, many=False)
self.fields["restriction_code_type"] = ComplexDynamicRelationField(

self.fields["use_constraint_restrictions"] = ComplexDynamicRelationField(
RestrictionCodeTypeSerializer, embed=True, many=True
)
self.fields["use_constrains"] = ComplexDynamicRelationField(
self.fields["use_constrains"] = serializers.CharField(read_only=True)
self.fields["restriction_other"] = ComplexDynamicRelationField(
RestrictionCodeTypeSerializer, embed=True, many=True
)
self.fields["constraints_other"] = serializers.CharField(read_only=True)
self.fields["license"] = ComplexDynamicRelationField(LicenseSerializer, embed=True, many=False)
self.fields["metadata_license"] = ComplexDynamicRelationField(LicenseSerializer, embed=True, many=False)
self.fields["spatial_representation_type"] = ComplexDynamicRelationField(
Expand Down Expand Up @@ -791,9 +794,10 @@ class Meta:
"edition",
"purpose",
"maintenance_frequency",
"restriction_code_type",
"use_constraint_restrictions",
"use_constrains",
"constraints_other",
"restriction_other",
"license",
"language",
"spatial_representation_type",
Expand Down
9 changes: 8 additions & 1 deletion geonode/base/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
LinkedResource,
Region,
ResourceBase,
RestrictionCodeType,
Thesaurus,
ThesaurusKeyword,
ThesaurusKeywordLabel,
Expand Down Expand Up @@ -517,7 +518,13 @@ class ResourceBaseForm(TranslationModelForm, LinkedResourceForm):
)

purpose = forms.CharField(label=_("Purpose"), required=False, widget=TinyMCE())

use_constraint_restrictions = forms.ModelMultipleChoiceField(
RestrictionCodeType.objects.all(),
# widget=forms.SelectMultiple,
widget=forms.SelectMultiple(attrs={"class": "bg-primary"}),
required=False,
)
use_constrains = forms.CharField(label=_("Use Constraints"), required=False, widget=TinyMCE())
constraints_other = forms.CharField(label=_("Other constraints"), required=False, widget=TinyMCE())

supplemental_information = forms.CharField(label=_("Supplemental information"), required=False, widget=TinyMCE())
Expand Down
33 changes: 12 additions & 21 deletions geonode/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class RestrictionCodeType(models.Model):
is_choice = models.BooleanField(default=True)

def __str__(self):
return str(self.gn_description)
return str(self.identifier)

class Meta:
ordering = ("identifier",)
Expand Down Expand Up @@ -791,7 +791,7 @@ class ResourceBase(PolymorphicModel, PermissionLevelMixin, ItemBase):
use_constrains_help_text = _(
"This metadata element shall provide information on the Use constraints applied to assure the protection of privacy or intellectual property (e.g. Trademark)"
)
restriction_code_type_help_text = _("limitation(s) placed upon the access or use of the data.")
restriction_other_help_text = _("limitation(s) placed upon the access or use of the data.")
constraints_other_help_text = _(
"other restrictions and legal prerequisites for accessing and using the resource or" " metadata"
)
Expand Down Expand Up @@ -953,22 +953,22 @@ class ResourceBase(PolymorphicModel, PermissionLevelMixin, ItemBase):
regions = models.ManyToManyField(
Region, verbose_name=_("keywords region"), null=True, blank=True, help_text=regions_help_text
)
use_constrains = models.ManyToManyField(

use_constraint_restrictions = models.ManyToManyField(
RestrictionCodeType,
verbose_name=_("use_constrains"),
help_text=use_constrains_help_text,
verbose_name=_("Use Constrain Restrictions"),
null=True,
blank=True,
related_name="use_constrains",
limit_choices_to=Q(is_choice=True),
)
restriction_code_type = models.ManyToManyField(

use_constrains = models.TextField(_("Use Constraints"), null=True, blank=True)
restriction_other = models.ManyToManyField(
RestrictionCodeType,
verbose_name=_("restrictions"),
help_text=restriction_code_type_help_text,
help_text=restriction_other_help_text,
null=True,
blank=True,
related_name="restriction_code_type",
related_name="restriction_other",
limit_choices_to=Q(is_choice=True),
)
constraints_other = models.TextField(
Expand Down Expand Up @@ -1160,15 +1160,6 @@ class ResourceBase(PolymorphicModel, PermissionLevelMixin, ItemBase):
verbose_name=_("Related Project"),
)

use_contraints = models.TextField(
_("use_constraints"),
max_length=2000,
blank=True,
help_text=_(
"This metadata element shall provide information on the Use constraints applied to assure the protection of privacy or intellectual property (e.g. Trademark)"
),
)

objects = ResourceBaseManager()

class Meta:
Expand Down Expand Up @@ -1377,7 +1368,7 @@ def organizationname(self):

@property
def restriction_code(self):
return self.restriction_code_type.gn_description if self.restriction_code_type else None
return self.restriction_other.gn_description if self.restriction_other else None

@property
def topiccategory(self):
Expand Down Expand Up @@ -1512,7 +1503,7 @@ def metadata_completeness(self):
"regions",
"title",
]
if self.restriction_code_type == "otherRestrictions":
if self.restriction_other == "otherRestrictions":
required_fields.append("constraints_other")
filled_fields = []
for required_field in required_fields:
Expand Down
Loading

0 comments on commit 0c9caeb

Please sign in to comment.