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)
|
location = get_location_by_id_for_request(position_id, request)
|
||||||
if not isinstance(location, DynamicLocation):
|
if not isinstance(location, DynamicLocation):
|
||||||
raise API404()
|
raise API404()
|
||||||
if location is None and position_id.startswith('p:'):
|
if location is None and position_id.startswith('m:'):
|
||||||
try:
|
try:
|
||||||
location = Position.objects.get(secret=position_id[2:])
|
location = Position.objects.get(secret=position_id[2:])
|
||||||
except Position.DoesNotExist:
|
except Position.DoesNotExist:
|
||||||
|
@ -317,7 +317,7 @@ class UpdatePositionSchema(BaseSchema):
|
||||||
response={200: AnyPositionStatusSchema, **API404.dict(), **auth_permission_responses})
|
response={200: AnyPositionStatusSchema, **API404.dict(), **auth_permission_responses})
|
||||||
def set_position(request, position_id: AnyPositionID, update: UpdatePositionSchema):
|
def set_position(request, position_id: AnyPositionID, update: UpdatePositionSchema):
|
||||||
# todo: may an API key do this?
|
# 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()
|
raise API404()
|
||||||
try:
|
try:
|
||||||
location = Position.objects.get(secret=position_id[2:])
|
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)
|
custom_location = self.get_custom_location(request=request)
|
||||||
if custom_location is None:
|
if custom_location is None:
|
||||||
return {
|
return {
|
||||||
'id': 'p:%s' % self.secret,
|
'id': 'm:%s' % self.secret,
|
||||||
'slug': 'p:%s' % self.secret,
|
'slug': 'm:%s' % self.secret,
|
||||||
'available': False,
|
'available': False,
|
||||||
'icon': 'my_location',
|
'icon': 'my_location',
|
||||||
'title': self.name,
|
'title': self.name,
|
||||||
|
@ -622,8 +622,8 @@ class Position(CustomLocationProxyMixin, models.Model):
|
||||||
result = CustomLocationSchema.model_validate(custom_location).model_dump()
|
result = CustomLocationSchema.model_validate(custom_location).model_dump()
|
||||||
result.update({
|
result.update({
|
||||||
'available': True,
|
'available': True,
|
||||||
'id': 'p:%s' % self.secret,
|
'id': 'm:%s' % self.secret,
|
||||||
'slug': 'p:%s' % self.secret,
|
'slug': 'm:%s' % self.secret,
|
||||||
'icon': 'my_location',
|
'icon': 'my_location',
|
||||||
'title': self.name,
|
'title': self.name,
|
||||||
'subtitle': '%s, %s, %s' % (
|
'subtitle': '%s, %s, %s' % (
|
||||||
|
@ -640,7 +640,7 @@ class Position(CustomLocationProxyMixin, models.Model):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def slug(self):
|
def slug(self):
|
||||||
return 'p:%s' % self.secret
|
return 'm:%s' % self.secret
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def subtitle(self):
|
def subtitle(self):
|
||||||
|
|
|
@ -213,7 +213,7 @@ def get_location_by_id_for_request(pk, request):
|
||||||
if isinstance(pk, str):
|
if isinstance(pk, str):
|
||||||
if pk.isdigit():
|
if pk.isdigit():
|
||||||
pk = int(pk)
|
pk = int(pk)
|
||||||
elif pk.startswith('p:'):
|
elif pk.startswith('m:'):
|
||||||
try:
|
try:
|
||||||
# return immediately, don't cache for obvious reasons
|
# return immediately, don't cache for obvious reasons
|
||||||
return Position.objects.get(secret=pk[2:])
|
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)
|
location = get_custom_location_for_request(slug, request)
|
||||||
if location is None:
|
if location is None:
|
||||||
return None
|
return None
|
||||||
elif slug.startswith('p:'):
|
elif slug.startswith('m:'):
|
||||||
try:
|
try:
|
||||||
# return immediately, don't cache for obvious reasons
|
# return immediately, don't cache for obvious reasons
|
||||||
return Position.objects.get(secret=slug[2:])
|
return Position.objects.get(secret=slug[2:])
|
||||||
|
|
|
@ -63,8 +63,8 @@ def locate(instance, interface=None, sudo=False, secret=None, api_secret=None, l
|
||||||
}
|
}
|
||||||
|
|
||||||
if secret and api_secret:
|
if secret and api_secret:
|
||||||
if not secret.startswith('p:'):
|
if not secret.startswith('m:'):
|
||||||
secret = 'p:' + secret
|
secret = 'm:' + secret
|
||||||
|
|
||||||
json['set_position'] = secret
|
json['set_position'] = secret
|
||||||
json['secret'] = api_secret
|
json['secret'] = api_secret
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue