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
|
||||
|
||||
if version == 'latest':
|
||||
version = query.query('latest')
|
||||
version = query.get_latest_tag()
|
||||
|
||||
symbol_definitions, symbol_references, symbol_doccomments = query.query('ident', version, ident, family)
|
||||
|
||||
|
|
|
|||
|
|
@ -109,17 +109,7 @@ class Query:
|
|||
return versions
|
||||
|
||||
elif cmd == 'latest':
|
||||
|
||||
# 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()
|
||||
return self.get_latest_tag()
|
||||
|
||||
elif cmd == 'type':
|
||||
|
||||
|
|
@ -264,6 +254,18 @@ class Query:
|
|||
else:
|
||||
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):
|
||||
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
|
||||
# point to latest.
|
||||
# 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,
|
||||
|
|
@ -210,7 +210,7 @@ class IndexResource:
|
|||
raise ElixirProjectError('Error', f'Unknown default project: {project}',
|
||||
status=falcon.HTTP_INTERNAL_SERVER_ERROR)
|
||||
|
||||
version = query.query('latest')
|
||||
version = query.get_latest_tag()
|
||||
resp.status = falcon.HTTP_FOUND
|
||||
resp.location = stringify_source_path(project, version, '/')
|
||||
return
|
||||
|
|
@ -235,7 +235,7 @@ class SourceResource:
|
|||
project=project, version=version, query=query)
|
||||
|
||||
if version == 'latest':
|
||||
version = query.query('latest')
|
||||
version = query.get_latest_tag()
|
||||
resp.status = falcon.HTTP_FOUND
|
||||
resp.location = stringify_source_path(project, version, path)
|
||||
return
|
||||
|
|
@ -326,7 +326,7 @@ class IdentResource(IdentPostRedirectResource):
|
|||
ident = validated_ident
|
||||
|
||||
if version == 'latest':
|
||||
version = query.query('latest')
|
||||
version = query.get_latest_tag()
|
||||
resp.status = falcon.HTTP_FOUND
|
||||
resp.location = stringify_ident_path(project, version, family, ident)
|
||||
return
|
||||
|
|
@ -354,7 +354,7 @@ class IncompleteURLRedirectResource:
|
|||
status=falcon.HTTP_INTERNAL_SERVER_ERROR)
|
||||
|
||||
if version == 'latest' or len(version) == 0:
|
||||
version = query.query('latest')
|
||||
version = query.get_latest_tag()
|
||||
|
||||
resp.status = falcon.HTTP_FOUND
|
||||
resp.location = stringify_source_path(project, version, '/')
|
||||
|
|
|
|||
Loading…
Reference in a new issue