コード例 #1
0
def createNotice(request):
    try:
        data = parse_arg(request.POST, ['content', 'title'])
    except KeyError:
        return JsonResponse({"code": ErrorCode.ARGUMENT_NONEXIST, "data": ""})
    if "attach" in request.FILES:
        attach = parse_arg(request.FILES, ['attach'])['attach']
        if attach.size > MAX_DOCUMENT_SIZE:
            return JsonResponse({
                "code": ErrorCode.RESOURCE_TOOLARGE,
                "data": ""
            })
        Notice.objects.create(attach=attach,
                              title=data['title'],
                              content=data['content'],
                              time=time.strftime("%Y-%m-%d %H:%M:%S",
                                                 time.localtime(
                                                     time.time()))).save()
        return JsonResponse({"code": ErrorCode.ERROR_NON, "data": ""})
    else:
        Notice.objects.create(title=data['title'],
                              content=data['content'],
                              time=time.strftime("%Y-%m-%d %H:%M:%S",
                                                 time.localtime(
                                                     time.time()))).save()
        return JsonResponse({"code": ErrorCode.ERROR_NON, "data": ""})
コード例 #2
0
ファイル: views.py プロジェクト: sfzyk/tscs
def make_comment(request):  #保存不提交
    try:
        data = parse_arg(request.POST, ['project_id', 'comment', 'score'])
    except KeyError:
        return JsonResponse({"code": ErrorCode.ARGUMENT_NONEXIST, "data": ""})
    try:
        comment_to = Project.objects.get(id=data['project_id'])
        expert = Expert.objects.get(id=request.e['id'])
    except ObjectDoesNotExist:
        return JsonResponse({"code": ErrorCode.PROJECT_NOTEXIST, "data": ""})
    if not valid_score_check(data['score']):
        return JsonResponse({"code": ErrorCode.ARGUMENT_INVALID, "data": ""})
    else:
        if Comment.objects.filter(Q(expert=expert)
                                  & Q(project=comment_to)).count() != 0:
            comment = Comment.objects.get(
                Q(expert=expert) & Q(project=comment_to))
            comment.comment = data['comment']
            comment.score = data['score']
            comment.save()
        else:
            Comment.objects.create(comment=data['comment'],
                                   score=data['score'],
                                   project=comment_to,
                                   expert=expert,
                                   state=0)
        return JsonResponse({"code": ErrorCode.ERROR_NON, "data": ""})
コード例 #3
0
ファイル: views.py プロジェクト: sfzyk/tscs
def getMyProjectComment(request):
    expert_id = request.e['id']
    try:
        project_id = parse_arg(request.POST, ['project_id'])['project_id']
    except KeyError:
        return JsonResponse({"code": ErrorCode.ARGUMENT_NONEXIST, "data": ""})
    try:
        expert = Expert.objects.get(id=expert_id)
        project = Project.objects.get(id=project_id)
    except ObjectDoesNotExist:
        return JsonResponse({"code": ErrorCode.PROJECT_NOTEXIST, "data": ""})
    if Comment.objects.filter(Q(expert=expert)
                              & Q(project=project)).count() == 0:
        return JsonResponse({
            "code": ErrorCode.ERROR_NON,
            "data": {
                "comment": "",
                "score": 0,
                "state": 0
            }
        })
    else:
        comment = Comment.objects.get(Q(expert=expert) & Q(project=project))
        return JsonResponse({
            "code": ErrorCode.ERROR_NON,
            "data": {
                "comment": comment.comment,
                "score": comment.score,
                "state": comment.state
            }
        })
コード例 #4
0
def login(request):
    try:
        data = parse_arg(request.POST, ['email', 'password'])
    except KeyError:
        return JsonResponse({
            "code": ErrorCode.ARGUMENT_NONEXIST,
            "data": ""
        })

    if valid_student_login(password=data['password'], user_email=data['email']):
        st = Student.objects.get(email=data['email'])
        request.session['user'] = {"email": data['email'],
                                   'id': st.id,
                                   'student_id': st.student_id,
                                   'name': st.name,
                                   'department': st.department,
                                   'major': st.major,
                                   'year': st.year,
                                   'telephone': st.telephone,
                                   'birth_date': str(st.birth_date)
                                   }
        request.session.modified = True
        return JsonResponse({
            "code": ErrorCode.ERROR_NON,
            "data": ""
        })
    else:
        return JsonResponse({
            "code": ErrorCode.ARGUMENT_INVALID,
            "data": ""
        })
コード例 #5
0
def delNotice(request):
    try:
        notice_id = parse_arg(request.POST, ['notice_id'])['notice_id']
    except KeyError:
        return JsonResponse({"code": ErrorCode.ARGUMENT_NONEXIST, "data": ""})
    try:
        Notice.objects.filter(id=notice_id).delete()
    except:  # 目前未知
        return JsonResponse({"code": ErrorCode.UNKNOWN_ERROR, "data": ""})
    return JsonResponse({"code": ErrorCode.ERROR_NON, "data": ""})
コード例 #6
0
def get_project_list(request, index, pagesize):
    if not valid_page_index(index):
        return JsonResponse({
            "code": ErrorCode.PAGE_INVALID,
            "data": ""
        })
    if not valid_page_size(pagesize):
        return JsonResponse({
            "code": ErrorCode.PAGE_INVALID,
            "data": ""
        })
    try:
        data = parse_arg(request.POST, ['field', 'search', 'order'])
    except KeyError:
        return JsonResponse({
            "code": ErrorCode.ARGUMENT_NONEXIST,
            "data": ""
        })

    project_list = Project.objects.filter(student_id=request.u['id'])
    pre_fix = None
    if data['order'] == '2':
        pre_fix = "+"
    elif data['order'] == '1':
        pre_fix = "-"
    if pre_fix:
        if pre_fix == '+':
            pre_fix = ""
        project_list = project_list.order_by(pre_fix + data['field'])

    search = json.loads(data['search'])
    str_item = ["innovation", "descriptions", "email", "telephone", "name", "keywords", 'full_name', "contest__name"]
    if "common_search" in search:
        project_list = project_list.filter(
            reduce(lambda x, y: x | y, [Q(**{i + "__contains": search['common_search']}) for i in str_item]))
    other_item = ['state', 'contest_id', 'expire', 'education_background', "category", "type", "id"]
    for i in str_item:
        if i in search:
            project_list = project_list.filter(**{i + "__contains": search[i]})
    for i in other_item:
        if i in search:
            project_list = project_list.filter(**{i: search[i]})

    object_num = (project_list.count() + pagesize - 1) // pagesize
    data = [project_get_student_name(i) for i in project_list[index * pagesize: (index + 1) * pagesize]]
    #print(data)
    return JsonResponse({
        "code": ErrorCode.ERROR_NON,
        "data": {
            "num": object_num,
            "data": data
        }
    })
コード例 #7
0
def getAttach(request):
    try:
        notice_id = parse_arg(request.GET, ['notice_id'])['notice_id']
    except KeyError:
        return JsonResponse({"code": ErrorCode.ARGUMENT_NONEXIST, "data": ""})
    try:
        attach = Notice.objects.get(id=notice_id).attach
    except ObjectDoesNotExist:
        return JsonResponse({"code": ErrorCode.EXPERT_NOTEXIST, "data": ""})
    return sendfile(request=request,
                    filename=attach.path,
                    attachment=True,
                    attachment_filename=attach)
コード例 #8
0
def register(request):
    try:
        data = parse_arg(request.POST, ['email', 'password', 'id', 'name',
                                        'department', 'year', 'telephone', 'major', 'birth_date'])
    except KeyError:
        return JsonResponse({
            "code": ErrorCode.ARGUMENT_NONEXIST,
            "data": ""
        })
    if not valid_email(data['email']):
        return JsonResponse({
            "code": ErrorCode.EMAIL_INVALID,
            "data": ""
        })
    if not valid_telephone(data['telephone']):
        return JsonResponse({
            "code": ErrorCode.TELEPHONE_INVALID,
            "data": ""
        })
    if not valid_password(data['password']):
        return JsonResponse({
            "code": ErrorCode.PASSWORD_INVALID,
            "data": ""
        })
    if not valid_birth_date(data['birth_date']):
        return JsonResponse({
            "code": ErrorCode.BIRTHDATE_INVALID,
            "data": ""
        })
    if len(data['name']) == 0 or len(data['id']) == 0:
        return JsonResponse({
            "code": ErrorCode.ARGUMENT_INVALID,
            "data": ""
        })
    res = Student.objects.filter(email=data['email'])
    if len(res) >= 1:
        return JsonResponse({
            "code": ErrorCode.EMAIL_DUP,
            "data": ""
        })
    else:
        Student.objects.create(student_id=data['id'], email=data['email'], password=data['password'],
                               telephone=data['telephone'], name=data['name'], birth_date=data['birth_date'],
                               year=data['year'], major=data['major'], department=data['department']).save()
        return JsonResponse({
            "code": ErrorCode.ERROR_NON,
            "data": ""
        })
コード例 #9
0
def get_contest(request, index, pagesize):
    if not valid_page_index(index):
        if not valid_page_index(index):
            return JsonResponse({
                "code": ErrorCode.PAGE_INVALID,
                "data": ""
            })
    try:
        data = parse_arg(request.POST, ['field', 'search', 'order'])
    except KeyError:
        return JsonResponse({
            "code": ErrorCode.ARGUMENT_NONEXIST,
            "data": ""
        })
    contest_list = Contest.objects.filter(~Q(state=0))
    pre_fix = None
    if data['order'] == '2':
        pre_fix = "+"
    elif data['order'] == '1':
        pre_fix = "-"
    if pre_fix:
        if pre_fix == '+':
            pre_fix = ""
        contest_list = contest_list.order_by(pre_fix + data['field'])
    search = json.loads(data['search'])
    str_item = ["name", "descriptions", "expire_date", "checkin_expire_date"]
    other_item = ['state', 'id']
    for i in str_item:
        if i in search:
            contest_list = contest_list.filter(**{i + "__contains": search[i]})
    for i in other_item:
        if i in search:
            contest_list = contest_list.filter(**{i: search[i]})
    object_num = (contest_list.count() + pagesize - 1) // pagesize
    data = [i.object2json() for i in contest_list[index * pagesize: (index + 1) * pagesize]]
    return JsonResponse({
        "code": ErrorCode.ERROR_NON,
        "data": {
            "num": object_num,
            "data": data
        }
    })
コード例 #10
0
def getNotice(request):
    try:
        id = parse_arg(request.POST, ['notice_id'])['notice_id']
    except KeyError:
        return JsonResponse({"code": ErrorCode.ARGUMENT_NONEXIST, "data": ""})
    try:
        notice = Notice.objects.get(id=id)
    except ObjectDoesNotExist:
        return JsonResponse({"code": ErrorCode.EXPERT_NOTEXIST, "data": ""})
    result = {
        "code": ErrorCode.ERROR_NON,
        "data": {
            "title": notice.title,
            "content": notice.content,
            "time": str(notice.time).split(" ")[0]
        }
    }
    if notice.attach != "":
        result['data']['attach'] = notice.attach.name
    return JsonResponse(result)
コード例 #11
0
ファイル: views.py プロジェクト: sfzyk/tscs
def commit(request):
    try:
        project_id = parse_arg(request.POST, ['project_id'])['project_id']
    except KeyError:
        return JsonResponse({"code": ErrorCode.ARGUMENT_NONEXIST, "data": ""})
    try:
        expert = Expert.objects.get(id=request.e['id'])
        project = Project.objects.get(id=project_id)
        comment = Comment.objects.get(Q(project=project) & Q(expert=expert))
    except ObjectDoesNotExist:
        return JsonResponse({"code": ErrorCode.PROJECT_NOTEXIST, "data": ""})
    if (project.state != 2 and project.state != 3) or comment.state != 0:
        return JsonResponse({
            "code": ErrorCode.UNACCEPTABLE_OPERATING,
            "data": ""
        })
    comment.state = 1
    comment.save()
    project.state = 3
    project.save()
    return JsonResponse({"code": ErrorCode.ERROR_NON, "data": ""})