def delete(self, id_following): oUser, _session = base.common.orm.get_orm_model('users') oFollower, _session = base.common.orm.get_orm_model('followers') u = _session.query(oUser).filter( oUser.id == id_following).one_or_none() if not u: return self.error("user with given id don't exists") f = _session.query(oFollower).filter( oFollower.id_user == self.auth_user.id, oFollower.id_following == id_following).one_or_none() if not f: return self.error("this user is not followed") _session.query(oFollower).filter( oFollower.id_user == self.auth_user.id, oFollower.id_following == id_following).delete() common.add_to_timeline( self.auth_user, "UNFOLLOW", { "target_user": id_following, "text": "user {} stop following {}".format( self.auth_user.user.display_name(), u.display_name()) }) _session.commit() return self.ok()
def put(self, name, location, lat, lon, website, date_start, date_end, price, cost, max_participants, id_region, logo, background_image): oTournament, _session = base.common.orm.get_orm_model('tournaments') oRegion, _session = base.common.orm.get_orm_model('regions') from base.common.sequencer import sequencer r = _session.query(oTournament).filter( oTournament.name == name, oTournament.date_start == date_start).one_or_none() if r: return self.ok({"id": r.id}) reg = _session.query(oRegion).filter( oRegion.id == id_region).one_or_none() if not reg: return self.error("invalid region") tid = sequencer().new('t') tournament = oTournament(id=tid, name=name, location=location, lat=lat, lon=lon, date_start=date_start, date_end=date_end, website=website, price=price, cost=cost, max_participants=max_participants, id_region=id_region, logo=logo, background_image=background_image) _session.add(tournament) common.add_to_timeline( None, "NEWTOURNAMENT", { "tournament": tid, "logo": logo, "background": background_image, "text": "New tournament {} at {} added / region: {}".format( name, location, reg.name_ger) }) _session.commit() return self.ok({"id": tid})
def put(self, status): oUser, _session = base.common.orm.get_orm_model('users') common.add_to_timeline( self.auth_user, "SETSTATUS", { "status": status, "text": "user {} set status to \"{}\"".format( self.auth_user.user.display_name(), status) }) _session.commit() return self.ok()
def delete(self, id_tournament): oTournament, _session = base.common.orm.get_orm_model('tournaments') oUser2Tournament, _session = base.common.orm.get_orm_model( 'user_2_tournament') t = _session.query(oTournament).filter( oTournament.id == id_tournament).one_or_none() if not t: return self.error( "tournament with given id does not exists in database") u2t = _session.query(oUser2Tournament).filter( oUser2Tournament.id_user == self.auth_user.id, oUser2Tournament.id_tournament == id_tournament).one_or_none() if not u2t: return self.error("there is no user assigned to tournament") else: _session.query(oUser2Tournament).filter( oUser2Tournament.id_user == self.auth_user.id, oUser2Tournament.id_tournament == id_tournament).delete() common.add_to_timeline( self.auth_user, "UNFOLLOWTOURNAMENT", { "tournament": t.id, "text": "User {} stop following tournament \"{}\"".format( self.auth_user.user.display_name(), t.name) }) _session.commit() return self.ok({"status": "ok", "id_tournament": id_tournament})
def put(self, id_tournament, following_only): print(id_tournament, self.auth_user.id) oTournament, _session = base.common.orm.get_orm_model('tournaments') oUser2Tournament, _session = base.common.orm.get_orm_model( 'user_2_tournament') t = _session.query(oTournament).filter( oTournament.id == id_tournament).one_or_none() if not t: return self.error( "tournament with given id does not exists in database") u2t = _session.query(oUser2Tournament).filter( oUser2Tournament.id_user == self.auth_user.id, oUser2Tournament.id_tournament == id_tournament).one_or_none() if not u2t: u2t = oUser2Tournament(self.auth_user.id, id_tournament, following_only) _session.add(u2t) if following_only: common.add_to_timeline( self.auth_user, "FOLLOWTOURNAMENT", { "tournament": t.id, "text": "User {} is following tournament \"{}\"".format( self.auth_user.user.display_name(), t.name) }) else: common.add_to_timeline( self.auth_user, "ATTENDINGTOURNAMENT", { "tournament": t.id, "text": "User {} attend to participante tournament \"{}\"". format(self.auth_user.user.display_name(), t.name) }) _session.commit() return self.ok({ 'id_tournament': id_tournament, 'image': hashlib.md5(self.auth_user.username.encode()).hexdigest() if self.auth_user.user.have_picture else 'avatar' }) else: if following_only != u2t.following_only: u2t.following_only = following_only if following_only: common.add_to_timeline( self.auth_user, "FOLLOWTOURNAMENT", { "tournament": t.id, "text": "User {} is following tournament \"{}\"".format( self.auth_user.user.display_name(), t.name) }) else: common.add_to_timeline( self.auth_user, "ATTENDINGTOURNAMENT", { "tournament": t.id, "text": "User {} attend to participante tournament \"{}\"". format(self.auth_user.user.display_name(), t.name) }) _session.commit() return self.ok({ 'id_tournament': id_tournament, 'image': hashlib.md5(self.auth_user.username.encode()).hexdigest() if self.auth_user.user.have_picture else 'avatar' }) return self.ok("ok") return self.ok("OK already here")