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