コード例 #1
0
ファイル: views.py プロジェクト: EdgarSun/Django-Demo
def retrieve_comment_list_JSON(request):
    if request.method == "GET":

        comment_list, startRecordIndex, endRecordIndex, page_index = retrieve_comment_list(request)

        if comment_list == None or len(comment_list) == 0:
            response_data = {"result": []}
            return HttpResponse(simplejson.dumps(response_data), mimetype="application/json")
        else:
            comments = []
            for commentItem in comment_list:
                comment_dict = {
                    "index": 0,
                    "id": commentItem.id,
                    "authorName": commentItem.author.get_full_name(),
                    "avatar": commentItem.author.get_profile().avatar,
                    "authorID": commentItem.author.id,
                    "content": commentItem.content,
                    "pubDate": str(commentItem.pub_date),
                    "verbosePubDate": pretty_date(commentItem.pub_date),
                    "tagID": 0,
                    "commentCount": commentItem.comment_count,
                    "platform": "the earth",
                }
                comments.append(comment_dict)
            response_data = {
                "result": comments,
                "start_index": startRecordIndex,
                "end_index": endRecordIndex,
                "maxDisplayItems": COMMENT_RETRIEVE_COUNT,
                "page": page_index,
            }
            return HttpResponse(simplejson.dumps(response_data), mimetype="application/json")
コード例 #2
0
ファイル: views.py プロジェクト: EdgarSun/Django-Demo
def convert_showcase_to_dict(request,showcaseItem):
        showcase_dict = {
                  'id' : showcaseItem.id,
                  'author' : showcaseItem.author.get_full_name(),
                  'authorID' : showcaseItem.author.id,
                  'content' : showcaseItem.content,
                  'slugContent' : showcaseItem.slugContent,
                  'description' : showcaseItem.description,
                  'resource' : showcaseItem.resource,
                  'resource_url_list' : generate_resource_url_list(request,showcaseItem.resource),
                  'isPublished' : showcaseItem.isPublished,
                  'isExternal' : showcaseItem.isExternal,
                  'spam' : showcaseItem.spam,
                  'isShader' : showcaseItem.isShader,
                  'tag_list' : showcaseItem.tag_list,
                  'link_list' : showcaseItem.link_list,
                  'verbosePubDate' : pretty_date(showcaseItem.pub_date),
                  'pub_date' : str(showcaseItem.pub_date)
                  }
        return showcase_dict
コード例 #3
0
ファイル: views.py プロジェクト: EdgarSun/Django-Demo
def retrieve_event_list_with_JSON(request):
    if request.method == "GET":
        
        event_list,start_index,end_index,page_index = retrieve_event_list(request)

        if event_list == None or len(event_list) == 0:
            response_data = {
                 'result' : []
                 };
            return HttpResponse(simplejson.dumps(response_data), mimetype="application/json")

        else:
            events = []
            for eventItem in event_list:
                event_dict = {
                                'index': 0,
                                'id': eventItem.id,
                                'authorName': eventItem.object.author.get_full_name(),
                                'avatar': eventItem.object.author.get_profile().avatar,
                                'authorID': eventItem.object.author.id,
                                'content': eventItem.object.content,
                                'pubDate': str(eventItem.object.pub_date),
                                'verbosePubDate':  pretty_date(eventItem.object.pub_date),
                                'tagID': eventItem.tag_id,
                                'commentCount': eventItem.comment_count,
                                'platform' : "the earth"
                             }
                events.append(event_dict)
            response_data = {
                 'result' : events,
                 'start_index' : start_index,
                 'end_index' : end_index,
                 'maxDisplayItems' : GENERAL_RETRIEVE_COUNT,
                 'page' : page_index
                 };
            return HttpResponse(simplejson.dumps(response_data), mimetype="application/json")
コード例 #4
0
def pretty_datetime(value):
    return pretty_date(value)