Add navigation bar
This commit is contained in:
		
							parent
							
								
									1a7872b136
								
							
						
					
					
						commit
						ded4b913da
					
				
							
								
								
									
										17
									
								
								app.py
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								app.py
									
									
									
									
									
								
							| 
						 | 
				
			
			@ -82,7 +82,11 @@ def current_url():
 | 
			
		|||
def init_profile():
 | 
			
		||||
    g.profiling = []
 | 
			
		||||
 | 
			
		||||
@app.route('/user/settings')
 | 
			
		||||
@app.before_request
 | 
			
		||||
def global_user():
 | 
			
		||||
    g.user = wikidata_oauth.get_username()
 | 
			
		||||
 | 
			
		||||
@app.route('/settings')
 | 
			
		||||
def user_settings():
 | 
			
		||||
    session['no_find_more'] = not session.get('no_find_more')
 | 
			
		||||
    display = {True: 'on', False: 'off'}[not session['no_find_more']]
 | 
			
		||||
| 
						 | 
				
			
			@ -261,7 +265,7 @@ def oauth_disconnect():
 | 
			
		|||
    for key in 'owner_key', 'owner_secret', 'username', 'after_login':
 | 
			
		||||
        if key in session:
 | 
			
		||||
            del session[key]
 | 
			
		||||
    return random_painting()
 | 
			
		||||
    return redirect(url_for('browse_page'))
 | 
			
		||||
 | 
			
		||||
def create_claim(painting_id, depicts_id, token):
 | 
			
		||||
    painting_qid = f'Q{painting_id}'
 | 
			
		||||
| 
						 | 
				
			
			@ -438,7 +442,7 @@ def get_other(entity):
 | 
			
		|||
    other_items = build_other_set(entity)
 | 
			
		||||
    return get_labels(other_items)
 | 
			
		||||
 | 
			
		||||
@app.route("/admin/edits")
 | 
			
		||||
@app.route("/edits")
 | 
			
		||||
def list_edits():
 | 
			
		||||
    edit_list = Edit.query.order_by(Edit.timestamp.desc())
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -640,14 +644,15 @@ def get_image_detail_with_cache(items, cache_name, thumbwidth=None):
 | 
			
		|||
 | 
			
		||||
    return detail
 | 
			
		||||
 | 
			
		||||
def browse_index():
 | 
			
		||||
    return render_template('browse_index.html', props=find_more_props)
 | 
			
		||||
 | 
			
		||||
@app.route('/browse')
 | 
			
		||||
def browse_page():
 | 
			
		||||
    params = get_painting_params()
 | 
			
		||||
 | 
			
		||||
    if not params:
 | 
			
		||||
        return render_template('browse_index.html',
 | 
			
		||||
                               props=find_more_props,
 | 
			
		||||
                               username=wikidata_oauth.get_username())
 | 
			
		||||
        return browse_index()
 | 
			
		||||
 | 
			
		||||
    flat = '_'.join(f'{pid}={qid}' for pid, qid in params)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,8 +11,10 @@
 | 
			
		|||
 | 
			
		||||
  {% block style %}{% endblock %}
 | 
			
		||||
</head>
 | 
			
		||||
{% from "navbar.html" import navbar with context %}
 | 
			
		||||
 | 
			
		||||
<body>
 | 
			
		||||
  {% block nav %}{{ navbar() }}{% endblock %}
 | 
			
		||||
  {% block content %}{% endblock %}
 | 
			
		||||
 | 
			
		||||
  <script src="{{ url_for('static', filename='javascript/jquery/jquery.min.js') }}"></script>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,16 +6,12 @@
 | 
			
		|||
<div class="m-3">
 | 
			
		||||
  <p><a href="{{ url_for('random_painting') }}">random painting</a>
 | 
			
		||||
 | 
			
		||||
  {% if not username %}
 | 
			
		||||
  {% if not g.user %}
 | 
			
		||||
  | <a href="{{ url_for('start_oauth') }}">connect to Wikidata account</a>
 | 
			
		||||
  {% endif %}
 | 
			
		||||
  </p>
 | 
			
		||||
 | 
			
		||||
  {% if username %}
 | 
			
		||||
  <p>username: {{ username }}</p>
 | 
			
		||||
  {% endif %}
 | 
			
		||||
 | 
			
		||||
  {% if not username %}
 | 
			
		||||
  {% if not g.user %}
 | 
			
		||||
    <p>This tool must be connected with Wikidata to work.</p>
 | 
			
		||||
    <p><a href="{{ url_for('start_oauth') }}" class="btn btn-primary btn-lg">Connect with Wikidata</a>
 | 
			
		||||
  {% endif %}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										44
									
								
								templates/navbar.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								templates/navbar.html
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,44 @@
 | 
			
		|||
{% macro nav_item(name, label) %}
 | 
			
		||||
<li class="nav-item{% if name == active %} active{% endif %}">
 | 
			
		||||
  <a class="nav-link" href="{{ url_for(name) }}">{{ label }}{% if name == active %} <span class="sr-only">(current)</span>{% endif %}</a>
 | 
			
		||||
</li>
 | 
			
		||||
{% endmacro %}
 | 
			
		||||
 | 
			
		||||
{% macro navbar_inner(name) %}
 | 
			
		||||
  <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
 | 
			
		||||
    <span class="navbar-toggler-icon"></span>
 | 
			
		||||
  </button>
 | 
			
		||||
  <a class="navbar-brand" href="{{ url_for('browse_page') }}">Wikidata Art Depiction Explorer</a>
 | 
			
		||||
 | 
			
		||||
  <div class="collapse navbar-collapse" id="navbarSupportedContent">
 | 
			
		||||
    <ul class="navbar-nav mr-auto">
 | 
			
		||||
    <ul class="navbar-nav mr-auto">
 | 
			
		||||
      {{ nav_item('browse_page', 'Browse') }}
 | 
			
		||||
      {{ nav_item('list_edits', 'Recent changes') }}
 | 
			
		||||
      {{ nav_item('random_painting', 'Random painting') }}
 | 
			
		||||
    </ul>
 | 
			
		||||
    </ul>
 | 
			
		||||
    <ul class="navbar-nav">
 | 
			
		||||
      <li class="nav-item">
 | 
			
		||||
        {% if g.user %}
 | 
			
		||||
          <li class="nav-item">
 | 
			
		||||
            <a class="nav-link" href="{{ url_for('user_page', username=g.user) }}">{{ g.user }}</a>
 | 
			
		||||
          </li>
 | 
			
		||||
          <li class="nav-item">
 | 
			
		||||
            <a class="nav-link" href="{{ url_for('oauth_disconnect', next=request.script_root + request.full_path) }}">switch user</a>
 | 
			
		||||
          </li>
 | 
			
		||||
        {% else %}
 | 
			
		||||
          <li class="nav-item">
 | 
			
		||||
            {% set login_url = url_for('start_oauth', next=request.script_root + request.full_path) %}
 | 
			
		||||
            <a class="nav-link" href="{{ login_url }}">connect with Wikidata</a>
 | 
			
		||||
          </li>
 | 
			
		||||
        {% endif %}
 | 
			
		||||
    </ul>
 | 
			
		||||
  </div>
 | 
			
		||||
{% endmacro %}
 | 
			
		||||
 | 
			
		||||
{% macro navbar() %}
 | 
			
		||||
<nav class="navbar navbar-toggleable-md navbar-expand-lg navbar-dark bg-dark">
 | 
			
		||||
  {{ navbar_inner() }}
 | 
			
		||||
</nav>
 | 
			
		||||
{% endmacro %}
 | 
			
		||||
		Loading…
	
		Reference in a new issue