-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
apps: add kiezradar models, serialisers, api ,admin
- Loading branch information
Showing
18 changed files
with
592 additions
and
2 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
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.
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,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) |
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 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) |
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,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class Config(AppConfig): | ||
name = "meinberlin.apps.kiezradar" | ||
label = "meinberlin_kiezradar" |
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,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.
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,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}" |
Oops, something went wrong.