コード例 #1
0
ファイル: writers.py プロジェクト: EzerchE/askbot-devel
def __generate_comments_json(obj, type, user):#non-view generates json data for the post comments
    comments = obj.comments.all().order_by('id')
    # {"Id":6,"PostId":38589,"CreationDate":"an hour ago","Text":"hello there!","UserDisplayName":"Jarrod Dixon","UserUrl":"/users/3/jarrod-dixon","DeleteUrl":null}
    json_comments = []
    from forum.templatetags.extra_tags import diff_date
    for comment in comments:
        comment_user = comment.user
        delete_url = ""
        if user != None and auth.can_delete_comment(user, comment):
            #/posts/392845/comments/219852/delete
            #todo translate this url
            delete_url = reverse('index') + type + "s/%s/comments/%s/delete/" % (obj.id, comment.id)
        json_comments.append({"id" : comment.id,
            "object_id" : obj.id,
            "comment_age" : diff_date(comment.added_at),
            "text" : comment.comment,
            "user_display_name" : comment_user.username,
            "user_url" : comment_user.get_profile_url(),
            "delete_url" : delete_url
        })

    data = simplejson.dumps(json_comments)
    return HttpResponse(data, mimetype="application/json")
コード例 #2
0
ファイル: exporter.py プロジェクト: p2pu/osqa-badges
 def set_state():
     full_state['time_started'] = diff_date(start_time)
     cache.set(CACHE_KEY, full_state)
コード例 #3
0
 def set_state():
     full_state['time_started'] = diff_date(start_time)
     cache.set(CACHE_KEY, full_state)