Exemple #1
0
def delete_entry(request):
    if request.method == 'OPTIONS':
        return util.return_header(200)
    if request.method != 'POST':
        return HttpResponse(status=412)
    body = util.getBody(request)

    obj = Entry.objects.get(no=body.get("entryNo"),
                            user_id=body.get("user_id"))
    obj.delete()
    return util.return_header(200)
Exemple #2
0
def update_entry(request):
    if request.method == 'OPTIONS':
        return util.return_header(200)
    if request.method != 'POST':
        return HttpResponse(status=412)
    body = util.getBody(request)
    body = util.setUpDt(body)

    obj = Entry.objects.get(no=body.get("entryNo"),
                            user_id=body.get("user_id"))
    obj = EntryForm(body, instance=obj)
    obj.save()
    return util.return_header(200)
Exemple #3
0
def login(request):
    if request.method == 'OPTIONS':
        return util.return_header(200)
    if request.method != 'POST':
        return HttpResponse(status=412)

    body = util.getBody(request)

    if LoginUser.objects.filter(user_id=body.get("user_id"),
                                password=body.get("password"),
                                site_id='1').exists():
        return util.return_header(200)
    else:
        return util.return_header(401)
Exemple #4
0
def get_entry_list(request):
    if request.method == 'OPTIONS':
        return util.return_header(200)
    if request.method != 'GET':
        return HttpResponse(status=412)

    if "page" in request.GET:
        page = int(request.GET.get("page"))
    else:
        return HttpResponse(status=412)

    if "perpage" in request.GET:
        perpage = int(request.GET.get("perpage"))
    else:
        return HttpResponse(status=412)

    if "site_name" in request.GET:
        site = request.GET.get("site_name")
        cond = Q(site_name__contains=site)
    else:
        cond = Q()

    if "user_id" in request.GET:
        userid = request.GET.get("user_id")
        cond2 = Q(user_id__contains=userid)
    else:
        cond2 = Q(user_id=None)

    data = Entry.objects.filter(cond, cond2).order_by('no').reverse().values(
        'no', 'url', 'site_name', 'version',
        'user_id')[(page - 1) * perpage:page * perpage]
    count = Entry.objects.filter(cond, cond2).count()
    list_result = [entry for entry in data]
    res = {"tableData": list_result, "pagerTotalCount": count}
    return util.add_header(res)
Exemple #5
0
def create_entry(request):
    if request.method == 'OPTIONS':
        return util.return_header(200)
    if request.method != 'POST':
        return HttpResponse(status=412)
    obj = Entry()
    info = EntryForm(util.getBody(request), instance=obj)
    info.save()
    ret = {"entryNo": obj.no}
    return util.add_header(ret)
Exemple #6
0
def update_user(request):
    if request.method == 'OPTIONS':
        return util.return_header(200)
    if request.method != 'POST':
        return HttpResponse(status=412)

    body = util.getBody(request)

    obj = LoginUser(user_id=body.get("user_id"), site_id='1')
    obj.password = body.get("password")
    obj.update_at = datetime.datetime.now().strftime('%Y-%m-%d')
    obj.save()
    ret = {"Msg": "更新しました", "OK": True}
    return util.add_header(ret)
Exemple #7
0
def get_entry(request):
    if request.method == 'OPTIONS':
        return util.return_header(200)
    if request.method != 'GET':
        return HttpResponse(status=412)
    if "entryNo" in request.GET:
        entryNo = request.GET.get("entryNo")
    else:
        return HttpResponse(status=412)
    if "user_id" in request.GET:
        user = request.GET.get("user_id")
    else:
        user = None

    obj = Entry.objects.get(no=entryNo, user_id=user)
    return util.add_header(model_to_dict(obj))
Exemple #8
0
def create_user(request):
    if request.method == 'OPTIONS':
        return util.return_header(200)
    if request.method != 'POST':
        return HttpResponse(status=412)

    body = util.getBody(request)

    if LoginUser.objects.filter(user_id=body.get("user_id"),
                                site_id='1').exists():
        ret = {"Msg": "指定されたユーザIDはすでに登録されています。別のユーザIDを入力してください。", "OK": False}
        return util.add_header(ret)

    obj = LoginUser()
    info = LoginUserForm(body, instance=obj)
    info.save()
    ret = {"Msg": "登録しました", "OK": True}
    return util.add_header(ret)