def view_profile(request, alias): """ Show developer profile page """ developer = Developer.all().filter('alias =', alias).get() if developer is None: raise Http404 try: near_me = Developer.proximity_fetch(Developer.all().filter('country =', developer.country).filter('alias !=', developer.alias), geotypes.Point(developer.location.lat, developer.location.lon), max_results=20, max_distance=1000000) except ValueError: logging.exception("problem resolving near users for lat/long %s %s" % (developer.location.lat, developer.location.lon)) near_me = [] params = { 'developer': developer, 'near_me': near_me } if developer.email_contact: try: from recaptcha.client import mailhide params['email_contact'] = mailhide.ashtml(developer.email_contact, settings.MAILHIDE_PUBLIC, settings.MAILHIDE_PRIVATE) except: logger.exception("problems") return render_to_response('users/profile.html', params, RequestContext(request))
class UsersTest(TestCase): def setUp(self): appengine_user = users.User("*****@*****.**", _user_id="*****@*****.**") logging.info(appengine_user) django_user = User.get_djangouser_for_user(appengine_user) logging.info(django_user) self.developer = Developer(user=django_user, alias="test", first_name="test", last_name="test", location="0,0") self.developer.put() def testRemove(self): self.developer.delete()
def sign_up(request): """ Sign_up a new developer """ #just in case is already registered if Developer.all().filter("user ="******"/") return SignUpWizard([SignUpStep1Form, SignUpStep2Form, SignUpStep3Form])(request)
def developers_json(request): def dump_developer(d): return {"lat": d.location.lat, "lon": d.location.lon } data = simplejson.dumps([dump_developer(d) for d in Developer.all()]) return HttpResponse(data)
def avatar(request, developer_id): developer = Developer.get_by_id(int(developer_id)) if developer is None: raise Http404 if developer.photo is None: return HttpResponseRedirect("/static/images/no_avatar.png") return HttpResponse(developer.photo, mimetype="image/jpeg")
def search(request): params = {} form = SearchForm(request.GET or None) if form.is_valid(): query = form.cleaned_data['query'] params['developers'] = Developer.search(query=query) params['form'] = form return render_to_response('search.html', params, RequestContext(request))
def check_profile(request): developer = Developer.all().filter('user ='******'next', None) if next: return HttpResponseRedirect(next) else: return HttpResponseRedirect('/')
def developers_by_country(request, country_code): """ Show developers for a country """ country_code = country_code.upper() developers = Developer.all().filter('country =', country_code).fetch(1000) country = Country.get_by_key_name(country_code) if country is None: raise Http404 return render_to_response('country/country.html', {'developers': developers, 'country': country }, RequestContext(request))
def index(request): query = Developer.all() query.order('-sign_up_date') developers = query.fetch(100) countries = Country.all().filter("total >", 0).fetch(300) countries = sorted(countries, key=lambda x: unicode(x.name)) return render_to_response('index.html', {'developers': developers, 'countries': countries }, RequestContext(request))
def update_real(cls, timestamp, cursor=None, stats=None): """ Real update """ query = Developer.all() if cursor: query.with_cursor(cursor) if stats is None: stats = { 'total': 0, 'tags': {}, 'python': 0, 'java': 0 } devs = query.fetch(100) stats['total'] += len(devs) for dev in devs: if dev.python_sdk: stats['python'] += 1 if dev.java_sdk: stats['java'] += 1 for tag in dev.tags: stats['tags'][tag] = stats['tags'].get(tag, 0) + 1 if len(devs) == 100: #continue deferred.defer(cls.update, timestamp=timestamp, cursor=query.cursor(), stats=stats) else: dev_stats = DeveloperStats(timestamp=timestamp, total = stats['total'], python = stats['python'], java = stats['java']) dev_stats.put() #Track the Top 100 tags tags = sorted(stats['tags'].iteritems(), key=lambda t: t[1], reverse=True)[:100] batch = [TagStats(developer_stats=dev_stats, timestamp=timestamp, name=k, total=v, popularity=float(v)/stats['total']) for k, v in tags] db.put(batch) return None
def update(cls, country_code): """ Update the count of developers by country """ if not country_code in COUNTRIES_CODE: raise Error("Country code doesn't exist") country = cls.get_by_key_name(country_code) if country is None: country = cls.get_or_insert(country_code, code=country_code) from users.models import Developer country.total = Developer.all().filter("country =", country_code).count(limit=1000) country.put()
def developer_sitemap(request): sitemap = """<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">""" for dev in Developer.all(): sitemap += """ <url> <loc>%s%s</loc> <lastmod>2010-04-21</lastmod> <changefreq>monthly</changefreq> <priority>0.8</priority> </url> """ % (settings.SITE_URL, reverse('users_profile', args=[dev.alias])) sitemap += "</urlset>" return HttpResponse(sitemap)
def fusiontable_build(request): """ Update the fusion table table = {'developers': { 'alias': 'STRING', 'name': 'STRING', 'location': 'LOCATION', 'address': 'STRING', 'profile': 'STRING', 'country': 'STRING', 'about_me': 'STRING', } } #created with tableid = int(ft_client.query(SQL().createTable(table)).split("\n")[1]) """ FETCH = 10 cursor = request.POST.get('cursor', None) query = Developer.all() if cursor is None: #first call truncate table from ft import ftclient from ft.sql.sqlbuilder import SQL from ft.authorization.clientlogin import ClientLogin token = ClientLogin().authorize(settings.GOOGLE_USER, settings.GOOGLE_PASSWORD) ft_client = ftclient.ClientLoginFTClient(token) ft_client.query("DELETE FROM %d" % settings.FUSIONTABLE_ID) else: query = query.with_cursor(cursor) developers = query.fetch(FETCH) for i, d in enumerate(developers): taskqueue.add(url=reverse("users_fusiontable_insert", args=[str(d.key())]), countdown=i) if len(developers) == FETCH: taskqueue.add(url=reverse("users_fusiontable_build"), params={'cursor': query.cursor()}, countdown=40) return HttpResponse("")
def fusiontable_insert(request, key): import textile from ft import ftclient from ft.sql.sqlbuilder import SQL from ft.authorization.clientlogin import ClientLogin d = Developer.get(key) if d is None: raise Http404 token = ClientLogin().authorize(settings.GOOGLE_USER, settings.GOOGLE_PASSWORD) ft_client = ftclient.ClientLoginFTClient(token) try: rowid = int(ft_client.query(SQL().select(settings.FUSIONTABLE_ID, ['rowid'], "alias='%s'" % d.alias)).split("\n")[1]) ft_client.query(SQL().delete(settings.FUSIONTABLE_ID, rowid)) except (ValueError): pass about_me = striptags(textile.textile(d.about_me or ""))[:200] if len(about_me) == 200: about_me += "..." u = { 'alias': d.alias, 'name': d.getname(), 'location': "%0.3f,%0.3f" % (d.location.lat, d.location.lon), 'address': d.location_description or "", 'country': d.get_country(), 'avatar': reverse('users_avatar', args=[d.key().id()]), 'profile': reverse('users_profile', args=[d.alias]), 'about_me': about_me } ft_client.query(SQL().insert(settings.FUSIONTABLE_ID, u)) return HttpResponse("")
def edit_profile(request, alias=None): if alias != request.user.developer.alias: return render_to_response('error.html', {'message': "Permiso denegado" }, RequestContext(request)) developer = Developer.all().filter('alias =', alias).get() if developer is None: return render_to_response('error.html', {'message': "Usuario inexistente" }, RequestContext(request)) if request.method == 'POST': form = DeveloperForm(request.POST, instance=developer) if form.is_valid(): developer = form.save(commit=False) if request.FILES.has_key('photo'): developer.photo = request.FILES['photo'].read() developer.put() taskqueue.add(url=reverse("users_fusiontable_insert", args=[str(developer.key())])) return HttpResponseRedirect(reverse('users_profile', args=[alias])) else: form = DeveloperForm(instance=developer) return render_to_response('users/edit.html', {'form' : form}, RequestContext(request))
def developers_by_tag(request, tag): developers = Developer.all().filter('tags =', tag).fetch(100) return render_to_response('users/tags.html', {'developers': developers, 'tag': tag }, RequestContext(request))