Skip to content

Commit

Permalink
add district neighborhood owners
Browse files Browse the repository at this point in the history
  • Loading branch information
NvdLaan committed Oct 31, 2024
1 parent 3ffc0b5 commit b136408
Show file tree
Hide file tree
Showing 19 changed files with 496 additions and 66 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.8 on 2024-10-31 08:20

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("cases", "0005_casedocument"),
]

operations = [
migrations.RenameField(
model_name="casedocument",
old_name="created_at",
new_name="created",
),
]
2 changes: 1 addition & 1 deletion app/apps/cases/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class CaseDocument(models.Model):
name = models.CharField(max_length=100)
case = models.ForeignKey(Case, on_delete=models.PROTECT, related_name="documents")
document = models.FileField(upload_to=get_upload_path)
created_at = models.DateTimeField(auto_now_add=True)
created = models.DateTimeField(auto_now_add=True)

def __str__(self):
return f"Document: {self.id}"
Expand Down
3 changes: 2 additions & 1 deletion app/apps/cases/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from .serializers import CaseCreateSerializer, CaseDocumentSerializer, CaseSerializer
from django.shortcuts import get_object_or_404
from django.core.files.storage import default_storage
from django.http import FileResponse


class CaseViewSet(
Expand Down Expand Up @@ -80,7 +81,7 @@ def download_document(self, request, pk=None, doc_id=None):
case = self.get_object()
case_document = get_object_or_404(CaseDocument, case=case, id=doc_id)
with default_storage.open(case_document.document.name, "rb") as file:
response = Response(file.read(), content_type="application/octet-stream")
response = FileResponse(file, content_type="application/octet-stream")
response["Content-Disposition"] = (
f'attachment; filename="{case_document.document.name}"'
)
Expand Down
6 changes: 3 additions & 3 deletions app/apps/events/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
admin.site.register(
CaseEvent,
admin.ModelAdmin,
readonly_fields=("date_created", "event_values"),
readonly_fields=("created", "event_values"),
list_display=(
"id",
"emitter",
"emitter_id",
"emitter_type",
"type",
"date_created",
"created",
),
list_filter=(
"date_created",
"created",
"type",
),
search_fields=("emitter_id",),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 5.0.8 on 2024-10-31 08:20

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("events", "0001_initial"),
]

operations = [
migrations.AlterModelOptions(
name="caseevent",
options={"ordering": ["created"]},
),
migrations.RenameField(
model_name="caseevent",
old_name="date_created",
new_name="created",
),
]
7 changes: 3 additions & 4 deletions app/apps/events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class CaseEvent(models.Model):

TYPE_CASE = "CASE"
TYPE_CASE_CLOSE = "CASE_CLOSE"
TYPE_GENERIC_TASK = "GENERIC_TASK"
Expand All @@ -14,7 +13,7 @@ class CaseEvent(models.Model):
(TYPE_GENERIC_TASK, TYPE_GENERIC_TASK),
)

date_created = models.DateTimeField(auto_now_add=True)
created = models.DateTimeField(auto_now_add=True)
case = models.ForeignKey(
to="cases.Case",
on_delete=models.CASCADE,
Expand Down Expand Up @@ -51,10 +50,10 @@ def event_variables(self):
return variables_list

def __str__(self):
return f"{self.case.id} Case - Event {self.id} - {self.date_created}"
return f"{self.case.id} Case - Event {self.id} - {self.created}"

class Meta:
ordering = ["date_created"]
ordering = ["created"]


class ModelEventEmitter(models.Model):
Expand Down
2 changes: 1 addition & 1 deletion app/apps/events/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Meta:
"id",
"event_values",
"event_variables",
"date_created",
"created",
"type",
"emitter_id",
"case",
Expand Down
46 changes: 42 additions & 4 deletions app/apps/homeownerassociation/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
from django.contrib import admin

from apps.homeownerassociation.models import HomeownerAssociation
from apps.homeownerassociation.models import Contact
from apps.homeownerassociation.models import (
HomeownerAssociation,
Contact,
Neighborhood,
Owner,
District,
)


class ContactInline(admin.TabularInline):
Expand All @@ -22,8 +27,8 @@ class HomeownerAssociationAdmin(admin.ModelAdmin):
"name",
"build_year",
"number_of_appartments",
"created_at",
"updated_at",
"created",
"updated",
)
search_fields = ("id",)
inlines = [ContactInline]
Expand All @@ -33,3 +38,36 @@ class HomeownerAssociationAdmin(admin.ModelAdmin):
class ContactAdmin(admin.ModelAdmin):
list_display = ("id", "fullname", "email", "phone", "role")
search_fields = ("id", "fullname", "email", "phone", "role")


@admin.register(Owner)
class OwnerAdmin(admin.ModelAdmin):
list_display = (
"id",
"get_homeowner_association_name",
"type",
"name",
"number_of_appartments",
)
search_fields = (
"id",
"type",
"name",
"number_of_appartments",
"homeowner_association__name",
)

def get_homeowner_association_name(self, obj):
return obj.homeowner_association.name


@admin.register(District)
class DistrictAdmin(admin.ModelAdmin):
list_display = ("id", "name")
search_fields = ("id", "name")


@admin.register(Neighborhood)
class NeighborhoodAdmin(admin.ModelAdmin):
list_display = ("id", "name", "district")
search_fields = ("id", "name", "district__name")
39 changes: 39 additions & 0 deletions app/apps/homeownerassociation/migrations/0003_owner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Generated by Django 5.0.8 on 2024-10-30 13:08

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


class Migration(migrations.Migration):

dependencies = [
("homeownerassociation", "0002_contact"),
]

operations = [
migrations.CreateModel(
name="Owner",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("type", models.CharField(max_length=255)),
("name", models.CharField(max_length=255)),
("number_of_appartments", models.IntegerField()),
(
"homeowner_association",
models.ForeignKey(
on_delete=django.db.models.deletion.DO_NOTHING,
related_name="owners",
to="homeownerassociation.homeownerassociation",
),
),
],
),
]
18 changes: 18 additions & 0 deletions app/apps/homeownerassociation/migrations/0004_alter_owner_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.8 on 2024-10-30 13:17

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("homeownerassociation", "0003_owner"),
]

operations = [
migrations.AlterField(
model_name="owner",
name="name",
field=models.CharField(max_length=255, null=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.8 on 2024-10-31 08:20

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("homeownerassociation", "0004_alter_owner_name"),
]

operations = [
migrations.RenameField(
model_name="homeownerassociation",
old_name="created_at",
new_name="created",
),
]
46 changes: 46 additions & 0 deletions app/apps/homeownerassociation/migrations/0006_district_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Generated by Django 5.0.8 on 2024-10-31 11:50

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


class Migration(migrations.Migration):

dependencies = [
("homeownerassociation", "0005_rename_created_at_homeownerassociation_created"),
]

operations = [
migrations.CreateModel(
name="District",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.CharField(max_length=255, unique=True)),
("created", models.DateTimeField(auto_now_add=True)),
("updated", models.DateTimeField(auto_now=True)),
],
),
migrations.RenameField(
model_name="homeownerassociation",
old_name="updated_at",
new_name="updated",
),
migrations.AddField(
model_name="homeownerassociation",
name="district",
field=models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.DO_NOTHING,
related_name="homeowner_associations",
to="homeownerassociation.district",
),
),
]
40 changes: 40 additions & 0 deletions app/apps/homeownerassociation/migrations/0007_neighborhood.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Generated by Django 5.0.8 on 2024-10-31 12:02

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


class Migration(migrations.Migration):

dependencies = [
("homeownerassociation", "0006_district_and_more"),
]

operations = [
migrations.CreateModel(
name="Neighborhood",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.CharField(max_length=255)),
(
"district",
models.ForeignKey(
on_delete=django.db.models.deletion.DO_NOTHING,
related_name="neighborhoods",
to="homeownerassociation.district",
),
),
],
options={
"unique_together": {("name", "district")},
},
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 5.0.8 on 2024-10-31 12:28

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


class Migration(migrations.Migration):

dependencies = [
("homeownerassociation", "0007_neighborhood"),
]

operations = [
migrations.AddField(
model_name="homeownerassociation",
name="neighborhood",
field=models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.DO_NOTHING,
related_name="homeowner_associations",
to="homeownerassociation.neighborhood",
),
),
]
Loading

0 comments on commit b136408

Please sign in to comment.