コード例 #1
0
def get_available_themes():
    dbsession = DBSession()
    themes = [
        ('default', _('Default theme (internal)')),
        ('green', _('Green theme (internal)')),
        ('blog.regolit.com', _('blog.regolit.com style (internal)'))]

    # load suitable css files from the storage
    storage_dirs = get_storage_dirs()
    storage_path = storage_dirs['orig']
    style_files = dbsession.query(File).filter(File.dltype=='auto', File.content_type=='text/css').all()
    theme_data_re = re.compile(r'/\* pyrone-theme-data:([0-9a-z-]+):\s*(.+)\s*\*/')

    for f in style_files:
        # open css file and read metadata
        filename = os.path.join(storage_path, f.name)
        description = f.name
        theme_data = {}

        try:
            with open(filename) as fp:
                # analyze first line
                line = fp.readline(100)
                if not line.startswith('/* pyrone-theme-css */'):
                    continue

                # now read remaining file and search for metadata
                for line in fp:
                    mo = theme_data_re.match(line)
                    if mo is None:
                        continue
                    theme_data[mo.group(1)] = mo.group(2)

        except Exception as e:
            log.error(e)
            continue

        # get description from the data
        request = threadlocal.get_current_request()
        key = 'title-{0}'.format(lang.lang(request))
        if key in theme_data:
            description = theme_data[key]

        themes.append((f.name, description))

    return themes
コード例 #2
0
ファイル: notifications.py プロジェクト: sigsergv/pyrone
def send_email_process(request, template_name, recipients, sender, params):
    """Process for real sending emails"""
    language = lang(request)

    html = render('/email/'+template_name+'.mako', params, request)

    # now cut out subject line from the message
    mo = SUBJECT_RE.match(html)
    if mo is None:
        subject = 'NO-SUBJECT'
    else:
        subject = mo.group(1)
        html = SUBJECT_RE.sub('', html, 1)

    msg = MIMEMultipart()
    msg['Subject'] = subject
    msg['From'] = sender
    msg['To'] = COMMASPACE.join(recipients)
    msg.preamble = 'Use multipart, Luke'

    html_part = MIMEText(html, 'html', 'utf-8')
    msg.attach(html_part)

    log.debug('--------------------------------------------------')
    debug_data = '''
        SEND NOTIFICATION:
        Subject: {subject}
        To: {to}

        {body}
        '''.format(subject=subject, to=msg['To'], body=html)
    log.debug(debug_data)
    log.debug('--------------------------------------------------')

    with SMTP(smtp_server) as smtp:
        smtp.send_message(msg)