Beispiel #1
0
 def has_role(self, role):
     # predefined user in project config file
     if self.nick in get_config('user.%ss' % role, []):
         return True
     if self.roles and role in self.roles:
         return True
     return False
Beispiel #2
0
def get_language():
    '''eturn current active language'''
    global _language
    # language is not defined - load from config
    if not _language:
        _language = get_config('site.language', 'en')
    return _language
Beispiel #3
0
def migrate_object(request, app, model_name, key=None):
    '''
    Migrate only one model object.
    '''
    # TODO: this handler is not completed!
    current_app_version = get_config("%s.version" % app, '1.0')
    app_migrations = get_config("%s.migration" % app, [])
    app_models = __import__("apps.%s.models" % app)
    model = getattr(app_models, model_name)
    query = model.order('__key__')
    if key:
        query.filter('__key__ >', key)
    obj = query.get(key)
    if obj.version != current_app_version:
        for version in app_migrations:
            if version > obj.version and model_name in version.keys():
                changed_fields = version[model_name]
    return "Object migrated!"
Beispiel #4
0
 def _map_urls(self, app_name, parent_rule={}):
     urls = []
     if app_name not in installed_apps():
         raise Exception("Application %s defined in rule %r is not exists" % (app_name, parent_rule))
     for rule in get_config('%s.urls' % app_name, {}):
         if "url" not in rule:
             raise Exception("Not defined 'url' argument in the urls mapping for application '%s'. Rule: %r" % (app_name, rule))
         if "run" not in rule:
             raise Exception("Not defined 'run' argument in the urls mapping for application '%s'. Rule: %r" % (app_name, rule))
         
         if rule["run"].count('.') == 1: # run: app.controller
             try:
                 rule['url'] = self._prepare_url(rule['url'], parent_rule.get('url'))
             except IncorrectUrlDefinition, e:
                 raise IncorrectUrlDefinition("Url rule %r in app %s is incorrect. Error: %s" % (rule, app_name, e))
             urls.append(rule)
         elif rule["run"].count('.') == 0: # run: app
             urls.extend(self._map_urls(rule["run"], rule))
Beispiel #5
0
def get_available_languages():
    '''Return list of available site translations'''
    return get_config("site.languages", [])
Beispiel #6
0
import sys, os
import django.template, django.template.loader, django.conf
from gae.template.tag_elif import *
from gae.config import get_config

try:
    # configure django templates loader
    debug = os.environ['SERVER_SOFTWARE'].startswith('Development')
    django.conf.settings.configure(
        DEBUG = debug,
        TEMPLATE_DEBUG = debug,
        TEMPLATE_LOADERS=('gae.template.loader.Loader', 'django.template.loaders.filesystem.load_template_source',),
        LANGUAGE_CODE = get_config("site.language"),
        USE_I18N = True,
        USE_L10N = True,
    )
except (EnvironmentError, RuntimeError), e:
    pass

def render(template_path, template_dict, debug=False):
    """
    Renders the template at the given path with the given dict of values.
    
    Example usage:
      render("app_name/index.html", {"name": "Bret", "values": [1, 2, 3]})
    
    Args:
      template_path: path to a Django template
      template_dict: dictionary of values to apply to the template
    """
    t = load(template_path, debug)