-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'website' application for dynamic frontend fields
- Loading branch information
Showing
17 changed files
with
117 additions
and
3 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
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
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
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,13 @@ | ||
from django.contrib import admin | ||
from .models import WebsiteProperty | ||
|
||
|
||
@admin.register(WebsiteProperty) | ||
class WebsitePropertyAdmin(admin.ModelAdmin): | ||
list_display = ('key', 'value') | ||
|
||
def has_add_permission(self, request) -> bool: | ||
return False | ||
|
||
def has_delete_permission(self, request, obj=None) -> bool: | ||
return False |
Empty file.
Empty file.
23 changes: 23 additions & 0 deletions
23
backend/website/management/commands/seed_website_properties.py
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 @@ | ||
from django.core.management.base import BaseCommand | ||
from website.models import WebsiteProperty, PROPERTY_KEYS | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Seed website properties' | ||
|
||
def handle(self, *args, **options): | ||
self.stdout.write('Seeding website properties...') | ||
properties = set(PROPERTY_KEYS) | ||
existing = set(WebsiteProperty.objects.values_list('key', flat=True)) | ||
missing = properties - existing | ||
obsolete = existing - properties | ||
if missing: | ||
self.stdout.write(f'Creating missing properties: {", ".join(missing)}') | ||
WebsiteProperty.objects.bulk_create([ | ||
WebsiteProperty(key=key) | ||
for key in missing | ||
]) | ||
if obsolete: | ||
self.stdout.write(f'Deleting obsolete properties: {", ".join(obsolete)}') | ||
WebsiteProperty.objects.filter(key__in=obsolete).delete() | ||
self.stdout.write(self.style.SUCCESS('Website properties were seeded.')) |
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 @@ | ||
# Generated by Django 4.1.5 on 2023-03-02 15:25 | ||
|
||
import django.core.validators | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='WebsiteProperty', | ||
fields=[ | ||
('key', models.CharField(editable=False, max_length=100, primary_key=True, serialize=False, unique=True)), | ||
('description', models.TextField(blank=True)), | ||
('value', models.CharField(blank=True, help_text='Comma-separated list of values', max_length=1000, validators=[django.core.validators.RegexValidator('^[^\\,]+(?:\\,[^\\,]+)*$')])), | ||
], | ||
options={ | ||
'verbose_name': 'Website Property', | ||
'verbose_name_plural': 'Website Properties', | ||
}, | ||
), | ||
] |
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,21 @@ | ||
from django.db import models | ||
from django.core.validators import RegexValidator | ||
|
||
|
||
PROPERTY_KEYS = [ | ||
'featured_combos_title', | ||
'featured_set_codes', | ||
] | ||
|
||
|
||
class WebsiteProperty(models.Model): | ||
key = models.CharField(max_length=100, unique=True, blank=False, primary_key=True, editable=False) | ||
value = models.CharField(max_length=1000, blank=True, validators=[RegexValidator(r'^[^\,]+(?:\,[^\,]+)*$')], help_text='Comma-separated list of values') | ||
description = models.TextField(blank=True) | ||
|
||
def __str__(self): | ||
return self.key.replace("_", " ").title() | ||
|
||
class Meta: | ||
verbose_name = 'Website Property' | ||
verbose_name_plural = 'Website Properties' |
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,8 @@ | ||
from rest_framework import serializers | ||
from .models import WebsiteProperty | ||
|
||
|
||
class WebsitePropertySerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = WebsiteProperty | ||
fields = ['key', 'description', 'value'] |
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,10 @@ | ||
from django.urls import include, path | ||
from . import views | ||
from rest_framework.routers import DefaultRouter | ||
|
||
router = DefaultRouter() | ||
router.register(r'properties', views.WebsitePropertyViewSet, basename='properties') | ||
|
||
urlpatterns = [ | ||
path('', include(router.urls)) | ||
] |
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,8 @@ | ||
from rest_framework import viewsets | ||
from .models import WebsiteProperty | ||
from .serializers import WebsitePropertySerializer | ||
|
||
|
||
class WebsitePropertyViewSet(viewsets.ReadOnlyModelViewSet): | ||
queryset = WebsiteProperty.objects.all() | ||
serializer_class = WebsitePropertySerializer |