def generateMap(): print '[Info]', datetime.datetime.now().strftime("%Y-%m-%d %H:%M"), 'Generating map...' map = models.UserPreferences.objects.filter(latitude__isnull=False).select_related('user') mapcache = u'{# this file is generated, do not edit it #}{% extends "base.html" %}{% load l10n %}{% block content %}<div class="padding15" id="map-title">{% include \'include/page_title.html\' with show_small_title=True %}</div><div id="map"></div>{% endblock %}{% block afterjs %}{% localize off %}<script>var center=new google.maps.LatLng({% if center %}{{ center.latitude }},{{ center.longitude }}{% else %}30,0{% endif %});var zoom={% if zoom %}{{ zoom }}{% else %}2{% endif %};var addresses = [' for u in map: try: mapcache += u'{open}"user_id": {user_id}, "username": "******","avatar": "{avatar}","location": "{location}","icon": "{icon}","latlong": new google.maps.LatLng({latitude},{longitude}){close},'.format( open=u'{', user_id=u.user_id, username=escape(u.user.username), avatar=escape(models.avatar(u.user)), location=escape(u.location), icon=escape( getCharacterImageFromPk(u.favorite_character1) if u.favorite_character1 is not None else SITE_STATIC_URL + u'static/img/default_map_icon.png', ), latitude=u.latitude, longitude=u.longitude, close=u'}', ) except: print 'One user not added in map', u.user.username, u.location print sys.exc_info()[0] mapcache += u'];</script><script src="' + SITE_STATIC_URL + u'static/js/map.js?' + STATIC_FILES_VERSION + u'"></script>{% endlocalize %}{% endblock %}' with open(django_settings.BASE_DIR + '/' + django_settings.SITE + '/templates/pages/map.html', 'w') as f: f.write(mapcache.encode('UTF-8')) f.close() print '[Info]', datetime.datetime.now().strftime("%Y-%m-%d %H:%M"), 'Done'
def latlong(): map = models.UserPreferences.objects.filter( latitude__isnull=False).select_related('user') mapcache = u'{# this file is generated, do not edit it #}{% extends "base.html" %}{% load i18n %}{% load l10n %}{% block title %}{% trans "Map" %}{% endblock %}{% block content %}<div id="map"></div>{% endblock %}{% block afterjs %}{% localize off %}<script>var center=new google.maps.LatLng({% if center %}{{ center.latitude }},{{ center.longitude }}{% else %}30,0{% endif %});var zoom={% if zoom %}{{ zoom }}{% else %}2{% endif %};var addresses = [' for u in map: try: mapcache += u'{open}"username": "******","avatar": "{avatar}","location": "{location}","icon": "{icon}","latlong": new google.maps.LatLng({latitude},{longitude}){close},'.format( open=u'{', username=escape(u.user.username), avatar=escape(models.avatar(u.user)), location=escape(u.location), icon=escape(u.favorite_character1_image if u. favorite_character1_image else SITE_STATIC_URL + u'static/img/default_map_icon.png'), latitude=u.latitude, longitude=u.longitude, close=u'}', ) except: print 'One user not added in map', u.user.username, u.location print sys.exc_info()[0] mapcache += u'];</script><script src="' + SITE_STATIC_URL + u'static/js/map.js?' + STATIC_FILES_VERSION + u'"></script>{% endlocalize %}{% endblock %}' with open( django_settings.BASE_DIR + '/' + django_settings.SITE + '/templates/pages/map.html', 'w') as f: f.write(mapcache.encode('UTF-8')) f.close()
def latlong(): map = models.UserPreferences.objects.filter(latitude__isnull=False).select_related('user') mapcache = u'{# this file is generated, do not edit it #}{% extends "base.html" %}{% load i18n %}{% load l10n %}{% block title %}{% trans "Map" %}{% endblock %}{% block content %}<div id="map"></div>{% endblock %}{% block afterjs %}{% localize off %}<script>var center=new google.maps.LatLng({% if center %}{{ center.latitude }},{{ center.longitude }}{% else %}30,0{% endif %});var zoom={% if zoom %}{{ zoom }}{% else %}2{% endif %};var addresses = [' for u in map: try: mapcache += u'{open}"username": "******","avatar": "{avatar}","location": "{location}","icon": "{icon}","latlong": new google.maps.LatLng({latitude},{longitude}){close},'.format( open=u'{', username=escape(u.user.username), avatar=escape(models.avatar(u.user)), location=escape(u.location), icon=escape(u.favorite_character1_image if u.favorite_character1_image else SITE_STATIC_URL + u'static/img/default_map_icon.png'), latitude=u.latitude, longitude=u.longitude, close=u'}', ) except: print 'One user not added in map', u.user.username, u.location print sys.exc_info()[0] mapcache += u'];</script><script src="' + SITE_STATIC_URL + u'static/js/map.js?' + STATIC_FILES_VERSION + u'"></script>{% endlocalize %}{% endblock %}' with open(django_settings.BASE_DIR + '/' + django_settings.SITE + '/templates/pages/map.html', 'w') as f: f.write(mapcache.encode('UTF-8')) f.close()
def follow(request, username): context = ajaxContext(request) if not request.user.is_authenticated( ) or request.method != 'POST' or request.user.username == username: raise PermissionDenied() user = get_object_or_404(models.User.objects.extra( select={ 'followed': 'SELECT COUNT(*) FROM magi_userpreferences_following WHERE userpreferences_id = {} AND user_id = auth_user.id' .format(request.user.preferences.id), }).annotate( total_followers=Count('followers')).select_related('preferences'), username=username) # If the user being followed blocked the authenticated user if user.id in request.user.preferences.cached_blocked_by_ids: raise PermissionDenied() if 'follow' in request.POST and not user.followed: request.user.preferences.following.add(user) request.user.preferences.save() pushNotification( user, 'follow', [unicode(request.user)], url_values=[str(request.user.id), unicode(request.user)], image=models.avatar(request.user, size=100)) return JsonResponse({ 'total_followers': user.total_followers + 1, 'result': 'followed', }) if 'unfollow' in request.POST and user.followed: request.user.preferences.following.remove(user) request.user.preferences.save() return JsonResponse({ 'total_followers': user.total_followers - 1, 'result': 'unfollowed', }) return JsonResponse({ 'total_followers': user.total_followers, })
def avatar(user, size=200): return models.avatar(user, size)