Permalink
Browse files

Start with the Users view, default stuff inside

  • Loading branch information...
rhaamo committed Jan 12, 2014
1 parent 18cd48f commit 7b29831c5a1d2c7b10e97750742c948a4a0c6c57
View
@@ -2,6 +2,7 @@
from sqlalchemy import engine_from_config
from .models.meta import (DBSession, Base)
+from .views import (ViewHome, ViewUsers)
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
@@ -19,6 +20,23 @@ def main(global_config, **settings):
def add_routes(config):
# Splitted from main() to be used in unit test and better visibility
- config.add_static_view('static', 'static', cache_max_Age=3600)
+ config.add_static_view('static', 'static', cache_max_age=3600)
+
+ """
+ /resources GET / POST show / create
+ /resources/new GET new form
+ /resources/$id GET / DELETE show id / delete id
+ /resources/$id/edit GET / POST edit form / edit
+ """
+
+ # View Home
+ config.add_route('home', '/', request_method='GET')
+
+ # View Users
+ config.add_route('users', '/users', request_method='GET')
+ config.add_route('update_user', '/users', request_method='POST')
+ config.add_route('new_user', '/users/new', request_method='GET')
+ config.add_route('delete_user', '/users/{id}/delete', request_method='GET')
+ config.add_route('edit_user', '/users/{id}/edit', request_method='GET')
+ config.add_route('user', '/users/{id}', request_method='GET')
- config.add_route('home', '/')
@@ -39,7 +39,7 @@
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav side-nav">
<li class="active"><a href="{{'home'|route_url}}"><i class="fa fa-home"></i> Home</a></li>
- <li><a href="{{'home'|route_url}}"><i class="fa fa-wrench"></i> Register</a></li>
+ <li><a href="{{'new_user'|route_url}}"><i class="fa fa-wrench"></i> Register</a></li>
<li><a href="{{'home'|route_url}}"><i class="fa fa-user"></i> Login</a></li>
<li><a href="{{'home'|route_url}}"><i class="fa fa-question"></i> About</a></li>
</ul>
@@ -0,0 +1,6 @@
+{% extends "layout.jinja2" %}
+{% block content %}
+<p>
+ Create new user
+</p>
+{% endblock %}
@@ -1 +1,3 @@
# Package
+from .home import ViewHome
+from .users import ViewUsers
View
@@ -15,6 +15,10 @@
Is : Homepage
Route : /
"""
-@view_config(route_name='home', renderer='home/home.jinja2')
-def view_home(request):
- return {'one': "the one", 'project': 'codular'}
+class ViewHome(object):
+ def __init__(self, request):
+ self.request = request
+
+ @view_config(route_name='home', renderer='home/home.jinja2')
+ def home_get(self):
+ return {'one': "the one", 'project': 'codular'}
View
@@ -0,0 +1,49 @@
+"""
+Users view
+"""
+from pyramid.response import Response
+from pyramid.view import ( view_config, view_defaults )
+
+from sqlalchemy.exc import DBAPIError
+
+from ..models import (
+ DBSession,
+ User,
+)
+
+"""
+Routes:
+'users', '/users', request_method='GET'
+'user', '/users/{id}', request_method='GET'
+'update_user', '/users', request_method='POST'
+'delete_user', '/users/{id}/delete', request_method='GET'
+'new_user', '/users/new', request_method='GET'
+'edit_user', '/users/{id}/edit', request_method='GET'
+"""
+class ViewUsers(object):
+ def __init__(self, request):
+ self.request = request
+
+ @view_config(route_name='users', renderer='json')
+ def users(self):
+ return "users"
+
+ @view_config(route_name='user', renderer='json')
+ def user(self):
+ return "user"
+
+ @view_config(route_name='update_user', renderer='json')
+ def update_user(self):
+ return "update_user"
+
+ @view_config(route_name='delete_user', renderer='json')
+ def delete_user(self):
+ return "delete_user"
+
+ @view_config(route_name='new_user', renderer='users/new.jinja2')
+ def new_user(self):
+ return {'one': "the one", 'project': 'codular'}
+
+ @view_config(route_name='edit_user', renderer='json')
+ def edit_user(self):
+ return "edit_user"

0 comments on commit 7b29831

Please sign in to comment.