Beispiel #1
0
def add_sample_log(log_sample_data, album_sample_data, city_sample_data, user_sample_data):
    log = Log()
    log.city = City.objects.get(name=city_sample_data['name'])
    log.latitude = log_sample_data['latitude']
    log.longitude = log_sample_data['longitude']
    log.description = log_sample_data['description']
    user_profile = UserProfile.objects.get(user__username=user_sample_data['username'])
    log.user_profile = user_profile
    log.album = Album.objects.get(name=album_sample_data['name'], user_profile=user_profile)
    log.score = 0
    log.save()
    log_picture = LogPicture()
    log_picture.log = log
    log_picture.picture = File(get_small_image())
    log_picture.save()
Beispiel #2
0
def add_sample_log(log_sample_data, album_sample_data, city_sample_data,
                   user_sample_data):
    log = Log()
    log.city = City.objects.get(name=city_sample_data['name'])
    log.latitude = log_sample_data['latitude']
    log.longitude = log_sample_data['longitude']
    log.description = log_sample_data['description']
    user_profile = UserProfile.objects.get(
        user__username=user_sample_data['username'])
    log.user_profile = user_profile
    log.album = Album.objects.get(name=album_sample_data['name'],
                                  user_profile=user_profile)
    log.score = 0
    log.save()
    log_picture = LogPicture()
    log_picture.log = log
    log_picture.picture = File(get_small_image())
    log_picture.save()
Beispiel #3
0
def create_log(request):
    """
    Creates a new log using the provided POST data. First, the
    provided POST data is validated, if no errors are returned,
    then a log is created successfully. Also, new LogPicture is
    created for each of the pictures in the POST data. Also note
    that this view only accepts ajax requests, else a 404 error
    is raised.
    """
    if request.is_ajax():
        user = request.user
        return_data = {}
        if user.is_authenticated():
            post_data = request.POST
            file_data = request.FILES
            location = post_data.get('location', '')
            if ',' in location:
                location = location[0:location.index(',')]
            latitude = post_data.get('latitude', '')
            longitude = post_data.get('longitude', '')
            album_name = post_data.get('album_name', '')
            description = post_data.get('description', '')

            # validate log data
            error = validate_add_log_form(location, latitude, longitude, description, file_data)
            if error is None:
                # get user_profile, album and city associated with this log
                user_profile = UserProfile.objects.get(user=user)
                city = City.objects.get(name=location)
                if album_name != "None":
                    album = Album.objects.get(name=album_name, user_profile=user_profile)
                else:
                    album = None

                # create a new log
                new_log = Log()
                new_log.user_profile = user_profile
                new_log.city = city
                new_log.latitude = latitude
                new_log.longitude = longitude
                new_log.album = album
                new_log.description = description
                new_log.score = 0
                new_log.save()

                # now that we have created_at, update the log score and re-save
                new_log.score = new_log.get_log_score()
                new_log.save()

                # create new log picture for every image submitted by user
                for key, image_file in file_data.iteritems():
                    new_log_picture = LogPicture()
                    new_log_picture.log = new_log
                    new_log_picture.picture = image_file
                    new_log_picture.save()

                # finally, update user travel stats
                user_profile.update_user_travel_stats()

            else:
                return_data['error'] = error
        else:
            return_data['redirect_to'] = '/mytravelog/sign_in/'

        return_data = json.dumps(return_data)
        mimetype = "application/json"
        return HttpResponse(return_data, mimetype)

    else:
        raise Http404
Beispiel #4
0
def create_log(request):
    """
    Creates a new log using the provided POST data. First, the
    provided POST data is validated, if no errors are returned,
    then a log is created successfully. Also, new LogPicture is
    created for each of the pictures in the POST data. Also note
    that this view only accepts ajax requests, else a 404 error
    is raised.
    """
    if request.is_ajax():
        user = request.user
        return_data = {}
        if user.is_authenticated():
            post_data = request.POST
            file_data = request.FILES
            location = post_data.get('location', '')
            if ',' in location:
                location = location[0:location.index(',')]
            latitude = post_data.get('latitude', '')
            longitude = post_data.get('longitude', '')
            album_name = post_data.get('album_name', '')
            description = post_data.get('description', '')

            # validate log data
            error = validate_add_log_form(location, latitude, longitude,
                                          description, file_data)
            if error is None:
                # get user_profile, album and city associated with this log
                user_profile = UserProfile.objects.get(user=user)
                city = City.objects.get(name=location)
                if album_name != "None":
                    album = Album.objects.get(name=album_name,
                                              user_profile=user_profile)
                else:
                    album = None

                # create a new log
                new_log = Log()
                new_log.user_profile = user_profile
                new_log.city = city
                new_log.latitude = latitude
                new_log.longitude = longitude
                new_log.album = album
                new_log.description = description
                new_log.score = 0
                new_log.save()

                # now that we have created_at, update the log score and re-save
                new_log.score = new_log.get_log_score()
                new_log.save()

                # create new log picture for every image submitted by user
                for key, image_file in file_data.iteritems():
                    new_log_picture = LogPicture()
                    new_log_picture.log = new_log
                    new_log_picture.picture = image_file
                    new_log_picture.save()

                # finally, update user travel stats
                user_profile.update_user_travel_stats()

            else:
                return_data['error'] = error
        else:
            return_data['redirect_to'] = '/mytravelog/sign_in/'

        return_data = json.dumps(return_data)
        mimetype = "application/json"
        return HttpResponse(return_data, mimetype)

    else:
        raise Http404