Skip to content

Commit

Permalink
feat(pickups): map selector, time
Browse files Browse the repository at this point in the history
  • Loading branch information
thejoeejoee committed Nov 16, 2023
1 parent b404ad2 commit 04c55c3
Show file tree
Hide file tree
Showing 17 changed files with 204 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.7 on 2023-11-16 15:45

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('buddy_system', '0026_alter_buddyrequest_created_and_more'),
]

operations = [
migrations.AlterField(
model_name='buddysystemconfiguration',
name='matching_policy',
field=models.CharField(choices=[('manual-by-editor', 'Manual by editors'), ('manual-by-member', 'Manual by members'), ('same-faculty', 'Manual by members with restriction to same faculty')], default='manual-by-editor', help_text='Manual by editors: Matching is done manually only by editors. <br />Manual by members: Matching is done manually directly by members. <br />Manual by members with restriction to same faculty: Matching is done manually by members themselves, but limited to the same faculty.', max_length=32),
),
migrations.AlterField(
model_name='buddysystemconfiguration',
name='rolling_limit',
field=models.PositiveSmallIntegerField(default=0, editable=False),
),
]
14 changes: 13 additions & 1 deletion fiesta/apps/fiestaforms/forms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

from django.forms import DateInput as DjDateInput, Form, ModelForm
from django.forms import DateInput as DjDateInput, Form, Media, ModelForm
from django.utils.translation import gettext_lazy as _
from webpack_loader.utils import get_files


class DateInput(DjDateInput):
Expand All @@ -24,3 +25,14 @@ class BaseForm(Form):
@property
def base_form_class(self):
return BaseForm


class WebpackMediaFormMixin:
_webpack_bundle: str

@property
def media(self):
media = super().media
media += Media(js=[f["url"] for f in get_files(self._webpack_bundle)])

return media
4 changes: 4 additions & 0 deletions fiesta/apps/fiestaforms/templates/fiestaforms/classic.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
{% load fiestaforms %}
{% load as_widget_field as_label from fiestaforms %}
<div class="{{ form|get_form_classes }}">
{{ form.media }}

{% for f in form.fields.values %}{{ f.widget.media|default:"" }}{% endfor %}

{% for bf, errors in fields %}
{% include "fiestaforms/parts/field.html" with bf=bf errors=errors %}
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class="hidden">{{ field_input }}</div>
<div class="map-widget aspect-square lg:aspect-video w-full">
{# <label></label>#}

<div id="map_{{ field_name }}" class="w-full h-full"></div>
</div>
4 changes: 3 additions & 1 deletion fiesta/apps/fiestarequests/tables/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,14 @@ class Meta:
"issuer_name",
"issuer_picture",
"state",
"...",
"matcher_name",
"matcher_picture",
"requested",
"matched",
"...",
"match_request",
)

empty_text = _("No requests found")

attrs = dict(tbody={"hx-disable": True})
30 changes: 25 additions & 5 deletions fiesta/apps/pickup_system/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from django.utils.translation import gettext_lazy as _

from apps.accounts.models import UserProfile
from apps.fiestaforms.fields.datetime import DateTimeLocalField
from apps.fiestaforms.forms import WebpackMediaFormMixin
from apps.fiestarequests.forms.editor import BaseQuickMatchForm, BaseRequestEditorForm
from apps.fiestarequests.forms.request import BaseNewRequestForm
from apps.pickup_system.models import PickupRequest, PickupRequestMatch
Expand All @@ -16,18 +18,30 @@
)


class NewPickupRequestForm(BaseNewRequestForm):
class NewPickupRequestForm(WebpackMediaFormMixin, BaseNewRequestForm):
_webpack_bundle = "jquery"
submit_text = _("Send request for pickup")

class Meta(BaseNewRequestForm.Meta):
model = PickupRequest

fields = BaseNewRequestForm.Meta.fields + ()
field_classes = BaseNewRequestForm.Meta.field_classes | {}
fields = (
(
"time",
"place",
"location",
)
+ BaseNewRequestForm.Meta.fields
+ ()
)
field_classes = BaseNewRequestForm.Meta.field_classes | {"time": DateTimeLocalField}
widgets = BaseNewRequestForm.Meta.widgets | {}
labels = BaseNewRequestForm.Meta.labels | {
"note": _("Tell me details TODO"),
"interests": _("What are you into?"),
"approving_request": _("I really want a pickup"),
"place": _("Where do you want to be picked up?"),
"location": _("Place marker as accurately as possible"),
}
help_texts = BaseNewRequestForm.Meta.help_texts | {
"note": lazy(
Expand All @@ -40,13 +54,19 @@ class Meta(BaseNewRequestForm.Meta):
# TODO: add save/load of contacts to/from user_profile


class PickupRequestEditorForm(BaseRequestEditorForm):
class PickupRequestEditorForm(WebpackMediaFormMixin, BaseRequestEditorForm):
_webpack_bundle = "jquery"

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

class Meta(BaseRequestEditorForm.Meta):
model = PickupRequest
fields = BaseRequestEditorForm.Meta.fields + ()
fields = BaseRequestEditorForm.Meta.fields + (
"time",
"place",
"location",
)
field_classes = BaseRequestEditorForm.Meta.field_classes | {}
widgets = BaseRequestEditorForm.Meta.widgets | {}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Generated by Django 4.2.7 on 2023-11-16 15:45

from django.db import migrations, models
import django.utils.timezone
import location_field.models.plain


class Migration(migrations.Migration):

dependencies = [
('pickup_system', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='pickuprequest',
name='location',
field=location_field.models.plain.PlainLocationField(default='49.1922443,16.6113382', max_length=63),
),
migrations.AddField(
model_name='pickuprequest',
name='place',
field=models.CharField(default='default', max_length=256),
preserve_default=False,
),
migrations.AddField(
model_name='pickuprequest',
name='time',
field=models.DateTimeField(default=django.utils.timezone.now, verbose_name='pickup time'),
preserve_default=False,
),
migrations.AlterField(
model_name='pickupsystemconfiguration',
name='rolling_limit',
field=models.PositiveSmallIntegerField(default=0, editable=False),
),
]
20 changes: 19 additions & 1 deletion fiesta/apps/pickup_system/models/request.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from __future__ import annotations

from django.db import models
from django.db.models import DateTimeField
from django.utils.translation import gettext_lazy as _
from location_field.models.plain import PlainLocationField

from apps.fiestarequests.models import base_request_model_factory

Expand All @@ -11,7 +14,17 @@


class PickupRequest(BaseRequestForPickupSystem):
# TODO: date/time/place
time = DateTimeField(
verbose_name=_("pickup time"),
)
place = models.CharField(
max_length=256,
)
location = PlainLocationField(
based_fields=["pickup_place"],
default="49.1922443,16.6113382",
zoom=4,
)

class Meta(BaseRequestForPickupSystem.Meta):
verbose_name = _("pickup request")
Expand All @@ -20,6 +33,11 @@ class Meta(BaseRequestForPickupSystem.Meta):
def __str__(self):
return f"Pickup Request {self.issuer}: {self.get_state_display()}"

@property
def location_as_google_maps_link(self):
return f"https://www.google.com/maps/place/{self.location}?zoom=15"
# return f"https://www.google.com/maps/search/?api=1&query={self.location}"


class PickupRequestMatch(BaseRequestMatchForPickupSystem):
class Meta(BaseRequestForPickupSystem.Meta):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,35 @@ <h2 class="card-title flex flex-row justify-between">
</div>
</div>
<div class="chat-bubble">{{ br.note }}</div>
{# <div class="chat-bubble border-0 bg-transparent pl-0 pt-0 mt-2 text-base-content">#}
{# {% for interest in br.get_interests_display %}<span class="mr-2 badge badge-outline">{{ interest }}</span>{% endfor %}#}
{# </div>#}
<div class="chat-bubble border-0 bg-transparent pl-0 pt-0 mt-2 text-base-content min-w-full">
<table class="table text-lg [&_th]:pl-0 [&_th]:flex [&_th]:flex-row [&_th]:justify-end [&_th]:items-center [&_th]:gap-x-2 [&_td]:pl-0 w-96 mx-auto">
<tbody>
<tr class="border-b border-base-300">
<th>
time <span class="text-3xl">⏱️</span>
</th>
<td>{{ br.time|date:"SHORT_DATETIME_FORMAT" }}</td>
</tr>
<tr class="border-b border-base-300">
<th>
place <span class="text-3xl">📍</span>
</th>
<td>{{ br.place }}</td>
</tr>
<tr class="border-b border-base-300">
<th>
location <span class="text-3xl">🗺️</span>
</th>
<td>
<a class="link link-secondary"

Check warning

Code scanning / CodeQL

Potentially unsafe external link Medium

External links without noopener/noreferrer are a potential security risk.
href="{{ br.location_as_google_maps_link }}"
rel="nofollow,noreferrer,noopener"
target="_blank">see on maps</a>
</td>
</tr>
</tbody>
</table>
</div>
</div>

{% if br.state == br.State.MATCHED %}
Expand Down
14 changes: 12 additions & 2 deletions fiesta/apps/pickup_system/views/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from django.urls import reverse, reverse_lazy
from django.utils.translation import gettext_lazy as _
from django.views.generic import UpdateView
from django_tables2 import TemplateColumn
from django_tables2.columns.base import LinkTransform
from django_tables2 import TemplateColumn, tables
from django_tables2.columns.base import Column, LinkTransform
from django_tables2.utils import Accessor

from apps.fiestaforms.views.htmx import HtmxFormMixin
Expand All @@ -27,11 +27,21 @@ class PickupRequestsTable(BaseRequestsTable):
order_by="match",
)

time = tables.columns.DateTimeColumn()

place = Column(
linkify=lambda record: record.location_as_google_maps_link,
)

class Meta(BaseRequestsTable.Meta):
fields = BaseRequestsTable.Meta.fields + ("match_request",)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

if "matcher_picture" in self.columns:
self.columns["matcher_picture"].column.visible = False

if "issuer_name" in self.columns:
# sometimes excluded
self.columns["issuer_name"].link = LinkTransform(
Expand Down
8 changes: 8 additions & 0 deletions fiesta/fiesta/settings/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ def ALLOWED_HOSTS(self):
"loginas",
# editorjs integration
"django_editorjs_fields",
# location fields
"location_field.apps.DefaultConfig",
# for trees
"mptt",
# health checks
"health_check",
Expand Down Expand Up @@ -122,3 +125,8 @@ def ALLOWED_HOSTS(self):
# all EU countries first, then the rest
COUNTRIES_FIRST = "AT BE BG HR CY CZ DK EE FI FR DE GR HU IE IT LV LT LU MT NL PL PT RO SK SI ES SE GB".split()
COUNTRIES_FIRST_REPEAT = True

LOCATION_FIELD = {
"map.provider": "openstreetmap",
"search.provider": "nominatim",
}
13 changes: 12 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ dj-database-url = "^2.0.0"
django-health-check = "^3.17.0"
django-money = "^3.2.0"
gunicorn = "^21.2.0"
django-location-field = "^2.7.2"

[tool.poetry.dev-dependencies]
pre-commit = "^2.17.0"
Expand Down
1 change: 1 addition & 0 deletions webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"css-loader": "^6.6.0",
"daisyui": "^4.0.9",
"htmx.org": "^1.9.6",
"jquery": "^3.7.1",
"mini-css-extract-plugin": "^2.5.3",
"postcss": "^8.4.31",
"postcss-import": "^14.0.2",
Expand Down
3 changes: 3 additions & 0 deletions webpack/src/jquery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import jquery from "jquery"

window.jQuery = jquery
3 changes: 3 additions & 0 deletions webpack/webpack.base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ module.exports = {
main: [
path.join(__dirname, './src/main.js')
],
jquery: [
path.join(__dirname, './src/jquery.js')
],
},
output: {
publicPath: PUBLIC_PATH,
Expand Down
5 changes: 5 additions & 0 deletions webpack/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1845,6 +1845,11 @@ jiti@^1.18.2, jiti@^1.19.1:
resolved "https://registry.yarnpkg.com/jiti/-/jiti-1.21.0.tgz#7c97f8fe045724e136a397f7340475244156105d"
integrity sha512-gFqAIbuKyyso/3G2qhiO2OM6shY6EPP/R0+mkDbyspxKazh8BXDC5FiFsUjlczgdNz/vfra0da2y+aHrusLG/Q==

jquery@^3.7.1:
version "3.7.1"
resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.7.1.tgz#083ef98927c9a6a74d05a6af02806566d16274de"
integrity sha512-m4avr8yL8kmFN8psrbFFFmB/If14iN5o9nw/NgnnM+kybDJpRsAynV2BsfpTYrTRysYUdADVD7CkUUizgkpLfg==

js-tokens@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
Expand Down

0 comments on commit 04c55c3

Please sign in to comment.