def test_get_location(self): factory = RequestFactory() request = factory.get(reverse('home')) # No user and no code given self.assertEqual(get_location(request), None) # No user and a code self.assertEqual(get_location(request, "12065"), '12065') # User but no code user = User.objects.get(email='*****@*****.**') location = Location(pk=1) location.zip_code = Zipcode(pk=12065) location.pk = None location.save() contact = Contact(pk=1) contact.pk = None contact.save() contact_info = ContactInfo(location=location, contact=contact) contact_info.save() user.profile.contact_info = contact_info user.profile.save() request.user = user self.assertEqual(get_location(request), user.profile.contact_info.location.zip_code.code) # user and code self.assertEqual(get_location(request, "01225"), '01225')
def get_initial_data(self): return { 'signupForm': {}, 'zipcodeForm': { 'zip_code': get_location(self.request, None, 'code') }, }
def get_posts(self, **kwargs): location = get_location(self.request, self.kwargs.get('zipcode'), 'point') if location: return self.model.objects.filter( profile__contact_info__location__zip_code__point__distance_lte=(location, D(m=LocalFeed.distance)) ) else: return []
def get_activities(self, page_num, zipcode, **kwargs): location = get_location(self.request, zipcode, self.location_type) if location: params = (location, ) # TODO: paginate this feed feed = getattr(feedly, self.feed)(*params) activities = list(feed[:15]) return enrich_activities(activities) return None
def dispatch(self, *args, **kwargs): location = get_location(self.request, self.kwargs.get('zipcode'), 'point') if location: self.filters = { 'profile__contact_info__location__zip_code__point__distance_lte': (location, D(m=LocalFeed.distance)) } else: self.filters = {'profile__pk': -1} return super(LocalViewAuth, self).dispatch(*args, **kwargs)
def get_posts(self, **kwargs): posts = super(LocalViewAuth, self).get_posts(**kwargs) location = get_location(self.request, self.kwargs.get('zipcode'), 'point') if location: return posts.filter(info__location__zip_code__point__distance_lte=( location, D(m=LocalFeed.distance))) else: return []
def get_context_data(self, **kwargs): context = super(FollowingView, self).get_context_data(**kwargs) page_num = self.request.GET.get('page') feed = feedly.get_feeds(self.request.user.id)['normal'] activities = list(feed[:15]) activities = get_page(page_num, activities, 15) context['activities'] = enrich_activities(activities) context['location'] = get_location(self.request, self.kwargs.get('zipcode'), 'code') return context
def get_context_data(self, **kwargs): context = super(UpdateView, self).get_context_data(**kwargs) context.update(self.get_scope()) page_num = self.request.GET.get('page') zipcode = self.kwargs.get('zipcode') context['feedType'] = self.feedType context['order'] = 'latest' context['activities'] = self.get_activities(page_num, zipcode) context['location'] = get_location(self.request, zipcode, 'code') return context
def get_posts(self, **kwargs): location = get_location(self.request, self.kwargs.get('zipcode'), 'point') if location: posts = self.model.objects.filter( zip_code__point__distance_lte=(location, D(m=LocalFeed.distance))) return self.band_or_venue(posts, **kwargs) else: return []
def get_posts(self, **kwargs): # TODO: add checking for when its more then a (x time period) away the default to local start = datetime.combine(self.start_date, time()).replace(tzinfo=utc) end = datetime.combine(self.end_date, time()).replace(tzinfo=utc) posts = self.model.objects.exclude(**self.get_exclude(start, end)) calendar = self.request.user.calendar prev = calendar.get_prev_event(in_datetime=end) next = calendar.get_next_event(in_datetime=end) if prev: start = prev.get_location().zip_code.point else: start = get_location(self.request, self.kwargs.get('zipcode'), 'point') if next: end = next.get_location().zip_code.point else: end = get_location(self.request, self.kwargs.get('zipcode'), 'point') line = LineString(start,end) return posts.filter( profile__contact_info__location__zip_code__point__distance_lte=(line, D(m=LocalFeed.distance)) ).distinct()
def get_posts(self, **kwargs): # TODO: add checking for when its more then a (x time period) away the default to local start = datetime.combine(self.start_date, time()).replace(tzinfo=utc) end = datetime.combine(self.end_date, time()).replace(tzinfo=utc) posts = self.model.objects.exclude(**self.get_exclude(start, end)) location = get_location(self.request, self.kwargs.get('zipcode'), 'point') if location: return posts.filter( profile__contact_info__location__zip_code__point__distance_lte=(location, D(m=LocalFeed.distance)) ).distinct() else: return []
def get_posts(self, **kwargs): # TODO: make properally timezone aware start = datetime.combine(self.start_date, time()).replace(tzinfo=utc) end = datetime.combine(self.end_date, time()).replace(tzinfo=utc) location = get_location(self.request, self.kwargs.get('zipcode'), 'point') if location: return self.model.objects.exclude(**self.get_exclude(start, end)).filter( Q(profile__user__calendar__events__line__line__distance_lte=(location, D(m=LocalFeed.distance))) | Q(profile__contact_info__location__zip_code__point__distance_lte=(location, D(m=LocalFeed.distance))) ).distinct() else: return []
def get_context_data(self, **kwargs): context = super(ZipcodeMixin, self).get_context_data(**kwargs) context['locationForm'] = ZipcodeForm() context['zipcode'] = get_location(self.request, self.kwargs.get('zipcode'), 'code') return context