Beispiel #1
0
def location(request):
    """
    Location selection of the user profile
    """
    profile, created = Profile.objects.get_or_create(user=request.user)
    geoip = hasattr(settings, "GEOIP_PATH")
    if geoip and request.method == "GET" and request.GET.get("ip") == "1":
        from django.contrib.gis.utils import GeoIP

        g = GeoIP()
        c = g.city(request.META.get("REMOTE_ADDR"))
        if c and c.get("latitude") and c.get("longitude"):
            profile.latitude = "%.6f" % c.get("latitude")
            profile.longitude = "%.6f" % c.get("longitude")
            profile.country = c.get("country_code")
            profile.location = unicode(c.get("city"), "latin1")

    if request.method == "POST":
        form = LocationForm(request.POST, instance=profile)
        if form.is_valid():
            form.save()
            request.user.message_set.create(message=_("Your profile information has been updated successfully."))

            signal_responses = signals.post_signal.send(sender=location, request=request, form=form)
            last_reponse = signals.last_response(signal_responses)
            if last_reponse:
                return last_response

    else:
        form = LocationForm(instance=profile)

    template = "userprofile/profile/location.html"
    data = {"section": "location", "GOOGLE_MAPS_API_KEY": GOOGLE_MAPS_API_KEY, "form": form, "geoip": geoip}
    signals.context_signal.send(sender=location, request=request, context=data)
    return render_to_response(template, data, context_instance=RequestContext(request))
Beispiel #2
0
def location(request):
    """
    Location selection of the user profile
    """
    profile, created = Profile.objects.get_or_create(user=request.user)
    geoip = hasattr(settings, "GEOIP_PATH")
    if geoip and request.method == "GET" and request.GET.get('ip') == "1":
        from django.contrib.gis.utils import GeoIP
        g = GeoIP()
        c = g.city(request.META.get("REMOTE_ADDR"))
        if c and c.get("latitude") and c.get("longitude"):
            profile.latitude = "%.6f" % c.get("latitude")
            profile.longitude = "%.6f" % c.get("longitude")
            profile.country = c.get("country_code")
            profile.location = unicode(c.get("city"), "latin1")

    if request.method == "POST":
        form = LocationForm(request.POST, instance=profile)
        if form.is_valid():
            form.save()
            request.user.message_set.create(message=_("Your profile information has been updated successfully."))
    else:
        form = LocationForm(instance=profile)

    template = "userprofile/profile/location.html"
    data = { 'section': 'location', 'GOOGLE_MAPS_API_KEY': GOOGLE_MAPS_API_KEY,
             'form': form, 'geoip': geoip }
    return render_to_response(template, data, context_instance=RequestContext(request))
Beispiel #3
0
def location(request):
    """
    Location selection of the user profile
    """
    profile, created = Profile.objects.get_or_create(user=request.user)

    if request.method == "POST":
        form = LocationForm(request.POST, instance=profile)
        if form.is_valid():
            form.save()
            messages.add_message(request, messages.SUCCESS, 'Location set')
            return HttpResponseRedirect(reverse("profile_edit_location_done"))
        else:
            messages.add_message(request, messages.ERROR,
                                 'Avatar not set. Form is not valid.')
    else:
        form = LocationForm(instance=profile)

    template = "userprofile/profile/location.html"
    data = {
        'section': 'location',
        'GOOGLE_MAPS_API_KEY': GOOGLE_MAPS_API_KEY,
        'form': form,
    }
    return render_to_response(template,
                              data,
                              context_instance=RequestContext(request))
Beispiel #4
0
def location(request):
    """
    Location selection of the user profile
    """
    profile, created = Profile.objects.get_or_create(user=request.user)
    geoip = hasattr(settings, "GEOIP_PATH")
    if geoip and request.method == "GET" and request.GET.get('ip') == "1":
        from django.contrib.gis.utils import GeoIP
        g = GeoIP()
        c = g.city(request.META.get("REMOTE_ADDR"))
        if c and c.get("latitude") and c.get("longitude"):
            profile.latitude = "%.6f" % c.get("latitude")
            profile.longitude = "%.6f" % c.get("longitude")
            profile.country = c.get("country_code")
            profile.location = unicode(c.get("city"), "latin1")

    if request.method == "POST":
        form = LocationForm(request.POST, instance=profile)
        if form.is_valid():
            form.save()
            request.user.message_set.create(message=_("Your profile information has been updated successfully."))

            signal_responses = signals.post_signal.send(sender=location, request=request, form=form)
            last_reponse = signals.last_response(signal_responses)
            if last_reponse:
                return last_response

    else:
        form = LocationForm(instance=profile)

    template = "userprofile/profile/location.html"
    data = { 'section': 'location', 'GOOGLE_MAPS_API_KEY': GOOGLE_MAPS_API_KEY,
             'form': form, 'geoip': geoip }
    signals.context_signal.send(sender=location, request=request, context=data)
    return render_to_response(template, data, context_instance=RequestContext(request))
Beispiel #5
0
def location(request):
    """
    Location selection of the user profile
    """
    profile, created = Profile.objects.get_or_create(user=request.user)

    if request.method == "POST":
        form = LocationForm(request.POST, instance=profile)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse("profile_edit_location_done"))
    else:
        form = LocationForm(instance=profile)

    template = "userprofile/profile/location.html"
    data = { 'section': 'location', 'GOOGLE_MAPS_API_KEY': GOOGLE_MAPS_API_KEY,
             'form': form, }
    return render_to_response(template, data, context_instance=RequestContext(request))