Skip to content

Commit

Permalink
Merge pull request #63 from mpdavis/main_views_cleanup
Browse files Browse the repository at this point in the history
Some cleanup of main.py
  • Loading branch information
Michael Davis committed Dec 10, 2012
2 parents a68bd3b + 70bc66d commit e6d02fd
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 36 deletions.
18 changes: 18 additions & 0 deletions base/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from base import views as base_views
from flask import render_template


def setup_urls(app):
"""URLs for the base module"""
app.add_url_rule('/', view_func=base_views.MainHandler.as_view('home'))
app.add_url_rule('/about/', view_func=base_views.About.as_view('about'))
app.add_url_rule('/contact/', view_func=base_views.ContactUs.as_view('contact'))
app.add_url_rule('/demo/', view_func=base_views.DemoHandler.as_view('demo'))

@app.errorhandler(404)
def page_not_found(e):
return render_template('404.html'), 404

@app.errorhandler(500)
def server_error(e):
return render_template('500.html'), 500
27 changes: 27 additions & 0 deletions base/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,38 @@
import logging
import auth


class MainHandler(auth.UserAwareView):
active_nav = 'home'

def get(self):
context = self.get_context()

context['remove_header'] = True

if self.user:
context['username'] = self.user.username

context['login_mode'] = request.args.get('login_mode', None)

return render_template('home.html', **context)


class DemoHandler(auth.UserAwareView):
active_nav = 'home'

def get(self):
context = self.get_context()

return render_template('demo.html', **context)


class About(auth.UserAwareView):
def get(self):
context = self.get_context()
return render_template('about.html',**context)


class ContactUs(auth.UserAwareView):
def get(self):
context = self.get_context()
Expand Down
16 changes: 12 additions & 4 deletions build_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,22 @@
app.config.from_object('settings')

assets_env = Environment(app)
js = Bundle(Bundle('js/jquery-1.7.1.min.js'), Bundle('js/bootstrap.min.js'),
js = Bundle(Bundle('js/jquery-1.8.3.js', 'js/jquery-ui.min.js'),
Bundle('js/jquery.datatable.js'),
Bundle('js/bootstrap.js'), #Bundle('js/bootstrap-modal.js'),
Bundle('js/chosen.jquery.min.js', 'js/chosen.autoload.js'),
Bundle('js/bootstrap-modal.js'), Bundle('js/jquery.datatable.js'),
Bundle('js/boostrap-datepicker.js'), Bundle('js/jquery-ui.min.js'),
Bundle('js/d3.v2.min.js'),
Bundle('js/bootstrap-datepicker.js'),
Bundle('js/bootstrap-datatables.js'),
output='merged/merged.js')
assets_env.register('js_all', js)

css = Bundle('css/bootstrap.css', 'css/chosen.css', 'css/styles.css', 'css/datepicker.css',
css = Bundle('css/bootstrap.css',
'css/font-awesome.css',
'css/chosen.css',
'css/datepicker.css',
'css/bootstrap.datatables.css',
'css/styles.css',
filters='cssmin', output='merged/merged.css')
assets_env.register('css_all', css)
#comment out later?
Expand Down
34 changes: 2 additions & 32 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@
from google.appengine.ext.webapp.util import run_wsgi_app

from flask import Flask
from flask.templating import render_template
from flask import request

import auth
from auth import urls as auth_urls

from tournament import urls as tournament_urls
from tournament.templatetags import ttags

from base import views as base_views
from base import urls as base_urls


app = Flask(__name__)
Expand All @@ -26,36 +24,8 @@
app.secret_key = 'this-is-just-our-dev-key-oh-so-secret'


class MainHandler(auth.UserAwareView):
active_nav = 'home'

def get(self):
context = self.get_context()

context['remove_header'] = True

if self.user:
context['username'] = self.user.username

context['login_mode'] = request.args.get('login_mode', None)

return render_template('home.html', **context)


class DemoHandler(auth.UserAwareView):
active_nav = 'home'

def get(self):
context = self.get_context()

return render_template('demo.html', **context)


#Define URLs
app.add_url_rule('/', view_func=MainHandler.as_view('home'))
app.add_url_rule('/about/', view_func=base_views.About.as_view('about'))
app.add_url_rule('/demo/', view_func=DemoHandler.as_view('demo'))
app.add_url_rule('/contact/', view_func=base_views.ContactUs.as_view('contact'))
base_urls.setup_urls(app)
auth_urls.setup_urls(app)
tournament_urls.setup_urls(app)

Expand Down
12 changes: 12 additions & 0 deletions templates/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends "base.html" %}

{% block title %}404 - WebTournaments{% endblock %}

{% block content %}
<div class="row">
<div class="span6 offset3" style="text-align: center;">
<h1>Page Not Found - 404</h1>
<img src="/static/img/trophy_gold.svg" />
</div>
</div>
{% endblock %}
12 changes: 12 additions & 0 deletions templates/500.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends "base.html" %}

{% block title %}500 - WebTournaments{% endblock %}

{% block content %}
<div class="row">
<div class="span6 offset3" style="text-align: center;">
<h1>Page Not Found - 500</h1>
<img src="/static/img/trophy_gold.svg" />
</div>
</div>
{% endblock %}

0 comments on commit e6d02fd

Please sign in to comment.