Show More
@@ -0,0 +1,15 b'' | |||
|
1 | from sqlalchemy.interfaces import ConnectionProxy | |
|
2 | import time | |
|
3 | import logging | |
|
4 | log = logging.getLogger(__name__) | |
|
5 | ||
|
6 | class TimerProxy(ConnectionProxy): | |
|
7 | def cursor_execute(self, execute, cursor, statement, parameters, context, executemany): | |
|
8 | now = time.time() | |
|
9 | try: | |
|
10 | log.info(">>>>> STARTING QUERY >>>>>") | |
|
11 | return execute(cursor, statement, parameters, context) | |
|
12 | finally: | |
|
13 | total = time.time() - now | |
|
14 | log.info("Query: %s" % statement % parameters) | |
|
15 | log.info("<<<<< TOTAL TIME: %f <<<<<" % total) |
@@ -0,0 +1,24 b'' | |||
|
1 | from sqlalchemy.ext.declarative import declarative_base | |
|
2 | from sqlalchemy.orm import relation, backref | |
|
3 | from sqlalchemy import ForeignKey, Column, Table, Sequence | |
|
4 | from sqlalchemy.types import * | |
|
5 | from sqlalchemy.databases.sqlite import * | |
|
6 | from pylons_app.model.meta import Base | |
|
7 | ||
|
8 | ||
|
9 | class Users(Base): | |
|
10 | __tablename__ = 'users' | |
|
11 | __table_args__ = {'useexisting':True} | |
|
12 | user_id = Column("user_id", SLInteger(), nullable=False, unique=True, default=None, primary_key=1) | |
|
13 | username = Column("username", SLText(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) | |
|
14 | password = Column("password", SLText(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) | |
|
15 | active = Column("active", SLInteger(), nullable=True, unique=None, default=None) | |
|
16 | admin = Column("admin", SLInteger(), nullable=True, unique=None, default=None) | |
|
17 | ||
|
18 | class UserLogs(Base): | |
|
19 | __tablename__ = 'user_logs' | |
|
20 | __table_args__ = {'useexisting':True} | |
|
21 | id = Column("id", SLInteger(), nullable=False, unique=True, default=None, primary_key=1) | |
|
22 | user_id = Column("user_id", SLInteger(), nullable=True, unique=None, default=None) | |
|
23 | last_action = Column("last_action", SLText(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) | |
|
24 | last_action_date = Column("last_action_date", SLDateTime(timezone=False), nullable=True, unique=None, default=None) |
@@ -1,94 +1,118 b'' | |||
|
1 | 1 | ################################################################################ |
|
2 | 2 | ################################################################################ |
|
3 | 3 | # pylons_app - Pylons environment configuration # |
|
4 | 4 | # # |
|
5 | 5 | # The %(here)s variable will be replaced with the parent directory of this file# |
|
6 | 6 | ################################################################################ |
|
7 | 7 | |
|
8 | 8 | [DEFAULT] |
|
9 | 9 | debug = true |
|
10 | 10 | ############################################ |
|
11 | 11 | ## Uncomment and replace with the address ## |
|
12 | 12 | ## which should receive any error reports ## |
|
13 | 13 | ############################################ |
|
14 | 14 | #email_to = marcin.kuzminski@etelko.pl |
|
15 | 15 | #smtp_server = mail.etelko.pl |
|
16 | 16 | #error_email_from = paste_error@localhost |
|
17 | 17 | #smtp_username = |
|
18 | 18 | #smtp_password = |
|
19 | 19 | #error_message = 'mercurial crash !' |
|
20 | 20 | |
|
21 | 21 | [server:main] |
|
22 | 22 | use = egg:Paste#http |
|
23 | 23 | host = 127.0.0.1 |
|
24 | 24 | port = 5000 |
|
25 | 25 | |
|
26 | 26 | [app:main] |
|
27 | 27 | use = egg:pylons_app |
|
28 | 28 | full_stack = true |
|
29 | 29 | static_files = true |
|
30 | 30 | lang=en |
|
31 | 31 | cache_dir = %(here)s/data |
|
32 | 32 | repos_name = etelko |
|
33 | 33 | |
|
34 | #################################### | |
|
35 | ### BEAKER CACHE #### | |
|
36 | #################################### | |
|
37 | beaker.cache.data_dir=/tmp/cache/data | |
|
38 | beaker.cache.lock_dir=/tmp/cache/lock | |
|
39 | beaker.cache.regions=short_term | |
|
40 | beaker.cache.short_term.type=memory | |
|
41 | beaker.cache.short_term.expire=3600 | |
|
42 | ||
|
34 | 43 | ################################################################################ |
|
35 | 44 | ## WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT* ## |
|
36 | 45 | ## Debug mode will enable the interactive debugging tool, allowing ANYONE to ## |
|
37 | 46 | ## execute malicious code after an exception is raised. ## |
|
38 | 47 | ################################################################################ |
|
39 | 48 | #set debug = false |
|
40 | 49 | |
|
50 | ################################## | |
|
51 | ### LOGVIEW CONFIG ### | |
|
52 | ################################## | |
|
53 | logview.sqlalchemy = #faa | |
|
54 | logview.pylons.templating = #bfb | |
|
55 | logview.pylons.util = #eee | |
|
56 | ||
|
57 | ######################################################### | |
|
58 | ### DB CONFIGS - EACH DB WILL HAVE IT'S OWN CONFIG ### | |
|
59 | ######################################################### | |
|
60 | sqlalchemy.db1.url = sqlite:///%(here)s/auth.sqlite | |
|
61 | #sqlalchemy.db1.echo = True | |
|
62 | #sqlalchemy.db1.pool_recycle = 3600 | |
|
63 | sqlalchemy.convert_unicode = true | |
|
64 | ||
|
41 | 65 | ################################ |
|
42 | 66 | ### LOGGING CONFIGURATION #### |
|
43 | 67 | ################################ |
|
44 | 68 | [loggers] |
|
45 | 69 | keys = root, routes, pylons_app, sqlalchemy |
|
46 | 70 | |
|
47 | 71 | [handlers] |
|
48 | 72 | keys = console |
|
49 | 73 | |
|
50 | 74 | [formatters] |
|
51 | 75 | keys = generic |
|
52 | 76 | |
|
53 | 77 | ############# |
|
54 | 78 | ## LOGGERS ## |
|
55 | 79 | ############# |
|
56 | 80 | [logger_root] |
|
57 | 81 | level = NOTSET |
|
58 | 82 | handlers = console |
|
59 | 83 | |
|
60 | 84 | [logger_routes] |
|
61 | 85 | level = INFO |
|
62 | 86 | handlers = console |
|
63 | 87 | qualname = routes.middleware |
|
64 | 88 | # "level = DEBUG" logs the route matched and routing variables. |
|
65 | 89 | |
|
66 | 90 | [logger_pylons_app] |
|
67 | 91 | level = DEBUG |
|
68 | 92 | handlers = console |
|
69 | 93 | qualname = pylons_app |
|
70 | 94 | |
|
71 | 95 | |
|
72 | 96 | [logger_sqlalchemy] |
|
73 | 97 | level = DEBUG |
|
74 | 98 | handlers = console |
|
75 | 99 | qualname = sqlalchemy.engine |
|
76 | 100 | |
|
77 | 101 | ############## |
|
78 | 102 | ## HANDLERS ## |
|
79 | 103 | ############## |
|
80 | 104 | |
|
81 | 105 | [handler_console] |
|
82 | 106 | class = StreamHandler |
|
83 | 107 | args = (sys.stderr,) |
|
84 | 108 | level = NOTSET |
|
85 | 109 | formatter = generic |
|
86 | 110 | |
|
87 | 111 | ################ |
|
88 | 112 | ## FORMATTERS ## |
|
89 | 113 | ################ |
|
90 | 114 | |
|
91 | 115 | [formatter_generic] |
|
92 | 116 | format = %(asctime)s,%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s |
|
93 | 117 | datefmt = %Y-%m-%d %H:%M:%S |
|
94 | 118 |
@@ -1,94 +1,118 b'' | |||
|
1 | 1 | ################################################################################ |
|
2 | 2 | ################################################################################ |
|
3 | 3 | # pylons_app - Pylons environment configuration # |
|
4 | 4 | # # |
|
5 | 5 | # The %(here)s variable will be replaced with the parent directory of this file# |
|
6 | 6 | ################################################################################ |
|
7 | 7 | |
|
8 | 8 | [DEFAULT] |
|
9 | 9 | debug = true |
|
10 | 10 | ############################################ |
|
11 | 11 | ## Uncomment and replace with the address ## |
|
12 | 12 | ## which should receive any error reports ## |
|
13 | 13 | ############################################ |
|
14 | 14 | #email_to = marcin.kuzminski@etelko.pl |
|
15 | 15 | #smtp_server = mail.etelko.pl |
|
16 | 16 | #error_email_from = paste_error@localhost |
|
17 | 17 | #smtp_username = |
|
18 | 18 | #smtp_password = |
|
19 | 19 | #error_message = 'mercurial crash !' |
|
20 | 20 | |
|
21 | 21 | [server:main] |
|
22 | 22 | use = egg:Paste#http |
|
23 | 23 | host = 127.0.0.1 |
|
24 | 24 | port = 8001 |
|
25 | 25 | |
|
26 | 26 | [app:main] |
|
27 | 27 | use = egg:pylons_app |
|
28 | 28 | full_stack = true |
|
29 | 29 | static_files = true |
|
30 | 30 | lang=en |
|
31 | 31 | cache_dir = %(here)s/data |
|
32 | 32 | repos_name = etelko |
|
33 | 33 | |
|
34 | #################################### | |
|
35 | ### BEAKER CACHE #### | |
|
36 | #################################### | |
|
37 | beaker.cache.data_dir=/tmp/cache/data | |
|
38 | beaker.cache.lock_dir=/tmp/cache/lock | |
|
39 | beaker.cache.regions=short_term | |
|
40 | beaker.cache.short_term.type=memory | |
|
41 | beaker.cache.short_term.expire=3600 | |
|
42 | ||
|
34 | 43 | ################################################################################ |
|
35 | 44 | ## WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT* ## |
|
36 | 45 | ## Debug mode will enable the interactive debugging tool, allowing ANYONE to ## |
|
37 | 46 | ## execute malicious code after an exception is raised. ## |
|
38 | 47 | ################################################################################ |
|
39 | 48 | #set debug = false |
|
40 | 49 | |
|
50 | ################################## | |
|
51 | ### LOGVIEW CONFIG ### | |
|
52 | ################################## | |
|
53 | logview.sqlalchemy = #faa | |
|
54 | logview.pylons.templating = #bfb | |
|
55 | logview.pylons.util = #eee | |
|
56 | ||
|
57 | ######################################################### | |
|
58 | ### DB CONFIGS - EACH DB WILL HAVE IT'S OWN CONFIG ### | |
|
59 | ######################################################### | |
|
60 | sqlalchemy.db1.url = sqlite:///%(here)s/auth.sqlite | |
|
61 | #sqlalchemy.db1.echo = True | |
|
62 | #sqlalchemy.db1.pool_recycle = 3600 | |
|
63 | sqlalchemy.convert_unicode = true | |
|
64 | ||
|
41 | 65 | ################################ |
|
42 | 66 | ### LOGGING CONFIGURATION #### |
|
43 | 67 | ################################ |
|
44 | 68 | [loggers] |
|
45 | 69 | keys = root, routes, pylons_app, sqlalchemy |
|
46 | 70 | |
|
47 | 71 | [handlers] |
|
48 | 72 | keys = console |
|
49 | 73 | |
|
50 | 74 | [formatters] |
|
51 | 75 | keys = generic |
|
52 | 76 | |
|
53 | 77 | ############# |
|
54 | 78 | ## LOGGERS ## |
|
55 | 79 | ############# |
|
56 | 80 | [logger_root] |
|
57 | 81 | level = INFO |
|
58 | 82 | handlers = console |
|
59 | 83 | |
|
60 | 84 | [logger_routes] |
|
61 | 85 | level = INFO |
|
62 | 86 | handlers = console |
|
63 | 87 | qualname = routes.middleware |
|
64 | 88 | # "level = DEBUG" logs the route matched and routing variables. |
|
65 | 89 | |
|
66 | 90 | [logger_pylons_app] |
|
67 | 91 | level = DEBUG |
|
68 | 92 | handlers = console |
|
69 | 93 | qualname = pylons_app |
|
70 | 94 | |
|
71 | 95 | |
|
72 | 96 | [logger_sqlalchemy] |
|
73 | 97 | level = DEBUG |
|
74 | 98 | handlers = console |
|
75 | 99 | qualname = sqlalchemy.engine |
|
76 | 100 | |
|
77 | 101 | ############## |
|
78 | 102 | ## HANDLERS ## |
|
79 | 103 | ############## |
|
80 | 104 | |
|
81 | 105 | [handler_console] |
|
82 | 106 | class = StreamHandler |
|
83 | 107 | args = (sys.stderr,) |
|
84 | 108 | level = NOTSET |
|
85 | 109 | formatter = generic |
|
86 | 110 | |
|
87 | 111 | ################ |
|
88 | 112 | ## FORMATTERS ## |
|
89 | 113 | ################ |
|
90 | 114 | |
|
91 | 115 | [formatter_generic] |
|
92 | 116 | format = %(asctime)s,%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s |
|
93 | 117 | datefmt = %Y-%m-%d %H:%M:%S |
|
94 | 118 |
@@ -1,68 +1,68 b'' | |||
|
1 | 1 | """Pylons environment configuration""" |
|
2 | 2 | import logging |
|
3 | 3 | import os |
|
4 | 4 | |
|
5 | 5 | from mako.lookup import TemplateLookup |
|
6 | 6 | from pylons.configuration import PylonsConfig |
|
7 | 7 | from pylons.error import handle_mako_error |
|
8 | 8 | from sqlalchemy import engine_from_config |
|
9 | 9 | |
|
10 | 10 | import pylons_app.lib.app_globals as app_globals |
|
11 | 11 | import pylons_app.lib.helpers |
|
12 | 12 | from pylons_app.config.routing import make_map |
|
13 | 13 | from pylons_app.model import init_model |
|
14 | 14 | |
|
15 | 15 | log = logging.getLogger(__name__) |
|
16 | 16 | |
|
17 | 17 | def load_environment(global_conf, app_conf): |
|
18 | 18 | """Configure the Pylons environment via the ``pylons.config`` |
|
19 | 19 | object |
|
20 | 20 | """ |
|
21 | 21 | config = PylonsConfig() |
|
22 | 22 | |
|
23 | 23 | # Pylons paths |
|
24 | 24 | root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
|
25 | 25 | paths = dict(root=root, |
|
26 | 26 | controllers=os.path.join(root, 'controllers'), |
|
27 | 27 | static_files=os.path.join(root, 'public'), |
|
28 | 28 | templates=[os.path.join(root, 'templates')]) |
|
29 | 29 | |
|
30 | 30 | # Initialize config with the basic options |
|
31 | 31 | config.init_app(global_conf, app_conf, package='pylons_app', paths=paths) |
|
32 | 32 | |
|
33 | 33 | config['routes.map'] = make_map(config) |
|
34 | 34 | config['pylons.app_globals'] = app_globals.Globals(config) |
|
35 | 35 | config['pylons.h'] = pylons_app.lib.helpers |
|
36 | 36 | |
|
37 | 37 | # Setup cache object as early as possible |
|
38 | 38 | import pylons |
|
39 | 39 | pylons.cache._push_object(config['pylons.app_globals'].cache) |
|
40 | 40 | |
|
41 | 41 | |
|
42 | 42 | # Create the Mako TemplateLookup, with the default auto-escaping |
|
43 | 43 | config['pylons.app_globals'].mako_lookup = TemplateLookup( |
|
44 | 44 | directories=paths['templates'], |
|
45 | 45 | error_handler=handle_mako_error, |
|
46 | 46 | module_directory=os.path.join(app_conf['cache_dir'], 'templates'), |
|
47 | 47 | input_encoding='utf-8', default_filters=['escape'], |
|
48 | 48 | imports=['from webhelpers.html import escape']) |
|
49 | 49 | |
|
50 | 50 | #sets the c attribute access when don't existing attribute ar accessed |
|
51 | 51 | config['pylons.strict_tmpl_context'] = False |
|
52 | 52 | |
|
53 | 53 | #MULTIPLE DB configs |
|
54 | 54 | # Setup the SQLAlchemy database engine |
|
55 |
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
|
|
|
59 |
|
|
|
60 |
|
|
|
61 |
|
|
|
55 | if config['debug']: | |
|
56 | #use query time debugging. | |
|
57 | from pylons_app.lib.timerproxy import TimerProxy | |
|
58 | sa_engine_db1 = engine_from_config(config, 'sqlalchemy.db1.', | |
|
59 | proxy=TimerProxy()) | |
|
60 | else: | |
|
61 | sa_engine_db1 = engine_from_config(config, 'sqlalchemy.db1.') | |
|
62 | 62 | |
|
63 |
|
|
|
63 | init_model(sa_engine_db1) | |
|
64 | 64 | |
|
65 | 65 | # CONFIGURATION OPTIONS HERE (note: all config options will override |
|
66 | 66 | # any Pylons config options) |
|
67 | 67 | |
|
68 | 68 | return config |
@@ -1,70 +1,70 b'' | |||
|
1 | 1 | """Pylons middleware initialization""" |
|
2 | 2 | from beaker.middleware import SessionMiddleware |
|
3 | 3 | from paste.cascade import Cascade |
|
4 | 4 | from paste.registry import RegistryManager |
|
5 | 5 | from paste.urlparser import StaticURLParser |
|
6 | 6 | from paste.deploy.converters import asbool |
|
7 | 7 | from pylons.middleware import ErrorHandler, StatusCodeRedirect |
|
8 | 8 | from pylons.wsgiapp import PylonsApp |
|
9 | 9 | from routes.middleware import RoutesMiddleware |
|
10 | 10 | from paste.auth.basic import AuthBasicHandler |
|
11 | 11 | from pylons_app.config.environment import load_environment |
|
12 | 12 | from pylons_app.lib.auth import authfunc |
|
13 | 13 | |
|
14 | 14 | def make_app(global_conf, full_stack=True, static_files=True, **app_conf): |
|
15 | 15 | """Create a Pylons WSGI application and return it |
|
16 | 16 | |
|
17 | 17 | ``global_conf`` |
|
18 | 18 | The inherited configuration for this application. Normally from |
|
19 | 19 | the [DEFAULT] section of the Paste ini file. |
|
20 | 20 | |
|
21 | 21 | ``full_stack`` |
|
22 | 22 | Whether or not this application provides a full WSGI stack (by |
|
23 | 23 | default, meaning it handles its own exceptions and errors). |
|
24 | 24 | Disable full_stack when this application is "managed" by |
|
25 | 25 | another WSGI middleware. |
|
26 | 26 | |
|
27 | 27 | ``app_conf`` |
|
28 | 28 | The application's local configuration. Normally specified in |
|
29 | 29 | the [app:<name>] section of the Paste ini file (where <name> |
|
30 | 30 | defaults to main). |
|
31 | 31 | |
|
32 | 32 | """ |
|
33 | 33 | # Configure the Pylons environment |
|
34 | 34 | config = load_environment(global_conf, app_conf) |
|
35 | 35 | |
|
36 | 36 | |
|
37 | 37 | # The Pylons WSGI app |
|
38 | 38 | app = PylonsApp(config=config) |
|
39 | 39 | |
|
40 | 40 | # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) |
|
41 | 41 | |
|
42 | 42 | # Routing/Session/Cache Middleware |
|
43 | 43 | app = RoutesMiddleware(app, config['routes.map']) |
|
44 | 44 | app = SessionMiddleware(app, config) |
|
45 | 45 | app = AuthBasicHandler(app, config['repos_name'] + ' mercurial repository', authfunc) |
|
46 | 46 | |
|
47 | 47 | if asbool(full_stack): |
|
48 | 48 | # Handle Python exceptions |
|
49 | 49 | app = ErrorHandler(app, global_conf, **config['pylons.errorware']) |
|
50 | 50 | |
|
51 | 51 | # Display error documents for 401, 403, 404 status codes (and |
|
52 | 52 | # 500 when debug is disabled) |
|
53 | 53 | if asbool(config['debug']): |
|
54 | 54 | #don't handle 404, since mercurial does it for us. |
|
55 |
app = StatusCodeRedirect(app, [400, 401, 403 |
|
|
55 | app = StatusCodeRedirect(app, [400, 401, 403]) | |
|
56 | 56 | else: |
|
57 | 57 | app = StatusCodeRedirect(app, [400, 401, 403, 500]) |
|
58 | 58 | |
|
59 | 59 | # Establish the Registry for this application |
|
60 | 60 | app = RegistryManager(app) |
|
61 | 61 | |
|
62 | 62 | if asbool(static_files): |
|
63 | 63 | # Serve static files |
|
64 | 64 | static_app = StaticURLParser(config['pylons.paths']['static_files']) |
|
65 | 65 | app = Cascade([static_app, app]) |
|
66 | 66 | |
|
67 | 67 | app.config = config |
|
68 | 68 | |
|
69 | 69 | return app |
|
70 | 70 |
@@ -1,57 +1,59 b'' | |||
|
1 | 1 | import logging |
|
2 | 2 | |
|
3 | 3 | from pylons import request, response, session, tmpl_context as c, url, app_globals as g |
|
4 | 4 | from pylons.controllers.util import abort, redirect |
|
5 | 5 | from pylons_app.lib import auth |
|
6 | 6 | from pylons_app.lib.base import BaseController, render |
|
7 | ||
|
7 | from pylons_app.model import meta | |
|
8 | from pylons_app.model.db import Users, UserLogs | |
|
8 | 9 | log = logging.getLogger(__name__) |
|
9 | 10 | |
|
10 | 11 | class ReposController(BaseController): |
|
11 | 12 | """REST Controller styled on the Atom Publishing Protocol""" |
|
12 | 13 | # To properly map this controller, ensure your config/routing.py |
|
13 | 14 | # file has a resource setup: |
|
14 | 15 | # map.resource('repo', 'repos') |
|
15 | 16 | def __before__(self): |
|
16 | 17 | c.staticurl = g.statics |
|
17 | 18 | c.admin_user = session.get('admin_user') |
|
18 | 19 | c.admin_username = session.get('admin_username') |
|
19 | ||
|
20 | self.sa = meta.Session | |
|
21 | ||
|
20 | 22 | def index(self, format='html'): |
|
21 | 23 | """GET /repos: All items in the collection""" |
|
22 | 24 | # url('repos') |
|
23 | 25 | return render('/repos.html') |
|
24 | 26 | |
|
25 | 27 | def create(self): |
|
26 | 28 | """POST /repos: Create a new item""" |
|
27 | 29 | # url('repos') |
|
28 | 30 | |
|
29 | 31 | def new(self, format='html'): |
|
30 | 32 | """GET /repos/new: Form to create a new item""" |
|
31 | 33 | # url('new_repo') |
|
32 | 34 | |
|
33 | 35 | def update(self, id): |
|
34 | 36 | """PUT /repos/id: Update an existing item""" |
|
35 | 37 | # Forms posted to this method should contain a hidden field: |
|
36 | 38 | # <input type="hidden" name="_method" value="PUT" /> |
|
37 | 39 | # Or using helpers: |
|
38 | 40 | # h.form(url('repo', id=ID), |
|
39 | 41 | # method='put') |
|
40 | 42 | # url('repo', id=ID) |
|
41 | 43 | |
|
42 | 44 | def delete(self, id): |
|
43 | 45 | """DELETE /repos/id: Delete an existing item""" |
|
44 | 46 | # Forms posted to this method should contain a hidden field: |
|
45 | 47 | # <input type="hidden" name="_method" value="DELETE" /> |
|
46 | 48 | # Or using helpers: |
|
47 | 49 | # h.form(url('repo', id=ID), |
|
48 | 50 | # method='delete') |
|
49 | 51 | # url('repo', id=ID) |
|
50 | 52 | |
|
51 | 53 | def show(self, id, format='html'): |
|
52 | 54 | """GET /repos/id: Show a specific item""" |
|
53 | 55 | # url('repo', id=ID) |
|
54 | 56 | return render('/repos_show.html') |
|
55 | 57 | def edit(self, id, format='html'): |
|
56 | 58 | """GET /repos/id/edit: Form to edit an existing item""" |
|
57 | 59 | # url('edit_repo', id=ID) |
@@ -1,72 +1,77 b'' | |||
|
1 | 1 | import logging |
|
2 | 2 | |
|
3 | 3 | from pylons import request, response, session, tmpl_context as c, url, app_globals as g |
|
4 | 4 | from pylons.controllers.util import abort, redirect |
|
5 | 5 | |
|
6 | 6 | from pylons_app.lib.base import BaseController, render |
|
7 | from pylons_app.lib import auth | |
|
7 | from formencode import htmlfill | |
|
8 | from pylons_app.model import meta | |
|
9 | from pylons_app.model.db import Users, UserLogs | |
|
8 | 10 | log = logging.getLogger(__name__) |
|
9 | 11 | |
|
10 | 12 | class UsersController(BaseController): |
|
11 | 13 | """REST Controller styled on the Atom Publishing Protocol""" |
|
12 | 14 | # To properly map this controller, ensure your config/routing.py |
|
13 | 15 | # file has a resource setup: |
|
14 | 16 | # map.resource('user', 'users') |
|
15 | 17 | def __before__(self): |
|
16 | 18 | c.staticurl = g.statics |
|
17 | 19 | c.admin_user = session.get('admin_user') |
|
18 | 20 | c.admin_username = session.get('admin_username') |
|
19 | self.conn, self.cur = auth.get_sqlite_conn_cur() | |
|
21 | self.sa = meta.Session | |
|
20 | 22 | |
|
21 | 23 | def index(self, format='html'): |
|
22 | 24 | """GET /users: All items in the collection""" |
|
23 | 25 | # url('users') |
|
24 | 26 | |
|
25 | self.cur.execute('SELECT * FROM users') | |
|
26 | c.users_list = self.cur.fetchall() | |
|
27 | c.users_list = self.sa.query(Users).all() | |
|
27 | 28 | return render('/users.html') |
|
28 | 29 | |
|
29 | 30 | def create(self): |
|
30 | 31 | """POST /users: Create a new item""" |
|
31 | 32 | # url('users') |
|
32 | 33 | |
|
33 | 34 | def new(self, format='html'): |
|
34 | 35 | """GET /users/new: Form to create a new item""" |
|
35 | 36 | # url('new_user') |
|
36 | 37 | |
|
37 | 38 | def update(self, id): |
|
38 | 39 | """PUT /users/id: Update an existing item""" |
|
39 | 40 | # Forms posted to this method should contain a hidden field: |
|
40 | 41 | # <input type="hidden" name="_method" value="PUT" /> |
|
41 | 42 | # Or using helpers: |
|
42 | 43 | # h.form(url('user', id=ID), |
|
43 | 44 | # method='put') |
|
44 | 45 | # url('user', id=ID) |
|
45 | 46 | |
|
46 | 47 | def delete(self, id): |
|
47 | 48 | """DELETE /users/id: Delete an existing item""" |
|
48 | 49 | # Forms posted to this method should contain a hidden field: |
|
49 | 50 | # <input type="hidden" name="_method" value="DELETE" /> |
|
50 | 51 | # Or using helpers: |
|
51 | 52 | # h.form(url('user', id=ID), |
|
52 | 53 | # method='delete') |
|
53 | 54 | # url('user', id=ID) |
|
54 | 55 | try: |
|
55 | self.cur.execute("DELETE FROM users WHERE user_id=?", (id,)) | |
|
56 |
self. |
|
|
56 | self.sa.delete(self.sa.query(Users).get(id)) | |
|
57 | self.sa.commit() | |
|
57 | 58 | except: |
|
58 |
self. |
|
|
59 | self.sa.rollback() | |
|
59 | 60 | raise |
|
60 | 61 | return redirect(url('users')) |
|
61 | 62 | |
|
62 | 63 | def show(self, id, format='html'): |
|
63 | 64 | """GET /users/id: Show a specific item""" |
|
64 | 65 | # url('user', id=ID) |
|
65 | self.cur.execute("SELECT * FROM users WHERE user_id=?", (id,)) | |
|
66 | ret = self.cur.fetchone() | |
|
67 | c.user_name = ret[1] | |
|
68 |
|
|
|
66 | c.user = self.sa.query(Users).get(id) | |
|
67 | ||
|
68 | return htmlfill.render( | |
|
69 | render('/users_show.html'), | |
|
70 | defaults=c.user.__dict__, | |
|
71 | encoding="UTF-8", | |
|
72 | force_defaults=False | |
|
73 | ) | |
|
69 | 74 | |
|
70 | 75 | def edit(self, id, format='html'): |
|
71 | 76 | """GET /users/id/edit: Form to edit an existing item""" |
|
72 | 77 | # url('edit_user', id=ID) |
@@ -1,51 +1,51 b'' | |||
|
1 | 1 | <%inherit file="base/base.html"/> |
|
2 | 2 | <%def name="title()"> |
|
3 | 3 | ${_('Repository managment')} |
|
4 | 4 | </%def> |
|
5 | 5 | <%def name="breadcrumbs()"> |
|
6 | 6 | ${h.link_to(u'Home',h.url('/'))} |
|
7 | 7 | / |
|
8 | 8 | ${h.link_to(u'Admin',h.url('admin_home'))} |
|
9 | 9 | / |
|
10 | 10 | ${h.link_to(u'Users managment',h.url('users'))} |
|
11 | 11 | </%def> |
|
12 | 12 | <%def name="page_nav()"> |
|
13 | 13 | <li>${h.link_to(u'Home',h.url('/'))}</li> |
|
14 | 14 | <li class="current">${_('Admin')}</li> |
|
15 | 15 | </%def> |
|
16 | 16 | <%def name="main()"> |
|
17 | 17 | <ul class="submenu"> |
|
18 | 18 | <li> |
|
19 | 19 | ${h.link_to(u'Repos',h.url('repos'))} |
|
20 | 20 | </li> |
|
21 | 21 | <li class="current_submenu"> |
|
22 | 22 | ${h.link_to(u'Users',h.url('users'))} |
|
23 | 23 | </li> |
|
24 | 24 | </ul> |
|
25 | 25 | <div> |
|
26 | 26 | <h2>${_('Mercurial users')}</h2> |
|
27 | 27 | <table> |
|
28 | 28 | <tr> |
|
29 | 29 | <th>Id</th> |
|
30 | 30 | <th>Username</th> |
|
31 | 31 | <th>Active</th> |
|
32 | 32 | <th>Admin</th> |
|
33 | 33 | <th>Action</th> |
|
34 | 34 | </tr> |
|
35 |
%for |
|
|
35 | %for user in c.users_list: | |
|
36 | 36 | <tr> |
|
37 |
<td>${ |
|
|
38 |
<td>${h.link_to( |
|
|
39 |
<td>${ |
|
|
40 |
<td>${ |
|
|
37 | <td>${user.user_id}</td> | |
|
38 | <td>${h.link_to(user.username,h.url('user', id=user.user_id))}</td> | |
|
39 | <td>${user.active}</td> | |
|
40 | <td>${user.admin}</td> | |
|
41 | 41 | <td> |
|
42 |
${h.form(url('user', id= |
|
|
42 | ${h.form(url('user', id=user.user_id),method='delete')} | |
|
43 | 43 | ${h.submit('remove','remove',class_="submit")} |
|
44 | 44 | ${h.end_form()} |
|
45 | 45 | </td> |
|
46 | 46 | </tr> |
|
47 | 47 | %endfor |
|
48 | 48 | </table> |
|
49 | 49 | </div> |
|
50 | 50 | |
|
51 | 51 | </%def> No newline at end of file |
@@ -1,28 +1,50 b'' | |||
|
1 | 1 | <%inherit file="base/base.html"/> |
|
2 | 2 | <%def name="title()"> |
|
3 |
${_('User c.user |
|
|
3 | ${_('User')} - ${c.user.username} | |
|
4 | 4 | </%def> |
|
5 | 5 | <%def name="breadcrumbs()"> |
|
6 | 6 | ${h.link_to(u'Home',h.url('/'))} |
|
7 | 7 | / |
|
8 | 8 | ${h.link_to(u'Admin',h.url('admin_home'))} |
|
9 | 9 | / |
|
10 | 10 | ${h.link_to(u'Users',h.url('users'))} |
|
11 | 11 | </%def> |
|
12 | 12 | <%def name="page_nav()"> |
|
13 | 13 | <li>${h.link_to(u'Home',h.url('/'))}</li> |
|
14 | 14 | <li class="current">${_('Admin')}</li> |
|
15 | 15 | </%def> |
|
16 | 16 | <%def name="main()"> |
|
17 | 17 | <ul class="submenu"> |
|
18 | 18 | <li> |
|
19 | 19 | ${h.link_to(u'Repos',h.url('repos'))} |
|
20 | 20 | </li> |
|
21 | 21 | <li class="current_submenu"> |
|
22 | 22 | ${h.link_to(u'Users',h.url('users'))} |
|
23 | 23 | </li> |
|
24 | 24 | </ul> |
|
25 | 25 | <div> |
|
26 |
<h2>${_('User')} - ${c.user |
|
|
26 | <h2>${_('User')} - ${c.user.username}</h2> | |
|
27 | ${h.form(url('user', id=c.user.user_id),method='put')} | |
|
28 | <table> | |
|
29 | <tr> | |
|
30 | <td>${_('Username')}</td> | |
|
31 | <td>${h.text('username')}</td> | |
|
32 | </tr> | |
|
33 | <tr> | |
|
34 | <td>${_('New password')}</td> | |
|
35 | <td>${h.text('new_password')}</td> | |
|
36 | </tr> | |
|
37 | <tr> | |
|
38 | <td>${_('Active')}</td> | |
|
39 | <td>${h.checkbox('active')}</td> | |
|
40 | </tr> | |
|
41 | <tr> | |
|
42 | <td></td> | |
|
43 | <td>${h.submit('save','save')}</td> | |
|
44 | </tr> | |
|
45 | ||
|
46 | </table> | |
|
47 | ||
|
48 | ${h.end_form()} | |
|
27 | 49 | </div> |
|
28 | 50 | </%def> No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now