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

Improve source views #493

Merged
merged 9 commits into from
Feb 5, 2024
Merged
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
2 changes: 2 additions & 0 deletions docs/source/others/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Changelog
**Improvements:**

- Add "In progress" status to source
- Source list endpoint now also return ids of related layer
- Add author to Source

**Documentation:**

Expand Down
26 changes: 26 additions & 0 deletions project/geosource/migrations/0012_source_author.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 4.1.13 on 2023-12-05 08:26

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


class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("geosource", "0011_sourcereporting_source_status_alter_source_report"),
]

operations = [
migrations.AddField(
model_name="source",
name="author",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="sources",
to=settings.AUTH_USER_MODEL,
),
),
]
17 changes: 17 additions & 0 deletions project/geosource/migrations/0013_merge_20240205_1233.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.9 on 2024-02-05 12:33

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
(
"geosource",
"0012_alter_commandsource_options_alter_csvsource_options_and_more",
),
("geosource", "0012_alter_source_status"),
("geosource", "0012_source_author"),
]

operations = []
6 changes: 6 additions & 0 deletions project/geosource/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from celery.result import AsyncResult
from celery.utils.log import LoggingProxy
from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group
from django.contrib.gis.gdal.error import GDALException
from django.contrib.gis.geos import GEOSGeometry
Expand All @@ -33,6 +34,8 @@
from .mixins import CeleryCallMethodsMixin
from .signals import refresh_data_done

User = get_user_model()

# Decimal fields must be returned as float
DEC2FLOAT = psycopg2.extensions.new_type(
psycopg2.extensions.DECIMAL.values,
Expand Down Expand Up @@ -126,6 +129,9 @@ class Status(models.IntegerChoices):
status = models.PositiveSmallIntegerField(
choices=Status.choices, default=Status.NEED_SYNC
)
author = models.ForeignKey(
User, related_name="sources", blank=True, null=True, on_delete=models.SET_NULL
)

SOURCE_GEOM_ATTRIBUTE = "_geom_"
MAX_SAMPLE_DATA = 5
Expand Down
1 change: 1 addition & 0 deletions project/geosource/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class Meta:
"name",
"geom_type",
"report",
"layers",
)

def get__type(self, instance):
Expand Down
3 changes: 3 additions & 0 deletions project/geosource/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ def get_serializer_class(self):
def get_queryset(self):
return Source.objects.all().order_by("-id")

def perform_create(self, serializers):
serializers.save(author=self.request.user)

@action(detail=True, methods=["get"])
def refresh(self, request, pk):
"""Schedule a refresh now"""
Expand Down
Loading