Skip to content

Commit

Permalink
Merge pull request #226 from ohmg-dev/207_prep_sessions
Browse files Browse the repository at this point in the history
207 prep sessions
  • Loading branch information
mradamcox authored Nov 9, 2024
2 parents bfff81d + 70f4c23 commit d93f8b8
Show file tree
Hide file tree
Showing 60 changed files with 750 additions and 2,570 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from django.contrib.auth import get_user_model
from django.core.management.base import BaseCommand

Expand Down
9 changes: 4 additions & 5 deletions ohmg/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
from django.urls import reverse
from django.utils.functional import cached_property

from ohmg.core.models import Map
from ohmg.georeference.models import SessionBase
from ohmg.georeference.models import GCP

from ohmg.loc_insurancemaps.models import Volume

class User(AbstractUser):
class Meta:
db_table = 'auth_user'
Expand All @@ -19,7 +18,7 @@ def __str__(self):

@cached_property
def load_ct(self):
return Volume.objects.filter(loaded_by=self).count()
return Map.objects.filter(loaded_by=self).count()

@cached_property
def psesh_ct(self):
Expand All @@ -34,8 +33,8 @@ def gcp_ct(self):
return GCP.objects.filter(created_by=self).count()

@cached_property
def volumes(self):
return Volume.objects.filter(loaded_by=self).order_by("city")
def maps(self):
return Map.objects.filter(loaded_by=self).order_by("title")

@cached_property
def profile_url(self):
Expand Down
1 change: 0 additions & 1 deletion ohmg/core/api/filters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from typing import List, Optional
from django.db.models import Q
from ninja import (
Field,
FilterSchema,
Expand Down
9 changes: 2 additions & 7 deletions ohmg/core/api/routes.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from datetime import datetime
import logging
from typing import List, Optional
from typing import List

from django.conf import settings
from django.contrib.gis.geos import Polygon, MultiPolygon
from django.contrib.gis.geos import Polygon
from django.db.models import F
from django.shortcuts import get_object_or_404
from django.urls import reverse

from ninja import NinjaAPI, Query
from ninja.pagination import paginate
Expand All @@ -17,17 +15,14 @@
APIKey,
)
from ohmg.core.models import (
MapGroup,
Map,
Document,
Region,
Layer,
)
from ohmg.loc_insurancemaps.models import Volume
from ohmg.georeference.models import (
SessionBase,
LayerSet,
LayerV1,
SessionLock,
)
from ohmg.places.models import Place
Expand Down
40 changes: 12 additions & 28 deletions ohmg/core/api/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
from natsort import natsorted

from django.conf import settings
from django.db.models import Q
from django.urls import reverse
from ninja import (
Field,
Schema,
)

Expand All @@ -20,40 +18,31 @@
Region,
Layer,
)
from ohmg.loc_insurancemaps.models import Volume
from ohmg.georeference.models import (
PrepSession,
GeorefSession,
SessionLock,
SessionBase,
)

logger = logging.getLogger(__name__)


class MapListSchema(Schema):
identifier: str
title: str
year: str


class UserSchema(Schema):
username: str
profile_url: str
psesh_ct: int
gsesh_ct: int
total_ct: int = 0
gcp_ct: int
volumes: list
maps: List[MapListSchema]
load_ct: int
image_url: str
api_keys: List[str]

@staticmethod
def resolve_volumes(obj):
"""overrride the volumes property on the model in order to
create a super light-weight acquisition of volume info"""
values = Volume.objects.filter(loaded_by=obj) \
.order_by('city', 'year') \
.values('identifier', 'city', 'year', 'volume_no')
for i in values:
i['url'] = reverse('map_summary', args=(i['identifier'], ))
i['title'] = f"{i['city']} {i['year']}{' vol. ' + i['volume_no'] if i['volume_no'] else ''}"
return values

@staticmethod
def resolve_total_ct(obj):
Expand Down Expand Up @@ -301,10 +290,10 @@ def resolve_image_url(obj):
@staticmethod
def resolve_gcps_geojson(obj):
if not obj.region:
logger.warn(f"[WARNING] Layer {obj.pk} has no associated region")
logger.warning(f"[WARNING] Layer {obj.pk} has no associated region")
return None
elif not obj.region.gcp_group:
logger.warn(f"[WARNING] Region {obj.region.pk} attached to Layer {obj.pk} has no associated GCPGroup")
logger.warning(f"[WARNING] Region {obj.region.pk} attached to Layer {obj.pk} has no associated GCPGroup")
return None
return obj.region.gcp_group.as_geojson

Expand Down Expand Up @@ -347,10 +336,10 @@ def resolve_image_url(obj):
@staticmethod
def resolve_gcps_geojson(obj):
if not obj.region:
logger.warn(f"[WARNING] Layer {obj.pk} has no associated region")
logger.warning(f"[WARNING] Layer {obj.pk} has no associated region")
return None
elif not obj.region.gcp_group:
logger.warn(f"[WARNING] Region {obj.region.pk} attached to Layer {obj.pk} has no associated GCPGroup")
logger.warning(f"[WARNING] Region {obj.region.pk} attached to Layer {obj.pk} has no associated GCPGroup")
return None
return obj.region.gcp_group.as_geojson

Expand Down Expand Up @@ -431,8 +420,7 @@ class LayerSetSchema(Schema):

id: str
name: str
volume_id: str
is_geospatial: bool
map_id: str
layers: List[LayerSetLayer]
multimask_geojson: Optional[dict]
extent: Optional[tuple]
Expand All @@ -452,10 +440,6 @@ def resolve_layers(obj):
def resolve_name(obj):
return str(obj.category)

@staticmethod
def resolve_is_geospatial(obj):
return obj.category.is_geospatial


class PlaceSchema(Schema):
""" very lightweight serialization of a Place with its Maps"""
Expand Down
187 changes: 0 additions & 187 deletions ohmg/core/api_old.py

This file was deleted.

1 change: 1 addition & 0 deletions ohmg/core/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def user_info_from_request(request):
user = None
if user and user.is_authenticated:
user_info = UserSchema.from_orm(user).dict()
user_info['api_keys'] = user.api_keys
user_info['is_authenticated'] = True
user_info['is_staff'] = user.is_staff
else:
Expand Down
Loading

0 comments on commit d93f8b8

Please sign in to comment.