示例#1
0
def send_order_status(req, order):
    """ Send order status to order email.
        This function call calculate on order and create sha
    """
    cfg = Object()
    cfg.addresses_country = req.cfg.addresses_country
    cfg.addresses_region = req.cfg.addresses_region
    cfg.eshop_currency = req.cfg.eshop_currency

    order.calculate()   # calculate summary
    order.sha = sha1(str(order.create_date)).hexdigest()

    try:
        # TODO: use lang from cart when order was create
        req.smtp.send_email_alternative(
            morias_template(req, 'mail/eshop/order_subject.jinja',
                            order=order).encode('utf-8'),           # subject
            order.email,
            morias_template(req, 'mail/eshop/order.jinja',
                            order=order, cfg=cfg).encode('utf-8'),  # body
            morias_template(req, 'mail/eshop/order.html',
                            order=order, cfg=cfg).encode('utf-8'),  # body
            logger=req.log_info)
    except Exception as e:
        req.log_error('Mailing order[%d] error: %s' % (order.id, str(e)),
                      state.LOG_ERR)
示例#2
0
文件: login.py 项目: ondratu/morias
def login(req):
    referer = req.args.getfirst("referer", "", str)

    data = Object(referer=referer, email="")

    if req.method == "POST":
        login = Login()
        login.bind(req.form, req.cfg.login_rounds)

        ip = "ip" in req.form
        if login.find(req):
            do_login(req, login.simple(), ip)
            if referer:
                redirect(req, referer)
            if "admin" in login.rights or "super" in login.rights:
                redirect(req, "/admin")
            redirect(req, "/")

        data.ip = ip
        data.email = login.email
        data.error = BAD_LOGIN

    return generate_page(
        req, "login.html", data=data, sign_up=req.cfg.login_sign_up, password_link=req.cfg.login_forget_password_link
    )
示例#3
0
def req():
    obj = Object()
    obj.cfg = Object(redirects_timestamp='/dev/null')
    obj.db = Sql('sqlite:memory:')
    obj.log_info = error
    obj.log_error = error
    with obj.db.transaction(error) as c:
        sql_script(c, sql_path, 'redirects.sql')
    return obj
示例#4
0
def req():
    obj = Object()
    obj.db = Sql('sqlite:memory:')
    obj.log_info = error
    with obj.db.transaction(error) as c:
        sql_script(c, 'login.sql')
        sql_script(c, 'logins.01.sql')
        sql_script(c, 'logins.02.sql')
        sql_script(c, 'new.sql')
        sql_script(c, 'news.01.sql')
    return obj
示例#5
0
def req():
    obj = Object()
    obj.db = Sql('sqlite:memory:')
    obj.log_info = error
    obj.log_error = error
    with obj.db.transaction(error) as c:
        sql_script(c, sql_path, 'login.sql')
        sql_script(c, sql_path, 'logins.01.sql')
        sql_script(c, sql_path, 'logins.02.sql')
        sql_script(c, sql_path, 'tags.sql')
        sql_script(c, sql_path, 'articles.sql')
        sql_script(c, sql_path, 'articles_discussion.sql')
    return obj
示例#6
0
def admin_orders_mod(req, id):
    check_login(req)
    check_right(req, module_right)

    order = Order(id)
    if order.get(req) is None:
        raise SERVER_RETURN(state.HTTP_NOT_FOUND)

    cfg = Object()
    cfg.addresses_country = req.cfg.addresses_country
    cfg.addresses_region = req.cfg.addresses_region
    cfg.eshop_currency = req.cfg.eshop_currency

    order.calculate()
    return generate_page(req, "admin/eshop/orders_mod.html",
                         token=create_token(req),
                         order=order, cfg=cfg)
示例#7
0
def item_list(req, pager, **kwargs):    # static method
    client = kwargs.pop('client') if 'client' in kwargs else None
    keys = list("%s %s %%s" % ('o.'+k, 'in' if islistable(v) else '=')
                for k, v in kwargs.items())
    cond = "WHERE " + ' AND '.join(keys) if keys else ''
    if client:      # client have special OR mod
        cond = cond + ' AND ' if cond else "WHERE "
        cond += "(o.email LIKE %s OR c.email LIKE %s)"
        kwargs['o.email'] = "%{0}%".format(client)
        kwargs['c.email'] = "%{0}%".format(client)

    tran = req.db.transaction(req.log_info)
    c = tran.cursor()
    c.execute("""
        SELECT o.order_id, o.client_id, c.email, o.email, o.create_date,
            o.modify_date, o.state
        FROM eshop_orders o LEFT JOIN logins c ON (o.client_id = c.login_id)
            %s ORDER BY %s %s LIMIT %%s, %%s
        """ % (cond, pager.order, pager.sort),
              tuple(kwargs.values()) + (pager.offset, pager.limit))
    items = []
    for row in iter(c.fetchone, None):
        item = Object()
        item.id, item.client_id, item.client, item.email, item.create_date, \
            item.modify_date, item.state = row
        items.append(item)
    # endfor

    c.execute("""
        SELECT count(*) FROM eshop_orders o
            LEFT JOIN logins c ON (o.client_id = c.login_id) %s
        """ % cond, kwargs.values())
    pager.total = c.fetchone()[0]
    tran.commit()

    return items
示例#8
0
def user_orders_detail(req, id):
    sha = req.args.getfirst('sha', '', str)
    if not sha and not req.login:
        raise SERVER_RETURN(state.HTTP_FORBIDDEN)

    order = Order(id)
    if order.get(req) is None:
        raise SERVER_RETURN(state.HTTP_NOT_FOUND)
    order.sha = sha1(str(order.create_date)).hexdigest()

    if (sha and sha != order.sha):
        raise SERVER_RETURN(state.HTTP_FORBIDDEN)
    # if sha is set, you can see to order
    if (not sha and req.login and order.client_id != req.login.id):
        raise SERVER_RETURN(state.HTTP_FORBIDDEN)

    cfg = Object()
    cfg.addresses_country = req.cfg.addresses_country
    cfg.addresses_region = req.cfg.addresses_region
    cfg.eshop_currency = req.cfg.eshop_currency

    order.calculate()
    return generate_page(req, "eshop/orders_detail.html",
                         order=order, sha=sha, cfg=cfg)
示例#9
0
def _call_conf(cfg, parser):
    cfg.form_web_templates += '/'
    cfg.form_mail_templates += '/'

    if cfg.form_paths:
        cfg.forms = {}

    for uri in cfg.form_paths:
        app.set_route('/form/' + uri.encode('utf-8'),
                      form_send, state.METHOD_GET_POST)

        f = Object()
        f.template = parser.get('form_%s' % uri, 'template')
        f.required = parser.get('form_%s' % uri, 'required', '', tuple)
        f.protection = parser.get('form_%s' % uri, 'protection', True, bool)
        f.answer = parser.get('form_%s' % uri, 'answer', '')
        f.recipient = parser.get('form_%s' % uri, 'recipient',
                                 cfg.form_recipient)
        f.subject = parser.get('form_%s' % uri, 'subject',
                               cfg.site_name + ': ' + uri)

        cfg.forms[uri] = f
示例#10
0
def eshop_cart_address(req, cart=None, error=None):
    do_check_mgc(req)
    cart = cart or ShoppingCart(req)

    # get method returns HTML Form
    cfg = Object()
    cfg.addresses_country = req.cfg.addresses_country
    cfg.addresses_region = req.cfg.addresses_region
    cfg.eshop_currency = req.cfg.eshop_currency
    # all defined transportation (for universal use):
    for key, val in req.cfg.__dict__.items():
        if key.startswith('eshop_transportation_'):
            cfg.__dict__[key[6:]] = val
        elif key.startswith('eshop_payment_'):
            cfg.__dict__[key[6:]] = val

    # GET method only view shopping cart - no store was needed
    return generate_page(req, "eshop/shopping_address.html",
                         token=create_token(req),
                         cfg=cfg, cart=cart, error=error)
示例#11
0
文件: render.py 项目: ondratu/morias
def morias_template(req, template, **kwargs):
    if 'lang' not in kwargs:                # lang could be set explicit
        kwargs['lang'] = get_lang(req)
        languages = get_langs(req)
    else:
        languages = (kwargs['lang'],)       # then use languages

    kwargs['debug'] = req.cfg.debug

    if hasattr(req, 'login'):
        kwargs['login'] = req.login

    kwargs['site'] = Object()
    kwargs['site'].name = req.cfg.site_name
    kwargs['site'].description = req.cfg.site_description
    kwargs['site'].keywords = req.cfg.site_keywords
    kwargs['site'].author = req.cfg.site_author
    kwargs['site'].copyright = req.cfg.site_copyright
    kwargs['site'].styles = req.cfg.site_styles + kwargs.pop('styles', ())
    kwargs['site'].this = req.uri
    kwargs['site'].scheme = req.scheme
    kwargs['site'].domain = req.hostname

    kwargs['site'].modules = req.cfg.modules
    kwargs['site'].footers = req.cfg.footers

    kwargs['e'] = sdict()

    translations = translation('morias',
                               localedir=req.cfg.locales,
                               languages=languages,
                               fallback=True)

    return jinja_template(template, req.cfg.templates, translations, **kwargs)