Skip to content

Commit

Permalink
Revert postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
didrikmunther committed Oct 3, 2024
1 parent 54ebd9d commit 95da498
Show file tree
Hide file tree
Showing 21 changed files with 49 additions and 864 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ RUN apk update \
gdal-dev linux-headers g++ binutils geos-dev \
tiff-dev jpeg-dev openjpeg-dev zlib-dev freetype-dev lcms2-dev \
libwebp-dev tcl-dev tk-dev harfbuzz-dev fribidi-dev libimagequant-dev \
libxcb-dev libpng-dev
libxcb-dev libpng-dev libpq-dev
RUN pip install --upgrade pip==21.3.1
COPY ./requirements.txt .
RUN pip install -r requirements.txt
Expand Down
9 changes: 8 additions & 1 deletion ais/common/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,20 @@

DATABASES = {
"default": {
"ENGINE": "django.contrib.gis.db.backends.postgis",
# "ENGINE": "django.contrib.gis.db.backends.postgis",
"ENGINE": "dj_db_conn_pool.backends.postgresql",
"NAME": os.environ.get("DB_NAME", "ais_dev"),
"USER": os.environ.get("DB_USER", "ais_dev"),
"PASSWORD": os.environ.get("DB_PASSWORD", "ais_dev"),
"HOST": os.environ.get("DB_HOST", "127.0.0.1"),
"PORT": os.environ.get("DB_PORT", "5432"),
"CONN_MAX_AGE": 0,
# https://pypi.org/project/django-db-connection-pool/
"POOL_OPTIONS": {
"POOL_SIZE": 5,
"MAX_OVERFLOW": 10,
"RECYCLE": -1,
},
}
}

Expand Down
10 changes: 0 additions & 10 deletions exhibitors/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,6 @@ class LocationAdmin(ModelAdminImproved):
pass


@admin.register(Booth)
class BoothAdmin(ModelAdminImproved):
pass


@admin.register(ExhibitorInBooth)
class ExhibitorInBoothAdmin(ModelAdminImproved):
pass


@admin.register(FairLocationSpecial)
class FairLocationSpecialAdmin(ModelAdminImproved):
pass
99 changes: 1 addition & 98 deletions exhibitors/api.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,19 @@
import json
from collections import OrderedDict

from django.contrib.gis.geos import Polygon
from django.http import JsonResponse
from django.shortcuts import get_object_or_404
from django.views.decorators.cache import cache_page
from django.views.decorators.http import require_POST
from django.views.decorators.csrf import csrf_exempt

from exhibitors import serializers
from exhibitors.models import Exhibitor, Location, Booth, ExhibitorInBooth, LocationTick
from exhibitors.models import Exhibitor, Location, LocationTick
from fair.models import Fair, FairDay

MISSING_IMAGE = "/static/missing.png"


def serialize_booths(exhibitor):
return [
{
"id": eib.booth.pk,
"location": {
"parent": (
{
"id": eib.booth.location.parent.pk,
"name": eib.booth.location.parent.name,
}
if eib.booth.location.parent
else None
),
"id": eib.booth.location.pk,
"name": eib.booth.location.name,
},
"name": eib.booth.name,
"comment": eib.comment,
"days": [day.date for day in eib.days.all()],
}
for eib in exhibitor.exhibitorinbooth_set.all()
]


def serialize_exhibitor(exhibitor, request):
img_placeholder = request.GET.get("img_placeholder") == "true"

Expand Down Expand Up @@ -146,7 +121,6 @@ def serialize_exhibitor(exhibitor, request):
),
("climate_compensation", exhibitor.climate_compensation),
("flyer", (exhibitor.flyer.url) if exhibitor.flyer else ""),
("booths", serialize_booths(exhibitor)),
("map_coordinates", exhibitor.map_coordinates),
]
)
Expand Down Expand Up @@ -199,9 +173,6 @@ def exhibitors(request):
"catalogue_competences",
"catalogue_benefits",
"company__groups",
"exhibitorinbooth_set__booth__location__parent",
"exhibitorinbooth_set__booth__location",
"exhibitorinbooth_set__days",
)

data = [serialize_exhibitor(exhibitor, request) for exhibitor in exhibitors]
Expand All @@ -228,58 +199,6 @@ def locations(request):
return JsonResponse(data, safe=False)


def location(request, location_pk):
location = get_object_or_404(Location, fair__current=True, pk=location_pk)

booths = []

for booth in Booth.objects.filter(location=location):
booths.append(
{
"id": booth.pk,
"name": booth.name,
"boundaries": booth.boundaries.coords[0],
"centroid": booth.boundaries.centroid.coords,
"exhibitors": [
{
"id": exhibitor_in_booth.exhibitor.pk,
"name": exhibitor_in_booth.exhibitor.company.name,
"comment": exhibitor_in_booth.comment,
"days": [
{"id": day.pk, "date": day.date}
for day in exhibitor_in_booth.days.all()
],
}
for exhibitor_in_booth in ExhibitorInBooth.objects.filter(
booth=booth
)
],
}
)

data = {
"id": location.pk,
"parent": (
{"id": location.parent.pk, "name": location.parent.name}
if location.parent
else None
),
"name": location.name,
"map": (
{
"url": location.background.url,
"width": location.background.width,
"height": location.background.height,
}
if location.background
else None
),
"booths": booths,
}

return JsonResponse(data, safe=False)


def days(request):
data = []

Expand All @@ -289,22 +208,6 @@ def days(request):
return JsonResponse(data, safe=False)


@require_POST
def create_booth(request, location_pk):
location_obj = get_object_or_404(Location, pk=location_pk)

if not request.user:
return JsonResponse({"message": "Authentication required."}, status=403)

data = json.loads(request.body)

booth = Booth.objects.create(
location=location_obj, name=data["name"], boundaries=Polygon(data["boundaries"])
)

return JsonResponse({"booth": serializers.booth(booth)}, status=201)


@require_POST
@csrf_exempt
def people_count(request, location_pk):
Expand Down
2 changes: 0 additions & 2 deletions exhibitors/api_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ def cors_allow_api_to_exhibitors(sender, request, **kwargs):
urlpatterns = [
url(r"^$", api.exhibitors),
url(r"^locations$", api.locations),
url(r"^locations/(?P<location_pk>[0-9]+)$", api.location),
url(r"^locations/(?P<location_pk>[0-9]+)/create_booth$", api.create_booth),
url(r"^locations/(?P<location_pk>[0-9]+)/people_count$", api.people_count),
url(r"^days$", api.days),
]
16 changes: 1 addition & 15 deletions exhibitors/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import inspect

from companies.models import Company, CompanyCustomerComment
from .models import ExhibitorView, Exhibitor, Booth, ExhibitorInBooth
from .models import ExhibitorView, Exhibitor

from dal import autocomplete

Expand Down Expand Up @@ -126,12 +126,6 @@ class Meta:
fields = ["comment"]


class BoothForm(forms.ModelForm):
class Meta:
model = Booth
fields = ["location", "name"]


class ExhibitorForm(forms.ModelForm):
class Meta:
model = Exhibitor
Expand All @@ -143,14 +137,6 @@ class Meta:
}


class ExhibitorInBoothForm(forms.ModelForm):
class Meta:
model = ExhibitorInBooth
fields = ["exhibitor", "days", "comment"]

widgets = {"days": forms.CheckboxSelectMultiple()}


class ExhibitorSearchForm(forms.Form):
contact_persons = forms.ModelMultipleChoiceField(
queryset=User.objects.all(),
Expand Down
35 changes: 35 additions & 0 deletions exhibitors/migrations/0076_remove_gis_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 2.2.24 on 2024-10-03 13:59

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('exhibitors', '0075_change_exhibitor_application_status'),
]

operations = [
migrations.AlterUniqueTogether(
name='exhibitorinbooth',
unique_together=None,
),
migrations.RemoveField(
model_name='exhibitorinbooth',
name='booth',
),
migrations.RemoveField(
model_name='exhibitorinbooth',
name='days',
),
migrations.RemoveField(
model_name='exhibitorinbooth',
name='exhibitor',
),
migrations.DeleteModel(
name='Booth',
),
migrations.DeleteModel(
name='ExhibitorInBooth',
),
]
28 changes: 0 additions & 28 deletions exhibitors/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from django.forms import ValidationError
from lib.image import UploadToDirUUID
from django.contrib.auth.models import User
from django.contrib.gis.db import models
from django.utils.crypto import get_random_string

from accounting.models import Order
Expand Down Expand Up @@ -439,30 +438,3 @@ class LocationTick(models.Model):
timestamp = models.DateTimeField(auto_now_add=True)
change = models.IntegerField()
new_people_count = models.IntegerField()


class Booth(models.Model):
location = models.ForeignKey(Location, on_delete=models.CASCADE)
name = models.CharField(blank=False, null=False, max_length=255)
boundaries = models.PolygonField(blank=True, null=True)

class Meta:
ordering = ["location", "name"]
unique_together = [["location", "name"]]

def __str__(self):
return str(self.location) + " -> " + self.name


class ExhibitorInBooth(models.Model):
exhibitor = models.ForeignKey(Exhibitor, on_delete=models.CASCADE)
booth = models.ForeignKey(Booth, on_delete=models.CASCADE)
days = models.ManyToManyField(FairDay)
comment = models.CharField(max_length=255, null=True, blank=True)

class Meta:
ordering = ["exhibitor", "booth"]
unique_together = [["exhibitor", "booth"]]

def __str__(self):
return str(self.exhibitor) + " in " + str(self.booth)
Loading

0 comments on commit 95da498

Please sign in to comment.