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())
    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())