Add /userid/id redirect to /user/name

This commit is contained in:
voussoir 2017-06-19 17:03:07 -07:00
parent f61570acfb
commit 57355cb032
2 changed files with 19 additions and 7 deletions

View file

@ -18,7 +18,7 @@ Documentation is still a work in progress. In general, I use:
- Improve the "tags on this page" list. Maybe add separate buttons for must/may/forbid on each. - Improve the "tags on this page" list. Maybe add separate buttons for must/may/forbid on each.
- Some way for the database to re-identify a file that was moved / renamed (lost & found). Maybe file hash of the first few mb is good enough. - Some way for the database to re-identify a file that was moved / renamed (lost & found). Maybe file hash of the first few mb is good enough.
- Debate whether the `UserMixin.login` method should accept usernames or I should standardize the usage of IDs only internally. - Debate whether the `UserMixin.login` method should accept usernames or I should standardize the usage of IDs only internally.
- Ability to access user page and user photos by user's ID, not just username. - Ability to access user photos by user's ID, not just username.
- Should album size be cached on disk? - Should album size be cached on disk?
- Replace columns like area, ratio, bitrate by using expression indices or views (`width * height` etc). - Replace columns like area, ratio, bitrate by using expression indices or views (`width * height` etc).
- Add some way to support large image albums without flooding the search results. Considering a "hidden" property so that a handful of representative images can appear in the search results, and the rest can be found on the actual Album page. - Add some way to support large image albums without flooding the search results. Considering a "hidden" property so that a handful of representative images can appear in the search results, and the rest can be found on the actual Album page.

View file

@ -118,6 +118,10 @@ def P_tag(tagname):
def P_user(username): def P_user(username):
return P.get_user(username=username) return P.get_user(username=username)
@P_wrapper
def P_user_id(userid):
return P.get_user(id=userid)
def send_file(filepath, override_mimetype=None): def send_file(filepath, override_mimetype=None):
''' '''
Range-enabled file sending. Range-enabled file sending.
@ -347,10 +351,6 @@ def get_tags_core(specific_tag=None):
tags.sort(key=lambda x: x.qualified_name()) tags.sort(key=lambda x: x.qualified_name())
return tags return tags
def get_user_core(username):
user = P_user(username)
return user
def post_photo_add_remove_tag_core(photoid, tagname, add_or_remove): def post_photo_add_remove_tag_core(photoid, tagname, add_or_remove):
photo = P_photo(photoid, response_type='json') photo = P_photo(photoid, response_type='json')
tag = P_tag(tagname, response_type='json') tag = P_tag(tagname, response_type='json')
@ -833,17 +833,29 @@ def get_thumbnail(photoid):
@site.route('/user/<username>', methods=['GET']) @site.route('/user/<username>', methods=['GET'])
@session_manager.give_token @session_manager.give_token
def get_user_html(username): def get_user_html(username):
user = get_user_core(username) user = P_user(username, response_type='html')
session = session_manager.get(request) session = session_manager.get(request)
return flask.render_template('user.html', user=user, session=session) return flask.render_template('user.html', user=user, session=session)
@site.route('/user/<username>.json', methods=['GET']) @site.route('/user/<username>.json', methods=['GET'])
@session_manager.give_token @session_manager.give_token
def get_user_json(username): def get_user_json(username):
user = get_user_core(username) user = P_user(username, response_type='json')
user = etiquette.jsonify.user(user) user = etiquette.jsonify.user(user)
return jsonify.make_json_response(user) return jsonify.make_json_response(user)
@site.route('/userid/<userid>')
@site.route('/userid/<userid>.json')
def get_user_id_redirect(userid):
if request.url.endswith('.json'):
user = P_user_id(userid, response_type='json')
else:
user = P_user_id(userid, response_type='html')
url_from = '/userid/' + userid
url_to = '/user/' + user.username
url = request.url.replace(url_from, url_to)
return flask.redirect(url)
@site.route('/apitest') @site.route('/apitest')
@session_manager.give_token @session_manager.give_token