def create_undertake_need(self, request, team, **kwargs): if check_bad_words(kwargs["title"]) or check_bad_words( kwargs["description"]): abort(400, '含有非法词汇') team_needs = TeamNeed.objects.filter(team=team, type=2) if team_needs.count() == 0: team.score += get_score_stage(2) team.score_records.create(score=get_score_stage(2), type="初始数据", description="首次发布团队需求") team.save() n = team.needs.create(type=2) for k in kwargs: setattr(n, k, kwargs[k]) n.save() # 发布动态 action.send_member_need(team, n) # 增加积分 request.user.score += get_score_stage(1) request.user.score_records.create(score=get_score_stage(1), type="能力", description="发布一个团队需求") team.score += get_score_stage(1) team.score_records.create(score=get_score_stage(1), type="活跃度", description="发布一个团队需求") request.user.save() team.save() abort(200)
def post(self, request, team, **kwargs): """修改团队资料 :param team: 团队ID :param kwargs: name: 团队名 description: 团队简介 is_recruiting:是否招募新成员 url: 团队链接 advantage: 团队优势 business_stage: 工商阶段 financing_stage: 融资阶段 valuation: 团队估值 valuation_unit: 团队估值单位 province: city: county: fields: 团队领域,格式:'field1|field2' tags: 标签,格式:'tag1|tag2|tag3|...' """ if request.user != team.owner: abort(403, '只允许队长操作') fields = kwargs.pop('fields', None) tags = kwargs.pop('tags', None) for k in kwargs: if k == "name": name = kwargs['name'] # 昵称唯一性验证 if Team.enabled.filter(name=name).exclude( id=team.id).count() != 0: abort(403, '团队名已被注册') # 昵称非法词验证 if check_bad_words(name): abort(400, '团队名含非法词汇') if k == "description": if check_bad_words(kwargs['description']): abort(400, '含有非法词汇') setattr(team, k, kwargs[k]) if fields: fields = fields.split('|')[:2] if len(fields) < 2: fields.append('') team.field1, team.field2 = fields[0].strip(), fields[1].strip() if tags: tags = tags.split('|')[:5] with transaction.atomic(): team.tags.all().delete() order = 0 for tag in tags: tag = tag.strip() if tag: team.tags.create(name=tag, order=order) order += 1 team.save() abort(200)
def post(self, request, task, **kwargs): """再派任务状态下的任务修改 :param task_id: 任务ID :param title: 任务标题 :param content: 任务内容 :param deadline: 任务期限 """ if check_bad_words(kwargs["title"]) or check_bad_words( kwargs["content"]): abort(400, '含有非法词汇') if request.user != task.team.owner: abort(403, '不能给自己发送任务') if task.status != 1: abort(403, '任务状态错误') for k in kwargs: setattr(task, k, kwargs[k]) task.save() abort(200)
def post(self, request, exp, **kwargs): """修改用户的某条经历""" if check_bad_words(kwargs["description"]): abort(400, '含有非法词汇') if exp.user != request.user: abort(403, '只能修改自己的经历') for k in kwargs: setattr(exp, k, kwargs[k]) exp.save() abort(200)
def post(self, request, team, **kwargs): """发布外包任务 :param: executor_id: 执行者ID :param: title: 标题 :param: content: 内容 :param: expend: 预计费用 :param;deadline: 截止时间 """ if check_bad_words(kwargs["title"]) or check_bad_words( kwargs["content"]): abort(400, '含有非法词汇') if request.user != team.owner: abort(403, '只有队长可以操作') executor_id = kwargs.pop('executor_id') executor = None try: executor = Team.enabled.get(id=executor_id) except ObjectDoesNotExist: abort(401, '执行者不存在') if not team.members.filter(user=executor.owner).exists(): abort(403, '执行者非团队成员') t = team.outsource_external_tasks.create(status=0, executor=executor, deadline=kwargs['deadline']) for k in kwargs: setattr(t, k, kwargs[k]) t.save() request.user.score += get_score_stage(1) request.user.score_records.create(score=get_score_stage(1), type="能力", description="发布一个外部任务") team.score += get_score_stage(1) team.score_records.create(score=get_score_stage(1), type="能力", description="发布一个外部任务") request.user.save() team.save() abort(200)
def post(self, request, **kwargs): """新建团队,同时调用融云接口为该团队创建一个对应的群聊 :param kwargs: name: 团队名称 description: 团队描述 url: 团队链接 province: city: county: fields: 团队领域,格式:'field1|field2' tags: 标签,格式:'tag1|tag2|tag3|...' :return: team_id: 团队id """ name = kwargs.pop('name') fields = kwargs.pop('fields', None) tags = kwargs.pop('tags', None) # 昵称唯一性验证 if Team.enabled.filter(name=name).count() != 0: abort(403, '团队名已被注册') # 昵称非法词验证 if check_bad_words(name): abort(403, '团队名含非法词汇') team = Team(owner=request.user, name=name) team.save() for k in kwargs: setattr(team, k, kwargs[k]) fields = fields.split('|')[:2] if fields is not None else ('', '') team.field1, team.field2 = fields[0].strip(), fields[1].strip() if tags: tags = tags.split('|')[:5] with transaction.atomic(): team.tags.all().delete() order = 0 for tag in tags: tag = tag.strip() if tag: team.tags.create(name=tag, order=order) order += 1 team.save() action.create_team(request.user, team) request.user.score += get_score_stage(2) request.user.score_records.create( score=get_score_stage(2), type="能力", description="成功创建一个团队") request.user.save() return JsonResponse({'team_id': team.id})
def post(self, request, type, **kwargs): """增加一条经历""" if check_bad_words(kwargs['description']): abort(400, '含有非法词汇') request.user.experiences.create(type=type, description=kwargs['description'], unit=kwargs['unit'], profession=kwargs['profession'], degree=kwargs['degree'], time_in=kwargs['time_in'], time_out=kwargs['time_out']) request.user.score += get_score_stage(3) request.user.score_records.create(score=get_score_stage(3), type="活跃度", description="增加一条经历") request.user.save() abort(200)
def post(self, request, team, name, description, tags): """发布成果 :param description: 成果描述 :return: achievement_id: 成果id """ if request.user != team.owner: abort(403, '只有队长可以操作') if check_bad_words(description): abort(400, '含有非法词汇') achievement_num = team.achievements.count() if achievement_num == 0: team.score += get_score_stage(2) team.score_records.create(score=get_score_stage(2), type="初始数据", description="首次发布团队成果") achievement = Achievement(team=team, name=name, description=description, user=request.user, tags=tags) picture = request.FILES.get('image') if picture: filename = save_uploaded_image(picture) if filename: achievement.picture = filename else: abort(400, '图片上传失败') achievement.save() request.user.score += get_score_stage(1) request.user.score_records.create(score=get_score_stage(1), type="能力", description="发布一个团队成果") request.user.save() team.score += get_score_stage(1) team.score_records.create(score=get_score_stage(1), type="活跃度", description="发布一个团队成果") team.save() return JsonResponse({'achievement_id': achievement.id, 'code': 0})
def post(self, request, name, description, tags): """发布成果 :param description: 成果描述 :return: achievement_id: 成果id """ # 检查非法词汇 if check_bad_words(description): abort(400, '含有非法词汇') system_param = request.param # 检查发布的时间间隔 last_time = datetime.datetime.now() + datetime.timedelta( minutes=system_param.publish_min_minute) if Achievement.objects.filter(user=request.user, time_created__gt=last_time).count() > 0: abort( 403, '发布成果时间间隔不能小于{}分钟'.format_map(system_param.publish_min_minute)) # 检查上传图片数量 max_pic = system_param.pic_max + 1 if 'image' + str(max_pic) in request.FILES: abort(403, '最多上传' + str(system_param.pic_max) + '张图片') pics = [ request.FILES.get('image' + str(i)) if 'image' + str(i) in request.FILES else None for i in range(1, max_pic) ] achievement = Achievement(user=request.user, description=description, name=name, tags=tags) if len(pics) != 0: filenames = [] for p in pics: if p is None: continue filenames.append(save_uploaded_image(p)) achievement.picture = str(filenames) else: abort(500, '图片上传失败') achievement.save() return JsonResponse({'achievement_id': achievement.id, 'code': 0})
def post(self, request, **kwargs): """修改用户资料 :param kwargs: name: 昵称 description: 个人简介 qq: wechat: email: 电子邮箱 gender: 性别 birthday: 生日 province: city: county: tags: 标签,格式:'tag1|tag2|...',最多5个 role: adept_field: 擅长领域 adept_skill: 擅长技能 expect_role: 期望角色 follow_field: 关注领域 follow_skill: 关注技能 other_number: unit1: unit2: profession: """ name = kwargs.pop('name', '') user = request.user if len(name) > 0: # 昵称唯一性验证 if User.enabled.filter(name=name).exclude(id=user.id).count() != 0: abort(403, '昵称已存在') # 昵称非法词验证 if check_bad_words(name): abort(403, '昵称含非法词汇') # 首次修改昵称增加积分 if (user.name == "网络用户 #" + str(user.id)) and \ (user.name != name): user.score += get_score_stage(3) user.score_records.create(score=get_score_stage(3), type="初始数据", description="首次更换昵称") user.name = name update_nickname(user.phone_number, name) normal_keys = ('description', 'qq', 'wechat', 'email', 'gender', 'birthday', 'province', 'city', 'county', 'adept_field', 'adept_skill', 'expect_role', 'follow_field', 'follow_skill', 'goodat', 'follow') for k in normal_keys: if k in kwargs: setattr(user, k, kwargs[k]) tags = kwargs.pop('tags', None) if tags: tags = tags.split('|')[:5] with transaction.atomic(): user.tags.all().delete() order = 0 for tag in tags: tag = tag.strip() if tag: user.tags.create(name=tag, order=order) order += 1 role_keys = ('role', 'other_number', 'unit1', 'unit2', 'profession') if not user.is_role_verified: for k in role_keys: if k in kwargs: setattr(user, k, kwargs[k]) user.save() abort(200)