Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ForumViriumHelsinki/FVHFeedbackMap
Browse files Browse the repository at this point in the history
  • Loading branch information
aapris committed Sep 18, 2023
2 parents 4e41ca0 + 3136d7b commit f89db30
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 6 deletions.
18 changes: 18 additions & 0 deletions django_server/feedback_map/migrations/0009_mapdatapoint_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.18 on 2023-09-18 11:41

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('feedback_map', '0008_alter_tag_color'),
]

operations = [
migrations.AddField(
model_name='mapdatapoint',
name='status',
field=models.CharField(choices=[('NEW', 'New'), ('OPEN', 'Open'), ('IN_PROGRESS', 'In progress'), ('CLOSED', 'Closed'), ('OBSOLETE', 'Obsolete'), ('REOPENED', 'Reopened')], default='NEW', max_length=32),
),
]
11 changes: 11 additions & 0 deletions django_server/feedback_map/models/map_data_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,20 @@ def save(self, *args, **kwargs):
return super().save(*args, **kwargs)


STATUS_CHOICES = [
("NEW", "New"),
("OPEN", "Open"),
("IN_PROGRESS", "In progress"),
("CLOSED", "Closed"),
("OBSOLETE", "Obsolete"),
("REOPENED", "Reopened"),
]


class MapDataPoint(TimestampedModel):
lat = models.DecimalField(max_digits=11, decimal_places=8)
lon = models.DecimalField(max_digits=11, decimal_places=8)
status = models.CharField(max_length=32, choices=STATUS_CHOICES, default="NEW")
# Note https://docs.djangoproject.com/en/4.1/ref/contrib/gis/model-api/#geography-type
geog = models.PointField(srid=4326, null=True, blank=True, geography=True)
geom = models.PointField(srid=4326, null=True, blank=True, geography=False)
Expand Down
17 changes: 14 additions & 3 deletions django_server/feedback_map/rest/serializers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,20 @@
class BaseMapDataPointSerializer(serializers.ModelSerializer):
class Meta:
model = models.MapDataPoint
fields = ['id', 'comment', 'image', 'lat', 'lon', 'is_processed',
'created_by', 'tags', 'created_at', 'modified_at']
fields = [
"id",
"status",
"comment",
"image",
"lat",
"lon",
"is_processed",
"created_by",
"tags",
"created_at",
"modified_at",
]

def to_representation(self, instance):
result = super().to_representation(instance)
return OrderedDict([(key, result[key]) for key in result if result[key] not in [None, []]])
return OrderedDict([(key, result[key]) for key in result if result[key] not in [None, []]])
1 change: 0 additions & 1 deletion django_server/feedback_map/rest/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@
IotDeviceView as IotDeviceView,
)
from .recent_mappers import RecentMappersViewSet as RecentMappersViewSet

3 changes: 3 additions & 0 deletions django_server/feedback_map/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ def send_to_kafka(sender, instance, created, **kwargs):
for key in ["lat", "lon"]:
payload[key] = float(data["fields"][key])
payload["tags"] = json.loads(data["fields"]["tags"])
import httpx

httpx.post("https://iot-feedback-api.ecosystem-urbanage.eu/iot/send_data/", json=payload)
# convert dict to bytes
pl_bytes = json.dumps(payload, sort_keys=True).encode("utf-8")
if producer is not None and os.getenv("KAFKA_FORWARD_TOPIC_NAME") and created:
Expand Down
5 changes: 3 additions & 2 deletions django_server/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.black]
line-length = 120
target-version = ['py39', 'py310']
target-version = ['py310', 'py311']
exclude = '''
(
migrations # migrations are automatically generated and should we excluded
Expand Down Expand Up @@ -29,7 +29,8 @@ force-exclude = '''

[tool.ruff]
line-length = 120

ignore-init-module-imports = true
extend-exclude = ["migrations"]
# Enable Pyflakes `E` and `F` codes by default.
select = ["E", "F"]
ignore = []
Expand Down

0 comments on commit f89db30

Please sign in to comment.