-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement create / list / detail for datasets
- Loading branch information
Showing
18 changed files
with
455 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
metadata_catalogue/core/templates/core/partials/navigation.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from django.forms import ( | ||
ModelForm, | ||
widgets, | ||
CharField, | ||
IntegerField, | ||
) | ||
import logging | ||
from datetime import date | ||
from crispy_forms.helper import FormHelper | ||
from crispy_forms.layout import Submit | ||
from .models import Dataset | ||
|
||
from django.db import transaction | ||
|
||
|
||
class DatasetCreateForm(ModelForm): | ||
abstract = CharField(widget=widgets.Textarea(attrs=dict(rows=2))) | ||
formation_period_start = IntegerField(label="Temporal start (year)") | ||
formation_period_end = IntegerField(label="Temporal end (year)") | ||
geographic_description = CharField(label="Geographic description") | ||
|
||
def __init__(self, *args, user, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
|
||
self.user = user | ||
|
||
self.helper = FormHelper() | ||
self.helper.add_input(Submit("submit", "Submit", css_class="mt-2")) | ||
|
||
def save(self, commit: bool = True): | ||
with transaction.atomic(): | ||
instance = super().save(commit=False) | ||
instance.owner = self.user | ||
instance.public = False | ||
logging.warning( | ||
"This form will always commit, ensure you are using transaction.atomic to cancel this" | ||
) | ||
instance.save() | ||
|
||
instance.metadata.formation_period_start = date( | ||
self.cleaned_data["formation_period_start"], 1, 1 | ||
) | ||
instance.metadata.formation_period_end = date( | ||
self.cleaned_data["formation_period_end"], 1, 1 | ||
) | ||
instance.metadata.geographic_description = self.cleaned_data[ | ||
"geographic_description" | ||
] | ||
instance.metadata.abstract = self.cleaned_data["abstract"] | ||
instance.metadata.title = self.cleaned_data["name"] | ||
instance.metadata.save() | ||
|
||
return instance | ||
|
||
class Meta: | ||
model = Dataset | ||
fields = ( | ||
"name", | ||
"source", | ||
"notes", | ||
) | ||
widgets = { | ||
"source": widgets.Textarea( | ||
{"rows": 2, "class": "textarea-bordered"}, | ||
), | ||
"notes": widgets.Textarea({"rows": 2, "class": "textarea-bordered"}), | ||
} |
24 changes: 24 additions & 0 deletions
24
metadata_catalogue/datasets/migrations/0010_dataset_notes_dataset_source_offline_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Generated by Django 4.2.8 on 2024-10-21 06:59 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("datasets", "0009_content_created_at_content_modified_at"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="dataset", | ||
name="notes", | ||
field=models.TextField(blank=True, null=True), | ||
), | ||
migrations.AlterField( | ||
model_name="metadata", | ||
name="taxonomies", | ||
field=models.ManyToManyField( | ||
blank=True, related_name="metadatas", to="datasets.taxonomy" | ||
), | ||
), | ||
] |
Oops, something went wrong.