Exemple #1
0
def get_dudle(id):
    """
    Get dudle for id
    """
    key = Key.from_path('Dudle', id)
    dudle = Dudle.get(key)
    return dudle
Exemple #2
0
def update_dudle_strokes(id, data):
    """Update stroke data
    """
    key = Key.from_path('Dudle', id)
    dudle = Dudle.get(key);
    if not hasattr(dudle, 'partial_stroke_data'):
        dudle.partial_stroke_data = db.Blob('')
    dudle.partial_stroke_data = db.Blob(dudle.partial_stroke_data
            + data)
    dudle.put()
Exemple #3
0
def update_dudle(id, format, data):
    """
    Update DudlePartial with data received from client
    """
    key = Key.from_path('Dudle', id)
    dudle = Dudle.get(key);
    if not hasattr(dudle, 'partial_data'):
        dudle.partial_data = db.Blob('')
    dudle.partial_data = db.Blob(dudle.partial_data
            + ''.join([ chr(int(n)) for n in data.split(',') ]))
    dudle.put()
Exemple #4
0
def finalize_dudle(id, format, width, height):
    """
    Finalize the Dudle object based on associated DudlePartial
    object and remove the DudlePartial object from the datastore.
    """
    key = Key.from_path('Dudle', id)
    dudle = Dudle.get(key)
    dudle.image_data = _pngData(dudle.partial_data, width, height)
    del dudle.partial_data
    dudle.complete = True
    dudle.put()
Exemple #5
0
def finalize_dudle_strokes(id, public=True, anonymous=False):
    key = Key.from_path('Dudle', id)
    dudle = Dudle.get(key)
    dudle.anonymous = anonymous
    dudle.public = public
    dudle.strokes = dudle.partial_stroke_data
    if hasattr(dudle, 'partial_data'):
        del dudle.partial_data
    del dudle.partial_stroke_data
    if len(dudle.strokes) > 7:
        dudle.complete = True
    dudle.put()
Exemple #6
0
def rate_dudle(id, rating, user):
    """
    Rate a dudle - may only be done once per dudle per authenticated user.

    @param id: id of dudle to rate
    @param rating: the rating (0-100)
    @param user: the user rating the dudle
    """
    if not user:
        raise DudleException(ERROR_NOT_LOGGED_IN)
    dudle_rating = DudleRating.all().filter('user = '******'dudle_id = ', id).get()
    rated = True
    if not dudle_rating:
        rated = False
        dudle_rating = DudleRating(user=user, rating=rating, dudle_id=id)
    key = Key.from_path('Dudle', id)
    dudle = Dudle.get(key)
    if dudle.artist and dudle.artist.user.email() == user.email():
        raise DudleException(ERROR_CONFLICT_OF_INTEREST)
    if not rated:
        adj = rating / float(dudle.rated_count + 1)
        r = dudle.rating * (dudle.rated_count/float(dudle.rated_count + 1))
        dudle.rated_count += 1
        r = r + adj
    else:
        adj = rating / float(dudle.rated_count)
        r = dudle.rating - (dudle_rating.rating / float(dudle.rated_count))
        dudle_rating.rating = rating
        r = r + adj
    if r > 100:
        r = 100
    dudle.rating = int(round(r))
    logging.info('Updated rating : ' + str(dudle.rating));
    dudle.put()
    dudle_rating.put()
    return dudle