Skip to content
This repository has been archived by the owner on May 16, 2020. It is now read-only.

Commit

Permalink
Switch to .html.jinja2 templates, fixes #286 (#287)
Browse files Browse the repository at this point in the history
* Switch to .html.jinja2 templates, fixes #286

* fixed travis config

* installing coverage for tests

* added test settings

* missed one
  • Loading branch information
Bibhas authored Oct 14, 2017
1 parent 146f799 commit 0005333
Show file tree
Hide file tree
Showing 27 changed files with 88 additions and 54 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ dist/
.webassets-cache
nosetests.xml
.sass-cache
instance/testing.py
instance/development.py
instance/production.py
instance/settings.py
Expand Down
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ python:
- "2.7"
# command to install dependencies
install:
- pip install -r requirements.txt --use-mirrors
- pip install -r requirements.txt
- pip install -r test_requirements.txt
# command to run tests
script: python runtests.py
script: ./runtests.sh
notifications:
email: false
slack:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "layout.html" %}
{% from "forms.html" import renderform, ajaxform %}
{% extends "layout.html.jinja2" %}
{% from "forms.html.jinja2" import renderform, ajaxform %}
{% block content %}
<p>{{ message }}</p>
<form id="delete" method="POST">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "layout.html" %}
{% extends "layout.html.jinja2" %}
{% block title %}{{ event.title }}{% endblock %}

{% macro participant_list(event, participants) -%}
Expand All @@ -8,7 +8,7 @@
<a href="{{ p.user.profile_url }}"><div class="participant-img"><i class="icon-user icon-4x"></i></div></a>
<div class="participant-name">
<b><a href="{{ p.user.profile_url }}">{{ p.user.fullname }}</a></b>

<div class="participating-projects">
{% with projects = p.user.projects_in(event) %}
{%- if projects %}
Expand Down Expand Up @@ -116,7 +116,7 @@ <h1>{{ self.title() }}</h1>
{% endif -%}
{% endif -%}
</ul>

<div class="share">
<ul>
<li>
Expand All @@ -139,8 +139,8 @@ <h1>{{ self.title() }}</h1>
{% if event.sponsors %}
<hr class="clear-line">
<div class="sidebar-heading nav nav-list">
<h4 class="nav-header">Sponsors</h4>
</div>
<h4 class="nav-header">Sponsors</h4>
</div>
<ul class="sponsor-box">
{% for sponsor in event.sponsors %}
<li><a href="{{ sponsor.url_for() }}"><img src="{{ sponsor.image_url }}" class="sponsor-logo"></a></li>
Expand Down Expand Up @@ -250,7 +250,7 @@ <h2>New project...</h2>
$(".sync").on('click', function(e){
e.preventDefault();
$("#sync_form").submit();
});
});
});
</script>

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "layout.html" %}
{% from "baseframe/components.html" import networkbar with context %}
{% from "macros/cardset.html" import cardset with context %}
{% extends "layout.html.jinja2" %}
{% from "baseframe/components.html.jinja2" import networkbar with context %}
{% from "macros/cardset.html.jinja2" import cardset with context %}
{% block titletags -%}
<title>{% block title %}{{ config['SITE_TITLE'] }}{% endblock %}</title>
<meta name="DC.title" content="{{ config['SITE_TITLE'] }}"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "baseframe.html" %}
{% from "baseframe/components.html" import networkbar with context %}
{% extends "baseframe.html.jinja2" %}
{% from "baseframe/components.html.jinja2" import networkbar with context %}

{%- block image_src %}
<!-- Overriding so that facebook can pickup hacknight logo rather than HasGeek logo-->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "layout.html" %}
{% extends "layout.html.jinja2" %}
{% block title %}{{ event.title }}{% endblock %}

{% block baseheadline -%}
Expand Down Expand Up @@ -76,22 +76,22 @@ <h3 class="h3-title">Participants</h3>
newStatus = el.attr('data-status'),
statusLabels = {{statuslabels | tojson | safe}},
isFull = "{{ event.confirmed_participants_count() < event.maximum_participants }}";
if (newStatus == 2){ //if the new status is confirmed
if (newStatus == 2){ //if the new status is confirmed
if (isFull === "True") {
$('div#contact-info').html("");
$('div#contact-info').html("");
}
} else {
e.stopPropagation();
participantEl.children('.participant-status-label').text(statusLabels[newStatus]);
}
if (isFull === "True" || (isFull === "False" && newStatus != 2)){
if (isFull === "True" || (isFull === "False" && newStatus != 2)){
//Send Ajax request to accept participant incase of vacancy.
$.ajax({
type: "POST",
url: "{{ event.url_for('update') }}",
data: {participantid: id, status: newStatus},
success: function(){ window.location.reload(true);},
error: function(msg){ toastr.error("Unable to send request");}
error: function(msg){ toastr.error("Unable to send request");}
});
} else {
toastr.error("Venue capacity is full.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "layout.html" %}
{% from "macros/cardset.html" import cardset with context %}
{% extends "layout.html.jinja2" %}
{% from "macros/cardset.html.jinja2" import cardset with context %}
{% block title %}{{ profile.title }}{% endblock %}

{% block content %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "layout.html" %}
{% from "comments.html" import commenttree %}
{% from "forms.html" import renderform, ajaxform %}
{% extends "layout.html.jinja2" %}
{% from "comments.html.jinja2" import commenttree %}
{% from "forms.html.jinja2" import renderform, ajaxform %}

{% block title %}{{ project.title }} &mdash; {{ event.title }}{% endblock %}
{% block headline %}{% endblock %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "layout.html" %}
{% extends "layout.html.jinja2" %}
{% block title %}{{ sponsor.title }}{% endblock %}

{% block headline %}{% endblock %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "layout.html" %}
{% extends "layout.html.jinja2" %}

{% block content %}
<pre>{% for line in stream -%}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "layout.html" %}
{% extends "layout.html.jinja2" %}
{% block title %}{{ venue.title }}{% endblock %}

{% block content %}
Expand Down Expand Up @@ -35,7 +35,7 @@ <h2>Address</h2>
function onZoomend(){
map.setView(venue, map.getZoom());
};
{% endif %}
{% endif %}
});
</script>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "layout.html" %}
{% extends "layout.html.jinja2" %}
{% block title %}All Hacknight Venues {% endblock %}

{% block content %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "layout.html" %}
{% from "forms.html" import renderform, ajaxform %}
{% extends "layout.html.jinja2" %}
{% from "forms.html.jinja2" import renderform, ajaxform %}
{% block content %}
<p>{{ message }}</p>
<form id="delete" method="POST">
Expand Down
8 changes: 4 additions & 4 deletions hacknight/views/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def event_view(profile, event):
applied = True
break
current_participant = Participant.get(user=g.user, event=event) if g.user else None
return render_template('event.html', profile=profile, event=event,
return render_template('event.html.jinja2', profile=profile, event=event,
projects=event.projects,
accepted_participants=accepted_participants,
rest_participants=rest_participants,
Expand Down Expand Up @@ -161,7 +161,7 @@ def event_open(profile, event):
participants = Participant.query.filter(
Participant.status != PARTICIPANT_STATUS.WITHDRAWN,
Participant.event == event).order_by(Participant.status).order_by(Participant.created_at)
return render_template('manage_event.html', profile=profile, event=event,
return render_template('manage_event.html.jinja2', profile=profile, event=event,
participants=participants, statuslabels=participant_status_labels, enumerate=enumerate)


Expand All @@ -172,7 +172,7 @@ def event_open(profile, event):
(Event, {'name': 'event', 'profile': 'profile'}, 'event'), permission='edit')
def event_sync(profile, event):
participants = Participant.unconfirmed_for(event)
return Response(stream_template('stream.html',
return Response(stream_template('stream.html.jinja2',
stream=stream_with_context(event.sync_participants(participants)),
title="Syncing participants..."))

Expand Down Expand Up @@ -285,7 +285,7 @@ def event_withdraw(profile, event):
flash(u"Your request to withdraw from {0} is recorded".format(event.title), "success")
values = {'profile': profile.name, 'event': event.name}
return render_redirect(event.url_for(), code=303)
return render_template('withdraw.html', form=form, title=u"Confirm withdraw",
return render_template('withdraw.html.jinja2', form=form, title=u"Confirm withdraw",
message=u"Withdraw from '%s' ? You can come back anytime." % (event.title))
else:
abort(404)
Expand Down
4 changes: 2 additions & 2 deletions hacknight/views/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def index():
# TODO: Filter events by status
upcoming_events = Event.upcoming_events()
past_events = Event.past_events()
return render_template('index.html', upcoming_events=upcoming_events, past_events=past_events)
return render_template('index.html.jinja2', upcoming_events=upcoming_events, past_events=past_events)


@app.template_filter('startdate')
Expand Down Expand Up @@ -81,4 +81,4 @@ def page_not_found(e):
redirect_to = EventRedirect.query.filter_by(profile=profile, name=r['event']).first()
if redirect_to:
return redirect(redirect_to.event.url_for(), 302)
return render_template('404.html'), 404
return render_template('404.html.jinja2'), 404
2 changes: 1 addition & 1 deletion hacknight/views/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def profile_view(profile):
# User profile. Show all events this user owns or is participating in.
events = list(set(events + [p.event for p in Participant.query.filter_by(user=user).all()]))
events.sort(key=lambda item: item.start_datetime, reverse=True)
return render_template('profile.html', profile=profile, events=events, is_user=True if user else False)
return render_template('profile.html.jinja2', profile=profile, events=events, is_user=True if user else False)


@app.route('/<profile>/edit', methods=['GET', 'POST'])
Expand Down
8 changes: 4 additions & 4 deletions hacknight/views/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def project_delete(profile, project, event):
return render_redirect(event.url_for(), code=303)
elif 'cancel' in request.form:
return render_redirect(project.url_for(), code=303)
return render_template('baseframe/delete.html', form=form, title=u"Confirm delete",
return render_template('baseframe/delete.html.jinja2', form=form, title=u"Confirm delete",
message=u"Delete '%s' ? It will remove comments, votes and all information related to the project. This operation cannot be undone." % (project.title))


Expand Down Expand Up @@ -237,7 +237,7 @@ def project_view(profile, event, project):
else:
flash("No such comment.", "error")
return redirect(project.url_for())
return render_template('project.html', event=event, project=project, profile=profile,
return render_template('project.html.jinja2', event=event, project=project, profile=profile,
comments=comments, commentform=commentform, delcommentform=delcommentform,
breadcrumbs=[(url_for('index'), "home")], user_is_member=user_is_member)

Expand Down Expand Up @@ -461,7 +461,7 @@ def project_leave(profile, project, event):
else:
flash("You need to be a participant to leave this team.", "fail")
return redirect(project.url_for(), code=303)
return render_template('baseframe/delete.html', form=form, title=u"Confirm delete",
return render_template('baseframe/delete.html.jinja2', form=form, title=u"Confirm delete",
message=u"Leave project '%s'? It will remove your participation from this project. This operation cannot be undone." % (project.title))


Expand Down Expand Up @@ -489,7 +489,7 @@ def event_export(profile, event):
"Job": p.job_title,
"City": "",
"Twitter": "",
"Tshirt": 0, #tshirt size is integer in peopleflow
"Tshirt": 0, #tshirt size is integer in peopleflow
"Date": p.created_at,
"Order ID": "",
"Skill Level": p.skill_level,
Expand Down
2 changes: 1 addition & 1 deletion hacknight/views/sponsor.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ def sponsor_delete(profile, event, sponsor):
(Sponsor, {'name': 'sponsor', 'event': 'event'}, 'sponsor'),
)
def sponsor_view(profile, event, sponsor):
return render_template('sponsor.html', sponsor=sponsor, profile=profile, event=event)
return render_template('sponsor.html.jinja2', sponsor=sponsor, profile=profile, event=event)
4 changes: 2 additions & 2 deletions hacknight/views/venue.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
@app.route('/venue')
def venue_list():
venues = Venue.query.order_by('title').all()
return render_template('venuelist.html', venues=venues)
return render_template('venuelist.html.jinja2', venues=venues)


@app.route('/venue/<venue>')
@load_model(Venue, {'name': 'venue'}, 'venue')
def venue_view(venue):
return render_template('venue.html', venue=venue)
return render_template('venue.html.jinja2', venue=venue)


@app.route('/venue/new', methods=['GET', 'POST'])
Expand Down
35 changes: 35 additions & 0 deletions instance/testing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
#: Debug mode (put this value in development.py only, never in settings.py)
DEBUG = True
#: Site title
SITE_TITLE = 'HasGeek App'
#: Site id (for network bar)
SITE_ID = ''
#: Database backend
SQLALCHEMY_DATABASE_URI = 'sqlite:///test.db'
#: Secret key
SECRET_KEY = 'make this something random'
#: Timezone
TIMEZONE = 'Asia/Calcutta'
#: LastUser server
LASTUSER_SERVER = 'https://auth.hasgeek.com/'
#: LastUser client id
LASTUSER_CLIENT_ID = ''
#: LastUser client secret
LASTUSER_CLIENT_SECRET = ''
#: Mail settings
#: MAIL_FAIL_SILENTLY : default True
#: MAIL_SERVER : default 'localhost'
#: MAIL_PORT : default 25
#: MAIL_USE_TLS : default False
#: MAIL_USE_SSL : default False
#: MAIL_USERNAME : default None
#: MAIL_PASSWORD : default None
#: DEFAULT_MAIL_SENDER : default None
MAIL_FAIL_SILENTLY = False
MAIL_SERVER = 'localhost'
DEFAULT_MAIL_SENDER = ('HasGeek', 'test@example.com')
#: Logging: recipients of error emails
ADMINS = []
#: Log file
LOGFILE = 'error.log'
7 changes: 0 additions & 7 deletions runtests.py

This file was deleted.

5 changes: 5 additions & 0 deletions runtests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
set -e
export FLASK_ENV="TESTING"
coverage run `which nosetests` "$@"
coverage report -m
1 change: 1 addition & 0 deletions test_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
coverage

0 comments on commit 0005333

Please sign in to comment.