Skip to content

Commit

Permalink
implement create / list / detail for datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
nicokant committed Oct 21, 2024
1 parent ccfae33 commit 00fd259
Show file tree
Hide file tree
Showing 18 changed files with 455 additions and 132 deletions.
1 change: 1 addition & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"drf_standardized_errors",
"django_filters",
"tailwind",
"django_tables2",
"widget_tweaks",
"slippers",
"fontawesomefree",
Expand Down
4 changes: 2 additions & 2 deletions metadata_catalogue/core/templates/core/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
{% endif %}
{% block content %}
{% endblock content %}
</main>
</div>
</div>
</main>
</div>
{% endblock body %}
{% block modal %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% load i18n %}

<header class="sticky top-0 z-999 flex w-full bg-white drop-shadow-1 dark:bg-boxdark dark:drop-shadow-none">
<header class="sticky top-0 z-999 flex w-full navbar bg-white drop-shadow-1 dark:bg-boxdark dark:drop-shadow-none">
<div class="flex flex-grow items-center justify-between px-4 py-4 shadow-2 md:px-6 2xl:px-11">
<div>
<a class="navbar-brand fw-bolder" href="{% url 'home' %}">
Expand Down
67 changes: 67 additions & 0 deletions metadata_catalogue/datasets/forms.py
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"}),
}
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"
),
),
]
Loading

0 comments on commit 00fd259

Please sign in to comment.