Skip to content

Commit

Permalink
Add the FAQ slug field translation
Browse files Browse the repository at this point in the history
  • Loading branch information
joahim committed Nov 26, 2021
1 parent 788a7d1 commit 0bdcd68
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 7 deletions.
33 changes: 33 additions & 0 deletions sledilnik/faq/migrations/0010_auto_20211126_1918.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 3.1.7 on 2021-11-26 18:18

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('faq', '0009_faq_slug'),
]

operations = [
migrations.AddField(
model_name='faq',
name='slug_en',
field=models.SlugField(blank=True, help_text='Used to reference the question with a hash link, e.g. https://sledilnik.org/faq#slug', max_length=100, null=True, verbose_name='Slug'),
),
migrations.AddField(
model_name='faq',
name='slug_sl',
field=models.SlugField(blank=True, help_text='Used to reference the question with a hash link, e.g. https://sledilnik.org/faq#slug', max_length=100, null=True, verbose_name='Slug'),
),
migrations.AddField(
model_name='glossaryterm',
name='slug_en',
field=models.SlugField(help_text='Used to reference the glossary term in the FAQ text: <span data-term="slug">some term</span>', max_length=100, null=True, verbose_name='Slug'),
),
migrations.AddField(
model_name='glossaryterm',
name='slug_sl',
field=models.SlugField(help_text='Used to reference the glossary term in the FAQ text: <span data-term="slug">some term</span>', max_length=100, null=True, verbose_name='Slug'),
),
]
25 changes: 25 additions & 0 deletions sledilnik/faq/migrations/0011_auto_20211126_1921.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 3.1.7 on 2021-11-26 18:21

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('faq', '0010_auto_20211126_1918'),
]

operations = [
migrations.RemoveConstraint(
model_name='glossaryterm',
name='unique_slug_per_project',
),
migrations.AddConstraint(
model_name='glossaryterm',
constraint=models.UniqueConstraint(fields=('project', 'slug_sl'), name='unique_slug_sl_per_project'),
),
migrations.AddConstraint(
model_name='glossaryterm',
constraint=models.UniqueConstraint(fields=('project', 'slug_en'), name='unique_slug_en_per_project'),
),
]
57 changes: 57 additions & 0 deletions sledilnik/faq/migrations/0012_auto_20211126_1931.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Generated by Django 3.1.7 on 2021-11-26 18:31

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('faq', '0011_auto_20211126_1921'),
]

operations = [
migrations.RemoveConstraint(
model_name='faq',
name='unique_question_per_project',
),
migrations.RemoveConstraint(
model_name='glossaryterm',
name='unique_slug_sl_per_project',
),
migrations.RemoveConstraint(
model_name='glossaryterm',
name='unique_slug_en_per_project',
),
migrations.AlterField(
model_name='faq',
name='slug',
field=models.SlugField(default='', help_text='Used to reference the question with a hash link, e.g. https://sledilnik.org/faq#slug', max_length=100, verbose_name='Slug'),
preserve_default=False,
),
migrations.AlterField(
model_name='faq',
name='slug_en',
field=models.SlugField(help_text='Used to reference the question with a hash link, e.g. https://sledilnik.org/faq#slug', max_length=100, null=True, verbose_name='Slug'),
),
migrations.AlterField(
model_name='faq',
name='slug_sl',
field=models.SlugField(help_text='Used to reference the question with a hash link, e.g. https://sledilnik.org/faq#slug', max_length=100, null=True, verbose_name='Slug'),
),
migrations.AddConstraint(
model_name='faq',
constraint=models.UniqueConstraint(fields=('project', 'slug'), name='unique_faq_slug_per_project'),
),
migrations.AddConstraint(
model_name='faq',
constraint=models.UniqueConstraint(fields=('project', 'question'), name='unique_faq_question_per_project'),
),
migrations.AddConstraint(
model_name='glossaryterm',
constraint=models.UniqueConstraint(fields=('project', 'slug_sl'), name='unique_glossary_slug_per_project'),
),
migrations.AddConstraint(
model_name='glossaryterm',
constraint=models.UniqueConstraint(fields=('project', 'term'), name='unique_glossary_term_per_project'),
),
]
21 changes: 21 additions & 0 deletions sledilnik/faq/migrations/0013_auto_20211126_1933.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 3.1.7 on 2021-11-26 18:33

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('faq', '0012_auto_20211126_1931'),
]

operations = [
migrations.RemoveConstraint(
model_name='glossaryterm',
name='unique_glossary_slug_per_project',
),
migrations.AddConstraint(
model_name='glossaryterm',
constraint=models.UniqueConstraint(fields=('project', 'slug'), name='unique_glossary_slug_per_project'),
),
]
10 changes: 5 additions & 5 deletions sledilnik/faq/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@ class Faq(models.Model):
project = models.ForeignKey(Project, verbose_name=_("Project"), on_delete=models.CASCADE, related_name="faqs")
position = models.PositiveIntegerField(_("Position"), default=0, null=False, blank=False)

# slug = models.SlugField(_("Slug"), max_length=100, help_text=_('Used to reference the question with a hash link, e.g. https://sledilnik.org/faq#slug'))
slug = models.SlugField(_("Slug"), max_length=100, help_text=_('Used to reference the question with a hash link, e.g. https://sledilnik.org/faq#slug'), null=True, blank=True)
slug = models.SlugField(_("Slug"), max_length=100, help_text=_('Used to reference the question with a hash link, e.g. https://sledilnik.org/faq#slug'))
question = models.CharField(_("Question"), max_length=500)
answer = MarkdownField(_("Answer"))

class Meta:
ordering = ["position"]
constraints = [
# models.UniqueConstraint(fields=["project", "slug"], name="unique_slug_per_project"),
models.UniqueConstraint(fields=["project", "question"], name="unique_question_per_project"),
models.UniqueConstraint(fields=["project", "slug"], name="unique_faq_slug_per_project"),
models.UniqueConstraint(fields=["project", "question"], name="unique_faq_question_per_project"),
]

def __str__(self):
Expand All @@ -46,7 +45,8 @@ class Meta:
verbose_name_plural = _("Glossary terms")
ordering = ["position"]
constraints = [
models.UniqueConstraint(fields=["project", "slug"], name="unique_slug_per_project"),
models.UniqueConstraint(fields=["project", "slug"], name="unique_glossary_slug_per_project"),
models.UniqueConstraint(fields=["project", "term"], name="unique_glossary_term_per_project"),
]

def __str__(self):
Expand Down
6 changes: 4 additions & 2 deletions sledilnik/faq/translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ class ProjectTranslationOptions(TranslationOptions):

@register(models.Faq)
class FaqTranslationOptions(TranslationOptions):
fields = ["question", "answer"]
fields = ["slug", "question", "answer"]
empty_values = {"slug": None}


@register(models.GlossaryTerm)
class GlossaryTermTranslationOptions(TranslationOptions):
fields = ["term", "definition"]
fields = ["slug", "term", "definition"]
empty_values = {"slug": None}

0 comments on commit 0bdcd68

Please sign in to comment.