def getGeolocationFromIP(ipaddr): g = GeoIP() request_src = g.city(ipaddr) logRequest(request_src) try: return (request_src['city'], request_src['country_name']) except: return ('', '')
def homepage(request): if request.user.is_authenticated(): #g = geoip.HAS_GEOIP g = GeoIP() ip = request.META.get('REMOTE_ADDR', None) if ip == '127.0.0.1': city='Seoul' if ip: city = g.city(ip) if ip == '127.0.0.1': city=city elif city == None: city= 'Seoul' else: city = city['city'] if city == None: city= 'Seoul' else: city = 'New York' # default city request.city = city request.ip = ip return render(request, "dashboard.html") else: #g = geoip.HAS_GEOIP g = GeoIP() ip = request.META.get('REMOTE_ADDR', None) if ip == '127.0.0.1': city='Seoul' if ip: city = g.city(ip) if ip == '127.0.0.1': city=city elif city == None: city= 'Seoul' else: city = city['city'] if city == None: city= 'Seoul, KR' else: city = 'New York' # default city request.city = city request.ip = ip return render(request, "homepage.html")
def get_context_data(self, **kwargs): ctx = super(ProfileListView, self).get_context_data(**kwargs) ctx['star_rating'] = Star_rating.objects.all() i=-1; for profile in ctx['profiles']: i = i+1 j=0 for star_rating in ctx['star_rating']: #print "blah=" + str(profile.user) if str(profile.user) == star_rating.profileName: j=j+1 try: ctx['profiles'][i].totalAmount = ctx['profiles'][i].totalAmount + star_rating.rating ctx['profiles'][i].starsCount = ctx['profiles'][i].starsCount +1 #ctx['profiles'][i]['stars'] =1 ctx['profiles'][i].stars = float(ctx['profiles'][i].totalAmount/ctx['profiles'][i].starsCount) print ctx['profiles'][i].stars except: print('except') setattr(ctx['profiles'][i], 'stars', int(star_rating.rating)) setattr(ctx['profiles'][i], 'totalAmount', int(star_rating.rating)) setattr(ctx['profiles'][i], 'starsCount', 1) #ctx['profiles'][i]['stars'] = 6 ctx['ip'] = self.request.META.get('REMOTE_ADDR', None) g = GeoIP() ip = self.request.META.get('REMOTE_ADDR', None) if ip == '127.0.0.1': city='Seoul' if ip: city = g.city(ip) if ip == '127.0.0.1': city=city elif city == None: city= 'Seoul, KR' else: city = city['city'] if city == None: city= 'Seoul, KR' else: city = 'New York' # default city ctx['city'] = city return ctx