Example #1
0
def user_weather_alert(request, user_weather_alert_id=None, user_weather_alert_short_url=None):
    if not (user_weather_alert_id or user_weather_alert_short_url):
        return redirect('wxwarn.views.home')
    if user_weather_alert_short_url:
        try:
            user_weather_alert_id = short_url.decode_url(user_weather_alert_short_url)
        except:  # No good exception to catch, library complains of substring error
            raise Http404

    try:
        a_user_weather_alert = UserWeatherAlert.objects.get(id=user_weather_alert_id)
    except UserWeatherAlert.DoesNotExist:
        raise Http404

    user_location_geojson = a_user_weather_alert.user_location.geojson()
    longitude, latitude = user_location_geojson['geometry']['coordinates']

    return render(
        request,
        'user_weather_alert.html',
        {
            'user': a_user_weather_alert.user,
            'user_location': a_user_weather_alert.user_location,
            'user_location_geojson': json.dumps(user_location_geojson),
            'weather_alert_geojson': json.dumps(a_user_weather_alert.weather_alert.geojson()),
            'user_location_latitude': latitude,
            'user_location_longitude': longitude,
            'user_location_last_located': localize_datetime(a_user_weather_alert.user, a_user_weather_alert.user_location.updated),
            'weather_alert': a_user_weather_alert.weather_alert,
            'weather_alert_location_id': a_user_weather_alert.weather_alert_location_id,
            'effective': localize_datetime(a_user_weather_alert.user, a_user_weather_alert.weather_alert.effective),
            'expires': localize_datetime(a_user_weather_alert.user, a_user_weather_alert.weather_alert.expires),
            'leaflet': True,
        })
Example #2
0
def account_landing(request):
    """
    GET /account/

    Account landing/status page
    """
    try:
        user_location_status = UserLocationStatus.objects.get(user=request.user)
    except UserLocationStatus.DoesNotExist:
        user_location_status = None

    status_message_template = None

    if user_location_status is not None:
        if user_location_status.location_status == UserLocationStatus.LOCATION_STATUS_OK:
            user_location_status_message = 'We\'re successfully tracking your location.'
        elif user_location_status.location_status == UserLocationStatus.LOCATION_STATUS_NOT_OPTED_IN:
            user_location_status_message = 'You have not opted in to Google Latitude.'
            status_message_template = 'account/status_enable_history.html'
        elif user_location_status.location_status == UserLocationStatus.LOCATION_STATUS_INVALID_CREDENTIALS:
            user_location_status_message = 'Invalid credentials.'
        elif user_location_status.location_status == UserLocationStatus.LOCATION_STATUS_NO_HISTORY:
            user_location_status_message = 'You have no Google Latitude history.'
        else:
            user_location_status_message = 'There was an error tracking your location.'

        user_location_status_success_error = 'success' if user_location_status.location_status == UserLocationStatus.LOCATION_STATUS_OK else 'error'
        last_location_check = localize_datetime(request.user, user_location_status.updated)
    else:
        user_location_status_message = 'You must be new here. We haven\'t quite got around to checking your location yet, but refresh to see if we have.'
        user_location_status_success_error = 'error'
        last_location_check = None

    user_profile = request.user.get_profile()

    user_last_location = user_profile.last_location
    user_last_locations = {
        'type': 'FeatureCollection',
        'features': [
            user_location.geojson() for user_location in user_profile.last_locations(minutes=1440)
        ]
    }

    return render(
        request,
        'account/status.html',
        {
            'page': 'landing',
            'user_profile_id': user_profile.id,
            'user_location_status': user_location_status,
            'user_location_status_ok': user_location_status is not None and user_location_status.location_status == UserLocationStatus.LOCATION_STATUS_OK,
            'user_location_status_message': user_location_status_message,
            'user_location_status_success_error': user_location_status_success_error,
            'last_location_check': last_location_check,
            'user_last_location': json.dumps(user_last_location.geojson() if user_last_location is not None else None),
            'user_last_locations': json.dumps(user_last_locations),
            'status_message_template': status_message_template,
            'leaflet': True,
        })
Example #3
0
def weather_alert(request, weather_alert_id):
    """
    GET /weather_alerts/<id>/

    View weather alert details
    """
    try:
        a_weather_alert = WeatherAlert.objects.get(id=weather_alert_id)
    except WeatherAlert.DoesNotExist:
        raise Http404
    return render(
        request,
        'weather_alert.html',
        {
            'weather_alert': a_weather_alert,
            'weather_alert_geojson': json.dumps(a_weather_alert.geojson()),
            'effective': localize_datetime(request.user, a_weather_alert.effective),
            'expires': localize_datetime(request.user, a_weather_alert.expires),
            'leaflet': True,
        })