def post_save(self, forum, post, **kwargs): cr, uid, context = request.cr, request.uid, request.context question_tags = [] Tag = request.registry['forum.tag'] tag_version = kwargs.get('tag_type', 'texttext') if tag_version == "texttext": # old version - retro v8 - #TODO Remove in master if kwargs.get('question_tag') and kwargs.get('question_tag').strip('[]'): tags = kwargs.get('question_tag').strip('[]').replace('"', '').split(",") for tag in tags: tag_ids = Tag.search(cr, uid, [('name', '=', tag)], context=context) if tag_ids: question_tags += tag_ids else: new_tag = Tag.create(cr, uid, {'name': tag, 'forum_id': forum.id}, context=context) question_tags.append(new_tag) tags_val = [(6, 0, question_tags)] elif tag_version == "select2": # new version tags_val = forum._tag_to_write_vals(kwargs.get('question_tag', '')) vals = { 'tag_ids': tags_val, 'name': kwargs.get('question_name'), 'content': kwargs.get('content'), } request.registry['forum.post'].write(cr, uid, [post.id], vals, context=context) question = post.parent_id if post.parent_id else post return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(question)))
def question(self, forum, question, **post): # increment view counter question.sudo().set_viewed() if question.parent_id: redirect_url = "/forum/%s/question/%s" % (slug(forum), slug(question.parent_id)) return werkzeug.utils.redirect(redirect_url, 301) filters = "question" values = self._prepare_forum_values(forum=forum, searches=post) values.update( { "main_object": question, "question": question, "can_bump": ( question.forum_id.allow_bump and not question.child_ids and ( datetime.today() - datetime.strptime(question.write_date, tools.DEFAULT_SERVER_DATETIME_FORMAT) ).days > 9 ), "header": {"question_data": True}, "filters": filters, "reversed": reversed, } ) return request.website.render("website_forum.post_description_full", values)
def question(self, forum, question, **post): cr, uid, context = request.cr, request.uid, request.context # Hide posts from abusers (negative karma), except for moderators if not question.can_view: raise werkzeug.exceptions.NotFound() # increment view counter request.registry["forum.post"].set_viewed(cr, SUPERUSER_ID, [question.id], context=context) if question.parent_id: redirect_url = "/forum/%s/question/%s" % (slug(forum), slug(question.parent_id)) return werkzeug.utils.redirect(redirect_url, 301) filters = "question" values = self._prepare_forum_values(forum=forum, searches=post) values.update( { "main_object": question, "question": question, "header": {"question_data": True}, "filters": filters, "reversed": reversed, } ) return request.website.render("website_forum.post_description_full", values)
def _get_print_urls(self): res = [] if self.env.context.get('relative_url'): base_url = '/' else: base_url = self.env['ir.config_parameter'].\ get_param('web.base.url') if self.env.context['active_model'] == u'stock.production.lot': obj_id = self.env['mrp.production'].search([('final_lot_id', '=', self.env.context['active_id'])]) else: obj = self.env[self.env.context['active_model']].browse(self.env.context['active_id']) use_protocol = False for workcenter_line in obj.workcenter_lines: for protocol in obj.product_id.protocol_ids: if protocol.type_id.id == workcenter_line.workcenter_id.protocol_type_id.id: use_protocol = protocol if not use_protocol: raise exceptions.except_orm(_('Not found'), _('Protocol not found for the product %s.') % obj.product_id.name) if not workcenter_line.realized_ids: for line in use_protocol.report_line_ids: if line.log_realization: self.env['quality.realization'].create( { 'name': line.name, 'workcenter_line_id': workcenter_line.id }) res.append(urljoin(base_url, "protocol/print/%s/%s/%s" % (slug(obj), slug(use_protocol), slug(workcenter_line)))) return res
def create(self, cr, uid, vals, context=None): if context is None: context = {} create_context = dict(context, mail_create_nolog=True) post_id = super(Post, self).create(cr, uid, vals, context=create_context) post = self.browse(cr, SUPERUSER_ID, post_id, context=context) # SUPERUSER_ID to avoid read access rights issues when creating # karma-based access if post.parent_id and not post.can_ask: raise KarmaError('Not enough karma to create a new question') elif not post.parent_id and not post.can_answer: raise KarmaError('Not enough karma to answer to a question') # messaging and chatter base_url = self.pool['ir.config_parameter'].get_param(cr, uid, 'web.base.url') if post.parent_id: body = _( '<p>A new answer for <i>%s</i> has been posted. <a href="%s/forum/%s/question/%s">Click here to access the post.</a></p>' % (post.parent_id.name, base_url, slug(post.parent_id.forum_id), slug(post.parent_id)) ) self.message_post(cr, uid, post.parent_id.id, subject=_('Re: %s') % post.parent_id.name, body=body, subtype='website_forum.mt_answer_new', context=context) else: body = _( '<p>A new question <i>%s</i> has been asked on %s. <a href="%s/forum/%s/question/%s">Click here to access the question.</a></p>' % (post.name, post.forum_id.name, base_url, slug(post.forum_id), slug(post)) ) self.message_post(cr, uid, post_id, subject=post.name, body=body, subtype='website_forum.mt_question_new', context=context) self.pool['res.users'].add_karma(cr, SUPERUSER_ID, [uid], post.forum_id.karma_gen_question_new, context=context) return post_id
def post_save(self, forum, post, **kwargs): cr, uid, context = request.cr, request.uid, request.context question_tags = [] Tag = request.registry["forum.tag"] Forum = request.registry["forum.forum"] tag_version = kwargs.get("tag_type", "texttext") vals = {"name": kwargs.get("question_name"), "content": kwargs.get("content")} if tag_version == "texttext": # old version - retro v8 - #TODO Remove in master if kwargs.get("question_tag") and kwargs.get("question_tag").strip("[]"): tags = kwargs.get("question_tag").strip("[]").replace('"', "").split(",") for tag in tags: tag_ids = Tag.search(cr, uid, [("name", "=", tag)], context=context) if tag_ids: question_tags += tag_ids else: new_tag = Tag.create(cr, uid, {"name": tag, "forum_id": forum.id}, context=context) question_tags.append(new_tag) vals["tag_ids"] = [(6, 0, question_tags)] elif tag_version == "select2": # new version vals["tag_ids"] = Forum._tag_to_write_vals(cr, uid, [forum.id], kwargs.get("question_tag", ""), context)[ forum.id ] request.registry["forum.post"].write(cr, uid, [post.id], vals, context=context) question = post.parent_id if post.parent_id else post return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(question)))
def create(self, vals): if 'content' in vals and vals.get('forum_id'): vals['content'] = self._update_content(vals['content'], vals['forum_id']) post = super(Post, self.with_context(mail_create_nolog=True)).create(vals) # deleted or closed questions if post.parent_id and (post.parent_id.state == 'close' or post.parent_id.active is False): raise UserError(_('Posting answer on a [Deleted] or [Closed] question is not possible')) # karma-based access if not post.parent_id and not post.can_ask: raise KarmaError('Not enough karma to create a new question') elif post.parent_id and not post.can_answer: raise KarmaError('Not enough karma to answer to a question') # messaging and chatter base_url = self.env['ir.config_parameter'].get_param('web.base.url') if post.parent_id: body = _( '<p>A new answer for <i>%s</i> has been posted. <a href="%s/forum/%s/question/%s">Click here to access the post.</a></p>' % (post.parent_id.name, base_url, slug(post.parent_id.forum_id), slug(post.parent_id)) ) post.parent_id.message_post(subject=_('Re: %s') % post.parent_id.name, body=body, subtype='website_forum.mt_answer_new') else: body = _( '<p>A new question <i>%s</i> has been asked on %s. <a href="%s/forum/%s/question/%s">Click here to access the question.</a></p>' % (post.name, post.forum_id.name, base_url, slug(post.forum_id), slug(post)) ) post.message_post(subject=post.name, body=body, subtype='website_forum.mt_question_new') self.env.user.sudo().add_karma(post.forum_id.karma_gen_question_new) return post
def confirm_order(self, country='', **post): cr, uid, context, registry = request.cr, request.uid, request.context, request.registry order = request.website.sale_get_order(context=context) if not order and country: return request.redirect("/shop/country/%s/country_defined" % slug(country)) if not order and not country: return request.redirect("/shop") redirection = self.checkout_redirection(order) if redirection: return redirection values = self.checkout_values(post) values["error"] = self.checkout_form_validate(values["checkout"]) if values["error"] and country: values.update({'current_country': country}) return request.website.render("website_sale.checkout", values) if values["error"] and not country: return request.website.render("website_sale.checkout", values) self.checkout_form_save(values["checkout"]) request.session['sale_last_order_id'] = order.id request.website.sale_get_order(update_pricelist=True, context=context) if country: return request.redirect("/shop/payment/%s" % slug(country)) if not country: return request.redirect("/shop/payment")
def question(self, forum, question, **post): # Hide posts from abusers (negative karma), except for moderators if not question.can_view: raise werkzeug.exceptions.NotFound() # Hide pending posts from non-moderators and non-creator user = request.env.user if question.state == 'pending' and user.karma < forum.karma_post and question.create_uid != user: raise werkzeug.exceptions.NotFound() # increment view counter question.sudo().set_viewed() if question.parent_id: redirect_url = "/forum/%s/question/%s" % (slug(forum), slug(question.parent_id)) return werkzeug.utils.redirect(redirect_url, 301) filters = 'question' values = self._prepare_forum_values(forum=forum, searches=post) values.update({ 'main_object': question, 'question': question, 'can_bump': (question.forum_id.allow_bump and not question.child_ids and (datetime.today() - datetime.strptime(question.write_date, tools.DEFAULT_SERVER_DATETIME_FORMAT)).days > 9), 'header': {'question_data': True}, 'filters': filters, 'reversed': reversed, }) return request.website.render("website_forum.post_description_full", values)
def open_partner(self, forum, partner_id=0, **post): cr, uid, context = request.cr, request.uid, request.context if partner_id: partner = request.registry['res.partner'].browse(cr, SUPERUSER_ID, partner_id, context=context) if partner.exists() and partner.user_ids: return werkzeug.utils.redirect("/forum/%s/user/%d" % (slug(forum), partner.user_ids[0].id)) return werkzeug.utils.redirect("/forum/%s" % slug(forum))
def convert_comment_to_answer(self, forum, post, comment, **kwarg): new_post_id = request.registry['forum.post'].convert_comment_to_answer(request.cr, request.uid, comment.id, context=request.context) if not new_post_id: return werkzeug.utils.redirect("/forum/%s" % slug(forum)) post = request.registry['forum.post'].browse(request.cr, request.uid, new_post_id, context=request.context) question = post.parent_id if post.parent_id else post return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(question)))
def question_undelete(self, forum, question, **kwarg): check_res = self._has_enough_karma(question.create_uid.id == request.uid and '_karma_modo_unlink_own' or '_karma_modo_unlink_all') if not check_res[0]: return werkzeug.utils.redirect("/forum/%s" % slug(forum)) request.registry['forum.post'].write(request.cr, request.uid, [question.id], {'active': True}, context=request.context) return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(question)))
def build_details(self, build): tec_info = self.get_technical_information(build) state = build.state context = { 'time_ago': self.time_ago, 'build': build, 'fqdn': socket.getfqdn(), 'slug': slug, 'tec_info': tec_info, 'state': state, 'breadcrumbs': [ { 'string': 'Repositories', 'url': '/runbot', 'active': False, }, { 'string': build.repo_id.name, 'url': '/runbot/repo/%s' % slug(build.repo_id), 'active': False, }, { 'string': 'Build: %s' % build.short_name, 'url': '/runbot/build/%s' % slug(build), 'active': True, }, ], } return request.website.render('runbot.build_details', context)
def questions(self, forum, tag=None, page=1, filters='all', sorting='date', search='', **post): cr, uid, context = request.cr, request.uid, request.context Post = request.registry['forum.post'] user = request.registry['res.users'].browse(cr, uid, uid, context=context) domain = [('forum_id', '=', forum.id), ('parent_id', '=', False), ('state', '=', 'active')] if search: domain += ['|', ('name', 'ilike', search), ('content', 'ilike', search)] if tag: domain += [('tag_ids', 'in', tag.id)] if filters == 'unanswered': domain += [('child_ids', '=', False)] elif filters == 'followed': domain += [('message_follower_ids', '=', user.partner_id.id)] else: filters = 'all' if sorting == 'answered': order = 'child_count desc' elif sorting == 'vote': order = 'vote_count desc' elif sorting == 'date': order = 'write_date desc' else: sorting = 'creation' order = 'create_date desc' question_count = Post.search(cr, uid, domain, count=True, context=context) if tag: url = "/forum/%s/tag/%s/questions" % (slug(forum), slug(tag)) else: url = "/forum/%s" % slug(forum) url_args = {} if search: url_args['search'] = search if filters: url_args['filters'] = filters if sorting: url_args['sorting'] = sorting pager = request.website.pager(url=url, total=question_count, page=page, step=self._post_per_page, scope=self._post_per_page, url_args=url_args) obj_ids = Post.search(cr, uid, domain, limit=self._post_per_page, offset=pager['offset'], order=order, context=context) question_ids = Post.browse(cr, uid, obj_ids, context=context) values = self._prepare_forum_values(forum=forum, searches=post) values.update({ 'main_object': tag or forum, 'question_ids': question_ids, 'question_count': question_count, 'pager': pager, 'tag': tag, 'filters': filters, 'sorting': sorting, 'search': search, }) return request.website.render("website_forum.forum_index", values)
def questions(self, forum, tag=None, page=1, filters='all', sorting=None, search='', post_type=None, **post): Post = request.env['forum.post'] domain = [('forum_id', '=', forum.id), ('parent_id', '=', False), ('state', '=', 'active')] if search: domain += ['|', ('name', 'ilike', search), ('content', 'ilike', search)] if tag: domain += [('tag_ids', 'in', tag.id)] if filters == 'unanswered': domain += [('child_ids', '=', False)] elif filters == 'followed': domain += [('message_partner_ids', '=', request.env.user.partner_id.id)] if post_type: domain += [('post_type', '=', post_type)] if sorting: # check that sorting is valid # retro-compatibily for V8 and google links try: Post._generate_order_by(sorting, None) except ValueError: sorting = False if not sorting: sorting = forum.default_order question_count = Post.search_count(domain) if tag: url = "/forum/%s/tag/%s/questions" % (slug(forum), slug(tag)) else: url = "/forum/%s" % slug(forum) url_args = { 'sorting': sorting } if search: url_args['search'] = search if filters: url_args['filters'] = filters pager = request.website.pager(url=url, total=question_count, page=page, step=self._post_per_page, scope=self._post_per_page, url_args=url_args) question_ids = Post.search(domain, limit=self._post_per_page, offset=pager['offset'], order=sorting) values = self._prepare_forum_values(forum=forum, searches=post) values.update({ 'main_object': tag or forum, 'question_ids': question_ids, 'question_count': question_count, 'pager': pager, 'tag': tag, 'filters': filters, 'sorting': sorting, 'search': search, 'post_type': post_type, }) return request.website.render("website_forum.forum_index", values)
def convert_answer_to_comment(self, forum, post, **kwarg): question = post.parent_id new_msg_id = request.registry["forum.post"].convert_answer_to_comment( request.cr, request.uid, post.id, context=request.context ) if not new_msg_id: return werkzeug.utils.redirect("/forum/%s" % slug(forum)) return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(question)))
def _get_new_menu_pages(self): result = super(event_event, self)._get_new_menu_pages()[0] # TDE CHECK api.one -> returns a list with one item ? if self.show_tracks: result.append((_('Talks'), '/event/%s/track' % slug(self))) result.append((_('Agenda'), '/event/%s/agenda' % slug(self))) if self.show_track_proposal: result.append((_('Talk Proposals'), '/event/%s/track_proposal' % slug(self))) return result
def post_accept(self, forum, post): url = "/forum/%s/validation_queue" % (slug(forum)) if post.state == 'flagged': url = "/forum/%s/flagged_queue" % (slug(forum)) elif post.state == 'offensive': url = "/forum/%s/offensive_posts" % (slug(forum)) post.validate() return werkzeug.utils.redirect(url)
def open_partner(self, forum, partner_id=0, **post): cr, uid, context = request.cr, request.uid, request.context pids = request.registry["res.partner"].search(cr, SUPERUSER_ID, [("id", "=", partner_id)], context=context) if pids: partner = request.registry["res.partner"].browse(cr, SUPERUSER_ID, pids[0], context=context) if partner.user_ids: return werkzeug.utils.redirect("/forum/%s/user/%d" % (slug(forum), partner.user_ids[0].id)) return werkzeug.utils.redirect("/forum/%s" % slug(forum))
def post_mark_as_offensive(self, forum, post, **kwargs): post.mark_as_offensive(reason_id=int(kwargs.get('reason_id', False))) url = '' if post.parent_id: url = "/forum/%s/question/%s/#answer-%s" % (slug(forum), post.parent_id.id, post.id) else: url = "/forum/%s/question/%s" % (slug(forum), slug(post)) return werkzeug.utils.redirect(url)
def post_comment(self, forum, post, **kwargs): question = post.parent_id if post.parent_id else post if kwargs.get("comment") and post.forum_id.id == forum.id: # TDE FIXME: check that post_id is the question or one of its answers post.with_context(mail_create_nosubscribe=True).message_post( body=kwargs.get("comment"), message_type="comment", subtype="mt_comment" ) return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(question)))
def _get_new_menu_pages(self): self.ensure_one() result = super(Event, self)._get_new_menu_pages() if self.show_tracks: result.append((_('Talks'), '/event/%s/track' % slug(self))) result.append((_('Agenda'), '/event/%s/agenda' % slug(self))) if self.show_track_proposal: result.append((_('Talk Proposals'), '/event/%s/track_proposal' % slug(self))) return result
def questions(self, forum, tag=None, page=1, filters="all", sorting=None, search="", post_type=None, **post): Post = request.env["forum.post"] domain = [("forum_id", "=", forum.id), ("parent_id", "=", False), ("state", "=", "active")] if search: domain += ["|", ("name", "ilike", search), ("content", "ilike", search)] if tag: domain += [("tag_ids", "in", tag.id)] if filters == "unanswered": domain += [("child_ids", "=", False)] elif filters == "followed": domain += [("message_follower_ids", "=", request.env.user.partner_id.id)] if post_type: domain += [("post_type", "=", post_type)] if not sorting: sorting = forum.default_order question_count = Post.search_count(domain) if tag: url = "/forum/%s/tag/%s/questions" % (slug(forum), slug(tag)) else: url = "/forum/%s" % slug(forum) url_args = {"sorting": sorting} if search: url_args["search"] = search if filters: url_args["filters"] = filters pager = request.website.pager( url=url, total=question_count, page=page, step=self._post_per_page, scope=self._post_per_page, url_args=url_args, ) question_ids = Post.search(domain, limit=self._post_per_page, offset=pager["offset"], order=sorting) values = self._prepare_forum_values(forum=forum, searches=post) values.update( { "main_object": tag or forum, "question_ids": question_ids, "question_count": question_count, "pager": pager, "tag": tag, "filters": filters, "sorting": sorting, "search": search, "post_type": post_type, } ) return request.website.render("website_forum.forum_index", values)
def post_new(self, forum, post, **kwargs): if not request.session.uid: return login_redirect() request.registry["forum.post"].create( request.cr, request.uid, {"forum_id": forum.id, "parent_id": post.id, "content": kwargs.get("content")}, context=request.context, ) return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(post)))
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))
def post_new(self, forum, post, **kwargs): if not request.session.uid: return login_redirect() request.registry['forum.post'].create( request.cr, request.uid, { 'forum_id': forum.id, 'parent_id': post.id, 'content': kwargs.get('content'), }, context=request.context) return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(post)))
def forum_post(self, forum, post_type=None, **post): user = request.env.user if post_type not in ["question", "link", "discussion"]: # fixme: make dynamic return werkzeug.utils.redirect("/forum/%s" % slug(forum)) if not user.email or not tools.single_email_re.match(user.email): return werkzeug.utils.redirect( "/forum/%s/user/%s/edit?email_required=1" % (slug(forum), request.session.uid) ) values = self._prepare_forum_values(forum=forum, searches={}, header={"ask_hide": True}) return request.website.render("website_forum.new_%s" % post_type, values)
def post_save(self, forum, post, **kwargs): post_tags = forum._tag_to_write_vals(kwargs.get('post_tag', '')) vals = { 'tag_ids': post_tags, 'name': kwargs.get('post_name'), 'content': kwargs.get('content'), } post.write(vals) question = post.parent_id if post.parent_id else post return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(question)))
def post_delete(self, forum, post, **kwargs): check_res = self._has_enough_karma(post.create_uid.id == request.uid and '_karma_modo_unlink_own' or '_karma_modo_unlink_all') if not check_res[0]: return werkzeug.utils.redirect("/forum/%s" % slug(forum)) question = post.parent_id request.registry['forum.post'].unlink(request.cr, request.uid, [post.id], context=request.context) if question: werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(question))) return werkzeug.utils.redirect("/forum/%s" % slug(forum))
def _get_new_menu_pages(self, cr, uid, event, context=None): context = context or {} result = super(event_event, self)._get_new_menu_pages(cr, uid, event, context=context) if event.show_tracks: result.append((_("Talks"), "/event/%s/track/" % slug(event))) result.append((_("Agenda"), "/event/%s/agenda/" % slug(event))) if event.blog_id: result.append((_("News"), "/blogpost/" + slug(event.blog_ig))) if event.show_track_proposal: result.append((_("Talk Proposals"), "/event/%s/track_proposal/" % slug(event))) return result
def user_profile(self): user = request.env.user.sudo() birthday = '' if user.partner_id.date_birth: birthday = datetime.strptime(user.partner_id.date_birth, DEFAULT_SERVER_DATE_FORMAT) birthday = birthday.strftime('%d-%m-%Y') products = [] product_ids = request.env['product.product'].sudo().search([]) for product in product_ids: products.append({'id': product.id, 'name': product.name}) produces = [] for produce in user.partner_id.produce_ids: produces.append(produce.id) interests = [] for interest in user.partner_id.interest_in_ids: interests.append(interest.id) categories = [] category_ids = request.env['blog.post.category'].sudo().search([]) for categ in category_ids: categories.append({'id': categ.id, 'name': categ.name}) category_interest = [] for cat in user.partner_id.post_category_ids: category_interest.append(cat.id) user_question_ids = request.env['forum.post'].search([ ('parent_id', '=', False), ('create_uid', '=', user.id), ], order='create_date desc', limit=20) user_answer_ids = request.env['forum.post'].search([ ('parent_id', '!=', False), ('create_uid', '=', user.id), ], order='create_date desc', limit=20) model, comment = request.env[ 'ir.model.data'].get_object_reference('mail', 'mt_comment') activities = [] activity_ids = request.env['mail.message'].search( [('res_id', 'in', user_question_ids.ids + user_answer_ids.ids), ('model', '=', 'forum.post'), ('subtype_id', '!=', comment)], order='date DESC', limit=100) for act in activity_ids: post = request.env['forum.post'].browse(act.res_id) activities.append({'id': act.id, 'date': act.date, 'subtype': act.subtype_id.name, 'url': '/forum/%s/question/%s' % (slug(post.forum_id), slug(post)), 'name': act.subject}) return { 'id': user.id, 'name': user.name, 'email': user.login, 'partner_id': user.partner_id.id, 'birthday': birthday, 'gender': user.partner_id.gender, 'join_events': user.partner_id.join_events, 'supplier': user.partner_id.supplier, 'customer': user.partner_id.customer, 'zip': user.partner_id.zip or '', 'address': user.partner_id.street or '', 'number': user.partner_id.street2 or '', 'city': user.partner_id.l10n_br_city_id.name or '', 'city_id': user.partner_id.l10n_br_city_id.id or '', 'state': user.partner_id.state_id.name or '', 'country': user.partner_id.country_id.name or '', 'occupation': user.partner_id.function or '', 'phone': user.partner_id.phone or '', 'mobile': user.partner_id.mobile or '', 'karma': user.karma, 'comment': user.partner_id.comment or '', 'image': "/website/image/res.partner/%s/image_small" % user.partner_id.id, 'products': products, 'categories': categories, 'produce_ids': produces, 'interest_in_ids': interests, 'post_category_ids': category_interest, 'activities': activities, }
def question_reopen(self, forum, question, **kwarg): request.registry['forum.post'].reopen(request.cr, request.uid, [question.id], context=request.context) return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(question)))
def _website_url(self, name, arg): res = super(Channel, self)._website_url(name, arg) base_url = self.env['ir.config_parameter'].get_param('web.base.url') res.update({(channel.id, '%s/slides/%s' % (base_url, slug(channel))) for channel in self}) return res
def post_delete(self, forum, post, **kwargs): question = post.parent_id request.registry['forum.post'].unlink(request.cr, request.uid, [post.id], context=request.context) if question: werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(question))) return werkzeug.utils.redirect("/forum/%s" % slug(forum))
def question_undelete(self, forum, question, **kwarg): request.registry['forum.post'].write(request.cr, request.uid, [question.id], {'active': True}, context=request.context) return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(question)))
def question_reopen(self, forum, question, **kwarg): question.reopen() return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(question)))
def _compute_url_generated(self): self.url_generated = "/support/help/" + slug( self.group_id) + "/" + slug(self)
def partners(self, country=None, grade=None, page=0, **post): country_all = post.pop('country_all', False) partner_obj = request.registry['res.partner'] country_obj = request.registry['res.country'] search = post.get('search', '') base_partner_domain = [('is_company', '=', True), ('grade_id', '!=', False), ('website_published', '=', True)] if not request.registry['res.users'].has_group(request.cr, request.uid, 'base.group_website_publisher'): base_partner_domain += [('grade_id.website_published', '=', True)] if search: base_partner_domain += ['|', ('name', 'ilike', search), ('website_description', 'ilike', search)] # group by grade grade_domain = list(base_partner_domain) if not country and not country_all: country_code = request.session['geoip'].get('country_code') if country_code: country_ids = country_obj.search(request.cr, request.uid, [('code', '=', country_code)], context=request.context) if country_ids: country = country_obj.browse(request.cr, request.uid, country_ids[0], context=request.context) if country: grade_domain += [('country_id', '=', country.id)] grades = partner_obj.read_group( request.cr, SUPERUSER_ID, grade_domain, ["id", "grade_id"], groupby="grade_id", orderby="grade_id DESC", context=request.context) grades_partners = partner_obj.search( request.cr, SUPERUSER_ID, grade_domain, context=request.context, count=True) # flag active grade for grade_dict in grades: grade_dict['active'] = grade and grade_dict['grade_id'][0] == grade.id grades.insert(0, { 'grade_id_count': grades_partners, 'grade_id': (0, _("All Categories")), 'active': bool(grade is None), }) # group by country country_domain = list(base_partner_domain) if grade: country_domain += [('grade_id', '=', grade.id)] countries = partner_obj.read_group( request.cr, SUPERUSER_ID, country_domain, ["id", "country_id"], groupby="country_id", orderby="country_id", context=request.context) countries_partners = partner_obj.search( request.cr, SUPERUSER_ID, country_domain, context=request.context, count=True) # flag active country for country_dict in countries: country_dict['active'] = country and country_dict['country_id'] and country_dict['country_id'][0] == country.id countries.insert(0, { 'country_id_count': countries_partners, 'country_id': (0, _("All Countries")), 'active': bool(country is None), }) # current search if grade: base_partner_domain += [('grade_id', '=', grade.id)] if country: base_partner_domain += [('country_id', '=', country.id)] # format pager if grade and not country: url = '/partners/grade/' + slug(grade) elif country and not grade: url = '/partners/country/' + slug(country) elif country and grade: url = '/partners/grade/' + slug(grade) + '/country/' + slug(country) else: url = '/partners' url_args = {} if search: url_args['search'] = search if country_all: url_args['country_all'] = True partner_count = partner_obj.search_count( request.cr, SUPERUSER_ID, base_partner_domain, context=request.context) pager = request.website.pager( url=url, total=partner_count, page=page, step=self._references_per_page, scope=7, url_args=url_args) # search partners matching current search parameters partner_ids = partner_obj.search( request.cr, SUPERUSER_ID, base_partner_domain, order="grade_id DESC, display_name ASC", context=request.context) # todo in trunk: order="grade_id DESC, implemented_count DESC", offset=pager['offset'], limit=self._references_per_page partners = partner_obj.browse(request.cr, SUPERUSER_ID, partner_ids, request.context) # remove me in trunk partners = sorted(partners, key=lambda x: (x.grade_id.sequence if x.grade_id else 0, len([i for i in x.implemented_partner_ids if i.website_published])), reverse=True) partners = partners[pager['offset']:pager['offset'] + self._references_per_page] google_map_partner_ids = ','.join(map(str, [p.id for p in partners])) values = { 'countries': countries, 'current_country': country, 'grades': grades, 'current_grade': grade, 'partners': partners, 'google_map_partner_ids': google_map_partner_ids, 'pager': pager, 'searches': post, 'search_path': "%s" % werkzeug.url_encode(post), } return request.website.render("website_crm_partner_assign.index", values)
def shop(self, page=0, category=None, search='', **post): cr, uid, context, pool = request.cr, request.uid, request.context, request.registry attrib_list = request.httprequest.args.getlist('attrib') attrib_values = [map(int, v.split("-")) for v in attrib_list if v] attrib_set = set([v[1] for v in attrib_values]) domain = self._get_search_domain(search, category, attrib_values) keep = QueryURL('/shop', category=category and int(category), search=search, attrib=attrib_list) if not context.get('pricelist'): pricelist = self.get_pricelist() context['pricelist'] = int(pricelist) else: pricelist = pool.get('product.pricelist').browse( cr, uid, context['pricelist'], context) product_obj = pool.get('product.template') url = "/shop" product_count = product_obj.search_count(cr, uid, domain, context=context) if search: post["search"] = search if category: category = pool['product.public.category'].browse(cr, uid, int(category), context=context) url = "/shop/category/%s" % slug(category) if attrib_list: post['attrib'] = attrib_list pager = request.website.pager(url=url, total=product_count, page=page, step=PPG, scope=7, url_args=post) product_ids = product_obj.search( cr, uid, domain, limit=PPG, offset=pager['offset'], order='website_published desc, website_sequence desc', context=context) products = product_obj.browse(cr, uid, product_ids, context=context) style_obj = pool['product.style'] style_ids = style_obj.search(cr, uid, [], context=context) styles = style_obj.browse(cr, uid, style_ids, context=context) category_obj = pool['product.public.category'] category_ids = category_obj.search(cr, uid, [('parent_id', '=', False)], context=context) categs = category_obj.browse(cr, uid, category_ids, context=context) attributes_obj = request.registry['product.attribute'] attributes_ids = attributes_obj.search(cr, uid, [], context=context) attributes = attributes_obj.browse(cr, uid, attributes_ids, context=context) from_currency = pool.get('product.price.type')._get_field_currency( cr, uid, 'list_price', context) to_currency = pricelist.currency_id compute_currency = lambda price: pool['res.currency']._compute( cr, uid, from_currency, to_currency, price, context=context) values = { 'search': search, 'category': category, 'attrib_values': attrib_values, 'attrib_set': attrib_set, 'pager': pager, 'pricelist': pricelist, 'products': products, 'bins': table_compute().process(products), 'rows': PPR, 'styles': styles, 'categories': categs, 'attributes': attributes, 'compute_currency': compute_currency, 'keep': keep, 'style_in_product': lambda style, product: style.id in [s.id for s in product.website_style_ids], 'attrib_encode': lambda attribs: werkzeug.url_encode([('attrib', i) for i in attribs]), } return request.website.render("website_sale.products", values)
def portal_post(self, portal, portal_post, tag_id=None, page=1, enable_editor=None, **post): """ Prepare all values to display the portal. :return dict values: values for the templates, containing - 'portal_post': browse of the current post - 'portal': browse of the current portal - 'portals': list of browse records of portals - '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 portal post, to direct the user towards the next interesting post """ cr, uid, context = request.cr, request.uid, request.context tag_obj = request.registry['portal.tag'] portal_post_obj = request.registry['portal.post'] date_begin, date_end = post.get('date_begin'), post.get('date_end') pager_url = "/portalpost/%s" % portal_post.id pager = request.website.pager(url=pager_url, total=len( portal_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 = portal_post.website_message_ids[pager_begin:pager_end] tag = None if tag_id: tag = request.registry['portal.tag'].browse( request.cr, request.uid, int(tag_id), context=request.context) post_url = QueryURL('', ['portalpost'], portalpost=portal_post, tag_id=tag_id, date_begin=date_begin, date_end=date_end) portal_url = QueryURL('', ['portal', 'tag'], portal=portal_post.portal_id, tag=tag, date_begin=date_begin, date_end=date_end) if not portal_post.portal_id.id == portal.id: return request.redirect( "/portal/%s/post/%s" % (slug(portal_post.portal_id), slug(portal_post))) tags = tag_obj.browse(cr, uid, tag_obj.search(cr, uid, [], context=context), context=context) # Find next Post visited_portals = request.httprequest.cookies.get( 'visited_portals') or '' visited_ids = filter(None, visited_portals.split(',')) visited_ids = map(lambda x: int(x), visited_ids) if portal_post.id not in visited_ids: visited_ids.append(portal_post.id) next_post_id = portal_post_obj.search( cr, uid, [ ('id', 'not in', visited_ids), ], order='ranking desc', limit=1, context=context) if not next_post_id: next_post_id = portal_post_obj.search(cr, uid, [('id', '!=', portal.id)], order='ranking desc', limit=1, context=context) next_post = next_post_id and portal_post_obj.browse( cr, uid, next_post_id[0], context=context) or False values = { 'tags': tags, 'tag': tag, 'portal': portal, 'portal_post': portal_post, 'main_object': portal_post, 'nav_list': self.nav_list(), 'enable_editor': enable_editor, 'next_post': next_post, 'date': date_begin, 'post_url': post_url, 'portal_url': portal_url, 'pager': pager, 'comments': comments, } response = request.website.render( "website_portal.portal_post_complete", values) response.set_cookie('visited_portals', ','.join(map(str, visited_ids))) request.session[request.session_id] = request.session.get( request.session_id, []) if not (portal_post.id in request.session[request.session_id]): request.session[request.session_id].append(portal_post.id) # Increase counter portal_post_obj.write(cr, SUPERUSER_ID, [portal_post.id], { 'visits': portal_post.visits + 1, }, context=context) return response
def product_redirect(self, cfg_session): return request.redirect('/configurator/config/%s' % slug(cfg_session))
def help_page_create(self, group_id, **post): """Add new help page via content menu""" help_page = request.env['website.support.help.page'].create({'group_id': group_id,'name': "New Help Page"}) return werkzeug.utils.redirect("/support/help/%s/%s?enable_editor=1" % (slug(help_page.group_id), slug(help_page)))
def open_user(self, forum, user_id=0, **post): User = request.env['res.users'] Post = request.env['forum.post'] Vote = request.env['forum.post.vote'] Activity = request.env['mail.message'] Followers = request.env['mail.followers'] Data = request.env["ir.model.data"] user = User.sudo().search([('id', '=', user_id)]) current_user = request.env.user.sudo() # Users with high karma can see users with karma <= 0 for # moderation purposes, IFF they have posted something (see below) if (not user or (user.karma < 1 and current_user.karma < forum.karma_unlink_all)): return werkzeug.utils.redirect("/forum/%s" % slug(forum)) values = self._prepare_forum_values(forum=forum, **post) # questions and answers by user user_question_ids = Post.search([('parent_id', '=', False), ('forum_id', '=', forum.id), ('create_uid', '=', user.id)], order='create_date desc') count_user_questions = len(user_question_ids) if (user_id != request.session.uid and not (user.website_published or (count_user_questions and current_user.karma > forum.karma_unlink_all))): return request.website.render("website_forum.private_profile", values) # limit length of visible posts by default for performance reasons, except for the high # karma users (not many of them, and they need it to properly moderate the forum) post_display_limit = None if current_user.karma < forum.karma_unlink_all: post_display_limit = 20 user_questions = user_question_ids[:post_display_limit] user_answer_ids = Post.search([('parent_id', '!=', False), ('forum_id', '=', forum.id), ('create_uid', '=', user.id)], order='create_date desc') count_user_answers = len(user_answer_ids) user_answers = user_answer_ids[:post_display_limit] # showing questions which user following post_ids = [ follower.res_id for follower in Followers.sudo().search([( 'res_model', '=', 'forum.post'), ('partner_id', '=', user.partner_id.id)]) ] followed = Post.search([('id', 'in', post_ids), ('forum_id', '=', forum.id), ('parent_id', '=', False)]) # showing Favourite questions of user. favourite = Post.search([('favourite_ids', '=', user.id), ('forum_id', '=', forum.id), ('parent_id', '=', False)]) # votes which given on users questions and answers. data = Vote.read_group([('forum_id', '=', forum.id), ('recipient_id', '=', user.id)], ["vote"], groupby=["vote"]) up_votes, down_votes = 0, 0 for rec in data: if rec['vote'] == '1': up_votes = rec['vote_count'] elif rec['vote'] == '-1': down_votes = rec['vote_count'] # Votes which given by users on others questions and answers. vote_ids = Vote.search([('user_id', '=', user.id)]) # activity by user. model, comment = Data.get_object_reference('mail', 'mt_comment') activities = Activity.search( [('res_id', 'in', (user_question_ids + user_answer_ids).ids), ('model', '=', 'forum.post'), ('subtype_id', '!=', comment)], order='date DESC', limit=100) posts = {} for act in activities: posts[act.res_id] = True posts_ids = Post.search([('id', 'in', posts.keys())]) posts = dict( map( lambda x: (x.id, (x.parent_id or x, x.parent_id and x or False)), posts_ids)) # TDE CLEANME MASTER: couldn't it be rewritten using a 'menu' key instead of one key for each menu ? if user == request.env.user: post['my_profile'] = True else: post['users'] = True values.update({ 'uid': request.env.user.id, 'user': user, 'main_object': user, 'searches': post, 'questions': user_questions, 'count_questions': count_user_questions, 'answers': user_answers, 'count_answers': count_user_answers, 'followed': followed, 'favourite': favourite, 'up_votes': up_votes, 'down_votes': down_votes, 'activities': activities, 'posts': posts, 'vote_post': vote_ids, }) return request.website.render("website_forum.user_detail_full", values)
def question_undelete(self, forum, question, **kwarg): question.active = True return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(question)))
def question_close(self, forum, question, **post): request.registry['forum.post'].close(request.cr, request.uid, [question.id], reason_id=int(post.get('reason_id', False)), context=request.context) return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(question)))
def convert_answer_to_comment(self, forum, post, **kwarg): question = post.parent_id new_msg_id = post.convert_answer_to_comment()[0] if not new_msg_id: return werkzeug.utils.redirect("/forum/%s" % slug(forum)) return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(question)))
def shop(self, page=0, category=None, search='', **post): cr, uid, context, pool = request.cr, request.uid, request.context, request.registry domain = request.website.sale_product_domain() if search: domain += [ '|', '|', '|', ('name', 'ilike', search), ('description', 'ilike', search), ('description_sale', 'ilike', search), ('product_variant_ids.default_code', 'ilike', search) ] if category: domain += [('product_variant_ids.public_categ_ids', 'child_of', int(category))] attrib_list = request.httprequest.args.getlist('attrib') attrib_values = [map(int, v.split("-")) for v in attrib_list if v] attrib_set = set([v[1] for v in attrib_values]) if attrib_values: attrib = None ids = [] for value in attrib_values: if not attrib: attrib = value[0] ids.append(value[1]) elif value[0] == attrib: ids.append(value[1]) else: domain += [('attribute_line_ids.value_ids', 'in', ids)] attrib = value[0] ids = [value[1]] if attrib: domain += [('attribute_line_ids.value_ids', 'in', ids)] keep = QueryURL('/shop', category=category and int(category), search=search, attrib=attrib_list) if not context.get('pricelist'): pricelist = self.get_pricelist() context['pricelist'] = int(pricelist) else: pricelist = pool.get('product.pricelist').browse( cr, uid, context['pricelist'], context) product_obj = pool.get('product.template') url = "/shop" product_count = product_obj.search_count(cr, uid, domain, context=context) if search: post["search"] = search if category: url = "/shop/category/%s" % slug(category) pager = request.website.pager(url=url, total=product_count, page=page, step=PPG, scope=7, url_args=post) product_ids = product_obj.search( cr, uid, domain, limit=PPG + 10, offset=pager['offset'], order='website_published desc, website_sequence desc', context=context) products = product_obj.browse(cr, uid, product_ids, context=context) style_obj = pool['product.style'] style_ids = style_obj.search(cr, uid, [], context=context) styles = style_obj.browse(cr, uid, style_ids, context=context) category_obj = pool['product.public.category'] category_ids = category_obj.search(cr, uid, [], context=context) categories = category_obj.browse(cr, uid, category_ids, context=context) categs = filter(lambda x: not x.parent_id, categories) attributes_obj = request.registry['product.attribute'] attributes_ids = attributes_obj.search(cr, uid, [], context=context) attributes = attributes_obj.browse(cr, uid, attributes_ids, context=context) from_currency = pool.get('product.price.type')._get_field_currency( cr, uid, 'list_price', context) to_currency = pricelist.currency_id compute_currency = lambda price: pool['res.currency']._compute( cr, uid, from_currency, to_currency, price, context=context) values = { 'search': search, 'category': category, 'attrib_values': attrib_values, 'attrib_set': attrib_set, 'pager': pager, 'pricelist': pricelist, 'products': products, 'bins': table_compute().process(products), 'rows': PPR, 'styles': styles, 'categories': categs, 'attributes': attributes, 'compute_currency': compute_currency, 'keep': keep, 'style_in_product': lambda style, product: style.id in [s.id for s in product.website_style_ids], 'attrib_encode': lambda attribs: werkzeug.url_encode([('attrib', i) for i in attribs]), } return request.website.render("website_sale.products", values)
def questions(self, forum, tag=None, page=1, filters='all', sorting=None, search='', post_type=None, **post): Post = request.env['forum.post'] domain = [('forum_id', '=', forum.id), ('parent_id', '=', False), ('state', '=', 'active')] if search: domain += [ '|', ('name', 'ilike', search), ('content', 'ilike', search) ] if tag: domain += [('tag_ids', 'in', tag.id)] if filters == 'unanswered': domain += [('child_ids', '=', False)] elif filters == 'followed': domain += [('message_partner_ids', '=', request.env.user.partner_id.id)] if post_type: domain += [('post_type', '=', post_type)] if sorting: # check that sorting is valid # retro-compatibily for V8 and google links try: Post._generate_order_by(sorting, None) except ValueError: sorting = False if not sorting: sorting = forum.default_order question_count = Post.search_count(domain) if tag: url = "/forum/%s/tag/%s/questions" % (slug(forum), slug(tag)) else: url = "/forum/%s" % slug(forum) url_args = {'sorting': sorting} if search: url_args['search'] = search if filters: url_args['filters'] = filters pager = request.website.pager(url=url, total=question_count, page=page, step=self._post_per_page, scope=self._post_per_page, url_args=url_args) question_ids = Post.search(domain, limit=self._post_per_page, offset=pager['offset'], order=sorting) values = self._prepare_forum_values(forum=forum, searches=post) values.update({ 'main_object': tag or forum, 'question_ids': question_ids, 'question_count': question_count, 'pager': pager, 'tag': tag, 'filters': filters, 'sorting': sorting, 'search': search, 'post_type': post_type, }) return request.website.render("website_forum.forum_index", values)
def config_redirect(self, product_tmpl, config_step, post=None, value_ids=None, custom_vals=None): """ Redirect user to a certain url depending on the configuration state """ if post is None: post = {} if value_ids is None: value_ids = [] if custom_vals is None: custom_vals = {} cfg_steps = product_tmpl.config_step_line_ids product_tmpl_url = '/configurator/%s' % slug(product_tmpl) if not cfg_steps: # If there are no config steps and there's a post # it is a final one-step configuration if post: valid_config = product_tmpl.validate_configuration( value_ids, custom_vals) if valid_config: return None else: return request.redirect(product_tmpl_url) return None # Redirect the user towards the first step if they exist elif cfg_steps and not config_step: return request.redirect( '%s/%s' % (product_tmpl_url, slug(cfg_steps[0])) ) # TODO: Do not allow dependencies to be set on the first config step if config_step == cfg_steps[0] and not post: return False # elif product_tmpl.id not in cfg_session and config_step # != cfg_steps[0]: # return request.redirect(product_tmpl_nurl) for i, line in enumerate(cfg_steps): if config_step == line: try: next_step = cfg_steps[i + 1] except: next_step = None open_steps = product_tmpl.get_open_step_lines(value_ids) if post: if next_step: return request.redirect( '%s/%s' % (product_tmpl_url, slug(next_step)) ) # If this is the last step then validation and creation is next valid_config = product_tmpl.validate_configuration( value_ids, custom_vals) if not valid_config: return request.redirect( '%s/%s' % (product_tmpl_url, slug(open_steps[0])) ) else: return None elif config_step and config_step not in open_steps: if next_step: return request.redirect( '%s/%s' % (product_tmpl_url, slug(next_step)) ) return request.redirect( '%s/%s' % (product_tmpl_url, slug(open_steps[0])) ) return None
def convert_comment_to_answer(self, forum, post, comment, **kwarg): post = request.env['forum.post'].convert_comment_to_answer(comment.id) if not post: return werkzeug.utils.redirect("/forum/%s" % slug(forum)) question = post.parent_id if post.parent_id else post return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(question)))
def shop(self, page=1, category=None, search='', **post): cr, uid, context, pool = request.cr, request.uid, request.context, request.registry attrib_list = request.httprequest.args.getlist('attrib') attrib_values = [map(int, v.split("-")) for v in attrib_list if v] attrib_set = set([v[1] for v in attrib_values]) domain = self._get_search_domain(search, category, attrib_values) keep = QueryURL('/shop', category=category and int(category), search=search, attrib=attrib_list) #~ if not context.get('pricelist'): #~ if request.env['res.users'].browse(request.env.user.id) == request.env.ref('base.public_user'): #~ pricelist = request.env['res.lang'].search([('code', '=', request.context.get('lang'))]).pricelist or self.env.ref('product.list0') #~ else: #~ ppp = user.partner_id.property_product_pricelist #~ if ppp: #~ pricelist = get_user_pricelist(request.env.user) #~ else: #~ pricelist = request.env['res.lang'].search([('code', '=', request.context.get('lang'))]).pricelist or self.env.ref('product.list0') #~ context['pricelist'] = int(pricelist) #~ else: #~ pricelist = request.env['product.pricelist'].browse(context['pricelist']) if not context.get('pricelist'): pricelist = self.get_pricelist() context['pricelist'] = int(pricelist) else: pricelist = pool.get('product.pricelist').browse(cr, uid, context['pricelist'], context) product_obj = pool.get('product.template') url = "/shop" product_count = product_obj.search_count(cr, uid, domain, context=context) if search: post["search"] = search if category: category = pool['product.public.category'].browse(cr, uid, int(category), context=context) url = "/shop/category/%s" % slug(category) if attrib_list: post['attrib'] = attrib_list ppg = PPG if post.get('limit'): limit = post.get('limit') try: int(limit) ppg = abs(int(limit)) except: pass pager = request.website.pager(url=url, total=product_count, page=page, step=ppg, scope=7, url_args=post) post['order'] = post.get('order', 'name') product_ids = product_obj.search(cr, uid, domain, limit=ppg, offset=pager['offset'], order=self._get_search_order(post), context=context) products = product_obj.browse(cr, uid, product_ids, context=context) style_obj = pool['product.style'] style_ids = style_obj.search(cr, uid, [], context=context) styles = style_obj.browse(cr, uid, style_ids, context=context) category_obj = pool['product.public.category'] category_ids = category_obj.search(cr, uid, [('parent_id', '=', False)], context=context) categs = category_obj.browse(cr, uid, category_ids, context=context) attributes_obj = request.registry['product.attribute'] attributes_ids = attributes_obj.search(cr, uid, [], context=context) attributes = attributes_obj.browse(cr, uid, attributes_ids, context=context) from_currency = pool.get('product.price.type')._get_field_currency(cr, uid, 'list_price', context) to_currency = pricelist.currency_id compute_currency = lambda price: pool['res.currency']._compute(cr, uid, from_currency, to_currency, price, context=context) view_type = 'grid_view' if post.get('view_type') and post.get('view_type') == 'list_view': view_type = 'list_view' values = { 'search': search, 'category': category, 'attrib_values': attrib_values, 'attrib_set': attrib_set, 'page': page, 'pager': pager, 'pricelist': pricelist, 'products': products, 'bins': table_compute().process(products, ppg), 'rows': PPR, 'styles': styles, 'categories': categs, 'attributes': attributes, 'compute_currency': compute_currency, 'keep': keep, 'style_in_product': lambda style, product: style.id in [s.id for s in product.website_style_ids], 'attrib_encode': lambda attribs: werkzeug.url_encode([('attrib',i) for i in attribs]), 'product_count': product_count, 'view_type': view_type, 'limit': ppg, 'url': url, } return request.website.render("website_sale.products", values)
def to_url(self, value): return slug(value)
def campaign_shop(self, page=1, category=None, campaign=None, search='', **post): cr, uid, context, pool = request.cr, request.uid, request.context, request.registry attrib_list = request.httprequest.args.getlist('attrib') attrib_values = [map(int, v.split("-")) for v in attrib_list if v] attrib_set = set([v[1] for v in attrib_values]) if attrib_list: post['attrib'] = attrib_list domain = self._get_search_domain(search, category, attrib_values) keep = QueryURL('/campaign', category=category and int(category), search=search, attrib=attrib_list) if not context.get('pricelist'): pricelist = self.get_pricelist() context['pricelist'] = int(pricelist) else: pricelist = request.env['product.pricelist'].browse(context['pricelist']) url = "/campaign" product_count = request.env['product.template'].search_count(domain) if search: post["search"] = search if category: category = request.env['product.public.category'].browse(int(category)) url = "/shop/category/%s" % slug(category) ppg = PPG if post.get('limit'): limit = post.get('limit') try: int(limit) ppg = abs(int(limit)) except: pass pager = request.website.pager(url=url, total=product_count, page=page, step=ppg, scope=7, url_args=post) campaign = request.env['crm.tracking.campaign'].with_context(context).get_campaigns() if not campaign: return werkzeug.utils.redirect('/', 302) campaign.ensure_one() #~ if campaign: #~ products = self.get_products(campaign.object_ids) #~ else: #~ campaign = request.env['crm.tracking.campaign'].search([('date_start', '<=', fields.Date.today()), ('date_stop', '>=', fields.Date.today()), ('website_published', '=', True)]) #~ if not campaign: #~ return werkzeug.utils.redirect('/', 302) #~ campaign = campaign[0] #~ products = self.get_products(campaign.object_ids) styles = request.env['product.style'].search([]) categs = request.env['product.public.category'].search([('parent_id', '=', False)]) attributes = request.env['product.attribute'].search([]) from_currency = request.env['product.price.type']._get_field_currency('list_price', context) to_currency = pricelist.currency_id compute_currency = lambda price: request.env['res.currency']._compute(from_currency, to_currency, price) view_type = 'grid_view' if post.get('view_type') and post.get('view_type') == 'list_view': view_type = 'list_view' product_list = [] for product in campaign.campaign_product_ids.sorted(key=lambda c: c.sequence): product_list.append(product.product_id) return request.website.render("website_sale.products", { 'search': search, 'category': category, 'attrib_values': attrib_values, 'attrib_set': attrib_set, 'page': page, 'pager': pager, 'pricelist': pricelist, 'products': product_list, 'bins': table_compute().process(product_list, ppg), 'rows': PPR, 'styles': styles, 'categories': categs, 'attributes': attributes, 'compute_currency': compute_currency, 'keep': keep, 'style_in_product': lambda style, product: style.id in [s.id for s in product.website_style_ids], 'attrib_encode': lambda attribs: werkzeug.url_encode([('attrib',i) for i in attribs]), 'campaign': campaign, 'product_count': len(product_list), 'view_type': view_type, 'limit': ppg, 'url': url, })
def question_edit_answer(self, forum, question, **kwargs): for record in question.child_ids: if record.create_uid.id == request.uid: answer = record break return werkzeug.utils.redirect("/forum/%s/post/%s/edit" % (slug(forum), slug(answer)))
def convert_answer_to_comment(self, forum, post, **kwarg): question = post.parent_id new_msg_id = request.registry['forum.post'].convert_answer_to_comment(request.cr, request.uid, post.id, context=request.context) if not new_msg_id: return werkzeug.utils.redirect("/forum/%s" % slug(forum)) return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(question)))
def downloads(self, page=0, category=None, search='', ppg=False, **post): cr, uid, context, pool = request.cr, request.uid, request.context, request.registry user_obj = pool['res.users'].browse(cr, uid, [uid], context=context) #if not user_obj.active : # request.params['error'] = _("Please Login to See our download resources.") # return request.redirect('/web/login') category_obj = pool['download.category'] category_ids = category_obj.search(cr, uid, [('parent_id', '=', False)], context=context) categories = category_obj.browse( cr, uid, category_ids, context=context).sorted(key=lambda x: x.sequence) download_obj = pool.get('loewie.download') if category and category.name == 'All Downloads': category = None keep = QueryURL('/downloads', category=category and int(category), search=search) url = "/downloads" category_ids = [] if category: category_ids.append(category.id) url = "/downloads/category/%s" % slug(category) for categ in category.child_id: category_ids.append(categ.id) domain = [] if category_ids: domain = [('category_id', 'in', category_ids or [1])] if search: for srch in search.split(" "): domain += [('name', 'ilike', srch)] download_count = download_obj.search_count(cr, uid, domain, context=context) pager = request.website.pager(url=url, total=download_count, page=page, step=9, scope=7, url_args=post) download_ids = download_obj.search( cr, uid, domain, limit=9, offset=pager['offset'], context=context) # order=self._get_search_order(post), #download_ids = download_obj.search(cr, uid, domain, context=context) downloads = download_obj.browse(cr, uid, download_ids, context=context) parent_category_ids = [] if category: parent_category_ids = [category.id] current_category = category while current_category.parent_id: parent_category_ids.append(current_category.parent_id.id) current_category = current_category.parent_id values = { 'search': search, 'categories': categories, 'category': category, 'parent_category_ids': parent_category_ids, 'keep': keep, 'pager': pager, 'downloads': downloads, #'bins': table_compute().process(downloads, ppg), 'rows': 3, } return request.website.render("nomitang_download.downloads_tmpl", values)
def open_user(self, forum, user_id=0, **post): cr, uid, context = request.cr, request.uid, request.context User = request.registry['res.users'] Post = request.registry['forum.post'] Vote = request.registry['forum.post.vote'] Activity = request.registry['mail.message'] Followers = request.registry['mail.followers'] Data = request.registry["ir.model.data"] user = User.browse(cr, SUPERUSER_ID, user_id, context=context) current_user = User.browse(cr, SUPERUSER_ID, uid, context=context) # Users with high karma can see users with karma <= 0 for # moderation purposes, IFF they have posted something (see below) if (not user.exists() or (user.karma < 1 and current_user.karma < forum.karma_unlink_all)): return werkzeug.utils.redirect("/forum/%s" % slug(forum)) values = self._prepare_forum_values(forum=forum, **post) # questions and answers by user user_question_ids = Post.search(cr, uid, [ ('parent_id', '=', False), ('forum_id', '=', forum.id), ('create_uid', '=', user.id), ], order='create_date desc', context=context) count_user_questions = len(user_question_ids) if (user_id != request.session.uid and not (user.website_published or (count_user_questions and current_user.karma > forum.karma_unlink_all))): return request.website.render("website_forum.private_profile", values) # displaying only the 20 most recent questions user_questions = Post.browse(cr, uid, user_question_ids[:20], context=context) user_answer_ids = Post.search(cr, uid, [ ('parent_id', '!=', False), ('forum_id', '=', forum.id), ('create_uid', '=', user.id), ], order='create_date desc', context=context) count_user_answers = len(user_answer_ids) # displaying only the 20 most recent answers user_answers = Post.browse(cr, uid, user_answer_ids[:20], context=context) # showing questions which user following obj_ids = Followers.search(cr, SUPERUSER_ID, [('res_model', '=', 'forum.post'), ('partner_id', '=', user.partner_id.id)], context=context) post_ids = [ follower.res_id for follower in Followers.browse( cr, SUPERUSER_ID, obj_ids, context=context) ] que_ids = Post.search(cr, uid, [('id', 'in', post_ids), ('forum_id', '=', forum.id), ('parent_id', '=', False)], context=context) followed = Post.browse(cr, uid, que_ids, context=context) #showing Favourite questions of user. fav_que_ids = Post.search(cr, uid, [('favourite_ids', '=', user.id), ('forum_id', '=', forum.id), ('parent_id', '=', False)], context=context) favourite = Post.browse(cr, uid, fav_que_ids, context=context) #votes which given on users questions and answers. data = Vote.read_group(cr, uid, [('forum_id', '=', forum.id), ('recipient_id', '=', user.id)], ["vote"], groupby=["vote"], context=context) up_votes, down_votes = 0, 0 for rec in data: if rec['vote'] == '1': up_votes = rec['vote_count'] elif rec['vote'] == '-1': down_votes = rec['vote_count'] #Votes which given by users on others questions and answers. post_votes = Vote.search(cr, uid, [('user_id', '=', user.id)], context=context) vote_ids = Vote.browse(cr, uid, post_votes, context=context) #activity by user. model, comment = Data.get_object_reference(cr, uid, 'mail', 'mt_comment') activity_ids = Activity.search( cr, uid, [('res_id', 'in', user_question_ids + user_answer_ids), ('model', '=', 'forum.post'), ('subtype_id', '!=', comment)], order='date DESC', limit=100, context=context) activities = Activity.browse(cr, uid, activity_ids, context=context) posts = {} for act in activities: posts[act.res_id] = True posts_ids = Post.browse(cr, uid, posts.keys(), context=context) posts = dict( map( lambda x: (x.id, (x.parent_id or x, x.parent_id and x or False)), posts_ids)) # TDE CLEANME MASTER: couldn't it be rewritten using a 'menu' key instead of one key for each menu ? if user.id == uid: post['my_profile'] = True else: post['users'] = True values.update({ 'uid': uid, 'user': user, 'main_object': user, 'searches': post, 'questions': user_questions, 'count_questions': count_user_questions, 'answers': user_answers, 'count_answers': count_user_answers, 'followed': followed, 'favourite': favourite, 'up_votes': up_votes, 'down_votes': down_votes, 'activities': activities, 'posts': posts, 'vote_post': vote_ids, }) return request.website.render("website_forum.user_detail_full", values)
def post_delete(self, forum, post, **kwargs): question = post.parent_id post.unlink() if question: werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(question))) return werkzeug.utils.redirect("/forum/%s" % slug(forum))
def question_close(self, forum, question, **post): question.close(reason_id=int(post.get('reason_id', False))) return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(question)))
def open_partner(self, forum, partner_id=0, **post): if partner_id: partner = request.env['res.partner'].sudo().search([('id', '=', partner_id)]) if partner and partner.user_ids: return werkzeug.utils.redirect("/forum/%s/user/%d" % (slug(forum), partner.user_ids[0].id)) return werkzeug.utils.redirect("/forum/%s" % slug(forum))