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

Use auto slug #175

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 20 additions & 0 deletions project/geosource/migrations/0009_alter_source_slug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.1.8 on 2023-04-11 14:47

import autoslug.fields
from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("geosource", "0008_alter_field_sample"),
]

operations = [
migrations.AlterField(
model_name="source",
name="slug",
field=autoslug.fields.AutoSlugField(
editable=False, populate_from="name", unique=True
),
),
]
3 changes: 2 additions & 1 deletion project/geosource/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import fiona
import psycopg2
import pyexcel
from autoslug import AutoSlugField
from celery.result import AsyncResult
from celery.utils.log import LoggingProxy
from django.conf import settings
Expand Down Expand Up @@ -65,7 +66,7 @@ def get_type_from_data(cls, data):
class Source(PolymorphicModel, CeleryCallMethodsMixin):
name = models.CharField(max_length=255, unique=True)
credit = models.TextField(blank=True)
slug = models.SlugField(max_length=255, unique=True)
slug = AutoSlugField(unique=True, populate_from="name")
description = models.TextField(blank=True)

id_field = models.CharField(max_length=255, default="id")
Expand Down
20 changes: 20 additions & 0 deletions project/terra_layer/migrations/0010_alter_scene_slug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.1.8 on 2023-04-11 14:47

import autoslug.fields
from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("terra_layer", "0009_alter_scene_base_layers"),
]

operations = [
migrations.AlterField(
model_name="scene",
name="slug",
field=autoslug.fields.AutoSlugField(
editable=False, populate_from="name", unique=True
),
),
]
5 changes: 1 addition & 4 deletions project/terra_layer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Scene(models.Model):
"""

name = models.CharField(max_length=255, unique=True)
slug = models.SlugField(max_length=255, unique=True)
slug = AutoSlugField(unique=True, populate_from="name")
category = models.CharField(max_length=255, default="map")
custom_icon = models.ImageField(
max_length=255, upload_to=scene_icon_path, null=True, default=None
Expand Down Expand Up @@ -129,9 +129,6 @@ def insert_in_tree(self, layer, parts, group_config=None):
self.save()

def save(self, *args, **kwargs):
if not self.slug:
self.slug = slugify(self.name)

super().save(*args, **kwargs)
self.tree2models() # Generate LayerGroups according to the tree

Expand Down
20 changes: 20 additions & 0 deletions project/visu/migrations/0006_alter_extramenuitem_slug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.1.8 on 2023-04-11 14:47

import autoslug.fields
from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("visu", "0005_alter_extramenuitem_options"),
]

operations = [
migrations.AlterField(
model_name="extramenuitem",
name="slug",
field=autoslug.fields.AutoSlugField(
editable=False, populate_from="label", unique=True
),
),
]
8 changes: 2 additions & 6 deletions project/visu/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from autoslug import AutoSlugField
from django.db import models
from django.utils.text import slugify
from django.utils.translation import gettext_lazy as _
Expand All @@ -17,18 +18,13 @@ class ExtraMenuItem(models.Model):
"""Extra menu items included in frontend."""

label = models.CharField(max_length=255, unique=True)
slug = models.SlugField(max_length=255, unique=True, blank=True)
slug = AutoSlugField(unique=True, populate_from="label")
href = models.CharField(max_length=255)
icon = models.ImageField(upload_to="extra_menu_items/")

def __str__(self):
return self.label

def save(self, *args, **kwargs):
if not self.pk and not self.slug:
self.slug = slugify(self.label)
return super().save(*args, **kwargs)

class Meta:
verbose_name = _("Extra menu item")
verbose_name_plural = _("Extra menu items")