def _get_listings(self):
     """Query the recent listings from the MLS."""
     params = {
         'limit': self.limit,
         'offset': self.request.get('b_start', 0),
         'lang': self.portal_state.language(),
     }
     params.update(self.config)
     params = prepare_search_params(params)
     results, batching = search(params, context=self.context)
     self._listings = results
     self._batching = batching
Ejemplo n.º 2
0
    def results(self):
        items = []

        self.configured_fields = self.get_configured_fields()
        size_conf = [
            i for i in self.configured_fields if i['id'] == 'count'
        ]

        if size_conf and 'size' in size_conf[0].keys():
            size = int(size_conf[0]['size'])
        else:
            size = 5

        offset = 0
        offset_conf = [
            i for i in self.configured_fields if i['id'] == 'offset'
        ]
        if offset_conf:
            try:
                offset = int(offset_conf[0].get('offset', 0))
            except ValueError:
                offset = 0

        uuid = self.data.get('uuid', None)
        obj = uuidToObject(uuid)
        if uuid and obj:
            if not self.has_listing_collection(obj):
                return items
            config = copy.copy(self.get_config(obj))
            portal_state = getMultiAdapter(
                (self.context, self.request),
                name='plone_portal_state',
            )
            params = {
                'limit': size,
                'offset': offset,
                'lang': portal_state.language(),
            }
            config.update(params)
            items = api.search(
                params=api.prepare_search_params(config),
                batching=False,
                context=obj,
            )
        else:
            self.remove_relation()

        return items
Ejemplo n.º 3
0
    def update(self):
        """Prepare view related data."""
        super(ListingSearchViewlet, self).update()
        self.context_state = queryMultiAdapter((self.context, self.request), name="plone_context_state")

        self.limit = self.config.get("limit", 25)

        z2.switch_on(self, request_layer=IFormLayer)
        self.form = ListingSearchForm(aq_inner(self.context), self.request)
        if HAS_WRAPPED_FORM:
            alsoProvides(self.form, IWrappedForm)
        self.form.update()

        self.search_performed = bool(self.request.form)
        if self.available and len(self.request.form) > 0:
            data, errors = self.form.extractData()
            if not errors:
                self._get_listings(prepare_search_params(data))

            self.request.form = encode_dict(self.request.form)
Ejemplo n.º 4
0
    def _get_listings(self):
        """Query the recent listings from the MLS."""
        listing_ids = self.context.listing_ids
        if len(listing_ids) == 0:
            return
        listing_ids = [lid.lower() for lid in listing_ids]
        params = {
            'limit': 0,
            'offset': 0,
            'lang': self.portal_state.language(),
        }
        params.update({
            'listing_ids': listing_ids,
        })
        params = prepare_search_params(params)
        results = search(params, batching=False, context=self.context)
        if results is None or len(results) == 0:
            return

        # sort the results based on the listing_ids
        results = [(item['id']['value'], item) for item in results]
        results = dict(results)
        return [results.get(id) for id in listing_ids if id in results]
    def items(self):
        """Return the collection items."""
        items = []
        context = self.get_context
        if not context or not self.has_listing_collection(context):
            return items

        context_config = copy.copy(self.get_config(context))
        language = plone_api.portal.get_current_language(context=context)
        params = {
            'lang': language,
            'limit': self.size,
            'offset': self.start_at,
        }
        context_config.update(params)
        params = api.prepare_search_params(context_config)
        items = api.search(
            params=params,
            batching=False,
            context=context,
            config=self.get_config(context),
        )
        return items