def contact(self): if self.data is None: return mls_settings = api.get_settings(context=self.context) agency_id = mls_settings.get("agency_id", None) contact_data = self.data.get("contact", None) contact_data["overridden"] = False agency = contact_data.get("agency", {}) agent = contact_data.get("agent", {}) original_agent = self.data.get("original_agent") contact_data["original_agent"] = original_agent settings = get_agency_info(context=self.context) if agency.get("id", {}).get("value", None) == agency_id: if settings and settings.get("force", False) is True: pass else: return contact_data if settings: contact_data["overridden"] = True agency = self.update_agency_info(agency, settings) agent = self.update_agent_info(agent, settings) return contact_data
def search(params={}, batching=True, context=None, config=None): """Search for listings.""" if config is None: config = {} settings = get_settings(context=context) search_params = {"sort_on": "last_activated_date", "reverse": "1"} listing_types = set(config.get("listing_type", ())) if listing_types: # Available Listing Types are restricted. search_listing_types = params.get("listing_type", None) if search_listing_types: search_listing_types = set(search_listing_types.split(",")) listing_types = listing_types.intersection(search_listing_types) params["listing_type"] = ",".join(listing_types) agency_listings = params.pop("agency_listings", False) if agency_listings is True: search_params["agency_id"] = settings.get("agency_id", None) search_params.update(params) base_url = settings.get("mls_site", None) api_key = settings.get("mls_key", None) batch = None results = [] resource = ListingResource(base_url, api_key=api_key) try: results, batch = resource.search(search_params) except MLSError, e: logger.warn(e)
def is_calendar_visibile(self): """Check if the availability calendar can be shown.""" if self.registry is not None: try: settings = self.registry.forInterface(IMLSUISettings) # noqa except Exception: logger.warning("MLS UI settings not available.") return False else: return False # Check if the calender should be shown at all. enabled = getattr(settings, "availability_calendar") if not enabled: return False # Check if the calendar should not be hidden for 3rd party listings. agency_only = getattr(settings, "availability_calendar_agency") if not agency_only: return True # Check if the listing is owned by the agency. mls_settings = api.get_settings(context=self.context) agency_id = mls_settings.get("agency_id", None) contact_data = self.data.get("contact", None) agency = contact_data.get("agency", {}) if agency.get("id", {}).get("value", None) == agency_id: return True return False
def contact(self): if self.data is None: return mls_settings = api.get_settings(context=self.context) agency_id = mls_settings.get('agency_id', None) contact_data = self.data.get('contact', None) contact_data['overridden'] = False agency = contact_data.get('agency', {}) agent = contact_data.get('agent', {}) original_agent = self.data.get('original_agent') contact_data['original_agent'] = original_agent settings = get_agency_info(context=self.context) if agency.get('id', {}).get('value', None) == agency_id: if settings and settings.get('force', False) is True: pass else: return contact_data if settings: contact_data['overridden'] = True agency = self.update_agency_info(agency, settings) agent = self.update_agent_info(agent, settings) return contact_data
def _retrieveCategory(self): """do the actual work and try to retrieve the feed""" if self.category is not None: self._last_update_time_in_minutes = time.time() / 60 self._last_update_time = DateTime() settings = get_settings(context=self.context) base_url = settings.get('mls_site', None) api_key = settings.get('mls_key', None) debug = api.env.debug_mode resource = ListingResource(base_url, api_key=api_key, debug=debug) results = [] try: results = resource.category(self.category, self.language) except MLSError as e: self._loaded = True # we tried at least but have a failed load self._failed = True logger.warn(e) return False self._items = results self._loaded = True self._failed = False return True self._loaded = True self._failed = True # no url set means failed return False # no url set, although that should not really happen
def __call__(self, context): if isinstance(context, AnnotationStorage): context = context.context portal_state = queryMultiAdapter( (context, getRequest()), name='plone_portal_state', ) registry = getUtility(IRegistry) try: settings = registry.forInterface( IMLSVocabularySettings, check=False, ) except KeyError: priority_list = [] else: value = getattr(settings, self.priority, '') if value is None: value = '' priority_list = [ item.strip() for item in value.split(',') if len(item.strip()) > 0 ] mls_settings = api.get_settings(context=context) mls_url = mls_settings.get('mls_site', None) try: language = portal_state.language() except: language = None types = search_options( mls_url, self.vocabulary_name, language, context=context, ) if self.local_settings_key is not None: try: annotations = IAnnotations(context) except: pass else: local_settings = annotations.get(self.local_settings_key, {}) filtered = local_settings.get(self.filter_key, ()) if len(filtered) > 0: types = [(k, v) for k, v in types if k in filtered] terms = [] if types is not None: types = self._sort(types, priority_list) terms = [ SimpleTerm(item[0], item[0], item[1]) for item in types ] return SimpleVocabulary(terms)
def listing_details(listing_id, lang=None, context=None): """Return detail information for a listing.""" settings = get_settings(context=context) base_url = settings.get("mls_site", None) api_key = settings.get("mls_key", None) resource = ListingResource(base_url, api_key=api_key) try: listing = resource.get(listing_id, lang=lang) except MLSError, e: logger.warn(e) return None
def search(params={}, batching=True, context=None, config=None): """Search for listings.""" if config is None: config = {} settings = get_settings(context=context) search_params = { 'sort_on': 'last_activated_date', 'reverse': '1', } if config.get('show_unverified', False): search_params['apiowner'] = settings.get('agency_id') listing_types = set(config.get('listing_type', ())) if listing_types: # Available Listing Types are restricted. search_listing_types = params.get('listing_type', None) if search_listing_types: search_listing_types = set(search_listing_types.split(',')) listing_types = listing_types.intersection(search_listing_types) params['listing_type'] = ','.join(listing_types) agency_listings = params.pop('agency_listings', False) agency_priority = params.get('agency_priority', False) if agency_listings is True or agency_priority is True: agency_id = params.pop('overriding_agency_id', None) if not agency_id: agency_id = settings.get('agency_id', None) agency_id = agency_id.replace(' ', '') search_params['agency_id'] = agency_id search_params.update(params) base_url = settings.get('mls_site', None) api_key = settings.get('mls_key', None) batch = None results = [] debug = api.env.debug_mode resource = ListingResource(base_url, api_key=api_key, debug=debug) try: results, batch = resource.search(search_params) except MLSError as e: logger.warn(e) if batching: return results, batch return results
def _retrieveCategory(self): """do the actual work and try to retrieve the feed""" if self.category is not None: self._last_update_time_in_minutes = time.time() / 60 self._last_update_time = DateTime() settings = get_settings(context=self.context) base_url = settings.get("mls_site", None) api_key = settings.get("mls_key", None) resource = ListingResource(base_url, api_key=api_key) results = [] try: results = resource.category(self.category, self.language) except MLSError, e: self._loaded = True # we tried at least but have a failed load self._failed = True logger.warn(e) return False self._items = results self._loaded = True self._failed = False return True
def listing_details(listing_id, lang=None, context=None): """Return detail information for a listing.""" settings = get_settings(context=context) base_url = settings.get('mls_site', None) api_key = settings.get('mls_key', None) debug = api.env.debug_mode config = get_configs(context=context, merged=True) params = {} if config.get('show_unverified', False): params['apiowner'] = settings.get('agency_id') params['show_unverified'] = True if config.get('show_unverified_only', False): params['show_unverified_only'] = True resource = ListingResource(base_url, api_key=api_key, debug=debug) try: listing = resource.get(listing_id, lang=lang, params=params) except MLSError as e: logger.warn(e) return None listing = listing.get('listing', None) if listing is not None: agent = copy.deepcopy(listing.get('contact', {}).get('agent')) listing['original_agent'] = agent return listing