def can_quit(self): if self._activity.is_past: return False if not self._user: return False attender = Attender.get_unique(activity=self._activity, user=self._user) return attender is not None
def _quit(self): if not self.get_activity_access().can_quit(): message = "Current user cannot quit the activity." logging.error(message) raise BadRequestError(self.request, message) attender = Attender.get_unique(activity=self.get_activity(), user=self.current_user) if not attender: message = "Cannot find attender for current user." logging.error(message) raise BadRequestError(self.request, message) attender.delete()
def can_attend(self): if self._activity.is_past or self._activity.is_closed: return False if not self._user: return False if not self._group_access.member or not self._group_access.member.is_approved: return False if self._activity.places and self._activity.headcount >= self._activity.places: return False attender = Attender.get_unique(activity=self._activity, user=self._user) return attender is None
def _attend(self): if not self.get_activity_access().can_attend(): message = "Current user cannot attend the activity." logging.error(message) raise BadRequestError(self.request, message) try: with_friends = int(self.request.POST.get("with_friends", 0)) except (TypeError, ValueError): with_friends = 0 attender = Attender.create( activity=self.get_activity(), user=self.current_user, with_friends=with_friends ) attender.save()
def update_data(self, data): data["attenders"] = Attender.find_by_activity(self.get_activity()) return super(ViewAttenders, self).update_data(data)