Exemplo n.º 1
0
 def administration(self, group):
     c.messages = meta.Session.query(GroupMailingListMessage)\
         .filter_by(group_id=group.id, in_moderation_queue=True)\
         .order_by(desc(GroupMailingListMessage.sent)).all()
     c.group_menu_current_item = 'mailinglist'
     response.cache_expires(seconds=0)
     return render('mailinglist/administration.mako')
Exemplo n.º 2
0
 def js_localization(self, domain='baruwajs'):
     "Return dict of localized strings for JS"
     locale_t = {}
     locale = get_lang()[0]
     path = os.path.join(config['pylons.paths']['root'], 'i18n')
     try:
         catalog = gettext.translation(domain, path, [locale])
     except IOError:
         catalog = None
     if catalog is not None:
         locale_t.update(catalog._catalog)
     src = [LIBHEAD]
     plural = None
     if '' in locale_t:
         for l in locale_t[''].split('\n'):
             if l.startswith('Plural-Forms:'):
                 plural = l.split(':', 1)[1].strip()
     if plural is not None:
         plural = [
             el.strip() for el in plural.split(';')
             if el.strip().startswith('plural=')
         ][0].split('=', 1)[1]
         src.append(PLURALIDX % plural)
     else:
         src.append(SIMPLEPLURAL)
     csrc = []
     pdict = {}
     for k, v in locale_t.items():
         if k == '':
             continue
         if isinstance(k, basestring):
             csrc.append("catalog['%s'] = '%s';\n" %
                         (quote_js(k), quote_js(v)))
         elif isinstance(k, tuple):
             if k[0] not in pdict:
                 pdict[k[0]] = k[1]
             else:
                 pdict[k[0]] = max(k[1], pdict[k[0]])
             csrc.append("catalog['%s'][%d] = '%s';\n" %
                         (quote_js(k[0]), k[1], quote_js(v)))
         else:
             raise TypeError(k)
     csrc.sort()
     for k, v in pdict.items():
         src.append("catalog['%s'] = [%s];\n" %
                    (quote_js(k), ','.join(["''"] * (v + 1))))
     src.extend(csrc)
     src.append(LIBFOOT)
     src.append(INTERPOLATE)
     src = ''.join(src)
     del response.headers['Cache-Control']
     del response.headers['Pragma']
     response.cache_expires(seconds=360)
     response.headers['Content-Type'] = 'text/javascript;charset=utf-8'
     return src
Exemplo n.º 3
0
 def render(self, color_scheme=None, zoom=None, x=None, y=None):
     response.cache_expires(seconds=0)
     try:
         assert color_scheme in config['pylons.app_globals'].color_schemes, ("bad color_scheme: " + color_scheme)
         assert zoom.isdigit() and x.isdigit() and y.isdigit(), "not digits"
         zoom = int(zoom)
         x = int(x)
         y = int(y)
         assert 0 <= zoom <= 30, "bad zoom: %d" % zoom
     except AssertionError, err:
         log.warn(err.args[0])
         abort('Bad request.')
Exemplo n.º 4
0
 def js_localization(self, domain='baruwajs'):
     "Return dict of localized strings for JS"
     locale_t = {}
     locale = get_lang()[0]
     path = os.path.join(config['pylons.paths']['root'], 'i18n')
     try:
         catalog = gettext.translation(domain, path, [locale])
     except IOError:
         catalog = None
     if catalog is not None:
         locale_t.update(catalog._catalog)
     src = [LIBHEAD]
     plural = None
     if '' in locale_t:
         for l in locale_t[''].split('\n'):
             if l.startswith('Plural-Forms:'):
                 plural = l.split(':', 1)[1].strip()
     if plural is not None:
         plural = [el.strip() for el in plural.split(';')
         if el.strip().startswith('plural=')][0].split('=', 1)[1]
         src.append(PLURALIDX % plural)
     else:
         src.append(SIMPLEPLURAL)
     csrc = []
     pdict = {}
     for k, v in locale_t.items():
         if k == '':
             continue
         if isinstance(k, basestring):
             csrc.append("catalog['%s'] = '%s';\n" % (quote_js(k),
             quote_js(v)))
         elif isinstance(k, tuple):
             if k[0] not in pdict:
                 pdict[k[0]] = k[1]
             else:
                 pdict[k[0]] = max(k[1], pdict[k[0]])
             csrc.append("catalog['%s'][%d] = '%s';\n" % (quote_js(k[0]),
             k[1], quote_js(v)))
         else:
             raise TypeError(k)
     csrc.sort()
     for k, v in pdict.items():
         src.append("catalog['%s'] = [%s];\n" % (quote_js(k),
         ','.join(["''"] * (v + 1))))
     src.extend(csrc)
     src.append(LIBFOOT)
     src.append(INTERPOLATE)
     src = ''.join(src)
     del response.headers['Cache-Control']
     del response.headers['Pragma']
     response.cache_expires(seconds=360)
     response.headers['Content-Type'] = 'text/javascript;charset=utf-8'
     return src
Exemplo n.º 5
0
def serve_logo(obj_type, obj_id=None, width=None, height=None,
               default_img_path=None, cache=True, square=False):
    if cache:
        img_data = prepare_logo_cached(obj_type, obj_id, width, height, default_img_path, square)
    else:
        img_data = prepare_logo(obj_type, obj_id, width, height, default_img_path, square)

    if img_data is None:
        abort(404)
    response.headers['Content-Disposition'] = 'inline'
    response.headers['Content-Length'] = len(img_data)
    response.headers['Content-Type'] = 'image/png'

    if cache:
        # Clear the default cache headers
        del response.headers['Cache-Control']
        del response.headers['Pragma']
        response.cache_expires(seconds=3600, public=True)

    return img_data