Esempio n. 1
0
File: main.py Progetto: 10537/odoo
    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.render("website_forum.post_description_full", values)
Esempio n. 2
0
 def _get_slide_detail(self, slide):
     most_viewed_slides = slide._get_most_viewed_slides(self._slides_per_list)
     related_slides = slide._get_related_slides(self._slides_per_list)
     values = {
         'slide': slide,
         'most_viewed_slides': most_viewed_slides,
         'related_slides': related_slides,
         'user': request.env.user,
         'is_public_user': request.website.is_public_user(),
         'comments': slide.website_message_ids or [],
         'user_progress': {}
     }
     if slide.channel_id.channel_type == "training":
         channel_slides = slide.channel_id.slide_ids.ids
         slide_index = channel_slides.index(slide.id)
         previous_slide = None
         next_slide = None
         if slide_index > 0:
             previous_slide = slide.channel_id.slide_ids[slide_index-1]
         if slide_index < len(channel_slides) - 1:
             next_slide = slide.channel_id.slide_ids[slide_index+1]
         values.update({
             'previous_slide': slug(previous_slide) if previous_slide else "",
             'next_slide': slug(next_slide) if next_slide else ""
         })
     return values
Esempio n. 3
0
File: main.py Progetto: 10537/odoo
    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, header={'ask_hide': not forum.active})
        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.render("website_forum.forum_index", values)
Esempio n. 4
0
File: main.py Progetto: 10537/odoo
 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)
Esempio n. 5
0
File: main.py Progetto: 10537/odoo
 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)
Esempio n. 6
0
 def _compute_survey_url(self):
     """ Computes a public URL for the survey """
     base_url = '/' if self.env.context.get('relative_url') else \
                self.env['ir.config_parameter'].sudo().get_param('web.base.url')
     for survey in self:
         survey.public_url = urls.url_join(base_url, "survey/start/%s" % (slug(survey)))
         survey.print_url = urls.url_join(base_url, "survey/print/%s" % (slug(survey)))
         survey.result_url = urls.url_join(base_url, "survey/results/%s" % (slug(survey)))
         survey.public_url_html = '<a href="%s">%s</a>' % (survey.public_url, _("Click here to start survey"))
Esempio n. 7
0
File: main.py Progetto: 10537/odoo
 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
         body = tools.mail.plaintext2html(kwargs['comment'])
         post.with_context(mail_create_nosubscribe=True).message_post(
             body=body,
             message_type='comment',
             subtype='mt_comment')
     return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(question)))
Esempio n. 8
0
 def _get_menu_entries(self):
     self.ensure_one()
     res = super(Event, self)._get_menu_entries()
     if self.website_track:
         res += [
             (_('Talks'), '/event/%s/track' % slug(self), False),
             (_('Agenda'), '/event/%s/agenda' % slug(self), False)]
     if self.website_track_proposal:
         res += [(_('Talk Proposals'), '/event/%s/track_proposal' % slug(self), False)]
     return res
Esempio n. 9
0
File: main.py Progetto: 10537/odoo
 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 "/forum/%s" % slug(forum_id)
Esempio n. 10
0
File: main.py Progetto: 10537/odoo
 def post_save(self, forum, post, **kwargs):
     if 'post_name' in kwargs and not kwargs.get('post_name').strip():
         return request.render('website.http_error', {'status_code': _('Bad Request'), 'status_message': _('Title should not be empty.')})
     post_tags = forum._tag_to_write_vals(kwargs.get('post_tags', ''))
     vals = {
         'tag_ids': post_tags,
         'name': kwargs.get('post_name'),
         'content': kwargs.get('content'),
         'content_link': kwargs.get('content_link'),
     }
     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)))
Esempio n. 11
0
 def _compute_website_url(self):
     super(Slide, self)._compute_website_url()
     base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
     for slide in self:
         if slide.id:  # avoid to perform a slug on a not yet saved record in case of an onchange.
             # link_tracker is not in dependencies, so use it to shorten url only if installed.
             if self.env.registry.get('link.tracker'):
                 url = self.env['link.tracker'].sudo().create({
                     'url': '%s/slides/slide/%s' % (base_url, slug(slide)),
                     'title': slide.name,
                 }).short_url
             else:
                 url = '%s/slides/slide/%s' % (base_url, slug(slide))
             slide.website_url = url
Esempio n. 12
0
    def _set_website_menu(self):
        for event in self:
            if event.menu_id and not event.website_menu:
                event.menu_id.unlink()
            elif event.website_menu:
                if not event.menu_id:
                    root_menu = self.env['website.menu'].create({'name': event.name})
                    event.menu_id = root_menu

                existing_page_names = event.menu_id.child_id.mapped('name')
                required_page_names = [entry[0] for entry in self._get_menu_entries()]
                standard_page_names = self._get_standard_menu_entries_names()

                # remove entries that should not exist anymore
                submenu_to_delete = event.menu_id.child_id.filtered(lambda menu: menu.name not in required_page_names and menu.name in standard_page_names)
                submenu_to_delete.unlink()

                # create missing entries
                for sequence, (name, url, xml_id) in enumerate(self._get_menu_entries()):
                    if name not in existing_page_names:
                        if not url:
                            newpath = self.env['website'].new_page(name + ' ' + self.name, template=xml_id, ispage=False)['url']
                            url = "/event/" + slug(self) + "/page/" + newpath[1:]
                        self.env['website.menu'].create({
                            'name': name,
                            'url': url,
                            'parent_id': event.menu_id.id,
                            'sequence': sequence,
                        })
Esempio n. 13
0
    def _get_categorized_slides(self, base_domain, order, force_void=True, limit=False, offset=False):
        """ Return an ordered structure of slides by categories within a given
        base_domain that must fulfill slides. """
        self.ensure_one()
        all_categories = self.env['slide.category'].search([('channel_id', '=', self.id)])
        all_slides = self.env['slide.slide'].sudo().search(base_domain, order=order)
        category_data = []

        # First add uncategorized slides
        uncategorized_slides = all_slides.filtered(lambda slide: not slide.category_id)
        if uncategorized_slides or force_void:
            category_data.append({
                'category': False, 'id': False,
                'name': _('Uncategorized'), 'slug_name': _('Uncategorized'),
                'total_slides': len(uncategorized_slides),
                'slides': uncategorized_slides[(offset or 0):(offset + limit or len(uncategorized_slides))],
            })
        # Then all categories by natural order
        for category in all_categories:
            category_slides = all_slides.filtered(lambda slide: slide.category_id == category)
            if not category_slides and not force_void:
                continue
            category_data.append({
                'category': category, 'id': category.id,
                'name': category.name, 'slug_name': slug(category),
                'total_slides': len(category_slides),
                'slides': category_slides[(offset or 0):(limit + offset or len(category_slides))],
            })
        return category_data
Esempio n. 14
0
File: main.py Progetto: 1806933/odoo
    def thread_headers(self, group, page=1, mode='thread', date_begin=None, date_end=None, **post):
        if group.channel_type != 'channel':
            raise werkzeug.exceptions.NotFound()

        Message = request.env['mail.message']

        domain = [('model', '=', 'mail.channel'), ('res_id', '=', group.id), ('message_type', '!=', 'notification')]
        if mode == 'thread':
            domain += [('parent_id', '=', False)]
        if date_begin and date_end:
            domain += [('date', '>=', date_begin), ('date', '<=', date_end)]

        pager = request.website.pager(
            url='/groups/%s' % slug(group),
            total=Message.search_count(domain),
            page=page,
            step=self._thread_per_page,
            url_args={'mode': mode, 'date_begin': date_begin or '', 'date_end': date_end or ''},
        )
        messages = Message.search(domain, limit=self._thread_per_page, offset=pager['offset'])
        values = {
            'messages': messages,
            'group': group,
            'pager': pager,
            'mode': mode,
            'archives': self._get_archives(group.id),
            'date_begin': date_begin,
            'date_end': date_end,
            'replies_per_page': self._replies_per_page,
        }
        return request.render('website_mail_channel.group_messages', values)
Esempio n. 15
0
File: main.py Progetto: initOS/odoo
 def add_product(self, name=None, category=0, **post):
     product = request.env['product.product'].create({
         'name': name or _("New Product"),
         'public_categ_ids': category,
         'website_id': request.website.id,
     })
     return "/shop/product/%s?enable_editor=1" % slug(product.product_tmpl_id)
Esempio n. 16
0
File: main.py Progetto: 1806933/odoo
 def sitemap_slide(env, rule, qs):
     Channel = env['slide.channel']
     dom = sitemap_qs2dom(qs=qs, route='/slides/', field=Channel._rec_name)
     for channel in Channel.search(dom):
         loc = '/slides/%s' % slug(channel)
         if not qs or qs.lower() in loc:
             yield {'loc': loc}
Esempio n. 17
0
    def users(self, forum, page=1, **searches):
        User = request.env['res.users']
        step = 30
        dom = [('karma', '>', 1), ('website_published', '=', True)]
        tag_count = User.sudo().search_count(dom)
        pager = request.website.pager(url="/forum/%s/users" % slug(forum), total=tag_count, page=page, step=step, scope=30)

        if searches.get('user'):
            dom += [('name', 'ilike', searches.get('user'))]

        user_obj = User.sudo().search(dom, limit=step, offset=pager['offset'], order='karma DESC')
        # put the users in block of 3 to display them as a table
        users = [[] for i in range(len(user_obj) // 3 + 1)]
        for index, user in enumerate(user_obj):
            users[index // 3].append(user)
        searches['users'] = 'True'
        values = self._prepare_forum_values(forum=forum, searches=searches)
        values .update({
            'users': users,
            'main_object': forum,
            'notifications': self._get_notifications(),
            'pager': pager,
        })

        return request.render("website_forum.users", values)
Esempio n. 18
0
File: main.py Progetto: 10537/odoo
 def sitemap_forum(env, rule, qs):
     Forum = env['forum.forum']
     dom = sitemap_qs2dom(qs, '/forum', Forum._rec_name)
     for f in Forum.search(dom):
         loc = '/forum/%s' % slug(f)
         if not qs or qs.lower() in loc:
             yield {'loc': loc}
Esempio n. 19
0
 def _notify_email_header_dict(self):
     headers = super(MailGroup, self)._notify_email_header_dict()
     base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
     headers['List-Archive'] = '<%s/groups/%s>' % (base_url, slug(self)),
     headers['List-Subscribe'] = '<%s/groups>' % (base_url),
     headers['List-Unsubscribe'] = '<%s/groups?unsubscribe>' % (base_url,),
     return headers
Esempio n. 20
0
    def test_08_survey_urls(self):
        def validate_url(url):
            """ Reference: https://github.com/django/django/blob/master/django/core/validators.py """
            url_regex = re.compile(
                r'^https?://'  # http:// or https://
                r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|'  # domain...
                r'localhost|'  # localhost...
                r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|'  # ...or ipv4
                r'\[?[A-F0-9]*:[A-F0-9:]+\]?)'  # ...or ipv6
                r'(?::\d+)?'  # optional port
                r'(?:/?|[/?]\S+)$', re.IGNORECASE)
            return True if url_regex.match(url) else False

        base_url = self.env['ir.config_parameter'].get_param('web.base.url')
        urltypes = {'public': 'start', 'print': 'print', 'result': 'results'}
        for urltype, urltxt in pycompat.items(urltypes):
            survey_url = getattr(self.survey1, urltype + '_url')
            survey_url_relative = getattr(self.survey1.with_context({'relative_url': True}), urltype + '_url')
            self.assertTrue(validate_url(survey_url))
            url = "survey/%s/%s" % (urltxt, slug(self.survey1))
            full_url = urls.url_join(base_url, url)
            self.assertEqual(full_url, survey_url)
            self.assertEqual('/' + url, survey_url_relative)
            if urltype == 'public':
                url_html = '<a href="%s">Click here to start survey</a>'
                self.assertEqual(url_html % full_url, getattr(self.survey1, urltype + '_url_html'), msg="Public URL is incorrect")
                self.assertEqual(url_html % ('/' + url), getattr(self.survey1.with_context({'relative_url': True}), urltype + '_url_html'), msg="Public URL is incorrect.")
Esempio n. 21
0
    def add_category(self, channel_id, name, **kw):
        channel = request.env['slide.channel'].browse(channel_id)
        request.env['slide.category'].create({
            'name': name,
            'channel_id': channel.id
        })

        return {'url': "/slides/%s" %(slug(channel))}
Esempio n. 22
0
 def tags_list(tag_ids, current_tag):
     tag_ids = list(tag_ids) # required to avoid using the same list
     if current_tag in tag_ids:
         tag_ids.remove(current_tag)
     else:
         tag_ids.append(current_tag)
     tag_ids = request.env['blog.tag'].browse(tag_ids).exists()
     return ','.join(slug(tag) for tag in tag_ids)
Esempio n. 23
0
 def sitemap_forum(env, rule, qs):
     Forum = env['forum.forum']
     dom = sitemap_qs2dom(qs, '/forum', Forum._rec_name)
     dom += env['website'].get_current_website().website_domain()
     for f in Forum.search(dom):
         loc = '/forum/%s' % slug(f)
         if not qs or qs.lower() in loc:
             yield {'loc': loc}
Esempio n. 24
0
File: main.py Progetto: 10537/odoo
 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.render("website_forum.new_%s" % post_type, values)
Esempio n. 25
0
    def create_slide(self, *args, **post):
        # check the size only when we upload a file.
        if post.get('datas'):
            file_size = len(post['datas']) * 3 / 4  # base64
            if (file_size / 1024.0 / 1024.0) > 25:
                return {'error': _('File is too big. File size cannot exceed 25MB')}

        values = dict((fname, post[fname]) for fname in self._get_valid_slide_post_values() if post.get(fname))

        if post.get('category_id'):
            if post['category_id'][0] == 0:
                values['category_id'] = request.env['slide.category'].create({
                    'name': post['category_id'][1]['name'],
                    'channel_id': values.get('channel_id')}).id
            else:
                values['category_id'] = post['category_id'][0]

        values['is_preview'] = post.get('is_preview') == 'true'

        # handle exception during creation of slide and sent error notification to the client
        # otherwise client slide create dialog box continue processing even server fail to create a slide
        try:
            channel = request.env['slide.channel'].browse(values['channel_id'])
            can_upload = channel.can_upload
            can_publish = channel.can_publish
        except (UserError, AccessError) as e:
            _logger.error(e)
            return {'error': e.name}
        else:
            if not can_upload:
                return {'error': _('You cannot upload on this channel.')}

        try:
            values['user_id'] = request.env.uid
            values['website_published'] = values.get('website_published', False) and can_publish
            slide = request.env['slide.slide'].sudo().create(values)
        except (UserError, AccessError) as e:
            _logger.error(e)
            return {'error': e.name}
        except Exception as e:
            _logger.error(e)
            return {'error': _('Internal server error, please try again later or contact administrator.\nHere is the error message: %s') % e}

        redirect_url = "/slides/slide/%s" % (slide.id)
        if channel.channel_type == "training" and not slide.slide_type == "webpage":
            redirect_url = "/slides/%s" % (slug(channel))
        if slide.slide_type == 'webpage':
            redirect_url += "?enable_editor=1"
        if slide.slide_type == "quiz":
            action_id = request.env.ref('website_slides.action_slides_slides').id
            redirect_url = '/web#id=%s&action=%s&model=slide.slide&view_type=form' %(slide.id,action_id)
        return {
            'url': redirect_url,
            'channel_type': channel.channel_type,
            'slide_id': slide.id,
            'category_id': slide.category_id
            }
Esempio n. 26
0
File: main.py Progetto: Gorrice/odoo
    def sitemap_industry(env, rule, qs):
        if not qs or qs.lower() in '/customers':
            yield {'loc': '/customers'}

        Industry = env['res.partner.industry']
        dom = sitemap_qs2dom(qs, '/customers/industry', Industry._rec_name)
        for industry in Industry.search(dom):
            loc = '/customers/industry/%s' % slug(industry)
            if not qs or qs.lower() in loc:
                yield {'loc': loc}

        dom = [('website_published', '=', True), ('assigned_partner_id', '!=', False), ('country_id', '!=', False)]
        dom += sitemap_qs2dom(qs, '/customers/country')
        countries = env['res.partner'].sudo().read_group(dom, ['id', 'country_id'], groupby='country_id')
        for country in countries:
            loc = '/customers/country/%s' % slug(country['country_id'])
            if not qs or qs.lower() in loc:
                yield {'loc': loc}
Esempio n. 27
0
    def blog_post_copy(self, blog_post_id, **post):
        """ Duplicate a blog.

        :param blog_post_id: id of the blog post currently browsed.

        :return redirect to the new blog created
        """
        new_blog_post = request.env['blog.post'].with_context(mail_create_nosubscribe=True).browse(int(blog_post_id)).copy()
        return werkzeug.utils.redirect("/blog/%s/post/%s?enable_editor=1" % (slug(new_blog_post.blog_id), slug(new_blog_post)))
Esempio n. 28
0
File: event.py Progetto: Vauxoo/odoo
 def _get_menu_entries(self):
     """ Method returning menu entries to display on the website view of the
     event, possibly depending on some options in inheriting modules. """
     self.ensure_one()
     return [
         (_('Introduction'), False, 'website_event.template_intro'),
         (_('Location'), False, 'website_event.template_location'),
         (_('Register'), '/event/%s/register' % slug(self), False),
     ]
Esempio n. 29
0
File: main.py Progetto: 1806933/odoo
    def sitemap_partners(env, rule, qs):
        if not qs or qs.lower() in '/partners':
            yield {'loc': '/partners'}

        Grade = env['res.partner.grade']
        dom = [('website_published', '=', True)]
        dom += sitemap_qs2dom(qs=qs, route='/partners/grade/', field=Grade._rec_name)
        for grade in env['res.partner.grade'].search(dom):
            loc = '/partners/grade/%s' % slug(grade)
            if not qs or qs.lower() in loc:
                yield {'loc': loc}

        partners_dom = [('is_company', '=', True), ('grade_id', '!=', False), ('website_published', '=', True), ('grade_id.website_published', '=', True)]
        dom += sitemap_qs2dom(qs=qs, route='/partners/country/')
        countries = env['res.partner'].sudo().read_group(partners_dom, fields=['id', 'country_id'], groupby='country_id')
        for country in countries:
            loc = '/partners/country/%s' % slug(country['country_id'])
            if not qs or qs.lower() in loc:
                yield {'loc': loc}
Esempio n. 30
0
    def post_create(self, forum, post_parent=None, **post):
        if post.get('content', '') == '<p><br></p>':
            return request.render('website.http_error', {
                'status_code': _('Bad Request'),
                'status_message': post_parent and _('Reply should not be empty.') or _('Question should not be empty.')
            })

        post_tag_ids = forum._tag_to_write_vals(post.get('post_tags', ''))

        if request.env.user.forum_waiting_posts_count:
            return werkzeug.utils.redirect("/forum/%s/ask" % slug(forum))

        new_question = request.env['forum.post'].create({
            'forum_id': forum.id,
            'name': post.get('post_name') or (post_parent and 'Re: %s' % (post_parent.name or '')) or '',
            'content': post.get('content', False),
            'parent_id': post_parent and post_parent.id or False,
            'tag_ids': post_tag_ids
        })
        return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), post_parent and slug(post_parent) or new_question.id))
Esempio n. 31
0
 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)))
Esempio n. 32
0
 def question_reopen(self, forum, question, **kwarg):
     question.reopen()
     return werkzeug.utils.redirect("/forum/%s/question/%s" %
                                    (slug(forum), slug(question)))
Esempio n. 33
0
 def question_undelete(self, forum, question, **kwarg):
     question.active = True
     return werkzeug.utils.redirect("/forum/%s/question/%s" %
                                    (slug(forum), slug(question)))
Esempio n. 34
0
 def add_event(self, event_name="New Event", **kwargs):
     event = self._add_event(event_name, request.context)
     return "/event/%s/register?enable_editor=1" % slug(event)
Esempio n. 35
0
 def _get_track_proposal_menu_entries(self):
     self.ensure_one()
     res = [(_('Talk Proposals'), '/event/%s/track_proposal' % slug(self), False, 'track_proposal')]
     return res
Esempio n. 36
0
 def slide_channel_create(self, *args, **kw):
     channel = request.env['slide.channel'].create(self._slide_channel_prepare_values(**kw))
     return werkzeug.utils.redirect("/slides/%s" % (slug(channel)))
Esempio n. 37
0
 def add_event(self, name, event_start, event_end, address_values,
               **kwargs):
     values = self._prepare_event_values(name, event_start, event_end,
                                         address_values)
     event = request.env['event.event'].create(values)
     return "/event/%s/register?enable_editor=1" % slug(event)
Esempio n. 38
0
 def _compute_website_url(self):
     super(Track, self)._compute_website_url()
     for track in self:
         if not isinstance(track.id, models.NewId):
             track.website_url = '/event/%s/track/%s' % (slug(
                 track.event_id), slug(track))
Esempio n. 39
0
 def slide_set_completed_and_redirect(self, slide, next_slide_id=None):
     self._set_completed_slide(slide)
     next_slide = None
     if next_slide_id:
         next_slide = self._fetch_slide(next_slide_id).get('slide', None)
     return werkzeug.utils.redirect("/slides/slide/%s" % (slug(next_slide) if next_slide else slug(slide)))
Esempio n. 40
0
 def _compute_website_url(self):
     super(Event, self)._compute_website_url()
     for event in self:
         if event.id:  # avoid to perform a slug on a not yet saved record in case of an onchange.
             event.website_url = '/event/%s' % slug(event)
Esempio n. 41
0
 def _compute_website_url(self):
     super(Plants, self)._compute_website_url()
     for plant in self:
         if plant.id:
             plant.website_url = '/plant/%s' % slug(plant)
Esempio n. 42
0
    def shop(self, page=0, category=None, search='', ppg=False, **post):
        if ppg:
            try:
                ppg = int(ppg)
            except ValueError:
                ppg = PPG
            post["ppg"] = ppg
        else:
            ppg = PPG

        if category:
            category = request.env['product.public.category'].search([('id', '=', int(category))], limit=1)
            if not category:
                raise NotFound()

        attrib_list = request.httprequest.args.getlist('attrib')
        attrib_values = [[int(x) for x in v.split("-")] for v in attrib_list if v]
        attributes_ids = {v[0] for v in attrib_values}
        attrib_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, order=post.get('order'))

        compute_currency, pricelist_context, pricelist = self._get_compute_currency_and_context()

        request.context = dict(request.context, pricelist=pricelist.id, partner=request.env.user.partner_id)

        url = "/shop"
        if search:
            post["search"] = search
        if attrib_list:
            post['attrib'] = attrib_list

        categs = request.env['product.public.category'].search([('parent_id', '=', False)])
        Product = request.env['product.template']

        parent_category_ids = []
        if category:
            url = "/shop/category/%s" % slug(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

        product_count = Product.search_count(domain)
        pager = request.website.pager(url=url, total=product_count, page=page, step=ppg, scope=7, url_args=post)
        products = Product.search(domain, limit=ppg, offset=pager['offset'], order=self._get_search_order(post))

        ProductAttribute = request.env['product.attribute']
        if products:
            # get all products without limit
            selected_products = Product.search(domain, limit=False)
            attributes = ProductAttribute.search([('attribute_line_ids.product_tmpl_id', 'in', selected_products.ids)])
        else:
            attributes = ProductAttribute.browse(attributes_ids)

        values = {
            'search': search,
            'category': category,
            'attrib_values': attrib_values,
            'attrib_set': attrib_set,
            'pager': pager,
            'pricelist': pricelist,
            'products': products,
            'search_count': product_count,  # common for all searchbox
            'bins': TableCompute().process(products, ppg),
            'rows': PPR,
            'categories': categs,
            'attributes': attributes,
            'compute_currency': compute_currency,
            'keep': keep,
            'parent_category_ids': parent_category_ids,
        }
        if category:
            values['main_object'] = category
        return request.render("website_sale.products", values)
Esempio n. 43
0
    def _get_categorized_slides(self,
                                base_domain,
                                order,
                                force_void=True,
                                limit=False,
                                offset=False):
        """ Return an ordered structure of slides by categories within a given
        base_domain that must fulfill slides. As a course structure is based on
        its slides sequences, uncategorized slides must have the lowest sequences.

        Example
          * category 1 (sequence 1), category 2 (sequence 3)
          * slide 1 (sequence 0), slide 2 (sequence 2)
          * course structure is: slide 1, category 1, slide 2, category 2
            * slide 1 is uncategorized,
            * category 1 has one slide : Slide 2
            * category 2 is empty.

        Backend and frontend ordering is the same, uncategorized first. It
        eases resequencing based on DOM / displayed order, notably when
        drag n drop is involved. """
        self.ensure_one()
        all_categories = self.env['slide.slide'].sudo().search([
            ('channel_id', '=', self.id), ('is_category', '=', True)
        ])
        all_slides = self.env['slide.slide'].sudo().search(base_domain,
                                                           order=order)
        category_data = []

        # Prepare all categories by natural order
        for category in all_categories:
            category_slides = all_slides.filtered(
                lambda slide: slide.category_id == category)
            if not category_slides and not force_void:
                continue
            category_data.append({
                'category':
                category,
                'id':
                category.id,
                'name':
                category.name,
                'slug_name':
                slug(category),
                'total_slides':
                len(category_slides),
                'slides':
                category_slides[(offset or 0):(
                    limit + offset or len(category_slides))],
            })

        # Add uncategorized slides in first position
        uncategorized_slides = all_slides.filtered(
            lambda slide: not slide.category_id)
        if uncategorized_slides or force_void:
            category_data.insert(
                0, {
                    'category':
                    False,
                    'id':
                    False,
                    'name':
                    _('Uncategorized'),
                    'slug_name':
                    _('Uncategorized'),
                    'total_slides':
                    len(uncategorized_slides),
                    'slides':
                    uncategorized_slides[(offset or 0):(
                        offset + limit or len(uncategorized_slides))],
                })

        return category_data
Esempio n. 44
0
 def slide_channel_join_http(self, channel_id):
     # TDE FIXME: why 2 routes ?
     if not request.website.is_public_user():
         channel = request.env['slide.channel'].browse(int(channel_id))
         channel.action_add_member()
     return werkzeug.utils.redirect("/slides/%s" % (slug(channel)))
Esempio n. 45
0
 def qrcode(self, tenant, package):
     return werkzeug.utils.redirect('/boxwise/labeling/%s' % slug(package))
Esempio n. 46
0
 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)))
Esempio n. 47
0
    def questions(self,
                  forum,
                  tag=None,
                  page=1,
                  filters='all',
                  my=None,
                  sorting=None,
                  search='',
                  **post):
        if not forum.can_access_from_current_website():
            raise werkzeug.exceptions.NotFound()

        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 == 'solved':
            domain += [('has_validated_answer', '=', True)]
        elif filters == 'unsolved':
            domain += [('has_validated_answer', '=', False)]

        user = request.env.user

        if my == 'mine':
            domain += [('create_uid', '=', user.id)]
        elif my == 'followed':
            domain += [('message_partner_ids', '=', user.partner_id.id)]
        elif my == 'tagged':
            domain += [('tag_ids.message_partner_ids', '=', user.partner_id.id)
                       ]
        elif my == 'favourites':
            domain += [('favourite_ids', '=', user.id)]

        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
        if my:
            url_args['my'] = my
        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_user_values(
            forum=forum, searches=post, header={'ask_hide': not forum.active})
        values.update({
            'main_object': tag or forum,
            'edit_in_backend': not tag,
            'question_ids': question_ids,
            'question_count': question_count,
            'pager': pager,
            'tag': tag,
            'filters': filters,
            'my': my,
            'sorting': sorting,
            'search': search,
        })
        return request.render("website_forum.forum_index", values)
Esempio n. 48
0
 def _get_track_menu_entries(self):
     self.ensure_one()
     res = [
         (_('Talks'), '/event/%s/track' % slug(self), False, 'track'),
         (_('Agenda'), '/event/%s/agenda' % slug(self), False, 'track')]
     return res
Esempio n. 49
0
 def _compute_website_url(self):
     super(BlogPost, self)._compute_website_url()
     for blog_post in self:
         blog_post.website_url = "/blog/%s/post/%s" % (slug(
             blog_post.blog_id), slug(blog_post))
Esempio n. 50
0
    def submit_other_info(self, **kwargs):
        vacancy = request.env['hr.job'].sudo().search([("id","=",kwargs.get('vacancy'))])
        partner_id = request.env.user.partner_id

        if kwargs.get('country_name'):
            country_id = request.env['res.country'].create({'name': kwargs.get('country_name')})
        elif kwargs.get('country'):
            country_id = request.env['res.country'].search([("id","=",kwargs.get('country'))])
        else:
            country_id = None

        if country_id:
            partner_id['birth_country_id'] = country_id
            if kwargs.get('state_name'):
                state_id = request.env['res.country.state'].create({
                    'name': kwargs.get('country_name'), 'country_id':country_id.id})
            elif kwargs.get('state'):
                state_id = request.env['res.country.state'].search([("id","=",kwargs.get('state'))])
            else:
                state_id = None
            
            if state_id:
                partner_id['birth_state_id'] = state_id
                if kwargs.get('city_name'):
                    city_id = request.env['res.city'].create({
                        'name': kwargs.get('city_name'), 'state_id':state_id.id})
                elif kwargs.get('city'):
                    city_id = request.env['res.city'].search([("id","=",kwargs.get('city'))])
                else:
                    city_id = None
                if city_id:
                    partner_id['birth_city_id'] = city_id
                
        if kwargs.get('citizen_name'):
            citizenship_id = request.env['res.country'].create({'name': kwargs.get('citizen_name')})
        elif kwargs.get('citizenship'):
            citizenship_id = request.env['res.country'].search([("id","=",kwargs.get('citizenship'))])
        else:
            citizenship_id = None
        if citizenship_id:
            partner_id['citizenship_id'] = citizenship_id

        if kwargs.get('religion_name'):
            religion_id = request.env['res.religion'].create({'name': kwargs.get('religion_name')})
        elif kwargs.get('religion'):
            religion_id = request.env['res.religion'].search([("id","=",kwargs.get('religion'))])
        else:
            religion_id = None
        if religion_id:
            partner_id['religion_id'] = religion_id

        if kwargs.get('ethnic_name'):
            ethnic_id = request.env['res.ethnic'].create({'name': kwargs.get('ethnic_name')})
        elif kwargs.get('ethnic'):
            ethnic_id = request.env['res.ethnic'].search([("id","=",kwargs.get('ethnic'))])
        else:
            ethnic_id = None
        if ethnic_id:
            partner_id['ethnic_id'] = ethnic_id

        if kwargs.get('birthday'):
            try:
                partner_id['birthday'] =  kwargs.get('birthday')
            except ValueError:
                error_fields.append(birthday)

        partner_id.update({
            'gender': kwargs.get('gender'),
            'marital': kwargs.get('marital'),
            'dependents': kwargs.get('dependents'),
            'height': kwargs.get('height'),
            'weight': kwargs.get('weight'),
            'blood': kwargs.get('blood'),
            'smoker': kwargs.get('smoker'),
        })
        if kwargs.get('word') == 'vacancy':
            return request.redirect('/new/vacancy')
        else:
            return request.redirect('/apply/vacancy/%s' % slug(vacancy))
Esempio n. 51
0
    def partners(self, country=None, grade=None, page=0, **post):
        country_all = post.pop('country_all', False)
        partner_obj = request.env['res.partner']
        country_obj = request.env['res.country']
        search = post.get('search', '')

        base_partner_domain = [('is_company', '=', True),
                               ('grade_id', '!=', False),
                               ('website_published', '=', True)]
        if not request.env['res.users'].has_group(
                'website.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 = country_obj.search([('code', '=', country_code)],
                                             limit=1)
        if country:
            grade_domain += [('country_id', '=', country.id)]
        grades = partner_obj.sudo().read_group(grade_domain,
                                               ["id", "grade_id"],
                                               groupby="grade_id")
        grades_partners = partner_obj.sudo().search_count(grade_domain)
        # 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.sudo().read_group(country_domain,
                                                  ["id", "country_id"],
                                                  groupby="country_id",
                                                  orderby="country_id")
        countries_partners = partner_obj.sudo().search_count(country_domain)
        # 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.sudo().search_count(base_partner_domain)
        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.sudo().search(
            base_partner_domain,
            order=
            "grade_sequence DESC, implemented_count DESC, display_name ASC, id ASC",
            offset=pager['offset'],
            limit=self._references_per_page)
        partners = partner_ids.sudo()

        google_map_partner_ids = ','.join(str(p.id) for p in partners)
        google_maps_api_key = request.website.google_maps_api_key

        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.urls.url_encode(post),
            'google_maps_api_key': google_maps_api_key,
        }
        return request.render("website_crm_partner_assign.index",
                              values,
                              status=partners and 200 or 404)
Esempio n. 52
0
    def apply(self, vacancy, **kwargs):
        partner = request.env.user.partner_id
        vacancy = request.env['hr.job'].sudo().search([("id","=",vacancy.id)])
        request.env['hr_apply.tryapply'].sudo().search([("job_id","=",vacancy.id), ("partner_id","=",partner.id)]).unlink()
        
        if not partner.street or not partner.email or not partner.description:
            request.env['hr_apply.tryapply'].create({'partner_id': partner.id,'job_id': vacancy.id})
            return request.redirect('/edit/informations/%s' % slug(vacancy))
        
        if not partner.identification_no or not partner.alias_id or not partner.alias_id.street:
            request.env['hr_apply.tryapply'].create({'partner_id': partner.id,'job_id': vacancy.id})
            return request.redirect('/edit/identity/%s' % slug(vacancy))
        
        if not partner.birthday or not partner.gender or not partner.marital:
            request.env['hr_apply.tryapply'].create({'partner_id': partner.id,'job_id': vacancy.id})
            return request.redirect('/edit/otherinfo/%s' % slug(vacancy))

        application = request.env['hr_apply.applicant'].sudo().search([("job_id","=",vacancy.id), ("partner_id","=",partner.id)])
        if application:
            application.update({
                    'name': partner.name,
                    'partner_id': partner.id,
                    'job_id': vacancy.id,
                    'job_owner_id': vacancy.user_id.id,
                    'create_date': datetime.now(),
            })
        if not application:
            application = request.env['hr_apply.applicant'].create({
                'name': partner.name,
                'partner_id': partner.id,
                'job_id': vacancy.id,
                'job_owner_id': vacancy.user_id.id,
                'create_date': datetime.now(),
            })

        criteria_total = 0
        criteria_match = 0
        qualification_total = 0
        qualification_match = 0
        match = 0
        
        if vacancy.criteria_ids:
            for criteria in vacancy.criteria_ids:
                match = 0
                for score in partner.classification_score_ids:
                    if criteria.classification_method_id == score.classification_method_id:
                        match += 1
                if match == 0:
                    questionaire = request.env['questionaire.questionaire'].search([("classification_method_id","=",criteria.classification_method_id.id)])
                    vals = {'questionaire_id': questionaire.id}
                    UserInput = request.env['questionaire.user_input']
                    if request.website.user_id != request.env.user:
                        vals['partner_id'] = request.env.user.partner_id.id
                    user_input = UserInput.create(vals)
                    request.env['hr_apply.tryapply'].create({'partner_id': partner.id,'job_id': vacancy.id})
                    return request.redirect('/apply/vacancy/%s/questionaire/fill/%s/%s' % (vacancy.id, questionaire.id, user_input.token))

        request.env['hr_apply.criteriascore'].sudo().search([('applicant_id','=',application.id)]).unlink()
        if vacancy.criteria_ids:
            for criteria in vacancy.criteria_ids:
                criteria_total += 2
                for score in partner.classification_score_ids:
                    if score.classification_id == criteria.classification_id:
                        if score.score >= criteria.classification_method_id.excellent_score:
                            match = 2
                        elif score.score <= criteria.classification_method_id.poor_score:
                            match = 0
                        else:
                            match = 1
                request.env['hr_apply.criteriascore'].create({
                    'partner_id': partner.id,
                    'criteria_id': criteria.id,
                    'applicant_id': application.id,
                    'score': match})
                criteria_match += match

        if vacancy.min_age or vacancy.max_age:
            qualification_total += 1
            applicant_age = int(relativedelta(datetime.now(),fields.Datetime.from_string(partner.birthday)).years)
            application['applicant_age'] = applicant_age
            qualified_age = True
            
            if vacancy.min_age:
                if applicant_age < int(vacancy.min_age):
                    qualified_age = False
            if vacancy.max_age:
                if applicant_age > int(vacancy.max_age):
                    qualified_age = False
            application['qualified_age']=qualified_age
            if qualified_age == True:
                qualification_match += 1
        
        if vacancy.ethnic_id:
            qualification_total += 1
            if vacancy.ethnic_id == partner.ethnic_id:
                application['qualified_ethnic']=True
                qualification_match += 1
            else:
                application['qualified_ethnic']=False
            
        if vacancy.religion_id:
            qualification_total += 1
            if vacancy.religion_id == partner.religion_id:
                application['qualified_religion']=True
                qualification_match += 1
            else:
                application['qualified_religion']=False
        
        if vacancy.country_id:
            qualification_total += 1
            if vacancy.country_id == partner.country_id:
                application['qualified_country']=True
                qualification_match += 1
            else:
                application['qualified_country']=False
        
        if vacancy.state_id:
            qualification_total += 1
            if vacancy.state_id == partner.state_id:
                application['qualified_state']=True
                qualification_match += 1
            else:
                application['qualified_state']=False
        
        if vacancy.city_id:
            qualification_total += 1
            if vacancy.city_id == partner.city_id:
                application['qualified_city']=True
                qualification_match += 1
            else:
                application['qualified_city']=False
        
        if vacancy.district_id:
            qualification_total += 1
            if vacancy.district_id == partner.district_id:
                application['qualified_district']=True
                qualification_match += 1
            else:
                application['qualified_district']=False
        
        if vacancy.village_id:
            qualification_total += 1
            if vacancy.village_id == partner.village_id:
                application['qualified_village']=True
                qualification_match += 1
            else:
                application['qualified_village']=False
        
        if vacancy.area_id:
            qualification_total += 1
            if vacancy.area_id == partner.area_id:
                application['qualified_area']=True
                qualification_match += 1
            else:
                application['qualified_area']=False
        
        application.qualified_tool_ids.unlink()
        if vacancy.required_tools_ids:
            for a in vacancy.required_tools_ids:
                qualification_total += 1
                qualified_tool_id = request.env['hr_apply.qualified_tools'].create({
                    'applicant_id': application.id,
                    'object_id': a.id,
                })
                for b in partner.tools_ids:
                    if a.object_id == b.tooltype_id:
                        qualified_tool_id['qualified'] = True
                        qualification_match += 1
                        break
                    
        application.qualified_certificate_ids.unlink()
        if vacancy.required_certificate_ids:
            for a in vacancy.required_certificate_ids:
                qualification_total += 1
                qualified_certificate_id = request.env['hr_apply.qualified_certificate'].create({
                    'applicant_id': application.id,
                    'object_id': a.id,
                })
                for b in partner.certificate_ids:
                    if a.object_id == b.certificate_id:
                        qualified_certificate_id['qualified'] = True
                        qualification_match += 1
                        break

        application.qualified_lisence_ids.unlink()
        if vacancy.required_lisence_ids:
            for a in vacancy.required_lisence_ids:
                qualification_total += 1
                qualified_lisence_id = request.env['hr_apply.qualified_lisence'].create({
                    'applicant_id': application.id,
                    'object_id': a.id,
                })
                for b in partner.lisence_ids:
                    if a.object_id == b.lisence_id:
                        qualified_lisence_id['qualified'] = True
                        qualification_match += 1
                        break

        application.qualified_driving_lisence_ids.unlink()
        if vacancy.required_driving_lisence_ids:
            for a in vacancy.required_driving_lisence_ids:
                qualification_total += 1
                qualified_driving_lisence_id = request.env['hr_apply.qualified_driving_lisence'].create({
                    'applicant_id': application.id,
                    'object_id': a.id,
                })
                for b in partner.driving_lisence_ids:
                    if a.object_id == b.lisence_type_id:
                        qualified_driving_lisence_id['qualified'] = True
                        qualification_match += 1
                        break

        application.qualified_skill_ids.unlink()
        if vacancy.required_skill_ids:
            for a in vacancy.required_skill_ids:
                qualification_total += 1
                qualified_skill_id = request.env['hr_apply.qualified_skill'].create({
                    'applicant_id': application.id,
                    'object_id': a.id,
                })
                for b in partner.skill_ids:
                    if a.object_id == b.skill_id:
                        qualified_skill_id['qualified'] = True
                        qualification_match += 1
                        break

        application.qualified_langskill_ids.unlink()
        if vacancy.required_langskill_ids:
            for a in vacancy.required_langskill_ids:
                qualification_total += 1
                qualified_langskill_id = request.env['hr_apply.qualified_langskill'].create({
                    'applicant_id': application.id,
                    'object_id': a.id,
                })
                for b in partner.langskill_ids:
                    if a.object_id == b.language_id:
                        qualified_langskill_id['qualified'] = True
                        qualification_match += 1
                        break

        application.qualified_comskill_ids.unlink()
        if vacancy.required_comskill_ids:
            for a in vacancy.required_comskill_ids:
                qualification_total += 1
                qualified_comskill_id = request.env['hr_apply.qualified_comskill'].create({
                    'applicant_id': application.id,
                    'object_id': a.id,
                })
                for b in partner.comskill_ids:
                    if a.object_id == b.language_id:
                        qualified_comskill_id['qualified'] = True
                        qualification_match += 1
                        break
        
        application.qualified_school_ids.unlink()
        if vacancy.required_school_ids:
            qualification_total += 1
            for a in vacancy.required_school_ids:
                qualified_school_id = request.env['hr_apply.qualified_school'].create({
                    'applicant_id': application.id,
                    'object_id': a.id,
                })
                for b in partner.school_ids:
                    if a.object_id == b.stage_id:
                        qualified_school_id['qualified'] = True
                        break
            for c in application.qualified_school_ids:
                if c.qualified == True:
                    qualification_match += 1
                    break
        
        application.qualified_university_ids.unlink()
        if vacancy.required_university_ids:
            qualification_total += 1
            for a in vacancy.required_university_ids:
                qualified_university_id = request.env['hr_apply.qualified_university'].create({
                    'applicant_id': application.id,
                    'object_id': a.id,
                })
                for b in partner.university_ids:
                    if a.degree_id:
                        if a.degree_id == b.degree_id:
                            if a.faculty_id:
                                if a.faculty_id == b.faculty_id:
                                    if a.major_id:
                                        if a.major_id == b.major_id:
                                            qualified_university_id['qualified'] = True
                                            break
                                        else:
                                            qualified_university_id['qualified'] = False
                                            break
                                    else:
                                        qualified_university_id['qualified'] = True
                                        break
                                else:
                                    qualified_university_id['qualified'] = False
                                    break
                            else:
                                qualified_university_id['qualified'] = True
                                break
                        else:
                            qualified_university_id['qualified'] = False
                            break
                    if a.faculty_id:
                        if a.faculty_id == b.faculty_id:
                            if a.major_id:
                                if a.major_id == b.major_id:
                                    qualified_university_id['qualified'] = True
                                    break
                                else:
                                    qualified_university_id['qualified'] = False
                                    break
                            else:
                                qualified_university_id['qualified'] = True
                                break
                        else:
                            qualified_university_id['qualified'] = False
                            break
            for c in application.qualified_university_ids:
                if c.qualified == True:
                    qualification_match += 1
                    break

        application.qualified_experience_ids.unlink()
        if vacancy.required_experience_ids:
            qualification_total += 1
            for a in vacancy.required_experience_ids:
                qualified_experience_id = request.env['hr_apply.qualified_experience'].create({
                    'applicant_id': application.id,
                    'object_id': a.id,
                })
                for b in partner.experience_ids:
                    if a.joblevel_id:
                        if a.joblevel_id == b.level_id:
                            if a.department_id:
                                if a.department_id == b.department_id:
                                    if a.industry_id:
                                        if a.industry_id == b.industry_id:
                                            qualified_experience_id['age'] += self._calculate_experience_age(b=b)
                                    else:
                                        qualified_experience_id['age'] += self._calculate_experience_age(b=b)
                            elif a.industry_id:
                                if a.industry_id == b.industry_id:
                                    qualified_experience_id['age'] += self._calculate_experience_age(b=b)
                            else:
                                qualified_experience_id['age'] += self._calculate_experience_age(b=b)
                    elif a.department_id:
                        if a.department_id == b.department_id:
                            if a.industry_id:
                                if a.industry_id == b.industry_id:
                                    qualified_experience_id['age'] += self._calculate_experience_age(b=b)
                            else:
                                qualified_experience_id['age'] += self._calculate_experience_age(b=b)
                    elif a.industry_id:
                        if a.industry_id == b.industry_id:
                            qualified_experience_id['age'] += self._calculate_experience_age(b=b)
                    else:
                        qualified_experience_id['age'] += self._calculate_experience_age(b=b)
                if qualified_experience_id['age'] > a.min_exp:
                    qualified_experience_id['qualified'] = True            
            for c in application.qualified_experience_ids:
                if c.qualified == True:
                    qualification_match += 1
                    break

        if qualification_total == 0:
            qualification_score = 100
        else:
            qualification_score = qualification_match / qualification_total * 100

        if criteria_total == 0:
            criteria_score = 100
        else:
            criteria_score = criteria_match / criteria_total * 100

        total_score = qualification_score * criteria_score / 100

        application['qualification_score'] = qualification_score
        application['criteria_score'] = criteria_score
        application['total_score'] = total_score
        application['status'] = 'draft'

        domain = [("application_id", "=", application.id)]
        messages = request.env['hr_apply.interview']
        total = messages.search_count(domain)
        pager = request.website.pager(
            url=('/application/%s' % (application.id)),
            total=total,
            page=1,
            step=self._message_per_page,
        )
        interview_ids = messages.search(domain, offset=(0) * self._message_per_page, limit=self._message_per_page)
        
        values = {
            'partner_id': partner,
            'application': application,
            'vacancy': vacancy,
            'partner': partner,
            'interview_ids': interview_ids,
            'pager': pager,
        }
        
        return request.render("hr_apply.application_form", values)
Esempio n. 53
0
    def shop(self, page=0, category=None, search='', ppg=False, **post):
        res = super(GunwerksWebsiteSale, self).shop(page=page,
                                                    category=category,
                                                    search=search,
                                                    ppg=ppg,
                                                    **post)
        if ppg:
            try:
                ppg = int(ppg)
            except ValueError:
                ppg = PPG
            post["ppg"] = ppg
        else:
            ppg = PPG

        parent_categories = []
        if category:
            url = "/shop/category/%s" % slug(category)
            current_category = category
            while current_category.parent_id:
                parent_categories.append(current_category.parent_id)
                current_category = current_category.parent_id

            parent_categories.reverse()
            child_category_ids = request.env['product.public.category'].search(
                [('parent_id', '=', category.id)])

            filter_list = request.httprequest.args.getlist('filter')
            filter_values = [[int(x) for x in v.split("-")]
                             for v in filter_list if v]
            filter_ids = {v[0] for v in filter_values}
            filter_set = {v[1] for v in filter_values}

            domain = self._get_filter_domain(search, category, filter_values)

            Product = request.env['product.template']
            product_count = Product.search_count(domain)
            pager = request.website.pager(url=url,
                                          total=product_count,
                                          page=page,
                                          step=ppg,
                                          scope=7,
                                          url_args=post)
            products = Product.search(domain,
                                      limit=ppg,
                                      offset=pager['offset'],
                                      order=self._get_search_order(post))

            filter_dict = {}
            if products:
                for product in products:
                    if product.filter_line_ids:
                        for filters_id in product.filter_line_ids:
                            for dataid in filters_id.filter_id:
                                for datavalue in filters_id.value_ids:
                                    if dataid in filter_dict:
                                        filter_dict[dataid] += (datavalue)
                                    else:
                                        filter_dict[dataid] = (datavalue)
            final_filter_dict = {
                a: list(set(b))
                for a, b in filter_dict.items()
            }
            res.qcontext.update({
                'filter_dict': final_filter_dict,
                'filter_values': filter_values,
                'filter_set': filter_set,
                'products': products,
                'search_count': product_count,
                'bins': TableCompute().process(products, ppg),
                'parent_categories': parent_categories,
            })
        else:
            child_category_ids = request.env['product.public.category'].search(
                [('parent_id', '=', False)])
        if child_category_ids:
            res.qcontext.update({
                'child_categories': child_category_ids,
            })
        return res
Esempio n. 54
0
 def _compute_website_url(self):
     super(ResPartnerGrade, self)._compute_website_url()
     for grade in self:
         grade.website_url = "/partners/grade/%s" % (slug(grade))
Esempio n. 55
0
 def _compute_website_url(self):
     super(ProductTemplate, self)._compute_website_url()
     for product in self:
         product.website_url = "/shop/product/%s" % slug(product)
Esempio n. 56
0
 def _get_community_menu_entries(self):
     self.ensure_one()
     return [(_('Community'), '/event/%s/community' % slug(self), False, 80,
              'community')]
Esempio n. 57
0
    def Brand(self,
              brand=None,
              page=0,
              category=None,
              search='',
              ppg=False,
              **post):
        add_qty = int(post.get('add_qty', 1))
        Category = request.env['product.public.category']
        if category:
            category = Category.search([('id', '=', int(category))], limit=1)
            if not category or not category.can_access_from_current_website():
                raise NotFound()
        else:
            category = Category

        if ppg:
            try:
                ppg = int(ppg)
                post['ppg'] = ppg
            except ValueError:
                ppg = False
        if not ppg:
            ppg = request.env['website'].get_current_website().shop_ppg or 20

        ppr = request.env['website'].get_current_website().shop_ppr or 4

        attrib_list = request.httprequest.args.getlist('attrib')
        attrib_values = [[int(x) for x in v.split("-")] for v in attrib_list
                         if v]
        attributes_ids = {v[0] for v in attrib_values}
        attrib_set = {v[1] for v in attrib_values}

        domain = WebsiteSale._get_search_domain(self, search, category,
                                                attrib_values)

        # Set the brand product
        if brand:
            domain += [('product_brand_ept_id.id', '=', brand.id)]
        else:
            domain += [('product_brand_ept_id', '!=', False)]

        keep = QueryURL('/shop',
                        category=category and int(category),
                        search=search,
                        attrib=attrib_list,
                        order=post.get('order'))

        pricelist_context, pricelist = WebsiteSale._get_pricelist_context(self)

        request.context = dict(request.context,
                               pricelist=pricelist.id,
                               partner=request.env.user.partner_id)

        url = "/brand"
        if brand:
            url = "/brand/%s" % slug(brand)
        if search:
            post["search"] = search
        if attrib_list:
            post['attrib'] = attrib_list

        Product = request.env['product.template'].with_context(bin_size=True)

        search_product = Product.search(domain)
        website_domain = request.website.website_domain()
        categs_domain = [('parent_id', '=', False)] + website_domain
        if search:
            search_categories = Category.search(
                [('product_tmpl_ids', 'in', search_product.ids)] +
                website_domain).parents_and_self
            categs_domain.append(('id', 'in', search_categories.ids))
        else:
            search_categories = Category
        categs = Category.search(categs_domain)

        if category:
            url = "/shop/category/%s" % slug(category)

        product_count = len(search_product)
        pager = request.website.pager(url=url,
                                      total=product_count,
                                      page=page,
                                      step=ppg,
                                      scope=7,
                                      url_args=post)
        products = Product.search(domain,
                                  limit=ppg,
                                  offset=pager['offset'],
                                  order=WebsiteSale._get_search_order(
                                      self, post))

        ProductAttribute = request.env['product.attribute']
        if products:
            # get all products without limit
            attributes = ProductAttribute.search([('product_tmpl_ids', 'in',
                                                   search_product.ids)])
        else:
            attributes = ProductAttribute.browse(attributes_ids)

        layout_mode = request.session.get('website_sale_shop_layout_mode')
        if not layout_mode:
            if request.website.viewref(
                    'website_sale.products_list_view').active:
                layout_mode = 'list'
            else:
                layout_mode = 'grid'

        values = {
            'search': search,
            'category': category,
            'attrib_values': attrib_values,
            'attrib_set': attrib_set,
            'pager': pager,
            'pricelist': pricelist,
            'add_qty': add_qty,
            'products': products,
            'search_count': product_count,  # common for all searchbox
            'bins': TableCompute().process(products, ppg, ppr),
            'ppg': ppg,
            'ppr': ppr,
            'categories': categs,
            'attributes': attributes,
            'keep': keep,
            'search_categories_ids': search_categories.ids,
            'layout_mode': layout_mode,
            'brand': brand,
            'is_brand_page': True
        }
        if category:
            values['main_object'] = category
        return request.render("website_sale.products", values)
Esempio n. 58
0
 def jobs_add(self, **kwargs):
     # avoid branding of website_description by setting rendering_bundle in context
     job = request.env['hr.job'].with_context(rendering_bundle=True).create({
         'name': _('Job Title'),
     })
     return request.redirect("/jobs/detail/%s?enable_editor=1" % slug(job))
Esempio n. 59
0
    def shop(self, page=0, category=None, search='', ppg=False, **post):
        website = request.website
        quantities_per_page = None
        quantities_per_page = request.env['product.qty_per_page'].search(
            [], order='sequence')
        if ppg:
            try:
                ppg = int(ppg)
            except ValueError:
                ppg = quantities_per_page[
                    0].name if quantities_per_page else PPG
            res = super(WebsiteSale, self).shop(page, category, search, ppg,
                                                **post)
            if 'ppg' in post:
                post["ppg"] = ppg
        else:
            ppg = quantities_per_page[0].name if quantities_per_page else PPG
            res = super(WebsiteSale, self).shop(page, category, search, ppg,
                                                **post)

        res.qcontext.update({
            'ppg': ppg,
            'quantities_per_page': quantities_per_page
        })

        if post.get('brand') or post.get('product_collection'):
            attrib_list = request.httprequest.args.getlist('attrib')
            attrib_values = [[int(x) for x in v.split("-")]
                             for v in attrib_list if v]
            attributes_ids = {v[0] for v in attrib_values}
            attrib_set = {v[1] for v in attrib_values}

            domain = self._get_search_domain(search, category, attrib_values)

            if post.get('brand'):
                product_designer_obj = request.env['product.brand']
                brand_ids = product_designer_obj.search([
                    ('id', '=', int(post.get('brand')))
                ])
                if brand_ids:
                    domain += [('product_brand_id', 'in', brand_ids.ids)]

            if post.get('product_collection'):
                prod_collection_rec = request.env['multitab.configure'].search(
                    [('id', '=', int(post.get('product_collection')))])
                if prod_collection_rec:
                    prod_id_list = list({
                        each_p.product_id.id
                        for each_p in prod_collection_rec.product_ids
                    })
                    domain += [('id', 'in', prod_id_list)]
            keep = QueryURL('/shop',
                            category=category and int(category),
                            search=search,
                            attrib=attrib_list,
                            order=post.get('order'))

            pricelist_context = dict(request.env.context)

            if not pricelist_context.get('pricelist'):
                pricelist = request.website.get_current_pricelist()
                pricelist_context['pricelist'] = pricelist.id
            else:
                pricelist = request.env['product.pricelist'].browse(
                    pricelist_context['pricelist'])

            request.context = dict(request.context,
                                   pricelist=pricelist.id,
                                   partner=request.env.user.partner_id)

            url = "/shop"
            if search:
                post["search"] = search
            if category:
                category = request.env['product.public.category'].browse(
                    int(category))
                url = "/shop/category/%s" % slug(category)
            if attrib_list:
                post['attrib'] = attrib_list

            categs = request.env['product.public.category'].search([
                ('parent_id', '=', False)
            ])
            Product = request.env['product.template']

            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

            product_count = Product.search_count(domain)

            pager = request.website.pager(url=url,
                                          total=product_count,
                                          page=page,
                                          step=ppg,
                                          scope=7,
                                          url_args=post)
            products = Product.search(domain,
                                      limit=ppg,
                                      offset=pager['offset'],
                                      order=self._get_search_order(post))

            ProductAttribute = request.env['product.attribute']

            if products:
                selected_products = Product.search(domain, limit=False)
                attributes = ProductAttribute.search([
                    ('attribute_line_ids.product_tmpl_id', 'in',
                     selected_products.ids)
                ])
            else:
                attributes = ProductAttribute.browse(attributes_ids)

            from_currency = request.env.user.company_id.currency_id
            to_currency = pricelist.currency_id
            compute_currency, pricelist_context, pricelist = self._get_compute_currency_and_context(
            )
            res.qcontext.update({
                'search':
                search,
                'category':
                category,
                'attrib_values':
                attrib_values,
                'attrib_set':
                attrib_set,
                'pager':
                pager,
                'products':
                products,
                'search_count':
                product_count,
                'bins':
                TableCompute().process(products, ppg),
                'categories':
                categs,
                'attributes':
                attributes,
                'compute_currency':
                compute_currency,
                'keep':
                keep,
                'parent_category_ids':
                parent_category_ids,
                'product_collection':
                post.get('product_collection'),
            })
        return res
Esempio n. 60
0
 def jobs_add(self, **kwargs):
     job = request.env['hr.job'].create({
         'name': _('Job Title'),
     })
     return request.redirect("/jobs/detail/%s?enable_editor=1" % slug(job))