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

[8473] add kiezradar models #5740

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions changelog/8473.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
### Added

- kiezradar app
- SearchProfile model with fields:
- name, description, disabled, status
- m2m relations for districts, project-types, topics, organisations
- FK relation to user, query
- KiezRadarQuery model with a FK relation with SearchProfile for queries
- serialiser with custom create() and update() methods for the m2m relations
- api view for searchprofile
Empty file.
28 changes: 28 additions & 0 deletions meinberlin/apps/kiezradar/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from django.contrib import admin

from .models import KiezradarQuery
from .models import ProjectType
from .models import SearchProfile


class SearchProfileAdmin(admin.ModelAdmin):
list_display = ("id", "name", "user")
list_filter = (
"name",
"status",
)


class KiezradarQueryAdmin(admin.ModelAdmin):
list_display = ("id", "text")
list_filter = ("text",)


class ProjectTypeAdmin(admin.ModelAdmin):
list_display = ("id", "participation")
list_filter = ("participation",)


admin.site.register(SearchProfile, SearchProfileAdmin)
admin.site.register(KiezradarQuery, KiezradarQueryAdmin)
admin.site.register(ProjectType, ProjectTypeAdmin)
21 changes: 21 additions & 0 deletions meinberlin/apps/kiezradar/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from rest_framework import viewsets
from rest_framework.permissions import IsAuthenticated

from .models import SearchProfile
from .serializers import SearchProfileSerializer


class SearchProfileViewSet(viewsets.ModelViewSet):
"""
ViewSet for managing SearchProfile objects.
"""

queryset = SearchProfile.objects.all()
serializer_class = SearchProfileSerializer
permission_classes = [IsAuthenticated]

def perform_create(self, serializer):
"""
Override to save the user from the request.
"""
serializer.save(user=self.request.user)
6 changes: 6 additions & 0 deletions meinberlin/apps/kiezradar/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class Config(AppConfig):
name = "meinberlin.apps.kiezradar"
label = "meinberlin_kiezradar"
142 changes: 142 additions & 0 deletions meinberlin/apps/kiezradar/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# Generated by Django 4.2.11 on 2024-11-21 13:17

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.A4_ORGANISATIONS_MODEL),
("a4administrative_districts", "0001_initial"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("a4projects", "0047_alter_project_image_alter_project_tile_image"),
]

operations = [
migrations.CreateModel(
name="KiezradarQuery",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("text", models.CharField(max_length=256, unique=True)),
],
options={
"verbose_name_plural": "queries",
},
),
migrations.CreateModel(
name="ProjectType",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"participation",
models.SmallIntegerField(
choices=[
(0, "information (no participation)"),
(1, "consultation"),
(2, "cooperation"),
(3, "decision-making"),
],
verbose_name="Type",
),
),
],
),
migrations.CreateModel(
name="SearchProfile",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.CharField(max_length=255)),
("description", models.TextField(blank=True, null=True)),
("disabled", models.BooleanField(default=False)),
(
"status",
models.SmallIntegerField(
choices=[(0, "running"), (1, "done")],
default=1,
verbose_name="Status",
),
),
(
"districts",
models.ManyToManyField(
blank=True,
related_name="search_profiles",
to="a4administrative_districts.administrativedistrict",
),
),
(
"organisations",
models.ManyToManyField(
blank=True,
related_name="search_profiles",
to=settings.A4_ORGANISATIONS_MODEL,
),
),
(
"project_types",
models.ManyToManyField(
blank=True,
related_name="search_profiles",
to="meinberlin_kiezradar.projecttype",
),
),
(
"query",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="search_profiles",
to="meinberlin_kiezradar.kiezradarquery",
),
),
(
"topics",
models.ManyToManyField(
blank=True,
related_name="search_profiles",
to="a4projects.topic",
),
),
(
"user",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="search_profiles",
to=settings.AUTH_USER_MODEL,
),
),
],
options={
"ordering": ["name"],
},
),
]
Empty file.
91 changes: 91 additions & 0 deletions meinberlin/apps/kiezradar/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
from django.conf import settings
from django.db import models
from django.utils.translation import gettext_lazy as _

from adhocracy4.administrative_districts.models import AdministrativeDistrict
from adhocracy4.projects.models import Topic

Organisation = settings.A4_ORGANISATIONS_MODEL


class KiezradarQuery(models.Model):
text = models.CharField(max_length=256, unique=True)

def __str__(self):
return f"kiezradar query - {self.text}"

class Meta:
verbose_name_plural = "queries"


class ProjectType(models.Model):
PARTICIPATION_INFORMATION = 0
PARTICIPATION_CONSULTATION = 1
PARTICIPATION_COOPERATION = 2
PARTICIPATION_DECISION_MAKING = 3
PARTICIPATION_CHOICES = (
(PARTICIPATION_INFORMATION, _("information (no participation)")),
(PARTICIPATION_CONSULTATION, _("consultation")),
(PARTICIPATION_COOPERATION, _("cooperation")),
(PARTICIPATION_DECISION_MAKING, _("decision-making")),
)
participation = models.SmallIntegerField(
choices=PARTICIPATION_CHOICES,
verbose_name=_("Type"),
)

def __str__(self):
return f"participation type - {self.participation}"


class SearchProfile(models.Model):
STATUS_ONGOING = 0
STATUS_DONE = 1
STATUS_CHOICES = ((STATUS_ONGOING, _("running")), (STATUS_DONE, _("done")))

user = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
related_name="search_profiles",
)
name = models.CharField(max_length=255)
description = models.TextField(blank=True, null=True)
disabled = models.BooleanField(default=False)
status = models.SmallIntegerField(
choices=STATUS_CHOICES,
default=1,
verbose_name=_("Status"),
)
query = models.ForeignKey(
KiezradarQuery,
models.SET_NULL,
related_name="search_profiles",
blank=True,
null=True,
)
organisations = models.ManyToManyField(
Organisation,
related_name="search_profiles",
blank=True,
)
districts = models.ManyToManyField(
AdministrativeDistrict,
related_name="search_profiles",
blank=True,
)
project_types = models.ManyToManyField(
ProjectType,
related_name="search_profiles",
blank=True,
)
topics = models.ManyToManyField(
Topic,
related_name="search_profiles",
blank=True,
)

class Meta:
ordering = ["name"]

def __str__(self):
return f"kiezradar search profile - {self.name}, disabled {self.disabled}"
Loading
Loading