Esempio n. 1
0
    def get(self):

        team = self.current_team
        if team.sport:
            team.sport = [s for s in Sport.select().where(Sport.id << team.sport)]

        form = TeamBasicFrom(obj=team)

        province = self.current_team.province
        if province:
            form.city.choices = ChinaCity.get_cities(province)

        self.render("settings/basic.html",
                    form=form,
                    cities=ChinaCity.get_cities()
                    )
Esempio n. 2
0
    def __init__(self, *args, **kwargs):
        super(CreateActivityFrom, self).__init__(*args, **kwargs)

        obj = kwargs.get("obj", None)
        team = kwargs.get("team", None)

        if not isinstance(team, Team):
            raise AssertionError("must a team")

        if obj and obj.province:
            province = obj.province

        else:
            province = self.province.choices[0][0]

        if province:
            self.city.choices = ChinaCity.get_cities(province)

        leaders = team.get_members(role="leader")
        leaders.insert(0, User.get_or_none(id=team.owner_id))

        if leaders:
            self.leader.choices = [(str(user.id), user.name or user.mobile)
                                   for user in leaders]

        groups = team.groups
        if groups:
            self.allow_groups.choices = [(str(group.id), group.name)
                                         for group in groups]
Esempio n. 3
0
    def get(self):
        team = self.current_team
        if team is not None:
            if team.state == 1:
                return self.redirect(self.reverse_url("club_home"))
            else:
                return self.redirect(self.reverse_url("club_wait_approve"))

        form = CreateTeamFrom()

        province = form.province.choices[0][0]
        if province:
            form.city.choices = ChinaCity.get_cities(province)

        self.render("club/create.html",
                    form=form,
                    cities=ChinaCity.get_cities())
    def get(self, activity_id):
        activity = Activity.get_or_404(id=activity_id)

        form = CreateActivityFrom(obj=activity, team=self.current_team)

        self.render("activity/edit.html",
                    form=form,
                    cities=ChinaCity.get_cities())
    def post(self):

        form = CreateActivityFrom(self.arguments, team=self.current_team)

        if form.validate():
            activity = Activity()
            form.populate_obj(activity)

            need_fields = self.get_arguments("need_fields")
            for field in need_fields:
                setattr(activity, field, True)

            geocode = yield self.get_geocode(activity.city, activity.address)

            if geocode.get("geocodes", []):
                location = geocode['geocodes'][0]['location'].split(",")
                activity.lat = location[1]
                activity.lng = location[0]
                activity.geohash = geohash.encode(float(location[1]), float(location[0]))

            if activity.repeat_type == "week":
                activity.week_day = activity.start_time.weekday() + 1

            elif activity.repeat_type == "month":
                activity.month_day = activity.start_time.day

            activity.team = self.current_team
            activity.creator = self.current_user
            activity.save()

            # 更新俱乐部活动数量
            Team.update_activities_count(self.current_team.id)

            self.redirect(self.reverse_url("club_activity_list"))
            return

        province = self.get_argument("province", None)
        if province:
            form.city.choices = ChinaCity.get_cities(province)

        self.render("activity/new.html",
                    form=form,
                    cities=ChinaCity.get_cities())
Esempio n. 6
0
    def post(self):

        team = self.current_team
        if team is None:
            team = Team(owner_id=self.current_user.id)

        form = CreateTeamFrom(self.arguments)

        if form.validate():
            form.populate_obj(team)
            team.owner_id = self.current_user.id
            team.sport = [str(n.id) for n in team.sport]

            if "iconfile" in self.request.files:
                to_bucket = self.settings['qiniu_avatar_bucket']
                to_key = "team:%s%s" % (self.current_user.id, time.time())
                to_key = hashlib.md5(to_key.encode()).hexdigest()

                icon_key = self.upload_file(
                    "iconfile",
                    to_bucket=to_bucket,
                    to_key=to_key,
                )

                team.icon_key = icon_key

            team.save()

            # TODO: 正式版本需要移除此自动通过审核功能
            tasks.team.approve_team.apply_async((team.id, ), countdown=30)

            return self.redirect(self.reverse_url("club_wait_approve"))

        province = self.get_argument("province", None)
        if province:
            form.city.choices = ChinaCity.get_cities(province)

        self.render("club/create.html",
                    form=form,
                    cities=ChinaCity.get_cities())
Esempio n. 7
0
    def post(self):

        form = TeamBasicFrom(self.arguments)

        if form.validate():
            team = self.current_team
            form.populate_obj(team)
            team.sport = [str(s.id) for s in team.sport]

            if "iconfile" in self.request.files:
                to_bucket = self.settings['qiniu_avatar_bucket']
                to_key = "team:%s%s" % (self.current_user.id, time.time())
                to_key = hashlib.md5(to_key.encode()).hexdigest()

                icon_key = self.upload_file("iconfile",
                                            to_bucket=to_bucket,
                                            to_key=to_key,
                                            )

                if icon_key:
                    team.icon_key = icon_key

            team.save()

            self.flash("修改俱乐部资料成功!", category='success')
            self.redirect(self.reverse_url("club_settings_basic"))
            return

        province = self.current_team.province
        if province:
            form.city.choices = ChinaCity.get_cities(province)

        self.render("settings/basic.html",
                    form=form,
                    cities=ChinaCity.get_cities()
                    )
Esempio n. 8
0
    def __init__(self, *args, **kwargs):
        super(CreateMatchFrom, self).__init__(*args, **kwargs)

        obj = kwargs.get("obj", None)
        team = kwargs.get("team", None)

        if not isinstance(team, Team):
            raise AssertionError("must a team")

        if obj and obj.province:
            province = obj.province

        else:
            province = self.province.choices[0][0]

        if province:
            self.city.choices = ChinaCity.get_cities(province)
    def get(self):

        match = Match(team_id=self.current_team.id,
                      contact_person=self.current_team.contact_person,
                      contact_phone=self.current_team.contact_phone,
                      province=self.current_team.province,
                      city=self.current_team.city,
                      address=self.current_team.address)

        form = CreateMatchFrom(obj=match, team=self.current_team)

        self.render("match/create.html",
                    match=match,
                    form=form,
                    cities=ChinaCity.get_cities(),
                    groups=[],
                    group_type=0,
                    options=[],
                    custom_options=[])
Esempio n. 10
0
    def get(self, match_id):

        match = Match.get_or_404(id=match_id)
        match.sport_id = Sport.get_or_none(id=match.sport_id)

        match.group_type = str(match.group_type)
        team = Team.get_or_404(id=match.team_id)
        form = EditMatchFrom(obj=match, team=team)

        # 获取赛事分组信息
        query = MatchGroup.select().where(
            MatchGroup.match_id == match.id).order_by(
                MatchGroup.sort_num.desc())

        groups = []
        for group in query:
            group = group.info
            group['max'] = group['max_members']
            groups.append(group)

        # 获取报名表自定义选项
        query = MatchOption.select().where(
            MatchOption.match_id == match.id).order_by(
                MatchOption.sort_num.desc())

        custom_options = []
        for option in query:
            option = option.info
            if 'choices' in option:
                option['choices'] = "|".join(option['choices'])
            custom_options.append(option)

        self.render("match/edit.html",
                    form=form,
                    match=match,
                    cities=ChinaCity.get_cities(),
                    group_type=match.group_type,
                    groups=groups,
                    custom_options=custom_options,
                    options=match.fields)
    def get(self):

        duplicate_id = self.get_argument("duplicate_id", None)

        if duplicate_id:
            activity = Activity.get_or_none(id=duplicate_id)
            activity.id = None

        else:
            activity = Activity(
                team=self.current_team,
                contact_person=self.current_team.contact_person,
                contact_phone=self.current_team.contact_phone,

                province=self.current_team.province,
                city=self.current_team.city,
                address=self.current_team.address
            )

        form = CreateActivityFrom(obj=activity, team=self.current_team)

        self.render("activity/new.html",
                    form=form,
                    cities=ChinaCity.get_cities())
Esempio n. 12
0
    def post(self, match_id):
        match = Match.get_or_404(id=match_id)
        team = Team.get_or_404(id=match.team_id)
        form = EditMatchFrom(self.arguments, team=team)

        groups = self.parse_groups()
        options = self.parse_options()
        custom_options = self.parse_custom_options()

        # 验证分组设置
        groups_validated = self.validate_groups(form, groups)

        if form.validate() and groups_validated:
            with (self.db.transaction()):
                form.populate_obj(match)

                # 计算赛事总人数限制
                if intval(match.group_type) == 1:
                    match.price = min(map(lambda x: float(x['price']),
                                          groups)) if groups else 0
                    match.max_members = reduce(lambda x, y: x + y,
                                               map(lambda x: x['max'],
                                                   groups)) if groups else 0

                if "coverfile" in self.request.files:
                    to_bucket = self.settings['qiniu_avatar_bucket']
                    to_key = "match:%s%s" % (self.current_user.id, time.time())
                    to_key = hashlib.md5(to_key.encode()).hexdigest()

                    cover_key = self.upload_file(
                        "coverfile",
                        to_bucket=to_bucket,
                        to_key=to_key,
                    )

                    match.cover_key = cover_key

                match.user_id = self.current_user.id
                match.fields = options

                if not match.join_end:
                    match.join_end = match.start_time

                match.save()

                if intval(match_id) > 0:
                    group_ids = [
                        group['id'] for group in groups if group['id'] > 0
                    ]

                    if len(group_ids) > 0:
                        MatchGroup.delete().where(
                            MatchGroup.match_id == intval(match_id),
                            MatchGroup.id.not_in(group_ids)).execute()

                    else:
                        MatchGroup.delete().where(
                            MatchGroup.match_id == intval(match_id)).execute()

                # 保存分组
                for group in groups:
                    if group['id'] > 0:
                        MatchGroup.update(
                            name=group['name'],
                            price=group['price'],
                            max_members=group['max']).where(
                                MatchGroup.id == group['id']).execute()

                    else:
                        MatchGroup.create(match_id=match.id,
                                          name=group['name'],
                                          price=group['price'],
                                          max_members=group['max'])

                if intval(match_id) > 0:
                    custom_option_ids = [
                        custom_option['id'] for custom_option in custom_options
                        if custom_option['id'] > 0
                    ]

                    if len(custom_option_ids) > 0:
                        MatchOption.delete().where(
                            MatchOption.match_id == intval(match_id),
                            MatchOption.id.not_in(
                                custom_option_ids)).execute()

                    else:
                        MatchOption.delete().where(MatchOption.match_id ==
                                                   intval(match_id)).execute()

                # 保存自定义选项
                for custom_option in custom_options:
                    if custom_option['id'] > 0:
                        MatchOption.update(
                            title=custom_option['title'],
                            field_type=custom_option['field_type'],
                            required=custom_option['required'],
                            choices=custom_option['choices'],
                        ).where(
                            MatchOption.id == custom_option['id']).execute()
                    else:
                        MatchOption.create(
                            match_id=match.id,
                            title=custom_option['title'],
                            field_type=custom_option['field_type'],
                            required=custom_option['required'],
                            choices=custom_option['choices'],
                        )

            # MatchService.add_match_start_notify(match)
            self.redirect(self.reverse_url("admin_match_detail", match.id))
            return

        province = self.get_argument("province", None)
        if province:
            form.city.choices = ChinaCity.get_cities(province)

        self.validate_groups(form, groups)

        self.render("match/edit.html",
                    form=form,
                    match=match,
                    cities=ChinaCity.get_cities(),
                    groups=groups,
                    group_type=self.get_argument("group_type", "0"),
                    options=options,
                    custom_options=custom_options)
Esempio n. 13
0
 def get(self):
     self.write(ChinaCity.get_cities())