-
-
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.
Merge branch 'main' of github.com:sledilnik/website-backend into main
- Loading branch information
Showing
15 changed files
with
175 additions
and
5 deletions.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,11 @@ | ||
from django.contrib import admin | ||
from sledilnik.utils import TranslationAdmin | ||
from adminsortable2.admin import SortableAdminMixin | ||
|
||
from .models import Restriction | ||
|
||
# Register your models here. | ||
@admin.register(Restriction) | ||
class RestrictionAdmin(SortableAdminMixin, TranslationAdmin): | ||
list_display = ['title', 'regions', 'valid_since', 'valid_until', 'published'] | ||
# ordering = ('-order',) |
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 django.utils import timezone | ||
|
||
from tastypie.resources import ModelResource | ||
from tastypie.cache import SimpleCache | ||
from sorl.thumbnail import get_thumbnail | ||
|
||
from django.conf import settings | ||
from django.utils import translation | ||
|
||
from .models import Restriction | ||
from django.db.models import Max | ||
|
||
class RestrictionResource(ModelResource): | ||
class Meta: | ||
resource_name = "restrictions" | ||
queryset = Restriction.objects.all() | ||
fields = ["id", "title", "rule", "regions", "exceptions", "extra_rules", | ||
"valid_since", "valid_until", "validity_comment", "comments", "legal_link", "order"] | ||
cache = SimpleCache(timeout=60, public=True) | ||
|
||
def get_object_list(self, request): | ||
return super().get_object_list(request).filter(published=True).order_by("order") | ||
|
||
def alter_list_data_to_serialize(self, request, data): | ||
data['meta']['last_update'] = self.get_object_list(request).aggregate(Max("updated")).get('updated__max') | ||
return data | ||
|
||
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 RestrictionsConfig(AppConfig): | ||
name = 'restrictions' |
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,52 @@ | ||
# Generated by Django 3.1.4 on 2020-12-15 09:14 | ||
|
||
from django.db import migrations, models | ||
import sledilnik.easymde.models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Restriction', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('title', models.CharField(max_length=255, verbose_name='Title')), | ||
('title_sl', models.CharField(max_length=255, null=True, verbose_name='Title')), | ||
('title_en', models.CharField(max_length=255, null=True, verbose_name='Title')), | ||
('rule', sledilnik.easymde.models.MarkdownField(verbose_name='Rule')), | ||
('rule_sl', sledilnik.easymde.models.MarkdownField(null=True, verbose_name='Rule')), | ||
('rule_en', sledilnik.easymde.models.MarkdownField(null=True, verbose_name='Rule')), | ||
('regions', models.CharField(max_length=255, verbose_name='Regions')), | ||
('regions_sl', models.CharField(max_length=255, null=True, verbose_name='Regions')), | ||
('regions_en', models.CharField(max_length=255, null=True, verbose_name='Regions')), | ||
('exceptions', sledilnik.easymde.models.MarkdownField(blank=True, verbose_name='Rule exceptions')), | ||
('exceptions_sl', sledilnik.easymde.models.MarkdownField(blank=True, null=True, verbose_name='Rule exceptions')), | ||
('exceptions_en', sledilnik.easymde.models.MarkdownField(blank=True, null=True, verbose_name='Rule exceptions')), | ||
('extra_rules', sledilnik.easymde.models.MarkdownField(blank=True, verbose_name='Extra rules')), | ||
('extra_rules_sl', sledilnik.easymde.models.MarkdownField(blank=True, null=True, verbose_name='Extra rules')), | ||
('extra_rules_en', sledilnik.easymde.models.MarkdownField(blank=True, null=True, verbose_name='Extra rules')), | ||
('valid_since', models.DateField(blank=True, null=True, verbose_name='Valid since')), | ||
('valid_until', models.DateField(blank=True, null=True, verbose_name='Valid until')), | ||
('validity_comment', sledilnik.easymde.models.MarkdownField(blank=True, verbose_name='Validity comment')), | ||
('validity_comment_sl', sledilnik.easymde.models.MarkdownField(blank=True, null=True, verbose_name='Validity comment')), | ||
('validity_comment_en', sledilnik.easymde.models.MarkdownField(blank=True, null=True, verbose_name='Validity comment')), | ||
('comments', sledilnik.easymde.models.MarkdownField(blank=True, verbose_name='Comments')), | ||
('comments_sl', sledilnik.easymde.models.MarkdownField(blank=True, null=True, verbose_name='Comments')), | ||
('comments_en', sledilnik.easymde.models.MarkdownField(blank=True, null=True, verbose_name='Comments')), | ||
('legal_link', models.URLField(blank=True, null=True, verbose_name='Legal link')), | ||
('created', models.DateTimeField(auto_now_add=True, verbose_name='Created')), | ||
('updated', models.DateTimeField(auto_now=True, verbose_name='Updated')), | ||
('published', models.BooleanField(default=False, verbose_name='Published')), | ||
('order', models.PositiveIntegerField(default=0, verbose_name='Order')), | ||
], | ||
options={ | ||
'ordering': ['order'], | ||
}, | ||
), | ||
] |
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,41 @@ | ||
from django.db import models | ||
from django.utils.translation import gettext_lazy as _ | ||
from sledilnik.easymde.models import MarkdownField | ||
|
||
# class Region(models.Model): | ||
# RED = 'RED' | ||
# ORANGE = 'ORANGE' | ||
# GREEN = 'GREEN' | ||
# STATUS_CHOICES = [ | ||
# (RED, _('Red')), | ||
# (ORANGE, _('Orange')), | ||
# (GREEN, _('Green')), | ||
# ] | ||
|
||
# title = models.CharField(max_length=255, blank=False, null=False, unique=True) | ||
# status = models.CharField(max_length=255, choices=STATUS_CHOICES, blank=True, null=True) | ||
|
||
# Create your models here. | ||
class Restriction(models.Model): | ||
title = models.CharField(_("Title"), max_length=255, blank=False, null=False) | ||
rule = MarkdownField(_("Rule"), blank=False, null=False) | ||
regions = models.CharField(_("Regions"), max_length=255, null=False, blank=False) | ||
exceptions = MarkdownField(_("Rule exceptions"), blank=True, null=False) | ||
extra_rules = MarkdownField(_("Extra rules"), blank=True, null=False) | ||
valid_since = models.DateField(_("Valid since"), blank=True, null=True) | ||
valid_until = models.DateField(_("Valid until"), blank=True, null=True) | ||
validity_comment = MarkdownField(_("Validity comment"), blank=True, null=False) | ||
comments = MarkdownField(_("Comments"), blank=True, null=False) | ||
legal_link = models.URLField(_("Legal link"), blank=True, null=True) | ||
|
||
created = models.DateTimeField(_("Created"), auto_now_add=True) | ||
updated = models.DateTimeField(_("Updated"), auto_now=True) | ||
published = models.BooleanField(_("Published"), default=False) | ||
|
||
order = models.PositiveIntegerField(_("Order"), default=0, null=False, blank=False) | ||
|
||
class Meta(object): | ||
ordering = ["order"] | ||
|
||
def __str__(self): | ||
return self.title |
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,7 @@ | ||
from modeltranslation.translator import register, TranslationOptions | ||
from .models import Restriction | ||
|
||
|
||
@register(Restriction) | ||
class RestrictionTranslationOptions(TranslationOptions): | ||
fields = ["title", "rule", "regions", "exceptions", "extra_rules", "validity_comment", "comments"] |
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