links to POIs without slugs were always dead because of prefix collision
This commit is contained in:
parent
12ab28da65
commit
d901b49314
4 changed files with 11 additions and 11 deletions
|
@ -285,7 +285,7 @@ def get_position_by_id(request, position_id: AnyPositionID):
|
|||
location = get_location_by_id_for_request(position_id, request)
|
||||
if not isinstance(location, DynamicLocation):
|
||||
raise API404()
|
||||
if location is None and position_id.startswith('p:'):
|
||||
if location is None and position_id.startswith('m:'):
|
||||
try:
|
||||
location = Position.objects.get(secret=position_id[2:])
|
||||
except Position.DoesNotExist:
|
||||
|
@ -317,7 +317,7 @@ class UpdatePositionSchema(BaseSchema):
|
|||
response={200: AnyPositionStatusSchema, **API404.dict(), **auth_permission_responses})
|
||||
def set_position(request, position_id: AnyPositionID, update: UpdatePositionSchema):
|
||||
# todo: may an API key do this?
|
||||
if not isinstance(position_id, str) or not position_id.startswith('p:'):
|
||||
if not isinstance(position_id, str) or not position_id.startswith('m:'):
|
||||
raise API404()
|
||||
try:
|
||||
location = Position.objects.get(secret=position_id[2:])
|
||||
|
|
|
@ -611,8 +611,8 @@ class Position(CustomLocationProxyMixin, models.Model):
|
|||
custom_location = self.get_custom_location(request=request)
|
||||
if custom_location is None:
|
||||
return {
|
||||
'id': 'p:%s' % self.secret,
|
||||
'slug': 'p:%s' % self.secret,
|
||||
'id': 'm:%s' % self.secret,
|
||||
'slug': 'm:%s' % self.secret,
|
||||
'available': False,
|
||||
'icon': 'my_location',
|
||||
'title': self.name,
|
||||
|
@ -622,8 +622,8 @@ class Position(CustomLocationProxyMixin, models.Model):
|
|||
result = CustomLocationSchema.model_validate(custom_location).model_dump()
|
||||
result.update({
|
||||
'available': True,
|
||||
'id': 'p:%s' % self.secret,
|
||||
'slug': 'p:%s' % self.secret,
|
||||
'id': 'm:%s' % self.secret,
|
||||
'slug': 'm:%s' % self.secret,
|
||||
'icon': 'my_location',
|
||||
'title': self.name,
|
||||
'subtitle': '%s, %s, %s' % (
|
||||
|
@ -640,7 +640,7 @@ class Position(CustomLocationProxyMixin, models.Model):
|
|||
|
||||
@property
|
||||
def slug(self):
|
||||
return 'p:%s' % self.secret
|
||||
return 'm:%s' % self.secret
|
||||
|
||||
@property
|
||||
def subtitle(self):
|
||||
|
|
|
@ -213,7 +213,7 @@ def get_location_by_id_for_request(pk, request):
|
|||
if isinstance(pk, str):
|
||||
if pk.isdigit():
|
||||
pk = int(pk)
|
||||
elif pk.startswith('p:'):
|
||||
elif pk.startswith('m:'):
|
||||
try:
|
||||
# return immediately, don't cache for obvious reasons
|
||||
return Position.objects.get(secret=pk[2:])
|
||||
|
@ -234,7 +234,7 @@ def get_location_by_slug_for_request(slug: str, request) -> Optional[Union[Locat
|
|||
location = get_custom_location_for_request(slug, request)
|
||||
if location is None:
|
||||
return None
|
||||
elif slug.startswith('p:'):
|
||||
elif slug.startswith('m:'):
|
||||
try:
|
||||
# return immediately, don't cache for obvious reasons
|
||||
return Position.objects.get(secret=slug[2:])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue