Exemplo n.º 1
0
 def validate_email(self, token, id, email, forum_id=None, **kwargs):
     if forum_id:
         try:
             forum_id = int(forum_id)
         except ValueError:
             forum_id = None
     done = request.env['res.users'].sudo().browse(int(id)).process_forum_validation_token(token, email, forum_id=forum_id)[0]
     if done:
         request.session['validation_email_done'] = True
     if forum_id:
         return request.redirect("/forum/%s" % int(forum_id))
     return request.redirect('/forum')
Exemplo n.º 2
0
Arquivo: main.py Projeto: ecoreos/hz
    def new_database(self, **post):
        if not request.session.uid:
            return login_redirect()
        plan_id = int(post.get('plan_id'))

        res = self.create_new_database(plan_id)
        return request.redirect(res.get('url'))
Exemplo n.º 3
0
    def new_database(self, **post):
        if not request.session.uid:
            return login_redirect()
        plan_id = int(post.get('plan_id'))

        res = self.create_new_database(plan_id)
        return request.redirect(res.get('url'))
Exemplo n.º 4
0
    def registration_confirm(self, event, **post):
        cr, uid, context = request.cr, request.uid, request.context
        order = request.website.sale_get_order(force_create=1)
        attendee_ids = set()

        registrations = self._process_registration_details(post)
        for registration in registrations:
            ticket = request.registry['event.event.ticket'].browse(
                cr,
                SUPERUSER_ID,
                int(registration['ticket_id']),
                context=context)
            cart_values = order.with_context(
                event_ticket_id=ticket.id)._cart_update(
                    product_id=ticket.product_id.id,
                    add_qty=1,
                    registration_data=[registration])
            attendee_ids |= set(cart_values.get('attendee_ids', []))

        # free tickets -> order with amount = 0: auto-confirm, no checkout
        if not order.amount_total:
            order.action_confirm()  # tde notsure: email sending ?
            attendees = request.registry['event.registration'].browse(
                cr, uid, list(attendee_ids), context=context)
            # clean context and session, then redirect to the confirmation page
            request.website.sale_reset(context=context)
            return request.website.render(
                "website_event.registration_complete", {
                    'attendees': attendees,
                    'event': event,
                })

        return request.redirect("/shop/checkout")
Exemplo n.º 5
0
 def chatter_post(self, res_model='', res_id=None, message='', redirect=None, **kw):
     res_id = int(res_id)
     url = request.httprequest.referrer
     if message:
         message = _message_post_helper(res_model, res_id, message, **kw)
         url = url + "#message-%s" % (message.id,)
     return request.redirect(url)
Exemplo n.º 6
0
 def forum_create(self, forum_name="New Forum", add_menu=False):
     forum_id = request.env['forum.forum'].create({'name': forum_name})
     if add_menu:
         request.env['website.menu'].create({
             'name': forum_name,
             'url': "/forum/%s" % slug(forum_id),
             'parent_id': request.website.menu_id.id,
             'website_id': request.website.id,
         })
     return request.redirect("/forum/%s" % slug(forum_id))
Exemplo n.º 7
0
    def post_toggle_correct(self, forum, post, **kwargs):
        if post.parent_id is False:
            return request.redirect('/')
        if not request.session.uid:
            return {'error': 'anonymous_user'}

        # set all answers to False, only one can be accepted
        (post.parent_id.child_ids - post).write(dict(is_correct=False))
        post.is_correct = not post.is_correct
        return post.is_correct
Exemplo n.º 8
0
 def chatter_post(self,
                  res_model='',
                  res_id=None,
                  message='',
                  redirect=None,
                  **kw):
     res_id = int(res_id)
     url = request.httprequest.referrer
     if message:
         message = _message_post_helper(res_model, res_id, message, **kw)
         url = url + "#message-%s" % (message.id, )
     return request.redirect(url)
Exemplo n.º 9
0
Arquivo: main.py Projeto: ecoreos/hz
 def web_portal_signup(self, redirect="/saas_portal/book_then_signup", **kw):
     dbname = request.params['dbname']
     if self.exists_database(dbname):
         full_dbname = self.get_full_dbname(dbname)
         params = {'db': full_dbname, 'login': '******', 'key': 'admin'}
         redirect = 'http://%s/login' % full_dbname.replace('_', '.')
     else:
         params = request.params
         auth_signup = signup.AuthSignupHome()
         qcontext = auth_signup.get_auth_signup_qcontext()
         auth_signup.do_signup(qcontext)
         params['uid'] = request.uid
     return request.redirect('%s?%s' % (redirect, werkzeug.url_encode(params)))
Exemplo n.º 10
0
    def start_survey(self, survey, token=None, **post):
        cr, uid, context = request.cr, request.uid, request.context
        survey_obj = request.registry['survey.survey']
        user_input_obj = request.registry['survey.user_input']

        # Test mode
        if token and token == "phantom":
            _logger.info("[survey] Phantom mode")
            user_input_id = user_input_obj.create(cr, uid, {'survey_id': survey.id, 'test_entry': True}, context=context)
            user_input = user_input_obj.browse(cr, uid, [user_input_id], context=context)[0]
            data = {'survey': survey, 'page': None, 'token': user_input.token}
            return request.website.render('survey.survey_init', data)
        # END Test mode

        # Controls if the survey can be displayed
        errpage = self._check_bad_cases(cr, uid, request, survey_obj, survey, user_input_obj, token=token, context=context)
        if errpage:
            return errpage

        # Manual surveying
        if not token:
            vals = {'survey_id': survey.id}
            if request.website.user_id.id != uid:
                vals['partner_id'] = request.registry['res.users'].browse(cr, uid, uid, context=context).partner_id.id
            user_input_id = user_input_obj.create(cr, uid, vals, context=context)
            user_input = user_input_obj.browse(cr, uid, [user_input_id], context=context)[0]
        else:
            try:
                user_input_id = user_input_obj.search(cr, SUPERUSER_ID, [('token', '=', token)], context=context)[0]
            except IndexError:  # Invalid token
                return request.website.render("website.403")
            else:
                user_input = user_input_obj.browse(cr, SUPERUSER_ID, [user_input_id], context=context)[0]

        # Do not open expired survey
        errpage = self._check_deadline(cr, uid, user_input, context=context)
        if errpage:
            return errpage

        # Select the right page
        if user_input.state == 'new':  # Intro page
            data = {'survey': survey, 'page': None, 'token': user_input.token}
            return request.website.render('survey.survey_init', data)
        else:
            return request.redirect('/survey/fill/%s/%s' % (survey.id, user_input.token))
Exemplo n.º 11
0
Arquivo: main.py Projeto: ecoreos/hz
 def book_then_signup(self, **post):
     saas_server = self.get_saas_server()
     scheme = request.httprequest.scheme
     full_dbname = self.get_full_dbname(post.get('dbname'))
     dbtemplate = self.get_config_parameter('dbtemplate')
     client_id = self.get_new_client_id(full_dbname)
     request.registry['oauth.application'].create(request.cr, SUPERUSER_ID, {'client_id': client_id, 'name':full_dbname})
     params = {
         'scope': 'userinfo force_login trial skiptheuse',
         'state': simplejson.dumps({
             'd': full_dbname,
             'u': '%s://%s' % (scheme, full_dbname.replace('_', '.')),
             'db_template': dbtemplate,
         }),
         'redirect_uri': '{scheme}://{saas_server}/saas_server/new_database'.format(scheme=scheme, saas_server=saas_server),
         'response_type': 'token',
         'organization': post.get('organization'),
         'client_id': client_id,
     }
     return request.redirect('/oauth2/auth?%s' % werkzeug.url_encode(params))
Exemplo n.º 12
0
    def blog_post(self, blog, blog_post, tag_id=None, page=1, enable_editor=None, **post):
        """ Prepare all values to display the blog.

        :return dict values: values for the templates, containing

         - 'blog_post': browse of the current post
         - 'blog': browse of the current blog
         - 'blogs': list of browse records of blogs
         - 'tag': current tag, if tag_id in parameters
         - 'tags': all tags, for tag-based navigation
         - 'pager': a pager on the comments
         - 'nav_list': a dict [year][month] for archives navigation
         - 'next_post': next blog post, to direct the user towards the next interesting post
        """
        cr, uid, context = request.cr, request.uid, request.context
        tag_obj = request.registry['blog.tag']
        blog_post_obj = request.registry['blog.post']
        date_begin, date_end = post.get('date_begin'), post.get('date_end')

        pager_url = "/blogpost/%s" % blog_post.id

        pager = request.website.pager(
            url=pager_url,
            total=len(blog_post.website_message_ids),
            page=page,
            step=self._post_comment_per_page,
            scope=7
        )
        pager_begin = (page - 1) * self._post_comment_per_page
        pager_end = page * self._post_comment_per_page
        comments = blog_post.website_message_ids[pager_begin:pager_end]

        tag = None
        if tag_id:
            tag = request.registry['blog.tag'].browse(request.cr, request.uid, int(tag_id), context=request.context)
        blog_url = QueryURL('', ['blog', 'tag'], blog=blog_post.blog_id, tag=tag, date_begin=date_begin, date_end=date_end)

        if not blog_post.blog_id.id == blog.id:
            return request.redirect("/blog/%s/post/%s" % (slug(blog_post.blog_id), slug(blog_post)))

        tags = tag_obj.browse(cr, uid, tag_obj.search(cr, uid, [], context=context), context=context)

        # Find next Post
        all_post_ids = blog_post_obj.search(cr, uid, [('blog_id', '=', blog.id)], context=context)
        # should always return at least the current post
        current_blog_post_index = all_post_ids.index(blog_post.id)
        next_post_id = all_post_ids[0 if current_blog_post_index == len(all_post_ids) - 1 \
                            else current_blog_post_index + 1]
        next_post = next_post_id and blog_post_obj.browse(cr, uid, next_post_id, context=context) or False

        values = {
            'tags': tags,
            'tag': tag,
            'blog': blog,
            'blog_post': blog_post,
            'blog_post_cover_properties': json.loads(blog_post.cover_properties),
            'main_object': blog_post,
            'nav_list': self.nav_list(blog),
            'enable_editor': enable_editor,
            'next_post': next_post,
            'next_post_cover_properties': json.loads(next_post.cover_properties) if next_post else {},
            'date': date_begin,
            'blog_url': blog_url,
            'pager': pager,
            'comments': comments,
        }
        response = request.website.render("website_blog.blog_post_complete", values)

        request.session[request.session_id] = request.session.get(request.session_id, [])
        if not (blog_post.id in request.session[request.session_id]):
            request.session[request.session_id].append(blog_post.id)
            # Increase counter
            blog_post_obj.write(cr, SUPERUSER_ID, [blog_post.id], {
                'visits': blog_post.visits+1,
            },context=context)
        return response
Exemplo n.º 13
0
    def blog_post(self,
                  blog,
                  blog_post,
                  tag_id=None,
                  page=1,
                  enable_editor=None,
                  **post):
        """ Prepare all values to display the blog.

        :return dict values: values for the templates, containing

         - 'blog_post': browse of the current post
         - 'blog': browse of the current blog
         - 'blogs': list of browse records of blogs
         - 'tag': current tag, if tag_id in parameters
         - 'tags': all tags, for tag-based navigation
         - 'pager': a pager on the comments
         - 'nav_list': a dict [year][month] for archives navigation
         - 'next_post': next blog post, to direct the user towards the next interesting post
        """
        cr, uid, context = request.cr, request.uid, request.context
        tag_obj = request.registry['blog.tag']
        blog_post_obj = request.registry['blog.post']
        date_begin, date_end = post.get('date_begin'), post.get('date_end')

        pager_url = "/blogpost/%s" % blog_post.id

        pager = request.website.pager(url=pager_url,
                                      total=len(blog_post.website_message_ids),
                                      page=page,
                                      step=self._post_comment_per_page,
                                      scope=7)
        pager_begin = (page - 1) * self._post_comment_per_page
        pager_end = page * self._post_comment_per_page
        comments = blog_post.website_message_ids[pager_begin:pager_end]

        tag = None
        if tag_id:
            tag = request.registry['blog.tag'].browse(request.cr,
                                                      request.uid,
                                                      int(tag_id),
                                                      context=request.context)
        blog_url = QueryURL('', ['blog', 'tag'],
                            blog=blog_post.blog_id,
                            tag=tag,
                            date_begin=date_begin,
                            date_end=date_end)

        if not blog_post.blog_id.id == blog.id:
            return request.redirect("/blog/%s/post/%s" %
                                    (slug(blog_post.blog_id), slug(blog_post)))

        tags = tag_obj.browse(cr,
                              uid,
                              tag_obj.search(cr, uid, [], context=context),
                              context=context)

        # Find next Post
        all_post_ids = blog_post_obj.search(cr,
                                            uid, [('blog_id', '=', blog.id)],
                                            context=context)
        # should always return at least the current post
        current_blog_post_index = all_post_ids.index(blog_post.id)
        next_post_id = all_post_ids[0 if current_blog_post_index == len(all_post_ids) - 1 \
                            else current_blog_post_index + 1]
        next_post = next_post_id and blog_post_obj.browse(
            cr, uid, next_post_id, context=context) or False

        values = {
            'tags': tags,
            'tag': tag,
            'blog': blog,
            'blog_post': blog_post,
            'blog_post_cover_properties':
            json.loads(blog_post.cover_properties),
            'main_object': blog_post,
            'nav_list': self.nav_list(blog),
            'enable_editor': enable_editor,
            'next_post': next_post,
            'next_post_cover_properties':
            json.loads(next_post.cover_properties) if next_post else {},
            'date': date_begin,
            'blog_url': blog_url,
            'pager': pager,
            'comments': comments,
        }
        response = request.website.render("website_blog.blog_post_complete",
                                          values)

        request.session[request.session_id] = request.session.get(
            request.session_id, [])
        if not (blog_post.id in request.session[request.session_id]):
            request.session[request.session_id].append(blog_post.id)
            # Increase counter
            blog_post_obj.write(cr,
                                SUPERUSER_ID, [blog_post.id], {
                                    'visits': blog_post.visits + 1,
                                },
                                context=context)
        return response
Exemplo n.º 14
0
    def payment_transaction(self, acquirer_id, order_id):
        """ Json method that creates a payment.transaction, used to create a
        transaction when the user clicks on 'pay now' button. After having
        created the transaction, the event continues and the user is redirected
        to the acquirer website.

        :param int acquirer_id: id of a payment.acquirer record. If not set the
                                user is redirected to the checkout page
        """
        cr, uid, context = request.cr, request.uid, request.context
        transaction_obj = request.registry.get('payment.transaction')
        order = request.registry.get('sale.order').browse(cr,
                                                          SUPERUSER_ID,
                                                          order_id,
                                                          context=context)

        if not order or not order.order_line or acquirer_id is None:
            return request.redirect("/quote/" + str(order_id))

        # find an already existing transaction
        tx_id = transaction_obj.search(cr,
                                       SUPERUSER_ID,
                                       [('reference', '=', order.name)],
                                       context=context)
        tx = transaction_obj.browse(cr, SUPERUSER_ID, tx_id, context=context)
        if tx:
            if tx.state == 'draft':  # button cliked but no more info -> rewrite on tx or create a new one ?
                tx.write({
                    'acquirer_id': acquirer_id,
                })
            tx_id = tx.id
        else:
            tx_id = transaction_obj.create(
                cr,
                SUPERUSER_ID, {
                    'acquirer_id':
                    acquirer_id,
                    'type':
                    'form',
                    'amount':
                    order.amount_total,
                    'currency_id':
                    order.pricelist_id.currency_id.id,
                    'partner_id':
                    order.partner_id.id,
                    'reference':
                    order.name,
                    'sale_order_id':
                    order.id,
                    'callback_eval':
                    "self.env['sale.order']._confirm_online_quote(self.sale_order_id.id, self)"
                },
                context=context)
            tx = transaction_obj.browse(cr,
                                        SUPERUSER_ID,
                                        tx_id,
                                        context=context)
            # update quotation
            request.registry['sale.order'].write(
                cr,
                SUPERUSER_ID, [order.id], {
                    'payment_acquirer_id': acquirer_id,
                    'payment_tx_id': tx_id
                },
                context=context)

        # confirm the quotation
        if tx.acquirer_id.auto_confirm == 'at_pay_now':
            request.registry['sale.order'].action_confirm(
                cr, SUPERUSER_ID, [order.id], context=request.context)

        return tx_id