query: Move 'latest' command to a function
This commit is contained in:
parent
0e846ccd6e
commit
64efb3d678
3 changed files with 19 additions and 17 deletions
|
|
@ -44,7 +44,7 @@ class ApiIdentGetterResource:
|
||||||
return
|
return
|
||||||
|
|
||||||
if version == 'latest':
|
if version == 'latest':
|
||||||
version = query.query('latest')
|
version = query.get_latest_tag()
|
||||||
|
|
||||||
symbol_definitions, symbol_references, symbol_doccomments = query.query('ident', version, ident, family)
|
symbol_definitions, symbol_references, symbol_doccomments = query.query('ident', version, ident, family)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -109,17 +109,7 @@ class Query:
|
||||||
return versions
|
return versions
|
||||||
|
|
||||||
elif cmd == 'latest':
|
elif cmd == 'latest':
|
||||||
|
return self.get_latest_tag()
|
||||||
# Returns the latest tag that is included in the database.
|
|
||||||
# This excludes release candidates.
|
|
||||||
sorted_tags = self.scriptLines('get-latest-tags')
|
|
||||||
|
|
||||||
for tag in sorted_tags:
|
|
||||||
if self.db.vers.exists(tag):
|
|
||||||
return tag.decode()
|
|
||||||
|
|
||||||
# return the oldest tag, even if it does not exist in the database
|
|
||||||
return sorted_tags[-1].decode()
|
|
||||||
|
|
||||||
elif cmd == 'type':
|
elif cmd == 'type':
|
||||||
|
|
||||||
|
|
@ -264,6 +254,18 @@ class Query:
|
||||||
else:
|
else:
|
||||||
return 'Unknown subcommand: ' + cmd + '\n'
|
return 'Unknown subcommand: ' + cmd + '\n'
|
||||||
|
|
||||||
|
# Returns the latest tag that is included in the database.
|
||||||
|
# This excludes release candidates.
|
||||||
|
def get_latest_tag(self):
|
||||||
|
sorted_tags = self.scriptLines('get-latest-tags')
|
||||||
|
|
||||||
|
for tag in sorted_tags:
|
||||||
|
if self.db.vers.exists(tag):
|
||||||
|
return tag.decode()
|
||||||
|
|
||||||
|
# return the oldest tag, even if it does not exist in the database
|
||||||
|
return sorted_tags[-1].decode()
|
||||||
|
|
||||||
def get_file_raw(self, version, path):
|
def get_file_raw(self, version, path):
|
||||||
return decode(self.script('get-file', version, path))
|
return decode(self.script('get-file', version, path))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,7 @@ def get_project_error_page(req, resp, exception: ElixirProjectError):
|
||||||
# If details about current version are not available, make base links
|
# If details about current version are not available, make base links
|
||||||
# point to latest.
|
# point to latest.
|
||||||
# current_tag is not set to latest to avoid latest being highlighted in the sidebar
|
# current_tag is not set to latest to avoid latest being highlighted in the sidebar
|
||||||
version = query.query('latest')
|
version = query.get_latest_tag()
|
||||||
|
|
||||||
template_ctx = {
|
template_ctx = {
|
||||||
**template_ctx,
|
**template_ctx,
|
||||||
|
|
@ -210,7 +210,7 @@ class IndexResource:
|
||||||
raise ElixirProjectError('Error', f'Unknown default project: {project}',
|
raise ElixirProjectError('Error', f'Unknown default project: {project}',
|
||||||
status=falcon.HTTP_INTERNAL_SERVER_ERROR)
|
status=falcon.HTTP_INTERNAL_SERVER_ERROR)
|
||||||
|
|
||||||
version = query.query('latest')
|
version = query.get_latest_tag()
|
||||||
resp.status = falcon.HTTP_FOUND
|
resp.status = falcon.HTTP_FOUND
|
||||||
resp.location = stringify_source_path(project, version, '/')
|
resp.location = stringify_source_path(project, version, '/')
|
||||||
return
|
return
|
||||||
|
|
@ -235,7 +235,7 @@ class SourceResource:
|
||||||
project=project, version=version, query=query)
|
project=project, version=version, query=query)
|
||||||
|
|
||||||
if version == 'latest':
|
if version == 'latest':
|
||||||
version = query.query('latest')
|
version = query.get_latest_tag()
|
||||||
resp.status = falcon.HTTP_FOUND
|
resp.status = falcon.HTTP_FOUND
|
||||||
resp.location = stringify_source_path(project, version, path)
|
resp.location = stringify_source_path(project, version, path)
|
||||||
return
|
return
|
||||||
|
|
@ -326,7 +326,7 @@ class IdentResource(IdentPostRedirectResource):
|
||||||
ident = validated_ident
|
ident = validated_ident
|
||||||
|
|
||||||
if version == 'latest':
|
if version == 'latest':
|
||||||
version = query.query('latest')
|
version = query.get_latest_tag()
|
||||||
resp.status = falcon.HTTP_FOUND
|
resp.status = falcon.HTTP_FOUND
|
||||||
resp.location = stringify_ident_path(project, version, family, ident)
|
resp.location = stringify_ident_path(project, version, family, ident)
|
||||||
return
|
return
|
||||||
|
|
@ -354,7 +354,7 @@ class IncompleteURLRedirectResource:
|
||||||
status=falcon.HTTP_INTERNAL_SERVER_ERROR)
|
status=falcon.HTTP_INTERNAL_SERVER_ERROR)
|
||||||
|
|
||||||
if version == 'latest' or len(version) == 0:
|
if version == 'latest' or len(version) == 0:
|
||||||
version = query.query('latest')
|
version = query.get_latest_tag()
|
||||||
|
|
||||||
resp.status = falcon.HTTP_FOUND
|
resp.status = falcon.HTTP_FOUND
|
||||||
resp.location = stringify_source_path(project, version, '/')
|
resp.location = stringify_source_path(project, version, '/')
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue