Exemplo n.º 1
0
def get_top_menu():
    config = get_config_by_name(app_config_context['top_menu'])
    if not config:
        raise ConfigNotExistError("配置 '%s' 不存在" %
                                  app_config_context['top_menu'])
    menu = literal_eval(config.cache)
    return menu
Exemplo n.º 2
0
def send_reply_email(comment):
    """

    :param comment:
    :type comment: app.app_models.content_model.Comment
    :return:
    :rtype:
    """

    if comment.type != 202:
        return

    to_comment = get_comment_by_id(comment.to_id)
    if not to_comment or not to_comment.email:
        return

    blog_config = get_config_by_name(
        v2_app_config_context['v2_blog_config']).v2_real_config
    blog_name = blog_config.get('blog_name', '')
    article = comment.article()
    comment_url = article.url() + '#comment-' + str(comment.id)
    email = blog_config['email']
    send_mail('你在《%s》下的评论有新回复 (来自于:%s)' % (article.title, blog_name),
              '', [to_comment.email],
              email_config=email,
              html_message=render_to_string(
                  'app/email/comment_email.html', {
                      'nickname': blog_config.get('nickname', ''),
                      'article': article,
                      'comment': comment,
                      'comment_url': comment_url,
                      'host': blog_config['host']
                  }))
Exemplo n.º 3
0
def get_theme_config():
    try:
        theme_config = cache.get(Theme_config_cache_key, None)
        assert theme_config is not None
    except:
        config = get_config_by_name(app_config_context['common_config'])
        theme_config = literal_eval(config.config)
        cache.set(Theme_config_cache_key, theme_config, 3600)

    return theme_config
Exemplo n.º 4
0
def get_global_value():
    try:
        global_value = cache.get(Global_value_cache_key, None)
        assert global_value is not None
    except:
        config = get_config_by_name(app_config_context['global_value'])
        global_value = literal_eval(config.cache)
        cache.set(Global_value_cache_key, global_value, 3600)

    return global_value
Exemplo n.º 5
0
def _send(subject,
          message,
          recipient_list,
          email_config=None,
          html_message=None,
          fail_silently=False):
    if not email_config:
        blog_config = get_config_by_name(
            v2_app_config_context['v2_blog_config']).v2_real_config
        email_config = blog_config['email']

    username = email_config.get('username', None) or settings.EMAIL_HOST_USER
    password = email_config.get('password', None)
    if password:
        password = descrypt(unsign(password))
    else:
        password = settings.EMAIL_HOST_PASSWORD
    smtp = email_config.get('smtp', None) or settings.EMAIL_HOST
    port = email_config.get('port', None) or settings.EMAIL_PORT
    secure = email_config.get('secure', None)
    if not secure:
        if settings.EMAIL_USE_TLS:
            secure = 'tls'
        elif settings.EMAIL_USE_SSL:
            secure = 'ssl'
    if not username or not password or not smtp or not port:
        return

    kwargs = {
        'host': smtp,
        'port': port,
        'username': username,
        'password': password,
        'fail_silently': fail_silently,
        'timeout': 10,
    }
    if secure == 'tls':
        kwargs['use_tls'] = True
    elif secure == 'ssl':
        kwargs['use_ssl'] = True

    connection = EmailBackend(**kwargs)
    mail = EmailMultiAlternatives(subject,
                                  message,
                                  username,
                                  recipient_list,
                                  connection=connection)
    if html_message:
        mail.attach_alternative(html_message, 'text/html')

    a = mail.send()
Exemplo n.º 6
0
def get_theme():
    try:
        theme = cache.get(Theme_cache_key, None)
        assert theme is not None

    except:
        config = get_config_by_name(app_config_context['common_config'])
        try:
            theme = literal_eval(config.cache)['theme']
        except:
            theme = 'base_theme'
        cache.set(Theme_config_cache_key, theme, 3600)

    return theme
Exemplo n.º 7
0
def get_theme():
    try:
        theme = cache.get(Theme_cache_key, None)
        assert theme is not None

    except:
        config = get_config_by_name(v2_app_config_context['v2_blog_config'])
        try:
            theme = config.v2_real_config['theme'].strip()
        except:
            theme = 'base_theme'
        if not theme:
            theme = 'base_theme'
        cache.set(Theme_config_cache_key, theme, 3600)

    return theme
Exemplo n.º 8
0
def get_config_context():
    from django.apps import apps
    import importlib
    from app.db_manager.config_manager import get_config_by_name

    result = {}

    for app in apps.get_app_configs():
        deeru_config = getattr(app, 'deeru_config_context', None)
        if deeru_config:
            deeru_config = deeru_config.split('.')
            module_name = '.'.join(deeru_config[:-1])
            consts = importlib.import_module(module_name)
            app_config = getattr(consts, deeru_config[-1], {})
            for k, v in app_config.items():
                config = get_config_by_name(v)
                if config:
                    result[k] = config.v2_real_config
    return result
Exemplo n.º 9
0
def get_top_menu():
    config = get_config_by_name(Config_Name['top_menu'])
    if not config:
        raise ConfigNotExistError("配置 '%s' 不存在" % Config_Name['top_menu'])
    menu = literal_eval(config.config)
    return menu