Example #1
0
    def details(self, redirect=None, **post):
        partner = request.env['res.users'].browse(request.uid).partner_id
        values = {
            'error': {},
            'error_message': []
        }

        if post:
            error, error_message = self.details_form_validate(post)
            values.update({'error': error, 'error_message': error_message})
            values.update(post)
            if not error:
                post.update({'zip': post.pop('zipcode', '')})
                partner.sudo().write(post)
                if redirect:
                    return request.redirect(redirect)
                return request.redirect('/my/home')

        countries = request.env['res.country'].sudo().search([])
        states = request.env['res.country.state'].sudo().search([])

        values.update({
            'partner': partner,
            'countries': countries,
            'states': states,
            'has_check_vat': hasattr(request.env['res.partner'], 'check_vat'),
            'redirect': redirect,
        })

        return request.website.render("website_portal.details", values)
Example #2
0
 def event(self, event, **post):
     if event.menu_id and event.menu_id.child_id:
         target_url = event.menu_id.child_id[0].url
     else:
         target_url = '/event/%s/register' % str(event.id)
     if post.get('enable_editor') == '1':
         target_url += '?enable_editor=1'
     return request.redirect(target_url)
Example #3
0
 def registration_new(self, event, **post):
     tickets = self._process_tickets_details(post)
     if not tickets:
         return request.redirect("/event/%s" % slug(event))
     return request.website._render(
         "website_event.registration_attendee_details", {
             'tickets': tickets,
             'event': event
         })
Example #4
0
    def payment(self, **post):
        cr, uid, context = request.cr, request.uid, request.context
        order = request.website.sale_get_order(context=context)
        carrier_id = post.get('carrier_id')
        if carrier_id:
            carrier_id = int(carrier_id)
        if order:
            request.registry['sale.order']._check_carrier_quotation(cr, uid, order, force_carrier_id=carrier_id, context=context)
            if carrier_id:
                return request.redirect("/shop/payment")

        res = super(website_sale, self).payment(**post)
        return res
Example #5
0
 def slides_index(self, *args, **post):
     """ Returns a list of available channels: if only one is available,
         redirects directly to its slides
     """
     channels = request.env['slide.channel'].search([], order='sequence, id')
     if not channels:
         return request.website.render("website_slides.channel_not_found")
     elif len(channels) == 1:
         return request.redirect("/slides/%s" % channels.id)
     return request.website.render('website_slides.channels', {
         'channels': channels,
         'user': request.env.user,
         'is_public_user': request.env.user == request.website.user_id
     })
Example #6
0
 def confirm(self, **kw):
     tx_id = request.session.pop('website_payment_tx_id', False)
     if tx_id:
         tx = request.env['payment.transaction'].browse(tx_id)
         status = (tx.state == 'done' and 'success') or 'danger'
         message = (
             tx.state == 'done' and
             'Your payment was successful! It may take some time to be validated on our end.'
         ) or 'OOps! There was a problem with your payment.'
         return request.website.render('website_payment.confirm', {
             'tx': tx,
             'status': status,
             'message': message
         })
     else:
         return request.redirect('/my/home')
Example #7
0
 def _add_event(self, event_name=None, context={}, **kwargs):
     if not event_name:
         event_name = _("New Event")
     Event = request.registry.get('event.event')
     date_begin = datetime.today() + timedelta(days=(14))
     vals = {
         'name': event_name,
         'date_begin': date_begin.strftime('%Y-%m-%d'),
         'date_end':
         (date_begin + timedelta(days=(1))).strftime('%Y-%m-%d'),
         'seats_available': 1000,
     }
     event_id = Event.create(request.cr, request.uid, vals, context=context)
     event = Event.browse(request.cr,
                          request.uid,
                          event_id,
                          context=context)
     return request.redirect("/event/%s/register?enable_editor=1" %
                             slug(event))
Example #8
0
    def post_toc_ok(self, forum, post_id, toc_id, **kwargs):
        cr, uid, context = request.cr, request.uid, request.context
        user = request.registry['res.users'].browse(cr,
                                                    uid,
                                                    uid,
                                                    context=context)
        assert user.karma >= 200, 'Not enough karma, you need 200 to promote a documentation.'

        toc_obj = request.registry['forum.documentation.toc']
        stage_ids = toc_obj.search(cr, uid, [], limit=1, context=context)

        post_obj = request.registry['forum.post']
        post_obj.write(
            cr,
            uid, [int(post_id)], {
                'documentation_toc_id': toc_id and int(toc_id) or False,
                'documentation_stage_id': stage_ids and stage_ids[0] or False
            },
            context=context)
        return request.redirect('/forum/' + str(forum.id) + '/question/' +
                                str(post_id))
Example #9
0
    def _dispatch(self):
        first_pass = not hasattr(request, 'website')
        request.website = None
        func = None
        try:
            if request.httprequest.method == 'GET' and '//' in request.httprequest.path:
                new_url = request.httprequest.path.replace(
                    '//', '/') + '?' + request.httprequest.query_string
                return werkzeug.utils.redirect(new_url, 301)
            func, arguments = self._find_handler()
            request.website_enabled = func.routing.get('website', False)
        except werkzeug.exceptions.NotFound:
            # either we have a language prefixed route, either a real 404
            # in all cases, website processes them
            request.website_enabled = True

        request.website_multilang = (
            request.website_enabled and func
            and func.routing.get('multilang', func.routing['type'] == 'http'))

        self._geoip_setup_resolver()
        self._geoip_resolve()

        cook_lang = request.httprequest.cookies.get('website_lang')
        if request.website_enabled:
            try:
                if func:
                    self._authenticate(func.routing['auth'])
                elif request.uid is None:
                    self._auth_method_public()
            except Exception as e:
                return self._handle_exception(e)

            request.redirect = lambda url, code=302: werkzeug.utils.redirect(
                url_for(url), code)
            request.website = request.registry['website'].get_current_website(
                request.cr, request.uid, context=request.context)
            request.context['website_id'] = request.website.id
            langs = [lg[0] for lg in request.website.get_languages()]
            path = request.httprequest.path.split('/')
            if first_pass:
                nearest_lang = not func and self.get_nearest_lang(path[1])
                url_lang = nearest_lang and path[1]
                preferred_lang = ((cook_lang if cook_lang in langs else False)
                                  or self.get_nearest_lang(request.lang)
                                  or request.website.default_lang_code)

                is_a_bot = self.is_a_bot()

                request.lang = request.context[
                    'lang'] = nearest_lang or preferred_lang
                # if lang in url but not the displayed or default language --> change or remove
                # or no lang in url, and lang to dispay not the default language --> add lang
                # and not a POST request
                # and not a bot or bot but default lang in url
                if ((url_lang and (url_lang != request.lang or url_lang == request.website.default_lang_code))
                        or (not url_lang and request.website_multilang and request.lang != request.website.default_lang_code)
                        and request.httprequest.method != 'POST') \
                        and (not is_a_bot or (url_lang and url_lang == request.website.default_lang_code)):
                    if url_lang:
                        path.pop(1)
                    if request.lang != request.website.default_lang_code:
                        path.insert(1, request.lang)
                    path = '/'.join(path) or '/'
                    redirect = request.redirect(
                        path + '?' + request.httprequest.query_string)
                    redirect.set_cookie('website_lang', request.lang)
                    return redirect
                elif url_lang:
                    path.pop(1)
                    return self.reroute('/'.join(path) or '/')
            if path[1] == request.website.default_lang_code:
                request.context['edit_translations'] = False
            if not request.context.get('tz'):
                request.context['tz'] = request.session.get(
                    'geoip', {}).get('time_zone')
            # bind modified context
            request.website = request.website.with_context(request.context)

        # cache for auth public
        cache_time = getattr(func, 'routing', {}).get('cache')
        cache_enable = cache_time and request.httprequest.method == "GET" and request.website.user_id.id == request.uid
        cache_response = None
        if cache_enable:
            key = self.get_page_key()
            try:
                r = self.pool.cache[key]
                if r['time'] + cache_time > time.time():
                    cache_response = yuancloud.http.Response(
                        r['content'], mimetype=r['mimetype'])
                else:
                    del self.pool.cache[key]
            except KeyError:
                pass

        if cache_response:
            request.cache_save = False
            resp = cache_response
        else:
            request.cache_save = key if cache_enable else False
            resp = super(ir_http, self)._dispatch()

        if request.website_enabled and cook_lang != request.lang and hasattr(
                resp, 'set_cookie'):
            resp.set_cookie('website_lang', request.lang)
        return resp
Example #10
0
 def slide_set_promoted(self, slide):
     slide.channel_id.promoted_slide_id = slide.id
     return request.redirect("/slides/%s" % slide.channel_id.id)
Example #11
0
 def process(self, **post):
     cr, uid, context = request.cr, request.uid, request.context
     parmsdata = request.params
     print parmsdata
     appid = parmsdata['appid']
     mch_id = parmsdata['mch_id']
     env = Environment(request.cr, SUPERUSER_ID, context)
     officialaccount = env['wx.officialaccount'].search([
         ('wx_appid', '=', appid), ('wx_mch_id', '=', mch_id)
     ])
     if officialaccount:
         appkey = officialaccount[0]['wx_mch_secret']
     else:
         appkey = ""
     nonce_str = parmsdata['noncestr']
     body = parmsdata['body']
     out_trade_no = parmsdata['out_trade_no'],
     total_fee = parmsdata['total_fee']
     spbill_create_ip = parmsdata['spbill_create_ip']
     notify_url = parmsdata['notify_url']
     trade_type = parmsdata['trade_type']
     product_id = parmsdata['product_id']
     process_url = parmsdata['process_url']
     notify_url_address = self._notify_url + "db:" + cr.dbname
     data_post = {}
     data_post.update({
         'appid':
         appid,
         'mch_id':
         mch_id,
         'nonce_str':
         nonce_str,
         'body':
         body,
         'out_trade_no':
         body,
         'total_fee':
         total_fee,
         'spbill_create_ip':
         spbill_create_ip,
         'notify_url':
         urlparse.urljoin(notify_url, notify_url_address),
         'trade_type':
         trade_type,
         'product_id':
         product_id,
     })
     if trade_type == "JSAPI":
         opendid = http.request.session['openid']
         print opendid
         data_post.update({'openid': opendid})
     _, prestr = util.params_filter(data_post)
     data_post['sign'] = util.build_mysign(prestr, appkey, 'MD5')
     print data_post
     data_xml = "<xml>" + util.json2xml(data_post) + "</xml>"
     print data_xml
     url = process_url
     requestdata = urllib2.Request(url, data_xml)
     result = util._try_url(requestdata, tries=3)
     weixin_tx_values = {}
     _logger.info(
         "request to %s and the request data is %s, and request result is %s"
         % (url, data_xml, result))
     return_xml = etree.fromstring(result)
     print return_xml
     if return_xml.find('return_code').text == "SUCCESS":
         if return_xml.find('code_url') == None:
             if return_xml.find('prepay_id') == None:
                 err_code = return_xml.find('err_code').text
                 err_code_des = return_xml.find('err_code_des').text
             else:
                 urlinfo = "/shop/confirmation"
                 sale_order_id = request.session.get('sale_last_order_id')
                 if sale_order_id:
                     order = request.registry['sale.order'].browse(
                         cr, SUPERUSER_ID, sale_order_id, context=context)
                 else:
                     return request.redirect('/shop')
                 print order
                 data_info = {}
                 data_info.update({
                     "order":
                     order,
                     "test":
                     "",
                     "appid":
                     appid,
                     "prepay_id":
                     return_xml.find('prepay_id').text,
                     "trade_type":
                     trade_type
                 })
                 request.website.sale_reset(context=context)  # 清除
                 return request.website.render("website_sale.confirmation",
                                               data_info)
                 # raise ValidationError("%s, %s" % (err_code, err_code_des))
         elif return_xml.find('code_url').text == False:
             err_code = return_xml.find('err_code').text
             err_code_des = return_xml.find('err_code_des').text
         else:
             weixin_tx_values['data_xml'] = data_xml
             qrcode = return_xml.find('code_url').text
             weixin_tx_values['qrcode'] = qrcode
             urlinfo = "/shop/confirmation"
             sale_order_id = request.session.get('sale_last_order_id')
             _logger.info("sale_order_id:" + str(sale_order_id))
             if sale_order_id:
                 order = request.registry['sale.order'].browse(
                     cr, SUPERUSER_ID, sale_order_id, context=context)
             else:
                 return request.redirect('/shop')
             print order
             data_info = {}
             data_info.update({
                 "order": order,
                 "test": qrcode,
                 "appid": appid,
                 "prepay_id": return_xml.find('prepay_id').text,
                 "trade_type": trade_type
             })
             request.website.sale_reset(context=context)  # 清除
             return request.website.render("website_sale.confirmation",
                                           data_info)
     else:
         return_code = return_xml.find('return_code').text
         return_msg = return_xml.find('return_msg').text
         raise ValidationError("%s, %s" % (return_code, return_msg))
Example #12
0
 def jobs_add(self, **kwargs):
     job = request.env['hr.job'].create({
         'name': _('New Job Offer'),
     })
     return request.redirect("/jobs/detail/%s?enable_editor=1" % slug(job))
Example #13
0
 def delete(self, delete_pm_id=None):
     if delete_pm_id:
         pay_meth = request.env['payment.method'].browse(int(delete_pm_id))
         pay_meth.unlink()
     return request.redirect('/my/payment_method')