[Refactor] Refactor the about page

This makes it available to logged in users, too.
This commit is contained in:
Gergely Polonkai 2018-07-17 10:04:58 +02:00
parent 372a1f756a
commit c90b261de3
3 changed files with 45 additions and 21 deletions

View File

@ -155,36 +155,53 @@ class CalendarSocialApp(Flask):
return self._timezone return self._timezone
@staticmethod @staticmethod
@route('/') def _current_calendar():
def hello():
"""View for the main page
This will display a welcome message for users not logged in; for others, their main
calendar view is displayed.
"""
from .calendar_system.gregorian import GregorianCalendar from .calendar_system.gregorian import GregorianCalendar
from .models import User, Event
try: try:
timestamp = datetime.fromtimestamp(float(request.args.get('date'))) timestamp = datetime.fromtimestamp(float(request.args.get('date')))
except TypeError: except TypeError:
timestamp = datetime.utcnow() timestamp = datetime.utcnow()
calendar = GregorianCalendar(timestamp.timestamp()) return GregorianCalendar(timestamp.timestamp())
@route('/about')
def about(self):
"""View for the about page
"""
from .models import User, Event
calendar = self._current_calendar()
if not current_user.is_authenticated: if not current_user.is_authenticated:
login_form_class = current_app.extensions['security'].login_form login_form_class = current_app.extensions['security'].login_form
login_form = login_form_class() login_form = login_form_class()
user_count = User.query.count() else:
event_count = Event.query.count() login_form = None
return render_template('welcome.html', user_count = User.query.count()
calendar=calendar, event_count = Event.query.count()
user_only=False,
login_form=login_form, return render_template('welcome.html',
user_count=user_count, calendar=calendar,
event_count=event_count) user_only=False,
login_form=login_form,
user_count=user_count,
event_count=event_count)
@route('/')
def hello(self):
"""View for the main page
This will display a welcome message for users not logged in; for others, their main
calendar view is displayed.
"""
calendar = self._current_calendar()
if not current_user.is_authenticated:
return self.about()
return render_template('index.html', calendar=calendar, user_only=True) return render_template('index.html', calendar=calendar, user_only=True)

View File

@ -45,6 +45,7 @@
{% block content %}{% endblock %} {% block content %}{% endblock %}
</div> </div>
<footer class="ui segment"> <footer class="ui segment">
<a href="{{ url_for('about') }}">{% trans %}About this instance{% endtrans %}</a><br>
Soon…™ Soon…™
</footer> </footer>
{% block scripts %}{% endblock %} {% block scripts %}{% endblock %}

View File

@ -4,6 +4,7 @@
<div class="ui grid"> <div class="ui grid">
<div class="row"> <div class="row">
<div class="four wide column"> <div class="four wide column">
{% if not current_user.is_authenticated %}
<h2>{% trans %}Login{% endtrans %}</h2> <h2>{% trans %}Login{% endtrans %}</h2>
<form class="ui form" method="post" action="{{ url_for('security.login') }}"> <form class="ui form" method="post" action="{{ url_for('security.login') }}">
{{ login_form.hidden_tag() }} {{ login_form.hidden_tag() }}
@ -13,18 +14,23 @@
{{ login_form.password }} {{ login_form.password }}
<button type="submit" class="fluid ui primary button">{% trans %}Login{% endtrans %}</button> <button type="submit" class="fluid ui primary button">{% trans %}Login{% endtrans %}</button>
</form> </form>
{% if config.REGISTRATION_ENABLED %} {% if config.REGISTRATION_ENABLED %}
<div class="ui horizontal divider"> <div class="ui horizontal divider">
{% trans %}Or{% endtrans %} {% trans %}Or{% endtrans %}
</div> </div>
<a href="{{ url_for('register' ) }}" class="fluid ui button">{% trans %}Register an account{% endtrans %}</a> <a href="{{ url_for('register' ) }}" class="fluid ui button">{% trans %}Register an account{% endtrans %}</a>
{% endif %} {% endif %}
<div class="ui horizontal divider"></div> <div class="ui horizontal divider"></div>
{% endif %}
<h2>{% trans %}What is Calendar.social?{% endtrans %}</h2> <h2>{% trans %}What is Calendar.social?{% endtrans %}</h2>
<p> <p>
{% trans %}Calendar.social is a calendar app based on open protocols and free, open source software.{% endtrans %} {% trans %}Calendar.social is a calendar app based on open protocols and free, open source software.{% endtrans %}
{% trans %}It is decentralised like one of its counterparts, email.{% endtrans %} {% trans %}It is decentralised like one of its counterparts, email.{% endtrans %}
</p> </p>
{% if current_user.is_authenticated %}
<div class="ui horizontal divider"></div>
<a href="" class="ui fluid primary button">{% trans %}Go to your calendar{% endtrans %}</a>
{% endif %}
</div> </div>
<div class="twelve wide column"> <div class="twelve wide column">
<h2>{% trans %}Peek inside{% endtrans %}</h2> <h2>{% trans %}Peek inside{% endtrans %}</h2>
@ -33,7 +39,7 @@
</div> </div>
<div class="row"> <div class="row">
<div class="four wide column"> <div class="four wide column">
<h2>{% trans %}Built for users in mind{% endtrans %}</h2> <h2>{% trans %}Built with users in mind{% endtrans %}</h2>
<p> <p>
{% trans %}From planning your appointments to organising large scale events Calendar.social can help with all your scheduling needs.{% endtrans %} {% trans %}From planning your appointments to organising large scale events Calendar.social can help with all your scheduling needs.{% endtrans %}
</p> </p>