Skip to content

Commit 00fd259

Browse files
committed
implement create / list / detail for datasets
1 parent ccfae33 commit 00fd259

File tree

18 files changed

+455
-132
lines changed

18 files changed

+455
-132
lines changed

config/settings/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
"drf_standardized_errors",
103103
"django_filters",
104104
"tailwind",
105+
"django_tables2",
105106
"widget_tweaks",
106107
"slippers",
107108
"fontawesomefree",

metadata_catalogue/core/templates/core/base.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
{% endif %}
5555
{% block content %}
5656
{% endblock content %}
57-
</main>
58-
</div>
57+
</div>
58+
</main>
5959
</div>
6060
{% endblock body %}
6161
{% block modal %}

metadata_catalogue/core/templates/core/partials/navigation.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{% load i18n %}
22

3-
<header class="sticky top-0 z-999 flex w-full bg-white drop-shadow-1 dark:bg-boxdark dark:drop-shadow-none">
3+
<header class="sticky top-0 z-999 flex w-full navbar bg-white drop-shadow-1 dark:bg-boxdark dark:drop-shadow-none">
44
<div class="flex flex-grow items-center justify-between px-4 py-4 shadow-2 md:px-6 2xl:px-11">
55
<div>
66
<a class="navbar-brand fw-bolder" href="{% url 'home' %}">

metadata_catalogue/datasets/forms.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
from django.forms import (
2+
ModelForm,
3+
widgets,
4+
CharField,
5+
IntegerField,
6+
)
7+
import logging
8+
from datetime import date
9+
from crispy_forms.helper import FormHelper
10+
from crispy_forms.layout import Submit
11+
from .models import Dataset
12+
13+
from django.db import transaction
14+
15+
16+
class DatasetCreateForm(ModelForm):
17+
abstract = CharField(widget=widgets.Textarea(attrs=dict(rows=2)))
18+
formation_period_start = IntegerField(label="Temporal start (year)")
19+
formation_period_end = IntegerField(label="Temporal end (year)")
20+
geographic_description = CharField(label="Geographic description")
21+
22+
def __init__(self, *args, user, **kwargs):
23+
super().__init__(*args, **kwargs)
24+
25+
self.user = user
26+
27+
self.helper = FormHelper()
28+
self.helper.add_input(Submit("submit", "Submit", css_class="mt-2"))
29+
30+
def save(self, commit: bool = True):
31+
with transaction.atomic():
32+
instance = super().save(commit=False)
33+
instance.owner = self.user
34+
instance.public = False
35+
logging.warning(
36+
"This form will always commit, ensure you are using transaction.atomic to cancel this"
37+
)
38+
instance.save()
39+
40+
instance.metadata.formation_period_start = date(
41+
self.cleaned_data["formation_period_start"], 1, 1
42+
)
43+
instance.metadata.formation_period_end = date(
44+
self.cleaned_data["formation_period_end"], 1, 1
45+
)
46+
instance.metadata.geographic_description = self.cleaned_data[
47+
"geographic_description"
48+
]
49+
instance.metadata.abstract = self.cleaned_data["abstract"]
50+
instance.metadata.title = self.cleaned_data["name"]
51+
instance.metadata.save()
52+
53+
return instance
54+
55+
class Meta:
56+
model = Dataset
57+
fields = (
58+
"name",
59+
"source",
60+
"notes",
61+
)
62+
widgets = {
63+
"source": widgets.Textarea(
64+
{"rows": 2, "class": "textarea-bordered"},
65+
),
66+
"notes": widgets.Textarea({"rows": 2, "class": "textarea-bordered"}),
67+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Generated by Django 4.2.8 on 2024-10-21 06:59
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
dependencies = [
8+
("datasets", "0009_content_created_at_content_modified_at"),
9+
]
10+
11+
operations = [
12+
migrations.AddField(
13+
model_name="dataset",
14+
name="notes",
15+
field=models.TextField(blank=True, null=True),
16+
),
17+
migrations.AlterField(
18+
model_name="metadata",
19+
name="taxonomies",
20+
field=models.ManyToManyField(
21+
blank=True, related_name="metadatas", to="datasets.taxonomy"
22+
),
23+
),
24+
]

0 commit comments

Comments
 (0)