Exemple #1
0
    def post(self, request):
        args = request.POST.copy()
        validator = Validator(params=args)

        page_size = validator.arg_check(arg_key="pageSize",
                                        arg_type=int,
                                        default=PAGE_SIZE)
        page_index = validator.arg_check(arg_key="pageIndex",
                                         arg_type=int,
                                         default=PAGE_INDEX)

        is_arg_valid, err_msg = validator.arg_msg()
        if is_arg_valid:
            user_objs = (self.objects.all().values(*UserInfo.DISPLAY_FIELD))
            if user_objs:
                paginator = Paginator(user_objs, page_size)
                page_info = {
                    "pageSize": page_size,
                    "pageIndex": page_index,
                    "itemTotal": paginator.count,
                    "pageTotal": paginator.num_pages
                }
                data = list(paginator.page(page_index).object_list)
            else:
                page_info = {}
                data = []
            return self.get_json_response(data, **page_info)
        else:
            self.code = "00001"
            self.status = False
            self.message = err_msg
        return self.get_json_response()
Exemple #2
0
    def post(self, request):
        args = request.POST.copy()
        validator = Validator(params=args)

        index = validator.arg_check(
            arg_key="index",
            arg_type=str,
            nullable=False)
        alias = validator.arg_check(
            arg_key="alias",
            arg_type=str,
            nullable=False)
        mappings = validator.arg_check(
            arg_key="mappings",
            arg_type='json',
            nullable=False)

        is_arg_valid, err_msg = validator.arg_msg()
        if is_arg_valid:
            es = ESHandler()
            msg = es.index_create(index, alias, mappings)
            if msg:
                self.code = "00007"
                self.status = False
                self.message = msg
        else:
            self.code = "00001"
            self.status = False
            self.message = err_msg
        return self.get_json_response()
Exemple #3
0
    def post(self, request):
        args = request.POST.copy()
        validator = Validator(params=args)

        username = validator.arg_check(arg_key="username",
                                       arg_type=str,
                                       nullable=False)
        password = validator.arg_check(arg_key="password",
                                       arg_type=str,
                                       nullable=False)

        is_arg_valid, err_msg = validator.arg_msg()
        if is_arg_valid:
            user_obj = authenticate(request,
                                    username=username,
                                    password=password)
            if user_obj:
                login(request, user_obj)
                request.session["username"] = username
                request.session["user_id"] = user_obj.id
            else:
                self.code = "00005"
                self.status = False
                self.message = "登录失败,用户名或密码错误"
        else:
            self.code = "00001"
            self.status = False
            self.message = err_msg
        return self.get_json_response()
Exemple #4
0
    def post(self, request):
        args = request.POST.copy()
        validator = Validator(params=args)

        hobby_id = validator.arg_check(arg_key="hobbyId",
                                       arg_type=int,
                                       nullable=False)
        desc = validator.arg_check(arg_key="desc", arg_type=str)

        is_arg_valid, err_msg = validator.arg_msg()
        if is_arg_valid:
            data = None
            if desc:
                update_field = {"desc": desc}
                hobby_obj = (self.hobby_extend.filter(id=hobby_id).update(
                    **update_field))
                if hobby_obj:
                    hobby_obj = self.hobby.filter(id=hobby_id)
                    data = list(hobby_obj.values(*Hobby.DISPLAY_FIELDS))
            return self.get_json_response(data)
        else:
            self.code = "00001"
            self.status = False
            self.message = err_msg
        return self.get_json_response()
Exemple #5
0
    def post(self, request):
        args = request.POST.copy()
        validator = Validator(params=args)

        skill_id = validator.arg_check(
            arg_key="skillId",
            arg_type=int,
            nullable=False)
        desc = validator.arg_check(
            arg_key="desc",
            arg_type=str)

        is_arg_valid, err_msg = validator.arg_msg()
        if is_arg_valid:
            skill_obj = (self.skill_extend
                         .update_by_id(skill_id, desc=desc))
            # skill_obj = self.skill.get(id=skill_id)
            if skill_obj:
                data = (skill_obj
                        .values(*Skill.DISPLAY_FIELDS)
                        .first())
                return self.get_json_response(data)
            else:
                self.code = "00002"
                self.status = False
                self.message = err_msg
        else:
            self.code = "00001"
            self.status = False
            self.message = err_msg
        return self.get_json_response()
Exemple #6
0
    def post(self, request):
        args = request.POST.copy()
        validator = Validator(params=args)

        project_id = validator.arg_check(
            arg_key="projectId",
            arg_type=int,
            nullable=False)
        project_name = validator.arg_check(
            arg_key="projectName",
            arg_type=str)
        project_desc = validator.arg_check(
            arg_key="projectDesc",
            arg_type=str)
        project_company = validator.arg_check(
            arg_key="projectCompany",
            arg_type=str)

        is_arg_valid, err_msg = validator.arg_msg()
        if is_arg_valid:
            project_obj = (self.projects_extend
                           .filter(id=project_id))
            if project_obj:
                update_fields = dict()
                if project_name:
                    update_fields["name"] = project_name
                if project_desc:
                    update_fields["desc"] = project_desc
                if project_company:
                    update_fields["company"] = project_company

                if update_fields:
                    project_obj.update(**update_fields)
                    project_obj = (self.projects_extend
                                   .filter(id=project_id))

                data = list(project_obj
                            .values(*Project.DISPLAY_FIELDS))
                return self.get_json_response(data)
            else:
                self.code = "00002"
                self.status = False
                self.message = "项目不存在"
        else:
            self.code = "00001"
            self.status = False
            self.message = err_msg
        return self.get_json_response()
Exemple #7
0
    def post(self, request):
        args = request.POST.copy()
        validator = Validator(params=args)

        username = validator.arg_check(arg_key="username", arg_type=str)
        password = validator.arg_check(arg_key="password", arg_type=str)

        is_arg_valid, err_msg = validator.arg_msg()
        if is_arg_valid:

            encrypt_password = Encryption.encrypt(password)

            user = (User.objects.filter(is_deleted=False,
                                        username=username,
                                        password=encrypt_password).first())
            if user:
                login_info = {"user_id": user.user_id}

                Login.objects.create(**login_info)

                self.message = "登陆成功"
                return self.get_json_response()
            else:
                self.code = "00005"
                self.message = "登录失败"
                return self.get_json_response()
        else:
            self.code = "00001"
            self.status = False
            self.message = err_msg
        return self.get_json_response()
Exemple #8
0
    def post(self, request):
        args = request.POST.copy()
        validator = Validator(params=args)

        user_id = validator.arg_check(
            arg_key="userId",
            arg_type=int)

        is_arg_valid, err_msg = validator.arg_msg()
        if is_arg_valid:
            job_infos = JobInfo.objects.filter(is_deleted=False, user_id=user_id)

            data = list()
            for info in job_infos:
                data_tmp = dict()
                data_tmp["job_id"] = info.job_id
                data_tmp["name"] = info.name
                data_tmp["status"] = info.get_status_display()
                data_tmp["modified"] = info.modified

                data.append(data_tmp)

            return self.get_json_response(data)
        else:
            self.code = "00001"
            self.status = False
            self.message = err_msg
        return self.get_json_response()
Exemple #9
0
    def post(self, request):
        args = request.POST.copy()
        validator = Validator(params=args)

        username = validator.arg_check(arg_key="username",
                                       arg_type=str,
                                       nullable=False)
        password = validator.arg_check(arg_key="password",
                                       arg_type=str,
                                       nullable=False)
        age = validator.arg_check(arg_key="age", arg_type=int)
        phone = validator.arg_check(arg_key="phone", arg_type=str)
        email = validator.arg_check(arg_key="email", arg_type=str)
        role = validator.arg_check(arg_key="role", arg_type=int)

        is_arg_valid, err_msg = validator.arg_msg()
        if is_arg_valid:
            user_field = {
                "username": username,
                "password": make_password(password),
            }
            check_field = {"username": username}
            if age:
                user_field["age"] = age
            if phone:
                user_field["phone"] = phone
            if email:
                user_field["email"] = email
            if role:
                user_field["role"] = role
            user = (self.object.create_with_field_check(
                check_field, **user_field))

            if user:
                data = (self.object.display_fields(user,
                                                   UserInfo.DISPLAY_FIELD))
                return self.get_json_response(data)
            else:
                self.code = "00004"
                self.status = False
                self.message = "用户创建失败"
        else:
            self.code = "00001"
            self.status = False
            self.message = err_msg
        return self.get_json_response()
Exemple #10
0
    def post(self, request):
        args = request.POST.copy()
        validator = Validator(params=args)

        search_desc = validator.arg_check(
            arg_key="searchDesc",
            arg_type=str)
        page_size = validator.arg_check(
            arg_key="pageSize",
            arg_type=int,
            default=PAGE_SIZE)
        page_index = validator.arg_check(
            arg_key="pageIndex",
            arg_type=int,
            default=PAGE_INDEX)

        is_arg_valid, err_msg = validator.arg_msg()
        if is_arg_valid:
            if search_desc:
                hobby_objs = (self.hobby_extend
                              .filter(desc__contains=search_desc)
                              .values(*Hobby.DISPLAY_FIELDS))
            else:
                hobby_objs = (self.hobby_extend
                              .values(*Hobby.DISPLAY_FIELDS))

            paginator = Paginator(hobby_objs, page_size)
            page_info = {
                "pageSize": page_size,
                "pageIndex": page_index,
                "itemTotal": paginator.count,
                "pageTotal": paginator.num_pages
            }
            data = list(paginator
                        .page(page_index)
                        .object_list)
            return self.get_json_response(data, **page_info)
        else:
            self.code = "00001"
            self.status = False
            self.message = err_msg
        return self.get_json_response()
Exemple #11
0
    def post(self, request):
        args = request.POST.copy()
        validator = Validator(params=args)

        skill_desc = validator.arg_check(
            arg_key="skillDesc",
            arg_type=str)
        page_size = validator.arg_check(
            arg_key="pageSize",
            arg_type=int,
            default=8)
        page_index = validator.arg_check(
            arg_key="pageIndex",
            arg_type=int,
            default=1)

        is_arg_valid, err_msg = validator.arg_msg()
        if is_arg_valid:
            if skill_desc:
                skill_objs = (self.skill_extend.existed()
                              .filter(desc__contains=skill_desc)
                              .values(*Skill.DISPLAY_FIELDS))
            else:
                skill_objs = (self.skill_extend.existed()
                              .values(*Skill.DISPLAY_FIELDS))

            paginator = Paginator(skill_objs, page_size)
            page_info = {
                "pageSize": page_size,           # 每页条数
                "pageIndex": page_index,         # 当前页数
                "itemTotal": paginator.count,    # 数据总数
                "itemPage": paginator.num_pages  # 分页总数
            }
            data = list(paginator
                        .page(page_index)
                        .object_list)
            return self.get_json_response(data, **page_info)
        else:
            self.code = "00001"
            self.status = False
            self.message = err_msg
            return self.get_json_response()
Exemple #12
0
    def post(self, request):
        args = request.POST.copy()
        validator = Validator(params=args)

        name = validator.arg_check(
            arg_key="name",
            arg_type=str,
            nullable=False)
        desc = validator.arg_check(
            arg_key="desc",
            arg_type=str,
            nullable=False)
        company = validator.arg_check(
            arg_key="company",
            arg_type=str,
            nullable=False)

        is_arg_valid, err_msg = validator.arg_msg()
        if is_arg_valid:
            project = {
                "name": name,
                "desc": desc,
                "company": company
            }

            project_obj = self.projects.create(**project)
            if project_obj:
                data = model_to_dict(project_obj)
                return self.get_json_response(data)
            else:
                self.code = "00004"
                self.status = False
                self.message = "项目创建失败"
        else:
            self.code = "00001"
            self.status = False
            self.message = err_msg
        return self.get_json_response()
Exemple #13
0
    def post(self, request):
        args = request.POST.copy()
        validator = Validator(params=args)

        user_ids = validator.arg_check(arg_key="userIds",
                                       arg_type='list',
                                       nullable=False)

        is_arg_valid, err_msg = validator.arg_msg()
        if is_arg_valid:
            user_objs = (self.objects.delete_with_field_check(user_ids))
        else:
            self.code = "00001"
            self.status = False,
            self.message = err_msg
        return self.get_json_response()
Exemple #14
0
    def post(self, request):
        args = request.POST.copy()
        validator = Validator(params=args)

        hobby_id = validator.arg_check(arg_key="hobbyId",
                                       arg_type=str,
                                       nullable=False)

        is_arg_valid, err_msg = validator.arg_msg()
        if is_arg_valid:
            hobby_obj = (self.hobby_extend.filter(id=hobby_id))
            if hobby_obj:
                hobby_obj.update(is_deleted=True)
            return self.get_json_response()
        else:
            self.code = "00001"
            self.status = False,
            self.message = err_msg
        return self.get_json_response()
Exemple #15
0
    def post(self, request):
        args = request.POST.copy()
        validator = Validator(params=args)

        project_ids = validator.arg_check(
            arg_key="projectIds",
            arg_type="list",
            nullable=False)

        is_arg_valid, err_msg = validator.arg_msg()
        if is_arg_valid:
            project_objs = (self.projects_extend
                            .filter(id__in=project_ids))
            project_objs.update(is_deleted=True)
        else:
            self.code = "00001"
            self.status = False
            self.message = err_msg
        return self.get_json_response()
Exemple #16
0
    def post(self, request):
        args = request.POST.copy()
        validator = Validator(params=args)

        project_id = validator.arg_check(arg_key="projectId",
                                         arg_type=int,
                                         nullable=False)

        is_arg_valid, err_msg = validator.arg_msg()
        if is_arg_valid:
            project_obj = (self.projects_extend.filter(id=project_id).values(
                *Project.DISPLAY_FIELDS))
            data = list(project_obj)
            return self.get_json_response(data)
        else:
            self.code = "00001"
            self.status = False
            self.message = err_msg
        return self.get_json_response()
Exemple #17
0
    def post(self, request):
        args = request.POST.copy()
        validator = Validator(params=args)

        username = validator.arg_check(arg_key="username", arg_type=str)
        password = validator.arg_check(arg_key="password", arg_type=str)

        is_arg_valid, err_msg = validator.arg_msg()
        if is_arg_valid:
            user_info = {
                "username": username,
                "password": Encryption.encrypt(password)
            }
            User.objects.create(**user_info)
            return self.get_json_response()
        else:
            self.code = "00001"
            self.status = False
            self.message = err_msg
        return self.get_json_response()
Exemple #18
0
    def post(self, request):
        args = request.POST.copy()
        validator = Validator(params=args)

        skill_ids = validator.arg_check(
            arg_key="skillIds",
            arg_type='list',
            nullable=False)

        is_arg_valid, err_msg = validator.arg_msg()
        if is_arg_valid:
            skill_obj = (self.skill
                         .filter(id__in=skill_ids)
                         .update(is_deleted=True))
            return self.get_json_response()
        else:
            self.code = "00001"
            self.status = False
            self.message = err_msg
        return self.get_json_response()
Exemple #19
0
    def post(self, request):
        args = request.POST.copy()
        validator = Validator(params=args)

        desc = validator.arg_check(
            arg_key="desc",
            arg_type=str,
            nullable=False)

        is_arg_valid, err_msg = validator.arg_msg()
        if is_arg_valid:
            skill_obj = Skill.objects.create(desc=desc)
            data = {
                "id": skill_obj.id,
                "desc": skill_obj.desc
            }
            return self.get_json_response(data)
        else:
            self.code = "00001"
            self.status = False
            self.message = err_msg
        return self.get_json_response()
Exemple #20
0
    def post(self, request):
        args = request.POST.copy()
        validator = Validator(params=args)

        skill_id = validator.arg_check(
            arg_key="skillId",
            arg_type=int,
            nullable=False)

        is_arg_valid, err_msg = validator.arg_msg()
        if is_arg_valid:
            data = (self.skill
                    .filter(id=skill_id,
                            is_deleted=False)
                    .values(*Skill.DISPLAY_FIELDS)
                    .first())
            return self.get_json_response(data)
        else:
            self.code = "00001"
            self.status = False
            self.message = err_msg
            return self.get_json_response()
Exemple #21
0
    def post(self, request):
        args = request.POST.copy()
        validator = Validator(params=args)

        desc = validator.arg_check(arg_key="desc",
                                   arg_type=str,
                                   nullable=False)

        is_arg_valid, err_msg = validator.arg_msg()
        if is_arg_valid:
            hobby_field = {"desc": desc}
            hobby_obj = (self.hobby.create(**hobby_field))
            if hobby_obj:
                data = model_to_dict(hobby_obj)
                return self.get_json_response(data)
            else:
                self.code = "00004"
                self.status = False
                self.message = "兴趣创建失败"
        else:
            self.code = "00001"
            self.status = False
            self.message = err_msg
        return self.get_json_response()