Skip to content

Commit

Permalink
Merge pull request #165 from OpenUpSA/order_point_theme_and_category
Browse files Browse the repository at this point in the history
Add order field to Point Theme and Profile Category
  • Loading branch information
milafrerichs authored Jan 11, 2021
2 parents f334b8e + 52dccbf commit 21e1e63
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 8 deletions.
5 changes: 3 additions & 2 deletions wazimap_ng/points/admin/profilecategory_admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from adminsortable2.admin import SortableAdminMixin
from django.contrib.gis import admin
from django import forms

Expand All @@ -17,8 +18,8 @@ def __init__(self, *args, **kwargs):


@admin.register(models.ProfileCategory)
class ProfileCategoryAdmin(BaseAdminModel):
list_display = ("label", "theme", "category", "profile")
class ProfileCategoryAdmin(SortableAdminMixin, BaseAdminModel):
list_display = ("label", "theme", "order", "category", "profile")
list_filter = (filters.ProfileFilter, filters.ThemeFilter, filters.CollectionFilter)

fieldsets = (
Expand Down
7 changes: 4 additions & 3 deletions wazimap_ng/points/admin/theme_admin.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
from adminsortable2.admin import SortableAdminMixin
from django.contrib.gis import admin
from django import forms

from wazimap_ng.general.admin.admin_base import BaseAdminModel
from wazimap_ng.general.admin import filters
from wazimap_ng.profile.models import Profile

from icon_picker_widget.widgets import IconPickerWidget

from .. import models


class ThemeAdminForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['icon'].widget = IconPickerWidget()


@admin.register(models.Theme)
class ThemeAdmin(BaseAdminModel):
list_display = ("name", "profile",)
class ThemeAdmin(SortableAdminMixin, BaseAdminModel):
list_display = ("name", "profile", "order")
list_filter = (filters.ProfileFilter,)

form = ThemeAdminForm
Expand Down
32 changes: 32 additions & 0 deletions wazimap_ng/points/migrations/0038_auto_20201117_1559.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by Django 2.2.13 on 2020-11-17 15:59

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('points', '0037_auto_20200928_2309'),
]

operations = [
migrations.AddField(
model_name='profilecategory',
name='order',
field=models.PositiveIntegerField(default=0),
),
migrations.AddField(
model_name='theme',
name='order',
field=models.PositiveIntegerField(default=0),
),
migrations.AlterModelOptions(
name='profilecategory',
options={'ordering': ['order'], 'verbose_name': 'Profile Collection',
'verbose_name_plural': 'Profile Collections'},
),
migrations.AlterModelOptions(
name='theme',
options={'ordering': ['order']},
),
]
14 changes: 14 additions & 0 deletions wazimap_ng/points/migrations/0040_merge_20210111_1807.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generated by Django 2.2.13 on 2021-01-11 18:07

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('points', '0038_auto_20201117_1559'),
('points', '0039_profilecategory_color'),
]

operations = [
]
11 changes: 8 additions & 3 deletions wazimap_ng/points/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import uuid

from django.contrib.gis.db import models
from django.contrib.postgres.fields import JSONField
Expand All @@ -11,26 +10,28 @@
from wazimap_ng.profile.models import Profile
from django_q.models import Task
from wazimap_ng import utils
from wazimap_ng.datasets.models import Licence
from wazimap_ng.general.models import BaseModel
from wazimap_ng.config.common import PERMISSION_TYPES
from colorfield.fields import ColorField



def get_file_path(instance, filename):
filename = utils.get_random_filename(filename)
return os.path.join('points', filename)


class Theme(BaseModel):
profile = models.ForeignKey(Profile, on_delete=models.CASCADE, null=True)
name = models.CharField(max_length=30)
icon = models.CharField(max_length=30, null=True, blank=True)
order = models.PositiveIntegerField(default=0, blank=False, null=False)

def __str__(self):
return f"{self.profile} | {self.name}"

class Meta:
ordering = ["profile__name"]
ordering = ["order"]


class Category(BaseModel):
Expand All @@ -46,6 +47,7 @@ class Meta:
verbose_name = "Collection"
verbose_name_plural = "Collections"


class Location(BaseModel):
name = models.CharField(max_length=255)
category = models.ForeignKey(Category, related_name="locations", on_delete=models.CASCADE, verbose_name="collection")
Expand All @@ -70,6 +72,7 @@ class ProfileCategory(BaseModel):
label = models.CharField(max_length=60, null=False, blank=True, help_text="Label for the category to be displayed on the front-end")
description = models.TextField(blank=True)
icon = models.CharField(max_length=30, null=True, blank=True)
order = models.PositiveIntegerField(default=0, blank=False, null=False)
color = ColorField(blank=True)

def __str__(self):
Expand All @@ -78,6 +81,8 @@ def __str__(self):
class Meta:
verbose_name = "Profile Collection"
verbose_name_plural = "Profile Collections"
ordering = ["order"]


class CoordinateFile(BaseModel):
document = models.FileField(
Expand Down

0 comments on commit 21e1e63

Please sign in to comment.