Пример #1
0
def save_annotation(request):
    comments = simplejson.loads(request.POST.get('comments'))
    user_id = request.user.id
    text_id = request.POST.get('text_id')
    text_title = request.POST.get('text_title')

    annotation_id = None
    if comments and user_id and text_id and text_title:
        annotation_id = Annotation.save_annotation(user_id, text_id, text_title, comments)

    if annotation_id is None:
        raise Exception("hell f**k")

    return HttpResponse(annotation_id)
Пример #2
0
def render_profile(request, *args, **kwargs):
    """
    Prints out the annotations that this user has made
    """
    c = RequestContext(request)
    username = kwargs.get('username')

    user = User.objects.get(username=username)
    if user is not None:
        #get list of annotations
        c['annotations'] = Annotation.find_by_user_id(user.id)
        c['profile_username'] = username
        c['profile_user_img'] = _get_fb_pic_url(username) + "?width=200"
        return render_to_response('profile.html', c)
    raise Exception("no user")
Пример #3
0
def render_annotation(request, username, text_id):
    annotation_user = Profile.objects.get(username=username)
    text_info = Text.find_by_id(text_id)
    c = RequestContext(request)
    c['annotation_username'] = annotation_user.username
    c['annotation_user_id'] = annotation_user.id
    c['text_id'] = text_id
    c['text'] = text_info.get('text')
    annotation = Annotation.find_by_user_id_and_text_id(annotation_user.id, text_id)
    
    comments = []
    if annotation:
        comments = annotation.get('comments')
    
    c['initial_comments'] = simplejson.dumps(comments)
    return render_to_response('annotation.html', c)
Пример #4
0
def edit_annotation(request, text_id):
    c = RequestContext(request)
    if text_id is not None and request.user.is_authenticated():
        text_info = Text.find_by_id(text_id)
    else:
        return redirect('/')

    c['user'] = request.user
    c['annotation_username'] = request.user.username
    c['annotation_user_id'] = request.user.id
    c['text_id'] = text_id
    c['text'] = text_info.get('text')
    c['text_title'] = text_info.get('title')
    c['edit_mode'] = True
    
    annotation = Annotation.find_by_user_id_and_text_id(request.user.id, text_id)
    
    comments = []
    if annotation:
        comments = annotation.get('comments')
    
    c['initial_comments'] = simplejson.dumps(comments)
    return render_to_response('annotation.html', c)