Beispiel #1
0
def get_order_status_msg(status):
    return {
        ORDER_STATUS.PENDING: _('Waiting for confirmation'),
        ORDER_STATUS.AWAITING_PAYMENT: _('Awaiting payment'),
        ORDER_STATUS.AWAITING_SHIPPING: _('Awaiting shipment'),
        ORDER_STATUS.COMPLETED: _('Shipped'),
    }.get(status) or status
Beispiel #2
0
def get_shipping_msg(order_status, order_created,
                     shipping_date, shipping_period):
    if order_status == ORDER_STATUS.AWAITING_SHIPPING:
        expected_shipping_date = format_date(order_created,
                            shipping_period, '%d/%m/%Y')
        shipping_msg = _('Off schedule by : %(date)s') \
                       % {'date': expected_shipping_date}
    elif order_status == ORDER_STATUS.COMPLETED:
        shipping_msg = _('Shipped at : %(date)s') \
                       % {'date': format_epoch_time(shipping_date)}
    else:
        shipping_msg = ''
    return shipping_msg
Beispiel #3
0
def send_new_user_email(to_addr, data):
    if not settings.SEND_EMAILS:
        return
    subject = _('Your account was created %(brand)s') \
              % {'brand': settings.BRAND_NAME}
    content = gen_html_body('new_user_email.html', data, layout=None)
    send_email(settings.SERVICE_EMAIL, to_addr, subject, content, settings)
Beispiel #4
0
    def _on_post(self, req, resp, **kwargs):
        # combine birthday fields
        if req.get_param('birthday0'):
            req._params['birthday'] = '%s-%02d-%02d' % (
                req.get_param('birthday0'), int(req.get_param('birthday1') or 1),
                int(req.get_param('birthday2') or 1))

        # check country
        white_countries = allowed_countries()
        if white_countries:
            for p in req._params:
                if p.startswith('country_code_') \
                        or p.startswith('country_num_'):
                    if req.get_param(p) not in white_countries:
                        raise ValidationError('ERR_EU_COUNTRY')

        remote_resp = data_access(REMOTE_API_NAME.SET_USERINFO,
                                  req, resp,
                                  action="modify",
                                  **req._params)
        resp_dict = {}
        resp_dict.update(remote_resp)

        if resp_dict.get('res') == RESP_RESULT.F:
            resp_dict['err'] = _(resp_dict['err'])
        else:
            if req.get_param('first_time') == 'True':
                # send email
                email_data = {'name': req.get_param('first_name')}
                email_data.update(common_email_data)
                gevent.spawn(send_new_user_email, req.get_param('email'), email_data)

        return resp_dict
Beispiel #5
0
 def _on_get(self, req, resp, **kwargs):
     res_name = req.get_param('get')
     remote_resp = data_access(REMOTE_API_NAME.AUX, req, resp,
                               **req._params)
     white_countries = allowed_countries()
     if remote_resp.get('res') != RESP_RESULT.F \
             and res_name == 'countries' and white_countries:
         accept = remote_resp['accept']
         remote_resp['accept'] = filter(lambda x: x[1] in white_countries,
                                        accept)
     if 'name' in remote_resp:
         remote_resp['name'] = _(remote_resp['name'])
     return remote_resp
Beispiel #6
0
    def _on_post(self, req, resp, **kwargs):
        email = req.get_param('email')
        if not is_valid_email(email):
            raise ValidationError('ERR_EMAIL')

        remote_resp = data_access(REMOTE_API_NAME.SET_USERINFO,
                                  req,
                                  resp,
                                  action="passwd",
                                  email=email)
        err = msg = ''
        if remote_resp.get('res') == RESP_RESULT.F:
            err = remote_resp.get('err')
        else:
            msg = _('The reset password email has been sent to %(email)s') \
                  % {'email': email}
        return {'err': err, 'msg': msg}
Beispiel #7
0
    def _get_user_info(self, req, resp):
        remote_resp = data_access(REMOTE_API_NAME.GET_USERINFO,
                                  req, resp)
        err = req.get_param('err') or ''
        user_profile = {}
        if remote_resp.get('res') == RESP_RESULT.F:
            err = remote_resp.get('err')
            first_time = False
        else:
            user_profile = remote_resp
            first_time = not user_profile['general']['values'][0].get('first_name')

            # translate name
            for fs_name, fs in user_profile.iteritems():
                if 'name' in fs:
                    fs['name'] = _(fs['name'])
                if 'fields' in fs:
                    for f_name, f in fs['fields']:
                        f['name'] = _(f['name'])
                        if f['type'] == 'radio':
                            f['accept'] = [[_(n), v] for n, v in f['accept']]

            # filter country list
            white_countries = allowed_countries()
            if white_countries:
                for f_name, f in user_profile['phone']['fields']:
                    if f_name == 'country_num':
                        f['accept'] = filter(lambda x:x[1]
                                             in white_countries, f['accept'])

            set_default_addr_country = not all(
                int(addr['id']) for addr in user_profile['address']['values'])
            set_default_phone_country = not all(
                int(p['id']) for p in user_profile['phone']['values'])
            if set_default_addr_country or set_default_phone_country:
                geolocation = get_location_by_ip(get_client_ip(req))

            # give geolocation country calling code if no values
            if set_default_phone_country:
                for p in user_profile['phone']['values']:
                    if not int(p['id']):
                        country_code = geolocation['country']['iso_code']
                        p['country_num'] = unicode2utf8(country_code)

            # give geolocation country/province if no address values.
            if set_default_addr_country:
                for address in user_profile['address']['values']:
                    if not int(address['id']):
                        country_code = geolocation['country']['iso_code']
                        province_name = geolocation['subdivision']['name']

                        if country_code and province_name:
                            remote_resp = data_access(REMOTE_API_NAME.AUX,
                                                      req, resp,
                                                      get='province_code',
                                                      ccode=country_code,
                                                      pname=province_name)
                            address['country_code'] = unicode2utf8(country_code)
                            if remote_resp and isinstance(remote_resp, str) \
                                    and RESP_RESULT.F not in remote_resp:
                                address['province_code'] = unicode2utf8(remote_resp)

        return {'user_profile': user_profile,
                'err': err,
                'succ_redirect_to': get_url_format(FRT_ROUTE_ROLE.MY_ACCOUNT),
                'first_time': first_time,
                'id_order': req.get_param('id_order') or ''}
Beispiel #8
0
        self.url = url
        self.err = err

    @property
    def redirect_to(self):
        redirect_to = self.url
        if self.err:
            redirect_to += "?%s" % urllib.urlencode({'err': self.err})
        return redirect_to


CURR_USER_BASKET_COOKIE_NAME = "CURR_%s" % USER_BASKET_COOKIE_NAME

# list user form labels to make them searchable for gettext
[
    _('Civility'),
    _('First name'),
    _('Last name'),
    _('Title'),
    _('Locale'),
    _('Gender'),
    _('Birthday'),
    _('Email'),
    _('Business Account'),
    _('Company name'),
    _('Position within the company'),
    _('Company\'s Tax Identification or Registration Number'),
    _('Phone number'),
    _('Calling code'),
    _('Number'),
    _('Address'),
Beispiel #9
0
def get_err_msg(err):
    return {
        'INVALID_REQUEST': _('Invalid request.'),
        'SERVER_ERR': _('Server error.'),
        'DB_ERR': _('Server error.'),
        'ERR_EMAIL': _('Invalid email.'),
        'ERR_PASSWORD': _('Invalid password.'),
        'ERR_LOGIN': _('Invalid email or password.'),
        'INVALID_FIRST_NAME': _('Invalid first name.'),
        'INVALID_LAST_NAME': _('Invalid last name.'),
        'INVALID_COMPANY_TAX_ID': _('Invalid Company\'s Tax Identification '
                                    'or Registration Number'),
        'INVALID_PHONE_NUMBER': _('Invalid phone number.'),
        'INVALID_ADDRESS': _('Invalid address.'),
        'INVALID_CITY': _('Invalid city.'),
        'INVALID_POSTAL_CODE': _('Invalid postal code.'),
        'FAILED_PLACE_ORDER': _('Failed to place your order.'),
        'ERR_QUANTITY': _('Invalid quantity.'),
    }.get(err) or err
Beispiel #10
0
def get_price_label(need_calc_before_tax):
    return _("Before tax") if need_calc_before_tax else _("After tax")
Beispiel #11
0
 def _on_get(self, req, resp, **kwargs):
     err = _('Sorry, our server met problems. Please try later.')
     return {'err': err}