Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
0426b9e
Initial linting and tests for phonebook
zarya May 12, 2025
baf256b
Finished ruffing the phonebook, added basic TestCase base class
zarya May 12, 2025
3c7be59
Merge branch 'main' into ruff_phonebook
zarya May 12, 2025
6410c0f
Run tests before you commit
zarya May 12, 2025
fd84e41
Use the right name
zarya May 12, 2025
5f135ca
Update src/phonebook/models.py
tykling May 12, 2025
840b252
Update src/phonebook/views.py
tykling May 12, 2025
415dc4c
Merge branch 'main' into ruff_phonebook
tykling May 12, 2025
20d9d2e
Move exceptions to there own file
zarya May 12, 2025
97ae94d
Merge branch 'main' into ruff_phonebook
tykling May 12, 2025
75af4a8
Merge branch 'main' into ruff_phonebook
tykling May 12, 2025
649d572
ruffed maps
zarya May 13, 2025
c5923fa
More linting
zarya May 13, 2025
c8cf8db
Small change to tests
zarya May 13, 2025
4f817ea
Small fixes
zarya May 13, 2025
ff241f8
Merge branch 'main' into ruff_maps
zarya May 13, 2025
a3ea0b8
Merge branch 'main' into ruff_maps
zarya May 13, 2025
6bf3484
Add more tests to maps
zarya May 13, 2025
f6b1018
Lint some more
zarya May 13, 2025
4f9e0e2
Merge branch 'main' into ruff_maps
zarya May 13, 2025
ec1b389
Remove unused variable
zarya May 13, 2025
e8bee4c
Merge branch 'main' into ruff_maps
tykling May 13, 2025
da9cfa7
Update src/maps/mixins.py
zarya May 13, 2025
85ecb69
Update src/maps/mixins.py
zarya May 13, 2025
8694a49
Update src/maps/admin.py
zarya May 13, 2025
43479ed
Update src/maps/mixins.py
zarya May 13, 2025
05c53d4
Remove unused
zarya May 13, 2025
e2cde8b
Update src/maps/mixins.py
tykling May 13, 2025
56a51b5
Update src/maps/mixins.py
tykling May 13, 2025
7d46bd9
Update src/maps/mixins.py
tykling May 13, 2025
4b5f259
add quoting
tykling May 13, 2025
e2eb748
run pre-commit in GH actions
tykling May 13, 2025
f1b7dc5
ruff linting
tykling May 13, 2025
d3e9249
Merge branch 'main' into ruff_maps
tykling May 13, 2025
582128c
Update src/maps/mixins.py
tykling May 13, 2025
8c3d138
Update src/maps/models.py
tykling May 13, 2025
688d8bd
Update src/maps/models.py
tykling May 13, 2025
21028cb
Update src/maps/models.py
tykling May 13, 2025
7e9b0ea
Be gone
zarya May 13, 2025
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
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ test = [
"coverage==7.8.0",
"factory_boy==3.3.3",
"hypothesis==6.131.15",
"beautifulsoup4==4.13.4",
"unittest-xml-reporting==3.2.0",
]

Expand Down Expand Up @@ -123,7 +124,8 @@ ignore = [
"ANN001", # Missing type annotation for function argument ...
"ANN201", # Missing return type annotation for public function ...
"S101", # Allow use of assert
"S106", # Allow passwords in tests
"S105", # Allow PASSWORD as password in tests
"S106", # Allow passwords in tests
"S113", # Probable use of requests call without timeout
"E501", # Line too long
"D104", # Missing docstring in public package
Expand Down
3 changes: 3 additions & 0 deletions src/bornhack/environment_settings.py.dist
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ SCHEDULE_TIMESLOT_LENGTH_MINUTES=30
SCHEDULE_EVENT_NOTIFICATION_MINUTES=10
SPEAKER_AVAILABILITY_DAYCHUNK_HOURS=3 # how many hours per speaker_availability form checkbox

# Map settings
MAPS_USER_LOCATION_MAX = 50 # Maximum number of UserLocations a user can create

# irc bot settings
IRCBOT_CHECK_MESSAGE_INTERVAL_SECONDS=10
IRCBOT_NICK='{{ django_ircbot_nickname }}'
Expand Down
3 changes: 3 additions & 0 deletions src/bornhack/environment_settings.py.dist.dev
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ SCHEDULE_TIMESLOT_LENGTH_MINUTES = 30
SCHEDULE_EVENT_NOTIFICATION_MINUTES = 10
SPEAKER_AVAILABILITY_DAYCHUNK_HOURS=3

# Map settings
MAPS_USER_LOCATION_MAX = 50 # Maximum number of UserLocations a user can create

PDF_TEST_MODE = True
PDF_ARCHIVE_PATH = os.path.join(MEDIA_ROOT, "pdf_archive")

Expand Down
1 change: 1 addition & 0 deletions src/maps/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Maps Application."""
35 changes: 24 additions & 11 deletions src/maps/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
"""Maps Django Admin."""

from __future__ import annotations

from typing import ClassVar

from django.contrib import admin
from leaflet.admin import LeafletGeoAdmin

Expand All @@ -13,47 +17,56 @@

@admin.register(Feature)
class FeatureAdmin(LeafletGeoAdmin, admin.ModelAdmin):
"""Feature Admin."""

display_raw = True
save_as = True
list_display = [
list_display: ClassVar[list[str]] = [
"name",
"description",
]
list_filter = [
list_filter: ClassVar[list[str]] = [
"layer",
]

def get_queryset(self, request):
self.request = request
return super().get_queryset(request)


@admin.register(Layer)
class LayerAdmin(admin.ModelAdmin):
"""Layer admin."""

save_as = True
list_display = ["name", "slug"]
list_display: ClassVar[list[str]] = ["name", "slug"]


@admin.register(ExternalLayer)
class ExternalLayerAdmin(admin.ModelAdmin):
"""Layer admin."""

save_as = True
list_display = ["name"]
list_display: ClassVar[list[str]] = ["name"]


@admin.register(Group)
class GroupAdmin(admin.ModelAdmin):
"""Group admin."""

save_as = True
list_display = ["name"]
list_display: ClassVar[list[str]] = ["name"]


@admin.register(UserLocationType)
class UserLocationTypeAdmin(admin.ModelAdmin):
"""User Location Type admin."""

save_as = True
list_display = ["name"]
list_display: ClassVar[list[str]] = ["name"]


@admin.register(UserLocation)
class UserLocationAdmin(admin.ModelAdmin):
"""User Location admin."""

save_as = True
list_display = ["name", "type", "user", "camp"]
list_filter = ["camp", "user"]
list_display: ClassVar[list[str]] = ["name", "type", "user", "camp"]
list_filter: ClassVar[list[str]] = ["camp", "user"]
4 changes: 4 additions & 0 deletions src/maps/apps.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
"""Apps for the Maps app."""

from __future__ import annotations

from django.apps import AppConfig


class MapsConfig(AppConfig):
"""Maps config."""

name = "maps"
33 changes: 27 additions & 6 deletions src/maps/mixins.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
"""Mixins for Maps app."""

from __future__ import annotations

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from django.http import HttpRequest

Check warning on line 9 in src/maps/mixins.py

View check run for this annotation

Codecov / codecov/patch

src/maps/mixins.py#L8-L9

Added lines #L8 - L9 were not covered by tests
from django.contrib import messages
from django.core.exceptions import PermissionDenied
from django.shortcuts import get_object_or_404
Expand All @@ -14,19 +21,26 @@
"""A mixin to get the Layer object based on layer_slug in url kwargs."""

def setup(self, *args, **kwargs) -> None:
"""Set self.layer based on layer_slug in url kwargs."""
super().setup(*args, **kwargs)
self.layer = get_object_or_404(Layer, slug=self.kwargs["layer_slug"])

def get_context_data(self, *args, **kwargs):
def get_context_data(self, *args, **kwargs) -> dict:
"""Add self.layer to context."""
context = super().get_context_data(*args, **kwargs)
context["layer"] = self.layer
return context


class LayerMapperViewMixin(LayerViewMixin):
"""A mixin for views only available to users with mapper permission for the team responsible for the layer and/or Mapper team permission."""
"""A mixin for LayerMapper.

def setup(self, request, *args, **kwargs) -> None:
For views only available to users with mapper permission for the team responsible
for the layer and/or Mapper team permission.
"""

def setup(self, request: HttpRequest, *args, **kwargs) -> None:
"""Check permissions."""
super().setup(request, *args, **kwargs)
if (
self.layer.responsible_team
Expand All @@ -40,7 +54,8 @@
class GisTeamViewMixin:
"""A mixin for views only available to users with `camps.gis_team_member` permission."""

def setup(self, request, *args, **kwargs) -> None:
def setup(self, request: HttpRequest, *args, **kwargs) -> None:
"""Check permissions."""
super().setup(request, *args, **kwargs)
if self.request.user.has_perm("camps.gis_team_member"):
return
Expand All @@ -52,6 +67,7 @@
"""A mixin to get the ExternalLayer object based on external_layer_uuid in url kwargs."""

def setup(self, *args, **kwargs) -> None:
"""Set self.layer."""
super().setup(*args, **kwargs)
self.layer = get_object_or_404(
ExternalLayer,
Expand All @@ -60,9 +76,14 @@


class ExternalLayerMapperViewMixin(ExternalLayerViewMixin):
"""A mixin for views only available to users with mapper permission for the team responsible for the layer and/or Mapper team permission."""
"""A mixin for views.

only available to users with mapper permission for the team responsible
for the layer and/or Mapper team permission.
"""

def setup(self, request, *args, **kwargs) -> None:
def setup(self, request: HttpRequest, *args, **kwargs) -> None:
"""Check permissions."""
super().setup(request, *args, **kwargs)
if (
self.layer.responsible_team
Expand Down
36 changes: 32 additions & 4 deletions src/maps/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
"""Maps models."""

from __future__ import annotations

import logging
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from camps.models import Camp

from typing import ClassVar

from colorfield.fields import ColorField
from django.contrib.auth.models import User
Expand All @@ -27,6 +35,7 @@ class Group(UUIDModel):
)

def __str__(self) -> str:
"""String formatter."""
return str(self.name)


Expand Down Expand Up @@ -73,13 +82,16 @@ class Layer(ExportModelOperationsMixin("layer"), UUIDModel):
)

@property
def camp(self):
def camp(self) -> Camp:
"""Camp object reference."""
return self.responsible_team.camp

def __str__(self) -> str:
"""String formatter."""
return str(self.name)

def save(self, **kwargs) -> None:
"""Set slug and save."""
self.slug = unique_slugify(
str(self.name),
slugs_in_use=self.__class__.objects.all().values_list(
Expand Down Expand Up @@ -134,22 +146,28 @@ class Feature(UUIDModel):
)

class Meta:
constraints = [
"""Meta data."""

constraints: ClassVar[list] = [
models.UniqueConstraint(
fields=["layer", "name"],
name="layer_and_name_uniq",
),
]

def __str__(self) -> str:
"""String formatter."""
return str(self.name)

@property
def camp(self):
def camp(self) -> Camp:
"""Camp object reference."""
return self.layer.team.camp


class ExternalLayer(UUIDModel):
"""External layer model."""

name = models.CharField(
max_length=100,
help_text="Name or description of this layer",
Expand Down Expand Up @@ -177,13 +195,16 @@ class ExternalLayer(UUIDModel):
)

@property
def camp(self):
def camp(self) -> Camp:
"""Camp object reference."""
return self.responsible_team.camp

def __str__(self) -> str:
"""String formatter."""
return str(self.name)

def save(self, **kwargs) -> None:
"""Set slug and save."""
self.slug = unique_slugify(
str(self.name),
slugs_in_use=self.__class__.objects.all().values_list(
Expand All @@ -195,6 +216,8 @@ def save(self, **kwargs) -> None:


class UserLocationType(UUIDModel):
"""User Location Type model."""

name = models.CharField(
max_length=100,
help_text="Name of the user location type",
Expand All @@ -220,9 +243,11 @@ class UserLocationType(UUIDModel):
)

def __str__(self) -> str:
"""String formatter."""
return self.name

def save(self, **kwargs) -> None:
"""Set slug and save."""
if not self.slug:
self.slug = unique_slugify(
self.name,
Expand All @@ -238,6 +263,8 @@ class UserLocation(
UUIDModel,
CampRelatedModel,
):
"""UserLocation model."""

name = models.CharField(
max_length=100,
help_text="Name of the location",
Expand Down Expand Up @@ -278,4 +305,5 @@ class UserLocation(
)

def __str__(self) -> str:
"""String formatter."""
return self.name
2 changes: 1 addition & 1 deletion src/maps/templates/maps_map.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
{{ mapData|json_script:"mapData" }}
<script src="{% static 'js/maps/generic/mapVars.js' %}?v=1" type="text/javascript"></script>
<script src="{% static 'js/maps/generic/mapProcessing.js' %}" type="text/javascript"></script>
<script src="{% static 'js/maps/generic/map.js?v=1' %}" type="text/javascript"></script>
<script src="{% static 'js/maps/generic/map.js' %}?v=1" type="text/javascript"></script>
{% endblock extra_head %}

{% block content %}
Expand Down
Loading
Loading