コード例 #1
0
def get_subscribed_sections(request):
    """
    USER: {
      id: <str>,
      nickname: <str>,
      gender: <str, 'M'/'F'>
    }
    SECTION: {
      name: <str>,
      creator: USER,
      description: <str>
    }
    {
      sections: [SECTION],
    }
    """

    json_dict = get_json_dict(data={})

    user = request.user
    sections = []
    default_sections = ["TechDaily"]
    if (user.is_authenticated):
        account = user.account
        for section in account.subscribed_sections.all():
            sections.append(section)
    if len(sections) == 0:
        for section in default_sections:
            sections.append(Section.objects.get(name=section))

    json_dict['data']['sections'] = []
    for section in sections:
        json_dict['data']['sections'].append(get_section_dict(section))

    return JsonResponse(json_dict)
コード例 #2
0
def get_created_sections(request):
    json_dict = get_json_dict(data={})
    account = request.user.account

    json_dict['data']['sections'] = []

    for section in account.created_sections:
        json_dict['data']['sections'].append(get_section_dict(section))

    return JsonResponse(json_dict)
コード例 #3
0
def get_hot_sections(request):
    json_dict = get_json_dict(data={})
    hot_sections = Section.objects.filter()[0:10]  # TODO - fake function

    json_dict['data']['sections'] = []

    for section in hot_sections:
        json_dict['data']['sections'].append(get_section_dict(section))

    return JsonResponse(json_dict)
コード例 #4
0
def search_for_sections(request):
    keyword = request.GET['keyword']

    sections = Section.objects.filter(name__contains=keyword)

    json_dict = get_json_dict(data={})
    json_dict['data']['sections'] = []

    for section in sections:
        json_dict['data']['sections'].append(get_section_dict(section))

    return JsonResponse(json_dict)
コード例 #5
0
def get_subscribed_sections(request):
    json_dict = get_json_dict(data={})

    user = request.user
    sections = []
    default_sections = ["TechDaily"]
    if (user.is_authenticated):
        account = user.account
        for section in account.subscribed_sections.all():
            sections.append(section)
    if len(sections) == 0:
        for section in default_sections:
            sections.append(Section.objects.get(name=section))

    json_dict['data']['sections'] = []
    for section in sections:
        json_dict['data']['sections'].append(get_section_dict(section))

    return JsonResponse(json_dict)
コード例 #6
0
def get_section_detail(request):
    section_name = request.GET["section"]
    section = Section.objects.get(name=section_name)
    return JsonResponse(
        get_json_dict(data={'section': get_section_dict(section)}))