def gen_next_activity(activity_id): """ 生成下期活动 """ if Activity.select().where(Activity.parent_id == activity_id).exists(): logging.debug("已经存在") return activity = Activity.get_or_404(id=activity_id) # 时间相关都顺延一周 delta = timedelta(days=7) if activity.repeat_end and \ datetime.now() + delta > activity.repeat_end: logging.debug("活动已经结束自动循环") return activity = copy.copy(activity) activity.id = None activity.members_count = 0 activity.comments_count = 0 activity.recommend_time = 0 activity.recommend_region = 0 if activity.join_start: activity.join_start += delta if activity.join_end: activity.join_end += delta activity.cancelled = None activity.cancel_reason = "" activity.finished = None activity.start_time += delta activity.end_time += delta activity.online_paid_amount = 0 activity.credit_paid_amount = 0 activity.cash_paid_amount = 0 activity.free_times_amount = 0 activity.created = datetime.now() activity.updated = datetime.now() activity.state = Activity.ActivityState.opening activity.parent_id = activity_id activity.save() # 更新俱乐部活动数 Team.update_activities_count(activity.team_id)
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())