예제 #1
0
 def _get_edit_announcement_dict(self, cr, uid, registry, announcement, context=None):
     """ Return dict of values needed to edit announcement template
     """
     date_format = get_date_format(cr, uid, context)
     res = {
         'announcement':announcement,
         'announcement_picture': ('data:image/jpeg;base64,%s' % announcement.picture)
                                                         if announcement.picture else '/web/static/src/img/placeholder.png',
         'announcement_group_ids': [group.id for group in announcement.context_group_ids],
         'author': announcement.partner_id,
         'us_state_dict': self.get_default_country_state(cr, uid, request.registry, context=context),
         'country_dict': self.get_all_records(cr, uid, request.registry, 'res.country', context=context),
         'type_dict': self.get_type_dict(cr, uid, request.registry, context=context),
         'category_dict': self.get_all_records(cr, uid, request.registry, \
                                                     'marketplace.announcement.category', context=context),
         'currency_dict': self.get_all_records(cr, uid, request.registry, 'res.currency', context=context),
         'group_dict': self.get_all_records(cr, uid, request.registry, 'mail.group', context=context),
         'attachment_dict': self.get_attachment_dict(cr, uid, request.registry, announcement, context=context),
         'tag_dict': self.get_all_records(cr, uid, request.registry, 'marketplace.tag', context=context),
         'uom_dict': self.get_all_records(cr, uid, registry, 'product.uom', context=context),
         'date_placeholder': date_format.replace('%d','DD').replace('%m','MM').replace('%Y','YYYY'),
         'date_from': announcement.date_from,
         'date_to': announcement.date_to,
         'format_date': format_date,
         'vote_list': dict([(v.partner_id.id, v) for v in announcement.vote_vote_ids]),
     }
     if type(announcement) != AttrDict:
         res.update({
             'date_from': '' if not announcement.date_from else \
                 datetime.strptime(announcement.date_from, DEFAULT_SERVER_DATE_FORMAT).strftime(date_format),
             'date_to': '' if not announcement.date_to else \
                 datetime.strptime(announcement.date_to, DEFAULT_SERVER_DATE_FORMAT).strftime(date_format),
         })
     return res
예제 #2
0
    def load_more(self, **kw):
        """ Display results after load more signal(only for ajax) 
        """
        cr, uid, context = request.cr, request.uid, request.context
        mp_announcement_pool = request.registry.get('marketplace.announcement')
        result = {'wants': [], 'offers': []}
        date_format = get_date_format(cr, uid, context)
        sql = self._build_query(
            dict([(k, v) for k, v in kw.iteritems()
                  if k in self.SEARCH_PARAMS]), date_format,
            kw.get('limit', self.QUERY_LIMIT), kw.get('offset'))
        cr.execute(sql[0], sql[1] or ())
        res_ids = [row[0] for row in cr.fetchall()]
        res_data = mp_announcement_pool.browse(cr,
                                               uid,
                                               res_ids,
                                               context=context)

        for item in res_data:
            if item.type == 'want':
                result['wants'].append(item)
            else:
                result['offers'].append(item)

        if kw.get('load_wants'):
            return request.render('website_project_weezer.mp_search_wants',
                                  {'result': result})
        else:
            return request.render('website_project_weezer.mp_search_offers',
                                  {'result': result})
예제 #3
0
 def _get_view_announcement_dict(self, cr, uid, registry, announcement, my_reply=None, 
                                 updated_reply=None, updated_reply_saved=False, my_vote=None, context=None):
     """ Return dict of values needed to view announcement template
     """
     user = registry.get('res.users').browse(cr, uid, uid, context=context)
     date_format = get_date_format(cr, uid, context)
     return {
         'announcement':announcement,
         'author': announcement.partner_id,
         'vote_list': dict([(v.partner_id.id, v) for v in announcement.vote_vote_ids]),
         'my_reply': my_reply or self._get_my_reply(),
         'updated_reply': updated_reply,
         'my_vote': my_vote or self._get_my_vote(cr, uid, request.registry, announcement, 
                                                 user.partner_id.id, context=context),
         'type_dict': self.get_type_dict(cr, uid, request.registry, context=context),
         'attachment_dict': self.get_attachment_dict(cr, uid, request.registry, announcement, context=context),
         'date_from': '' if not announcement.date_from else \
             datetime.strptime(announcement.date_from, DEFAULT_SERVER_DATE_FORMAT).strftime(date_format),
         'date_to': '' if not announcement.date_to else \
             datetime.strptime(announcement.date_to, DEFAULT_SERVER_DATE_FORMAT).strftime(date_format),
         'getattr': getattr,
         'currency_dict': self.get_all_records(cr, uid, registry, 'res.currency', context=context),
         'format_date': format_date,
         'vote_types': self.get_vote_types(cr, uid, registry, context=context),
         'allow_reply': len([1 for p in announcement.proposition_ids 
             if p.is_sender and p.state in ('draft', 'open')]) == 0,
         'updated_reply_saved': updated_reply_saved
     }
예제 #4
0
    def profile_values(self, partner, own_profile=False, data=None):
        """
        Collect data to render in profile view

        :param browse_record partner
        :param dict data: raw POST data
        :return: dict of values to render
        """
        cr, uid, context, registry = request.cr, request.uid, request.context, request.registry
        title_pool = registry.get('res.partner.title')
        country_pool = registry.get('res.country')
        state_pool = registry.get('res.country.state')
        currency_pool = registry.get('res.currency')
        self.date_format = get_date_format(cr, uid, context=context)
        values = {
            'errors': {},
            'partner': partner,
            'partner_titles': title_pool.name_search(cr, uid, '', [], context=context),
            'countries': country_pool.name_search(cr, uid, '', [], context=context),
            'states': state_pool.name_search(cr, uid, '', [], context=context),
            'is_administrator': uid == SUPERUSER_ID,
            'currencies': currency_pool.name_search(cr, uid, '', [('wallet_currency','=',True)], context=context),
            'date_placeholder': self.date_format.replace('%d','DD').replace('%m','MM').replace('%Y','YYYY'),
            'last_exchanges': self.profile_last_exchanges(partner.id),
            'wants': self.profile_announcements(partner.id, 'want', own_profile),
            'offers': self.profile_announcements(partner.id, 'offer', own_profile),
            'membership': self.get_partner_membership(partner),
            'groups': self.profile_last_groups(partner.id),
        }
        if data:
            values['profile'] = self.profile_parse_data(data)
        else:
            values['profile'] = self.profile_parse_partner(partner)
        return values
예제 #5
0
 def register_part2(self, **kw):
     cr, uid, context, registry = request.cr, request.uid, request.context, request.registry
     user_pool = registry.get('res.users')
     title_pool = registry.get('res.partner.title')
     country_pool = registry.get('res.country')
     state_pool = registry.get('res.country.state')
     product_pool = registry.get('product.product')
     currency_pool = registry.get('res.currency')
     partner = user_pool.browse(cr, uid, uid, context=context).partner_id
     self.date_format = get_date_format(cr, uid, context=context)
     values = {
         'errors': {},
         'partner':
         partner,
         'membership':
         self.get_partner_membership(partner),
         'images':
         self.profile_images(partner),
         'partner_titles':
         title_pool.name_search(cr, uid, '', [], context=context),
         'countries':
         country_pool.name_search(cr, uid, '', [], context=context),
         'memberships':
         product_pool.name_search(
             cr,
             uid,
             '', [('membership', '=', True),
                  ('membership_date_to', '>=', datetime.today())],
             context=context),
         'states':
         state_pool.name_search(cr, uid, '', [], context=context),
         'currencies':
         currency_pool.name_search(cr,
                                   uid,
                                   '', [('wallet_currency', '=', True)],
                                   context=context),
         'date_placeholder':
         self.date_format.replace('%d',
                                  'DD').replace('%m',
                                                'MM').replace('%Y', 'YYYY'),
     }
     if kw:
         values['profile'] = self.profile_parse_data(kw)
         values['errors'] = self.profile_form_validate(values['profile'])
         if not kw.get('agreement', False):
             values['errors']['agreement'] = _(
                 'Please read terms and make decision')
         if not values['errors']:
             self.profile_save(partner, values['profile'])
             request.session['profile_saved'] = True
             return request.redirect("/marketplace/profile/%s" % partner.id)
     else:
         values['profile'] = self.profile_parse_partner(partner)
     return request.website.render("website_project_weezer.register_part_2",
                                   values)
예제 #6
0
 def __parse_date_param(self, post, param, attr, error_msg):
     """ Process date value from post params and save it to vals dict
     """
     if post.get(param):
         try:
             date_val = datetime.strptime(post.get(param), \
                 get_date_format(self.cr, self.uid, self.context))
         except ValueError:
             self.error_message_list.append(_(error_msg))
             self.error_param_list.append(param)
         else:
             self.vals.update({attr: date_val})            
예제 #7
0
    def profile_values(self, partner, own_profile=False, data=None):
        """
        Collect data to render in profile view

        :param browse_record partner
        :param dict data: raw POST data
        :return: dict of values to render
        """
        cr, uid, context, registry = request.cr, request.uid, request.context, request.registry
        title_pool = registry.get('res.partner.title')
        country_pool = registry.get('res.country')
        state_pool = registry.get('res.country.state')
        currency_pool = registry.get('res.currency')
        self.date_format = get_date_format(cr, uid, context=context)
        values = {
            'errors': {},
            'partner':
            partner,
            'partner_titles':
            title_pool.name_search(cr, uid, '', [], context=context),
            'countries':
            country_pool.name_search(cr, uid, '', [], context=context),
            'states':
            state_pool.name_search(cr, uid, '', [], context=context),
            'is_administrator':
            uid == SUPERUSER_ID,
            'currencies':
            currency_pool.name_search(cr,
                                      uid,
                                      '', [('wallet_currency', '=', True)],
                                      context=context),
            'date_placeholder':
            self.date_format.replace('%d',
                                     'DD').replace('%m',
                                                   'MM').replace('%Y', 'YYYY'),
            'last_exchanges':
            self.profile_last_exchanges(partner.id),
            'wants':
            self.profile_announcements(partner.id, 'want', own_profile),
            'offers':
            self.profile_announcements(partner.id, 'offer', own_profile),
            'membership':
            self.get_partner_membership(partner),
            'groups':
            self.profile_last_groups(partner.id),
        }
        if data:
            values['profile'] = self.profile_parse_data(data)
        else:
            values['profile'] = self.profile_parse_partner(partner)
        return values
예제 #8
0
 def _get_new_announcement_dict(self, cr, uid, registry, partner, context=None):
     """ Return dict of values needed to new announcement template
     """
     return {
         'author': partner,
         'us_state_dict': self.get_default_country_state(cr, uid, registry, context=context),
         'country_dict': self.get_all_records(cr, uid, registry, 'res.country', context=context),
         'type_dict': self.get_type_dict(cr, uid, request.registry, context=context),
         'category_dict': self.get_all_records(cr, uid, registry, \
                                                         'marketplace.announcement.category', context=context),
         'currency_dict': self.get_all_records(cr, uid, registry, 'res.currency', context=context),
         'group_dict': self.get_all_records(cr, uid, registry, 'mail.group', context=context),
         'uom_dict': self.get_all_records(cr, uid, registry, 'product.uom', context=context),
         'date_placeholder': get_date_format(cr, uid, context) \
             .replace('%d','DD').replace('%m','MM').replace('%Y','YYYY'),
     }
예제 #9
0
    def search(self, **kw):
        """ Display search page and first results 
        :param dict kw: POST data
        """
        cr, uid, context = request.cr, request.uid, request.context
        mp_announcement_pool = request.registry.get('marketplace.announcement')
        category_pool = request.registry.get('marketplace.announcement.category')
        result = {'wants': [], 'offers': []}
        date_format = get_date_format(cr, uid, context)
        post_params = dict([(k,v) for k,v in kw.iteritems() if k in self.SEARCH_PARAMS])
        # Search in child categories
        category_id = int(kw.get('category','0'))
        if category_id:
            post_params.update({
                'categories': category_pool.search(cr, uid, 
                    [('id','child_of',category_id)],context=context)
            })
        sql = self._build_query(post_params, date_format, kw.get('limit',self.QUERY_LIMIT), int(kw.get('page','1'))-1)
        cr.execute(sql[0], sql[1] or ())
        res_ids = [row[0] for row in cr.fetchall()]
        res_data = mp_announcement_pool.browse(cr, uid, res_ids, context=context)
        
        #select number both of wants and offers
        count_sql = self._build_query(post_params, date_format, False, False, True)
        cr.execute(count_sql[0], count_sql[1] or ())
        counts = cr.fetchall()
        if len(counts) > 1:
            count = max(counts[0][0], counts[1][0])
        else:
            count = counts[0][0]

        for item in res_data:
            if item.type == 'want':
                result['wants'].append(item)
            else:
                result['offers'].append(item)
        return http.request.website.render('website_project_weezer.mp_search', {
            'result': result,
            'page': int(kw.get('page', '1')),
            'page_count': count/self.QUERY_LIMIT + (1 if count%self.QUERY_LIMIT else 0),
            'next_url': self._get_url('next', int(kw.get('page', '1')), post_params),
            'prev_url': self._get_url('prev', int(kw.get('page', '1'))-1, post_params),
            'format_text': format_text
        })
예제 #10
0
 def profile_view(self, partner=None):
     """
     Display profile view page
     """
     cr, uid, context, registry = request.cr, request.uid, request.context, request.registry
     user_pool = registry.get('res.users')
     user = user_pool.browse(cr, uid, uid, context=context)
     date_format = get_date_format(cr, uid, context=context)
     return request.website.render("website_project_weezer.profile_view", {
         'partner': partner,
         'is_administrator': uid == SUPERUSER_ID,
         'images': self.profile_images(partner),
         'wants': self.profile_announcements(partner.id, 'want', user.partner_id.id == partner.id),
         'offers': self.profile_announcements(partner.id, 'offer', user.partner_id.id == partner.id),
         'format_text': format_text,
         'last_exchanges': self.profile_last_exchanges(partner.id),
         'birthdate': format_date(partner.birthdate, True) if partner.birthdate else '',
         'membership': self.get_partner_membership(partner),
         'groups': self.profile_last_groups(partner.id),
         'profile_saved': request.session.pop('profile_saved') if 'profile_saved' in request.session else False
     })
예제 #11
0
    def load_more(self, **kw):
        """ Display results after load more signal(only for ajax) 
        """
        cr, uid, context = request.cr, request.uid, request.context
        mp_announcement_pool = request.registry.get('marketplace.announcement')
        result = {'wants': [], 'offers': []}
        date_format = get_date_format(cr, uid, context)
        sql = self._build_query(dict([(k,v) for k,v in kw.iteritems() if k in self.SEARCH_PARAMS]), 
            date_format, kw.get('limit',self.QUERY_LIMIT), kw.get('offset'))
        cr.execute(sql[0], sql[1] or ())
        res_ids = [row[0] for row in cr.fetchall()]
        res_data = mp_announcement_pool.browse(cr, uid, res_ids, context=context)

        for item in res_data:
            if item.type == 'want':
                result['wants'].append(item)
            else:
                result['offers'].append(item)

        if kw.get('load_wants'):
            return request.render('website_project_weezer.mp_search_wants', {'result': result})
        else:
            return request.render('website_project_weezer.mp_search_offers', {'result': result})
예제 #12
0
 def profile_view(self, partner=None):
     """
     Display profile view page
     """
     cr, uid, context, registry = request.cr, request.uid, request.context, request.registry
     user_pool = registry.get('res.users')
     user = user_pool.browse(cr, uid, uid, context=context)
     date_format = get_date_format(cr, uid, context=context)
     return request.website.render(
         "website_project_weezer.profile_view", {
             'partner':
             partner,
             'is_administrator':
             uid == SUPERUSER_ID,
             'images':
             self.profile_images(partner),
             'wants':
             self.profile_announcements(partner.id, 'want',
                                        user.partner_id.id == partner.id),
             'offers':
             self.profile_announcements(partner.id, 'offer',
                                        user.partner_id.id == partner.id),
             'format_text':
             format_text,
             'last_exchanges':
             self.profile_last_exchanges(partner.id),
             'birthdate':
             format_date(partner.birthdate, True)
             if partner.birthdate else '',
             'membership':
             self.get_partner_membership(partner),
             'groups':
             self.profile_last_groups(partner.id),
             'profile_saved':
             request.session.pop('profile_saved')
             if 'profile_saved' in request.session else False
         })
예제 #13
0
 def register_part2(self, **kw):
     cr, uid, context, registry = request.cr, request.uid, request.context, request.registry
     user_pool = registry.get('res.users')
     title_pool = registry.get('res.partner.title')
     country_pool = registry.get('res.country')
     state_pool = registry.get('res.country.state')
     product_pool = registry.get('product.product')
     currency_pool = registry.get('res.currency')
     partner = user_pool.browse(cr, uid, uid, context=context).partner_id
     self.date_format = get_date_format(cr, uid, context=context)
     values = {
         'errors': {},
         'partner': partner,
         'membership': self.get_partner_membership(partner),
         'images': self.profile_images(partner),
         'partner_titles': title_pool.name_search(cr, uid, '', [], context=context),
         'countries': country_pool.name_search(cr, uid, '', [], context=context),
         'memberships': product_pool.name_search(cr, uid, '',[
             ('membership', '=', True),
             ('membership_date_to', '>=', datetime.today())], context=context),
         'states': state_pool.name_search(cr, uid, '', [], context=context),
         'currencies': currency_pool.name_search(cr, uid, '', [('wallet_currency','=',True)], context=context),
         'date_placeholder': self.date_format.replace('%d','DD').replace('%m','MM').replace('%Y','YYYY'),
     }
     if kw:
         values['profile'] = self.profile_parse_data(kw)
         values['errors'] = self.profile_form_validate(values['profile'])
         if not kw.get('agreement', False):
             values['errors']['agreement'] = _('Please read terms and make decision')
         if not values['errors']:
             self.profile_save(partner, values['profile'])
             request.session['profile_saved'] = True
             return request.redirect("/marketplace/profile/%s" % partner.id)
     else:
         values['profile'] = self.profile_parse_partner(partner)
     return request.website.render("website_project_weezer.register_part_2", values)
예제 #14
0
    def search(self, **kw):
        """ Display search page and first results 
        :param dict kw: POST data
        """
        cr, uid, context = request.cr, request.uid, request.context
        mp_announcement_pool = request.registry.get('marketplace.announcement')
        category_pool = request.registry.get(
            'marketplace.announcement.category')
        result = {'wants': [], 'offers': []}
        date_format = get_date_format(cr, uid, context)
        post_params = dict([(k, v) for k, v in kw.iteritems()
                            if k in self.SEARCH_PARAMS])
        # Search in child categories
        category_id = int(kw.get('category', '0'))
        if category_id:
            post_params.update({
                'categories':
                category_pool.search(cr,
                                     uid, [('id', 'child_of', category_id)],
                                     context=context)
            })
        sql = self._build_query(post_params, date_format,
                                kw.get('limit', self.QUERY_LIMIT),
                                int(kw.get('page', '1')) - 1)
        cr.execute(sql[0], sql[1] or ())
        res_ids = [row[0] for row in cr.fetchall()]
        res_data = mp_announcement_pool.browse(cr,
                                               uid,
                                               res_ids,
                                               context=context)

        #select number both of wants and offers
        count_sql = self._build_query(post_params, date_format, False, False,
                                      True)
        cr.execute(count_sql[0], count_sql[1] or ())
        counts = cr.fetchall()
        if len(counts) > 1:
            count = max(counts[0][0], counts[1][0])
        else:
            count = counts[0][0]

        for item in res_data:
            if item.type == 'want':
                result['wants'].append(item)
            else:
                result['offers'].append(item)
        return http.request.website.render(
            'website_project_weezer.mp_search', {
                'result':
                result,
                'page':
                int(kw.get('page', '1')),
                'page_count':
                count / self.QUERY_LIMIT +
                (1 if count % self.QUERY_LIMIT else 0),
                'next_url':
                self._get_url('next', int(kw.get('page', '1')), post_params),
                'prev_url':
                self._get_url('prev',
                              int(kw.get('page', '1')) - 1, post_params),
                'format_text':
                format_text
            })