本文整理汇总了Python中hackathon.hmongo.models.UserHackathon.objects方法的典型用法代码示例。如果您正苦于以下问题:Python UserHackathon.objects方法的具体用法?Python UserHackathon.objects怎么用?Python UserHackathon.objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hackathon.hmongo.models.UserHackathon
的用法示例。
在下文中一共展示了UserHackathon.objects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: unlike_hackathon
# 需要导入模块: from hackathon.hmongo.models import UserHackathon [as 别名]
# 或者: from hackathon.hmongo.models.UserHackathon import objects [as 别名]
def unlike_hackathon(self, user, hackathon):
user_hackathon = UserHackathon.objects(user=user, hackathon=hackathon).first()
if user_hackathon:
user_hackathon.like = False
user_hackathon.save()
# sync the like count
like_count = UserHackathon.objects(hackathon=hackathon, like=True).count()
self.update_hackathon_stat(hackathon, HACKATHON_STAT.LIKE, like_count)
return ok()
示例2: delete_hackathon
# 需要导入模块: from hackathon.hmongo.models import UserHackathon [as 别名]
# 或者: from hackathon.hmongo.models.UserHackathon import objects [as 别名]
def delete_hackathon(self):
"""delete hackathon
:return hackathon in dict if updated successfully.
"""
hackathon = g.hackathon
try:
UserHackathon.objects(hackathon=hackathon).delete()
self.log.debug("delete hackathon:" + hackathon.name)
hackathon.delete()
hackathon.save()
return ok()
except Exception as e:
self.log.error(e)
return internal_server_error("fail to delete hackathon" + hackathon.name)
示例3: create_registration
# 需要导入模块: from hackathon.hmongo.models import UserHackathon [as 别名]
# 或者: from hackathon.hmongo.models.UserHackathon import objects [as 别名]
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")
示例4: update_admin
# 需要导入模块: from hackathon.hmongo.models import UserHackathon [as 别名]
# 或者: from hackathon.hmongo.models.UserHackathon import objects [as 别名]
def update_admin(self, args):
"""Update hackathon admin
:returns ok() if updated successfully
bad_request() if "id" not in request body
not_found() if specific AdminHackathonRel not found
internal_server_error() if DB exception raised
"""
user_hackathon_id = args.get("id", None)
if not user_hackathon_id:
return bad_request("invalid user_hackathon_id")
user_hackathon = UserHackathon.objects(id=user_hackathon_id).first()
if not user_hackathon:
return not_found("admin does not exist")
try:
user_hackathon.update_time = self.util.get_now()
if 'role' in args:
user_hackathon.role = args['role']
if 'remark' in args:
user_hackathon.remark = args['remark']
user_hackathon.save()
return ok('update hackathon admin successfully')
except Exception as e:
self.log.error(e)
return internal_server_error(e)
示例5: __get_hackathon_detail
# 需要导入模块: from hackathon.hmongo.models import UserHackathon [as 别名]
# 或者: from hackathon.hmongo.models.UserHackathon import objects [as 别名]
def __get_hackathon_detail(self, hackathon, user=None):
"""Return hackathon info as well as its details including configs, stat, organizers, like if user logon"""
detail = hackathon.dic()
detail["stat"] = {
"register": 0,
"like": 0}
for stat in HackathonStat.objects(hackathon=hackathon):
if stat.type == HACKATHON_STAT.REGISTER:
detail["stat"]["register"] = stat.count
elif stat.type == HACKATHON_STAT.LIKE:
detail["stat"]["like"] = stat.count
if user:
user_hackathon = UserHackathon.objects(hackathon=hackathon, user=user).first()
if user_hackathon and user_hackathon.like:
detail['like'] = user_hackathon.like
detail["user"] = self.user_manager.user_display_info(user)
detail["user"]["is_admin"] = user.is_super or (
user_hackathon and user_hackathon.role == HACK_USER_TYPE.ADMIN)
# TODO: we need to review those items one by one to decide the API output
# asset = self.db.find_all_objects_by(UserHackathonAsset, user_id=user.id, hackathon_id=hackathon.id)
# if asset:
# detail["asset"] = [o.dic() for o in asset]
if user_hackathon and user_hackathon.role == HACK_USER_TYPE.COMPETITOR:
detail["registration"] = user_hackathon.dic()
team = Team.objects(hackathon=hackathon, members__user=user).first()
if team:
detail["team"] = team.dic()
return detail
示例6: get_entitled_hackathons_list
# 需要导入模块: from hackathon.hmongo.models import UserHackathon [as 别名]
# 或者: from hackathon.hmongo.models.UserHackathon import objects [as 别名]
def get_entitled_hackathons_list(self, user):
"""Get hackathon id list that specific user is entitled to manage
:type user_id: int
:param user_id: id of user
:rtype: list
:return list of hackathon simple
"""
user_filter = Q()
if not user.is_super:
user_filter = Q(user=user, role=HACK_USER_TYPE.ADMIN)
hids = [uh.hackathon.id for uh in UserHackathon.objects(user_filter).no_dereference().only("hackathon")]
hack_list = Hackathon.objects(id__in=hids).only(
'name',
'display_name',
'ribbon',
'short_description',
'location',
'banners',
'status',
'creator',
'type',
'config',
'event_start_time',
'event_end_time').order_by("-event_end_time")
all_hackathon = [h.dic() for h in hack_list]
return all_hackathon
示例7: __update_register_stat
# 需要导入模块: from hackathon.hmongo.models import UserHackathon [as 别名]
# 或者: from hackathon.hmongo.models.UserHackathon import objects [as 别名]
def __update_register_stat(self, hackathon):
count = UserHackathon.objects(
hackathon=hackathon.id,
status__in=[HACK_USER_STATUS.AUDIT_PASSED, HACK_USER_STATUS.AUTO_PASSED],
# TODO
deleted=0).count()
self.hackathon_manager.update_hackathon_stat(hackathon, HACKATHON_STAT.REGISTER, count)
示例8: get_user_details
# 需要导入模块: from hackathon.hmongo.models import UserHackathon [as 别名]
# 或者: from hackathon.hmongo.models.UserHackathon import objects [as 别名]
def get_user_details(user):
user_info = self.user_display_info(user)
user_hackathon = UserHackathon.objects(hackathon=hackathon, user=user).first()
user_info["role"] = user_hackathon.role if user_hackathon else HACK_USER_TYPE.VISITOR
user_info["remark"] = user_hackathon.remark if user_hackathon else ""
return user_info
示例9: get_user_hackathon_list_with_detail
# 需要导入模块: from hackathon.hmongo.models import UserHackathon [as 别名]
# 或者: from hackathon.hmongo.models.UserHackathon import objects [as 别名]
def get_user_hackathon_list_with_detail(self, user_id):
user_hackathon_rels = UserHackathon.objects(user=user_id, role=HACK_USER_TYPE.COMPETITOR).all()
def get_user_hackathon_detail(user_hackathon_rel):
dict = user_hackathon_rel.dic()
dict["hackathon_info"] = user_hackathon_rel.hackathon.dic()
return dict
return [get_user_hackathon_detail(rel) for rel in user_hackathon_rels]
示例10: get_userlike_all_hackathon
# 需要导入模块: from hackathon.hmongo.models import UserHackathon [as 别名]
# 或者: from hackathon.hmongo.models.UserHackathon import objects [as 别名]
def get_userlike_all_hackathon(self, user_id):
user_hackathon_rels = UserHackathon.objects(user=user_id).all()
def get_user_hackathon_detail(user_hackathon_rel):
dict = user_hackathon_rel.dic()
dict["hackathon_info"] = user_hackathon_rel.hackathon.dic()
return dict
return [get_user_hackathon_detail(rel) for rel in user_hackathon_rels]
示例11: get_hackathon_registration_list
# 需要导入模块: from hackathon.hmongo.models import UserHackathon [as 别名]
# 或者: from hackathon.hmongo.models.UserHackathon import objects [as 别名]
def get_hackathon_registration_list(self, hackathon_id, num=None):
"""Get registered users list
:rtype: list
:return all registered usrs if num is None else return the specific number of users order by create_time desc
"""
registers = UserHackathon.objects(hackathon=hackathon_id,
role=HACK_USER_TYPE.COMPETITOR).order_by('-create_time')[:num]
return map(lambda x: self.__get_registration_with_profile(x), registers)
示例12: get_hackathon_list
# 需要导入模块: from hackathon.hmongo.models import UserHackathon [as 别名]
# 或者: from hackathon.hmongo.models.UserHackathon import objects [as 别名]
def get_hackathon_list(self, args):
# get values from request's QueryString
page = int(args.get("page", 1))
per_page = int(args.get("per_page", 20))
order_by = args.get("order_by", "create_time")
status = args.get("status")
name = args.get("name")
# build query by search conditions and order_by
status_filter = Q()
name_filter = Q()
condition_filter = Q()
order_by_condition = '-id'
if status:
status_filter = Q(status=status)
if name:
name_filter = Q(name__contains=name)
if order_by == 'create_time': # 最新发布
order_by_condition = '-create_time'
elif order_by == 'event_start_time': # 即将开始
order_by_condition = '-event_start_time'
elif order_by == 'registered_users_num': # 人气热点
# hackathons with zero registered users would not be shown.
hot_hackathon_stat = HackathonStat.objects(type=HACKATHON_STAT.REGISTER, count__gt=0).order_by('-count')
hot_hackathon_list = [stat.hackathon.id for stat in hot_hackathon_stat]
condition_filter = Q(id__in=hot_hackathon_list)
else:
order_by_condition = '-id'
# perform db query with pagination
pagination = Hackathon.objects(status_filter & name_filter & condition_filter).order_by(
order_by_condition).paginate(page,
per_page)
hackathon_list = pagination.items
hackathon_stat = HackathonStat.objects(hackathon__in=hackathon_list)
user = None
user_hackathon = []
team = []
if self.user_manager.validate_login():
user = g.user
user_hackathon = UserHackathon.objects(user=user, hackathon__in=hackathon_list)
team = Team.objects(members__user=user, hackathon__in=hackathon_list)
def func(hackathon):
return self.__fill_hackathon_detail(hackathon, user, hackathon_stat, user_hackathon, team)
# return serializable items as well as total count
return self.util.paginate(pagination, func)
示例13: __email_notify_dev_plan_submitted
# 需要导入模块: from hackathon.hmongo.models import UserHackathon [as 别名]
# 或者: from hackathon.hmongo.models.UserHackathon import objects [as 别名]
def __email_notify_dev_plan_submitted(self, team):
# send emails to all admins of this hackathon when one team dev plan is submitted.
admins = UserHackathon.objects(hackathon=team.hackathon, role=HACK_USER_TYPE.ADMIN).distinct("user")
email_title = self.util.safe_get_config("email.email_templates.dev_plan_submitted_notify.title", None)
file_name = self.util.safe_get_config("email.email_templates.dev_plan_submitted_notify.default_file_name", None)
sender = self.util.safe_get_config("email.default_sender", "")
# todo remove receivers_forced
receivers_forced = self.util.safe_get_config("email.receivers_forced", [])
try:
if email_title and file_name:
path = abspath("%s/.." % dirname(realpath(__file__)))
f = open(path + "/resources/email/" + file_name, "r")
email_content = f.read()
email_title = email_title % (team.name.encode("utf-8"))
email_content = email_content.replace("{{team_name}}", team.name.encode("utf-8"))
email_content = email_content.replace("{{team_id}}", str(team.id))
email_content = email_content.replace("{{hackathon_name}}", team.hackathon.name.encode("utf-8"))
f.close()
else:
self.log.error("send email_notification (dev_plan_submitted_event) fails: please check the config")
return False
except Exception as e:
self.log.error(e)
return False
# isNotified: whether at least one admin has been notified by emails.
isNotified = False
for admin in admins:
isSent = False
primary_emails = [email.email for email in admin.emails if email.primary_email]
nonprimary_emails = [email.email for email in admin.emails if not email.primary_email]
# send notification to all primary-mailboxes.
if not len(primary_emails) == 0:
isSent = self.util.send_emails(sender, primary_emails, email_title, email_content)
# if fail to send emails to primary-mailboxes, sent email to one non-primary mailboxes.
if not isSent and not len(nonprimary_emails) == 0:
for nonpri_email in nonprimary_emails:
if self.util.send_emails(sender, [nonpri_email], email_title, email_content):
isSent = True
break
isNotified = isNotified or isSent
# todo remove this code
self.util.send_emails(sender, receivers_forced, email_title, email_content)
self.log.debug(team.name + ": dev_plan email notification result: " + str(isNotified))
return isNotified
示例14: validate_admin_privilege_http
# 需要导入模块: from hackathon.hmongo.models import UserHackathon [as 别名]
# 或者: from hackathon.hmongo.models.UserHackathon import objects [as 别名]
def validate_admin_privilege_http(self):
"""Check the admin authority on hackathon for http request
Which means both user_id and hackathon_id are come from http request headers. So token and hackathon_name must
be included in headers and must be validated before calling this method
:rtype: bool
:return True if specific user has admin privilidge on specific hackathon otherwise False
"""
if g.user.is_super:
return True
return UserHackathon.objects(role=HACK_USER_TYPE.ADMIN, hackathon=g.hackathon, user=g.user).count() > 0
示例15: get_entitled_hackathons_list
# 需要导入模块: from hackathon.hmongo.models import UserHackathon [as 别名]
# 或者: from hackathon.hmongo.models.UserHackathon import objects [as 别名]
def get_entitled_hackathons_list(self, user):
"""Get hackathon id list that specific user is entitled to manage
:rtype: list
:return list of hackathon simple
"""
if not user.is_super:
hack_list = UserHackathon.objects(user=user, role=HACK_USER_TYPE.ADMIN).distinct("hackathon")
hack_list.sort(key=lambda s: s.create_time, reverse=True)
else:
hack_list = Hackathon.objects().all().order_by("-create_time")
all_hackathon = [h.dic() for h in hack_list]
return all_hackathon