def create_registration(self, hackathon, user, args): """Register hackathon for user Will add a new record in table UserRegistrationRel if precondition fulfilled """ self.log.debug("create_register: %r" % args) user_id = args['user_id'] check_login_provider = self.__is_user_hackathon_login_provider(user, hackathon) if check_login_provider["fail"]: return login_provider_error( "hackathon registration not login provider", friendly_message="当前黑客松活动只是使用" + ",".join(check_login_provider["provides"]) + "账户才能报名", provides=",".join(check_login_provider["provides"])) if self.is_user_registered(user.id, hackathon): self.log.debug("user %s already registered on hackathon %s" % (user_id, hackathon.id)) return self.get_registration_detail(user, hackathon) if self.admin_manager.is_hackathon_admin(hackathon.id, user.id): return precondition_failed("administrator cannot register the hackathon", friendly_message="管理员或裁判不能报名") if hackathon.registration_start_time and hackathon.registration_start_time > self.util.get_now(): return precondition_failed("hackathon registration not opened", friendly_message="报名尚未开始") if hackathon.registration_end_time and hackathon.registration_end_time < self.util.get_now(): return precondition_failed("hackathon registration has ended", friendly_message="报名已经结束") if self.__is_hackathon_filled_up(hackathon): return precondition_failed("hackathon registers reach the upper threshold", friendly_message="报名人数已满") try: is_auto_approve = hackathon.config.get(HACKATHON_CONFIG.AUTO_APPROVE, True) status = HACK_USER_STATUS.AUTO_PASSED if is_auto_approve else HACK_USER_STATUS.UNAUDIT args.pop("user_id") args.pop("hackathon_id") user_hackathon = UserHackathon.objects(user=user, hackathon=hackathon).first() if not user_hackathon: user_hackathon = UserHackathon.objects.create( user=user, hackathon=hackathon, status=status, **args) else: # visitor -> competitor user_hackathon.role = HACK_USER_TYPE.COMPETITOR user_hackathon.status = status user_hackathon.save() # create a team as soon as user registration approved(auto or manually) if is_auto_approve: self.team_manager.create_default_team(hackathon, user) self.__ask_for_dev_plan(hackathon, user) self.__update_register_stat(hackathon) return user_hackathon.dic() except Exception as e: self.log.error(e) return internal_server_error("fail to create register")
def create_registration(self, hackathon, user, args): """Register hackathon for user Will add a new record in table UserRegistrationRel if precondition fulfilled """ self.log.debug("create_register: %r" % args) user_id = args['user_id'] check_login_provider = self.__is_user_hackathon_login_provider(user, hackathon) if check_login_provider["fail"]: return login_provider_error( "hackathon registration not login provider", friendly_message="当前黑客松活动只是使用" + ",".join(check_login_provider["provides"]) + "账户才能报名", provides=",".join(check_login_provider["provides"])) if self.is_user_registered(user.id, hackathon): self.log.debug("user %s already registered on hackathon %s" % (user_id, hackathon.id)) return self.get_registration_detail(user, hackathon) if self.admin_manager.is_hackathon_admin(hackathon.id, user.id): return precondition_failed("administrator cannot register the hackathon", friendly_message="管理员或裁判不能报名") if hackathon.registration_start_time and hackathon.registration_start_time > self.util.get_now(): return precondition_failed("hackathon registration not opened", friendly_message="报名尚未开始") if hackathon.registration_end_time and hackathon.registration_end_time < self.util.get_now(): return precondition_failed("hackathon registration has ended", friendly_message="报名已经结束") if self.__is_hackathon_filled_up(hackathon): return precondition_failed("hackathon registers reach the upper threshold", friendly_message="报名人数已满") try: is_auto_approve = hackathon.config.get(HACKATHON_CONFIG.AUTO_APPROVE, True) status = HACK_USER_STATUS.AUTO_PASSED if is_auto_approve else HACK_USER_STATUS.UNAUDIT args.pop("user_id") args.pop("hackathon_id") user_hackathon = UserHackathon.objects(user=user, hackathon=hackathon).first() if not user_hackathon: user_hackathon = UserHackathon.objects.create( user=user, hackathon=hackathon, status=status, **args) else: # visitor -> competitor user_hackathon.role = HACK_USER_TYPE.COMPETITOR user_hackathon.status = status user_hackathon.save() # create a team as soon as user registration approved(auto or manually) if is_auto_approve: self.team_manager.create_default_team(hackathon, user) self.__ask_for_dev_plan(hackathon, user) self.__update_register_stat(hackathon) return user_hackathon.dic() except Exception as e: self.log.error(e) return internal_server_error("fail to create register")
def create_registration(self, hackathon, user, args): """Register hackathon for user Will add a new record in table UserRegistrationRel if precondition fulfilled """ self.log.debug("create_register: %r" % args) user_id = args['user_id'] check_login_provider = self.__is_user_hackathon_login_provider( user, hackathon) if check_login_provider["fail"]: return login_provider_error( "hackathon registration not login provider", friendly_message="当前黑客松活动只是使用" + ",".join(check_login_provider["provides"]) + "账户才能报名", provides=",".join(check_login_provider["provides"])) if self.is_user_registered(user.id, hackathon): self.log.debug("user %d already registered on hackathon %d" % (user_id, hackathon.id)) return self.get_registration_detail(user, hackathon) if self.admin_manager.is_hackathon_admin(hackathon.id, user.id): return precondition_failed( "administrator cannot register the hackathon", friendly_message="管理员或裁判不能报名") if hackathon.registration_start_time and hackathon.registration_start_time > self.util.get_now( ): return precondition_failed("hackathon registration not opened", friendly_message="报名尚未开始") if hackathon.registration_end_time and hackathon.registration_end_time < self.util.get_now( ): return precondition_failed("hackathon registration has ended", friendly_message="报名已经结束") if self.__is_hackathon_filled_up(hackathon): return precondition_failed( "hackathon registers reach the upper threshold", friendly_message="报名人数已满") try: args["status"] = RGStatus.AUTO_PASSED if hackathon.is_auto_approve( ) else RGStatus.UNAUDIT args['create_time'] = self.util.get_now() user_hackathon_rel = self.db.add_object_kwargs( UserHackathonRel, **args).dic() # create a team as soon as user registration approved(auto or manually) if hackathon.is_auto_approve(): self.team_manager.create_default_team(hackathon, user) self.__update_register_stat(hackathon) return user_hackathon_rel except Exception as e: self.log.error(e) return internal_server_error("fail to create register")
def create_registration(self, hackathon, user, args): """Register hackathon for user Will add a new record in table UserRegistrationRel if precondition fulfilled """ self.log.debug("create_register: %r" % args) user_id = args['user_id'] check_login_provider = self.__is_user_hackathon_login_provider(user, hackathon) if check_login_provider["fail"]: return login_provider_error("hackathon registration not login provider", friendly_message="当前黑客松活动只是使用"+",".join(check_login_provider["provides"])+"账户才能报名", provides=",".join(check_login_provider["provides"])) if self.is_user_registered(user.id, hackathon): self.log.debug("user %d already registered on hackathon %d" % (user_id, hackathon.id)) return self.get_registration_detail(user, hackathon) if self.admin_manager.is_hackathon_admin(hackathon.id, user.id): return precondition_failed("administrator cannot register the hackathon", friendly_message="管理员或裁判不能报名") if hackathon.registration_start_time and hackathon.registration_start_time > self.util.get_now(): return precondition_failed("hackathon registration not opened", friendly_message="报名尚未开始") if hackathon.registration_end_time and hackathon.registration_end_time < self.util.get_now(): return precondition_failed("hackathon registration has ended", friendly_message="报名已经结束") if self.__is_hackathon_filled_up(hackathon): return precondition_failed("hackathon registers reach the upper threshold", friendly_message="报名人数已满") try: args["status"] = RGStatus.AUTO_PASSED if hackathon.is_auto_approve() else RGStatus.UNAUDIT args['create_time'] = self.util.get_now() user_hackathon_rel = self.db.add_object_kwargs(UserHackathonRel, **args).dic() # create a team as soon as user registration approved(auto or manually) if hackathon.is_auto_approve(): self.team_manager.create_default_team(hackathon, user) self.__update_register_stat(hackathon) return user_hackathon_rel except Exception as e: self.log.error(e) return internal_server_error("fail to create register")