Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adminfuncs moved to other repo, kwd support

  • Loading branch information...
commit ec5ab024e80d7211618fc8995245b30b6318382f 1 parent e8fcece
@bthomson authored
View
4 apps/example_app/admin.py
@@ -39,7 +39,7 @@
confirm=False,
#: Functions only appear locally
- local_only=False,
+ dev_only=False,
#: Functions only appear in production
production_only=False,
@@ -143,7 +143,7 @@ def settings_example_2():
server.
"""
-@settings(local_only=True)
+@settings(dev_only=True)
def settings_example_3():
"""I will only show up in the dev_appserver environment (not in production)."""
View
12 apps/example_app/admin_2.py
@@ -16,9 +16,9 @@
You can also use the logging module to access App Engine's usual logging
interface.
-Be careful with decorators: inspection requires that the original function's
-argument information be left intact. See the settings decorator for an example
-of how to make decorators which preserve function arguments.
+Be careful with decorators: introspection requires that the original function's
+signature be left intact. See the settings decorator for an example of how to
+make decorators which preserve function arguments.
This module will not be imported until someone accesses the admin interface.
"""
@@ -38,10 +38,10 @@
#: Always display a confirmation dialog
confirm=False,
- #: Functions only appear locally
- local_only=False,
+ #: If true, functions will only appear and execute locally
+ dev_only=False,
- #: Functions only appear in production
+ #: If true, functions will only appear in production
production_only=False,
)
View
138 distlib/adminfuncs.py
@@ -1,138 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
- adminfuncs
- ~~~~~~~~~~
-
- Module for building simple admin page
-
- This module doesn't have much use by itself; for now it's only
- used with related tipfy extension
-
- :copyright: 2010 by Brandon Thomson
- :license: BSD, see LICENSE for more details.
-"""
-
-import functools
-
-import inspect
-
-from werkzeug import import_string
-
-def get_nice_defaults(f):
- args = inspect.getargspec(f)[0]
- defaults = inspect.getargspec(f)[3]
-
- if defaults:
- defaults = list(defaults)
- defaults.reverse()
- defaults.extend([None]*(len(args)-len(defaults)))
- defaults.reverse()
- else:
- defaults = [None]*len(args)
- return defaults
-
-def get_template_args(f):
- """
- Convert function arg data into a form that makes it more convenient for the
- template to generate the fields
- """
- args = inspect.getargspec(f)[0]
- defaults = get_nice_defaults(f)
- if defaults:
- arglist = zip(args, defaults)
- # for "def foo(a, b, c=3, d=4)"
- # arglist is [('a', None), ('b', None), ('c', 3), ('d', 4)]
- else:
- arglist = zip(args, [None]*len(args))
- #arglist = zip(args, args)
- t_args = []
- for argname, default in arglist:
- # Default arg value changed to a string for jinja
- box_text = str(default) if default else ""
- is_textarea = box_text.startswith("<big>")
- if is_textarea:
- box_text = box_text[5:]
-
- t_args.append((argname, box_text, is_textarea))
- return t_args
-
-def func_args_from_strings(farg, arg_strings):
- """
- Return function object and convert arg_strings list of positional args which
- can be expanded into selected admin function using * operator
-
- args with default values as ints in function definition are also converted
- from unicode to int
- """
-
- # XXX: probably a vulnerability if admin interface is not protected... could
- # check admin modules against the specified list for more safety
- func = import_string(farg)
-
- defaults = get_nice_defaults(func)
-
- args = []
- if arg_strings:
- for arg, default in zip(arg_strings, defaults):
- if type(default) == type(0):
- args.append(int(arg))
- else:
- args.append(arg)
-
- return func, args
-
-def build_list(is_deployed, module_paths):
- """Import modules and generate giant list of all admin functions.
-
- Could be cached if you want to save cpu time
- """
- funcs_by_module = []
-
- for module_path in module_paths:
- module = import_string(module_path)
- funcs = []
-
- try:
- objects = module.ORDER
- except AttributeError:
- objects = [getattr(module, name) for name in dir(module)]
-
- for obj in objects:
- if inspect.isfunction(obj):
- func = obj
- t_args = get_template_args(func)
-
- func_settings = dict(module.DEFAULTS)
- func_settings.update(getattr(func, 'settings', {}))
-
- if is_deployed and func_settings['local_only']:
- continue
- if not is_deployed and func_settings['production_only']:
- continue
-
- do_confirm = (is_deployed and func_settings['confirm_deployed']
- or func_settings['confirm'])
-
- funcs.append((func, t_args, do_confirm))
- funcs_by_module.append((module, funcs))
-
- return funcs_by_module
-
-class settings(object):
- """Use to alter settings from module defaults for an individual function"""
- def __init__(self, **kwds):
- self.settings = kwds
-
- def __call__(self, f):
- """
- Attach settings dict created from keyword args passed to this decorator to
- the function object for later reference.
- """
- @functools.wraps(f)
- def wrapper(*args, **kwds):
- return f(*args, **kwds)
-
- # Save settings dict on function object
- wrapper.settings = self.settings
-
- return wrapper
View
13 templates/adminfuncs/funclist.html
@@ -82,10 +82,12 @@
{% set func_num = 0 %}
{% for module, funcs in modules %}
- <h2>{{ module.__name__ }}: {{ module.TITLE }}</h2>
+ <h2>{{ module.TITLE }}
+ <span style="font-size: 70%; font-weight: normal; font-style: italic">{{ module.__name__ }}</span>
+ </h2>
<p>{{ module.DESCRIPTION }}</p>
<table>
- {% for func, args, do_confirm in funcs -%}
+ {% for func, args, do_confirm, keywords in funcs -%}
{%- set func_num = func_num + 1 -%}
{%- set funcid = func.__module__ + '.' + func.__name__ -%}
<tr>
@@ -94,8 +96,13 @@
onsubmit="return confirm('Are you sure you want to execute {{ funcid }}?');"
{%- endif -%}
>
+ <td style="font-weight: bold; color: #44F">
+ {% for keyword in keywords %}
+ {{ keyword }}<br>
+ {% endfor %}
+ </td>
<td align="right">
- <input id="button-{{func_num}}" type="submit" value="{{ func.__name__ }}">
+ <input style="width: 100%; text-align: left;" id="button-{{func_num}}" type="submit" value="{{ func.__name__ }}">
</td>
<td>
{% for arg_name, box_text, is_textarea in args %}
Please sign in to comment.
Something went wrong with that request. Please try again.