def serialize(self): ''' Temporary method to take the place of TastyPie serialization functionality. Will remove later in place of TastyPie functionality, but too many special issues (e.g. thumbnails) to worry about doing "right" at the moment. ''' thumb_small = get_cached_thumbnail(self.image, 'small') if self.image else None thumb_standard = get_cached_thumbnail(self.image, 'standard') if self.image else None return { 'name': self.name, 'description': truncatewords(self.description, 15), 'location': { 'address': self.location.address, 'latitude': float(self.location.latitude) if self.location.latitude is not None else None, 'longitude': float(self.location.longitude) if self.location.longitude is not None else None, 'is_gecoded': self.location.latitude is not None and self.location.longitude is not None, } if self.location else None, 'tags': [{ 'name': tag.name, 'permalink': tag.get_absolute_url(), } for tag in self.tags.all()[:4]], 'hours': [{ 'days': listing.days, 'hours': listing.hours } for listing in self.hours], 'image': self.image.url if self.image else '', # special fields only for JSON output 'permalink': self.get_absolute_url(), 'thumb_small': thumb_small.url if thumb_small else '', 'thumb_standard': thumb_standard.url if thumb_standard else '', }
def _autocomplete_response(request, place_choices, term, limit=4): ''' Return a Python dict with sorted autocomplete responses. ''' match_status = [] for p in place_choices: name = p.name.lower().strip() if name and name.startswith(term): match_status.append(1) elif name and any(word.startswith(term) for word in name.split()): match_status.append(2) else: match_status.append(3) results = [] for _, p in sorted(zip(match_status, place_choices))[:limit]: try: thumb = get_cached_thumbnail(p.image, 'small') if p.image else None except IOError: thumb = None image_url = thumb.url if thumb else '/static/img/defaults/default-place.png' results.append({ 'id': p.id, 'name': p.name, 'image_url': image_url, 'address': p.location.address if p.location else '', 'selected': render_safe('orgadmin/ac_place_selected.html', place=p, context_instance=RequestContext(request)) }) return results
def dehydrate_image(self, bundle): """ Ensures data includes a url for an app-sized thumbnail """ if bundle.obj.image: img = get_cached_thumbnail(bundle.obj.image, "app") if img is not None: return img.url return None
def serialize(self): ''' Temporary method to take the place of TastyPie serialization functionality. Will remove later in place of TastyPie functionality, but too many special issues (e.g. thumbnails) to worry about doing "right" at the moment. ''' thumb_small = get_cached_thumbnail(self.image, 'small') if self.image else None thumb_standard = get_cached_thumbnail(self.image, 'standard') if self.image else None return { 'id': self.id, 'name': self.name, 'description': truncatewords(self.description, 13), 'dtstart': str(self.dtstart), 'dtend': str(self.dtend), 'dtstart_str': self.dtstart_str, 'dtend_str': self.dtend_str, 'icon_day': self.icon_day, 'place': { 'name': self.place.name, 'location': { 'address': self.place.location.address, 'latitude': float(self.place.location.latitude) if self.place.location.latitude is not None else None, 'longitude': float(self.place.location.longitude) if self.place.location.longitude is not None else None, 'is_geocoded': self.place.location.latitude is not None and self.place.location.longitude is not None, } if self.place.location else None, 'permalink': self.place.get_absolute_url(), } if self.place else None, 'place_primitive': truncatewords(self.place_primitive, 6), 'image': self.image.url if self.image else '', 'tags': [{ 'name': tag.name, 'permalink': tag.get_absolute_url(), } for tag in self.tags.all()], # special fields only for JSON output 'permalink': self.get_absolute_url(), 'thumb_small': thumb_small.url if thumb_small else '', 'thumb_standard': thumb_standard.url if thumb_standard else '', }