-
-
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.
- Loading branch information
Showing
15 changed files
with
231 additions
and
2 deletions.
There are no files selected for viewing
Empty file.
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,18 @@ | ||
from adminsortable2.admin import SortableInlineAdminMixin | ||
from modeltranslation.admin import TranslationStackedInline | ||
|
||
from django.contrib import admin | ||
|
||
from sledilnik.utils import TranslationAdmin | ||
|
||
from . import models | ||
|
||
|
||
class FaqInline(SortableInlineAdminMixin, TranslationStackedInline): | ||
model = models.Faq | ||
extra = 0 | ||
|
||
|
||
@admin.register(models.Project) | ||
class ProjectAdmin(TranslationAdmin): | ||
inlines = [FaqInline] |
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,35 @@ | ||
from tastypie import fields | ||
from tastypie.resources import ModelResource | ||
from tastypie.cache import SimpleCache | ||
|
||
from django.conf import settings | ||
from django.utils import translation | ||
|
||
from .models import Project, Faq | ||
|
||
|
||
class FaqResource(ModelResource): | ||
class Meta: | ||
queryset = Faq.objects.all() | ||
fields = ["position", "question", "answer"] | ||
cache = SimpleCache(timeout=60, public=True) | ||
|
||
|
||
class FaqProjectResource(ModelResource): | ||
faq = fields.ToManyField(FaqResource, "faqs", full=True) | ||
|
||
class Meta: | ||
resource_name = "faq" | ||
queryset = Project.objects.all() | ||
fields = ["id", "name"] | ||
allowed_methods = ["get"] | ||
cache = SimpleCache(timeout=60, public=True) | ||
|
||
def dehydrate(self, bundle): | ||
lang = bundle.request.GET.get("lang") | ||
|
||
if lang not in [lng[0] for lng in settings.LANGUAGES]: | ||
lang = settings.LANGUAGE_CODE | ||
translation.activate(lang) | ||
|
||
return bundle |
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,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class FaqConfig(AppConfig): | ||
name = 'faq' |
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,45 @@ | ||
# Generated by Django 3.1.7 on 2021-11-24 13:01 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import sledilnik.easymde.models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Project', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=100, unique=True, verbose_name='Project name')), | ||
('name_sl', models.CharField(max_length=100, null=True, unique=True, verbose_name='Project name')), | ||
('name_en', models.CharField(max_length=100, null=True, unique=True, verbose_name='Project name')), | ||
], | ||
options={ | ||
'ordering': ['name'], | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='Faq', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('position', models.PositiveIntegerField(default=0, verbose_name='Position')), | ||
('question', models.CharField(max_length=500, verbose_name='Question')), | ||
('question_sl', models.CharField(max_length=500, null=True, verbose_name='Question')), | ||
('question_en', models.CharField(max_length=500, null=True, verbose_name='Question')), | ||
('answer', sledilnik.easymde.models.MarkdownField(verbose_name='Answer')), | ||
('answer_sl', sledilnik.easymde.models.MarkdownField(null=True, verbose_name='Answer')), | ||
('answer_en', sledilnik.easymde.models.MarkdownField(null=True, verbose_name='Answer')), | ||
('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='faq.project', verbose_name='Project')), | ||
], | ||
options={ | ||
'ordering': ['position'], | ||
}, | ||
), | ||
] |
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,34 @@ | ||
# Generated by Django 3.1.7 on 2021-11-24 13:14 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('faq', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='project', | ||
name='slug', | ||
field=models.SlugField(default='', help_text='Used to query the API', max_length=100, unique=True, verbose_name='Slug'), | ||
preserve_default=False, | ||
), | ||
migrations.AlterField( | ||
model_name='project', | ||
name='name', | ||
field=models.CharField(max_length=100, unique=True, verbose_name='Name'), | ||
), | ||
migrations.AlterField( | ||
model_name='project', | ||
name='name_en', | ||
field=models.CharField(max_length=100, null=True, unique=True, verbose_name='Name'), | ||
), | ||
migrations.AlterField( | ||
model_name='project', | ||
name='name_sl', | ||
field=models.CharField(max_length=100, null=True, unique=True, verbose_name='Name'), | ||
), | ||
] |
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,21 @@ | ||
# Generated by Django 3.1.7 on 2021-11-24 13:24 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('faq', '0002_auto_20211124_1414'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='project', | ||
name='name_en', | ||
), | ||
migrations.RemoveField( | ||
model_name='project', | ||
name='name_sl', | ||
), | ||
] |
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,23 @@ | ||
# Generated by Django 3.1.7 on 2021-11-24 14:15 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('faq', '0003_auto_20211124_1424'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='project', | ||
name='slug', | ||
), | ||
migrations.AlterField( | ||
model_name='faq', | ||
name='project', | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='faqs', to='faq.project', verbose_name='Project'), | ||
), | ||
] |
Empty file.
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,27 @@ | ||
from django.db import models | ||
from django.utils.translation import gettext_lazy as _ | ||
from sledilnik.easymde.models import MarkdownField | ||
|
||
|
||
class Project(models.Model): | ||
name = models.CharField(_("Name"), max_length=100, unique=True) | ||
|
||
class Meta: | ||
ordering = ["name"] | ||
|
||
def __str__(self): | ||
return self.name | ||
|
||
|
||
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) | ||
|
||
question = models.CharField(_("Question"), max_length=500) | ||
answer = MarkdownField(_("Answer")) | ||
|
||
class Meta: | ||
ordering = ["position"] | ||
|
||
def __str__(self): | ||
return self.question |
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,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
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,12 @@ | ||
from modeltranslation.translator import register, TranslationOptions | ||
from . import models | ||
|
||
|
||
@register(models.Project) | ||
class ProjectTranslationOptions(TranslationOptions): | ||
fields = [] | ||
|
||
|
||
@register(models.Faq) | ||
class FaqTranslationOptions(TranslationOptions): | ||
fields = ["question", "answer"] |
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,3 @@ | ||
from django.shortcuts import render | ||
|
||
# Create your views here. |
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