Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formulario para la gestión de las secciones de la tabla de contenidos de los NÚMEROS de las revistas #727

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added toc/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions toc/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions toc/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class TocConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "toc"
301 changes: 301 additions & 0 deletions toc/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,301 @@
# Generated by Django 5.0.3 on 2024-04-06 16:50

import django.db.models.deletion
import modelcluster.fields
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
("core", "0003_gender_created_gender_creator_gender_updated_and_more"),
("journal", "0022_alter_journal_vocabulary"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name="JournalSectionCode",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"sort_order",
models.IntegerField(blank=True, editable=False, null=True),
),
(
"created",
models.DateTimeField(
auto_now_add=True, verbose_name="Creation date"
),
),
(
"updated",
models.DateTimeField(
auto_now=True, verbose_name="Last update date"
),
),
("code", models.TextField(blank=True, null=True, verbose_name="Code")),
(
"creator",
models.ForeignKey(
editable=False,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="%(class)s_creator",
to=settings.AUTH_USER_MODEL,
verbose_name="Creator",
),
),
(
"updated_by",
models.ForeignKey(
blank=True,
editable=False,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="%(class)s_last_mod_user",
to=settings.AUTH_USER_MODEL,
verbose_name="Updater",
),
),
],
options={
"ordering": ["sort_order"],
"abstract": False,
},
),
migrations.CreateModel(
name="JournalSectionTitle",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"sort_order",
models.IntegerField(blank=True, editable=False, null=True),
),
(
"created",
models.DateTimeField(
auto_now_add=True, verbose_name="Creation date"
),
),
(
"updated",
models.DateTimeField(
auto_now=True, verbose_name="Last update date"
),
),
("text", models.TextField(blank=True, null=True, verbose_name="Texto")),
(
"creator",
models.ForeignKey(
editable=False,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="%(class)s_creator",
to=settings.AUTH_USER_MODEL,
verbose_name="Creator",
),
),
(
"journal_section_title",
modelcluster.fields.ParentalKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="journal_section_title",
to="toc.journalsectioncode",
),
),
(
"language",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to="core.language",
verbose_name="Idioma",
),
),
(
"updated_by",
models.ForeignKey(
blank=True,
editable=False,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="%(class)s_last_mod_user",
to=settings.AUTH_USER_MODEL,
verbose_name="Updater",
),
),
],
options={
"ordering": ["sort_order"],
"abstract": False,
},
),
migrations.CreateModel(
name="JournalTOC",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"created",
models.DateTimeField(
auto_now_add=True, verbose_name="Creation date"
),
),
(
"updated",
models.DateTimeField(
auto_now=True, verbose_name="Last update date"
),
),
(
"creator",
models.ForeignKey(
editable=False,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="%(class)s_creator",
to=settings.AUTH_USER_MODEL,
verbose_name="Creator",
),
),
(
"journal",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to="journal.journal",
verbose_name="Journal",
),
),
(
"updated_by",
models.ForeignKey(
blank=True,
editable=False,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="%(class)s_last_mod_user",
to=settings.AUTH_USER_MODEL,
verbose_name="Updater",
),
),
],
options={
"abstract": False,
},
),
migrations.AddField(
model_name="journalsectioncode",
name="journal_section_code",
field=modelcluster.fields.ParentalKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="journal_section_code",
to="toc.journaltoc",
),
),
migrations.CreateModel(
name="JournalSection",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"sort_order",
models.IntegerField(blank=True, editable=False, null=True),
),
(
"created",
models.DateTimeField(
auto_now_add=True, verbose_name="Creation date"
),
),
(
"updated",
models.DateTimeField(
auto_now=True, verbose_name="Last update date"
),
),
(
"section",
models.TextField(blank=True, null=True, verbose_name="Section"),
),
(
"creator",
models.ForeignKey(
editable=False,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="%(class)s_creator",
to=settings.AUTH_USER_MODEL,
verbose_name="Creator",
),
),
(
"updated_by",
models.ForeignKey(
blank=True,
editable=False,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="%(class)s_last_mod_user",
to=settings.AUTH_USER_MODEL,
verbose_name="Updater",
),
),
(
"journal_section",
modelcluster.fields.ParentalKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="journal_section",
to="toc.journaltoc",
),
),
],
options={
"ordering": ["sort_order"],
"abstract": False,
},
),
]
Empty file added toc/migrations/__init__.py
Empty file.
73 changes: 73 additions & 0 deletions toc/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
from django.db import models
from django.utils.translation import gettext_lazy as _
from modelcluster.fields import ParentalKey
from modelcluster.models import ClusterableModel
from core.models import (
CommonControlField,
TextWithLang,
)
from wagtail.models import Orderable
from wagtail.admin.panels import InlinePanel, FieldPanel
from wagtailautocomplete.edit_handlers import AutocompletePanel
from journal.models import Journal


class JournalTOC(CommonControlField, ClusterableModel):
journal = models.ForeignKey(
Journal,
verbose_name=_("Journal"),
on_delete=models.SET_NULL,
related_name="+",
null=True,
blank=True,
)

panels = [
AutocompletePanel("journal"),
InlinePanel("journal_section_code", label=_("Journal Section Code"), classname="collapsed"),
InlinePanel("journal_section", label=_("Journal Section"), classname="collapsed"),
]


class JournalSectionCode(Orderable, CommonControlField, ClusterableModel):
journal_section_code = ParentalKey(
JournalTOC,
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name="journal_section_code",
)

code = models.TextField(_("Code"), null=True, blank=True)

panels = [
FieldPanel("code"),
InlinePanel("journal_section_title", label=_("Journal Section Title"), classname="collapsed"),
]

autocomplete_search_field = "code"

def autocomplete_label(self):
return f"{self.code}"


class JournalSectionTitle(Orderable, TextWithLang, CommonControlField):
journal_section_title = ParentalKey(
JournalSectionCode,
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name="journal_section_title",
)


class JournalSection(Orderable, CommonControlField):
journal_section = ParentalKey(
JournalTOC,
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name="journal_section",
)

section = models.TextField(_("Section"), null=True, blank=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eduranm creo que es importante indica la lengua de la sección. Pienso que una forma de solucionar el problema que le había yo comentado es añadir um ForeignKey / Autocomplete para self (la propia clase)

3 changes: 3 additions & 0 deletions toc/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
3 changes: 3 additions & 0 deletions toc/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.shortcuts import render

# Create your views here.
Loading
Loading