Example #1
0
    def cast(self, text, target=None):
        if self.gs.player.status == 0:
            self.gs.logout()
            return
        self.text(text)
        words = self.text().split()

        cards = [session.query(WordCard).get(word) for word in words]

        # make a tally for our cards so we can check if we have enough
        cdict = {}
        for card in cards:
            if card in cdict:
                cdict[card] += 1
            else:
                cdict[card] = 1

        errorcards = []

        for card, count in cdict.iteritems():
            entry = session.query(BagEntry.count).get((self.gs.player.username, card.word))
            if not entry:
                errorcards.append(card.word)
            elif entry.count < count:
                errorcards.append(card.word)

        if errorcards:
            self.errorcards = errorcards
            return

        for card, count in cdict.iteritems():
            entry = session.query(BagEntry).get((self.gs.player.username, card.word))
            entry.count -= count
            print entry.word.word, " now has count ", entry.count
            if entry.count <= 0:
                session.delete(entry)

        # update wordbag display
        self.gs.playerBox.o.wordbag.getWords()

        print ["<%s %r>" % (word.word, word.rank) for word in cards]
        score = reduce(lambda scr, wrd: scr + wrd.rank, cards, 0)
        print score
        
        self.text("")

        self.gs.player.activity()
Example #2
0
    def cast(self, text, target=None):
        if self.gs.player.status == 0:
            self.gs.logout()
            return
        self.text(text)
        words = self.text().split()

        cards = [session.query(WordCard).get(word) for word in words]

        # make a tally for our cards so we can check if we have enough
        cdict = {}
        for card in cards:
            if card in cdict:
                cdict[card] += 1
            else:
                cdict[card] = 1

        errorcards = []

        for card, count in cdict.iteritems():
            entry = session.query(BagEntry.count).get((self.gs.player.username, card.word))
            if not entry:
                errorcards.append(card.word)
            elif entry.count < count:
                errorcards.append(card.word)

        if errorcards:
            self.errorcards = errorcards
            return

        for card, count in cdict.iteritems():
            entry = session.query(BagEntry).get((self.gs.player.username, card.word))
            entry.count -= count
            print entry.word.word, " now has count ", entry.count
            if entry.count <= 0:
                session.delete(entry)

        # update wordbag display
        self.gs.playerBox.o.wordbag.getWords()

        print ["<%s %r>" % (word.word, word.rank) for word in cards]
Example #3
0
 def delete(self):
     # Need to use session.delete to trigger delete cascades
     session.delete(self.i)
     flashmessage.set_flash(_(u'Idea deleted'))
     event_management._emit_signal(self, "VIEW_IDEAS")
Example #4
0
 def delete(self):
     # Need to use session.delete to trigger delete cascades
     session.delete(self.i)
     flashmessage.set_flash(_(u'Idea deleted'))
     event_management._emit_signal(self, "VIEW_IDEAS")
Example #5
0
 def delete_history(self):
     for event in self.history:
         session.delete(event)
     session.flush()
Example #6
0
 def delete_members(self):
     for member in self.board_members:
         session.delete(member)
     session.flush()
Example #7
0
 def delete(self):
     session.delete(self.data)
     session.flush()
Example #8
0
 def delete(self):
     session.delete(self.data)
     session.flush()
    def delete(self, uid):
        self.ensure_generic_user()
        user_to_delete = self.get_by_uid(uid)
        if not user_to_delete:
            return False

        # Idea submission
        for i in IdeaData.query.filter_by(submitted_by=user_to_delete).all():
            i.submitted_by = self.generic_user
        for i in IdeaData.query.filter_by(proxy_submitter=user_to_delete).all():
            i.proxy_submitter = self.generic_user

        # Idea authors
        for idea in user_to_delete.ideas_as_author:
            authors = list(idea.authors)
            if self.generic_user in authors:
                authors.remove(user_to_delete)
            else:
                idx = authors.index(user_to_delete)
                authors[idx] = self.generic_user
            idea.authors = authors
        user_to_delete.ideas_as_author = []

        # FI for other users
        for u in UserData.query.filter_by(fi=user_to_delete).all():
            u.fi = self.facilitator
        # user_to_delete.fi_for = []

        PointData.query.filter_by(user=user_to_delete).delete()

        # DI/FI ideas
        for wfcontext in IdeaWFContextData.query.filter_by(assignated_fi=user_to_delete).all():
            wfcontext.assignated_fi = self.facilitator
        for wfcontext in IdeaWFContextData.query.filter_by(assignated_di=user_to_delete).all():
            wfcontext.assignated_di = self.developer

        # Delete read ideas
        for read_idea in user_to_delete.read_ideas_association:
            session.delete(read_idea)
        user_to_delete.read_ideas_association = []

        # Votes for ideas
        for vote in VoteIdeaData.query.filter_by(user=user_to_delete).all():
            vote.user = self.generic_user

        # Votes for comments
        comments = set(e.comment for e in self.generic_user.votes_for_comments)
        for vote in user_to_delete.votes_for_comments:
            if vote.comment in comments:
                session.delete(vote)
            else:
                vote.user = self.generic_user
                comments.add(vote.comment)
        user_to_delete.votes_for_comments = []

        # Comments
        for e in CommentData.query.filter_by(created_by=user_to_delete).all():
            e.created_by = self.generic_user
        user_to_delete.comments = []

        # Votes for polls
        # Only one choice allowed per user and per poll, we need to check that
        choices = set(e.choice for e in self.generic_user.votes_for_polls)
        for vote in user_to_delete.votes_for_polls:
            if vote.choice in choices:
                session.delete(vote)
            else:
                vote.user = self.generic_user
                choices.add(vote.choice)
        user_to_delete.votes_for_polls = []

        # Tracked ideas
        ideas = list(set(self.generic_user.tracked_ideas) | set(user_to_delete.tracked_ideas))
        user_to_delete.tracked_ideas = []
        self.generic_user.tracked_ideas = ideas

        # DI for challenges
        self.generic_user.di_for_challenges = list(set(self.generic_user.di_for_challenges) | set(user_to_delete.di_for_challenges))
        user_to_delete.di_for_challenges = []

        for e in ChallengeData.query.filter_by(created_by=user_to_delete).all():
            e.created_by = self.generic_user

        # Domains
        self.developer.managed_domains = list(set(self.developer.managed_domains) | set(user_to_delete.managed_domains))
        user_to_delete.managed_domains = []

        # Comments in ideas' evaluation contexts
        for e in EvalCommentData.query.filter_by(created_by=user_to_delete):
            e.created_by = self.generic_user
        for e in EvalCommentData.query.filter_by(expert=user_to_delete):
            e.expert = self.generic_user

        # Workflow comments
        for e in WFCommentData.query.filter_by(created_by=user_to_delete):
            e.created_by = self.generic_user

        # Improvements
        for e in ImprovementData.query.filter_by(user=user_to_delete):
            e.user = self.generic_user

        # Delete photo
        user_to_delete._change_photo(None)

        # Home settings
        if user_to_delete._home_settings:
            # We need to manually delete the rows found in the ManyToMany tables used for domains and user filters
            # A better way would be to use cascade deletion
            user_to_delete._home_settings.domains = []
            user_to_delete._home_settings.users_filter = []
            session.delete(user_to_delete._home_settings)
            HomeSettingsData.query.filter_by(user=user_to_delete).delete()
            session.flush()

        session.delete(user_to_delete)
    def delete(self, uid):
        self.ensure_generic_user()
        user_to_delete = self.get_by_uid(uid)
        if not user_to_delete:
            return False

        # Idea submission
        for i in IdeaData.query.filter_by(submitted_by=user_to_delete).all():
            i.submitted_by = self.generic_user
        for i in IdeaData.query.filter_by(
                proxy_submitter=user_to_delete).all():
            i.proxy_submitter = self.generic_user

        # Idea authors
        for idea in user_to_delete.ideas_as_author:
            authors = list(idea.authors)
            if self.generic_user in authors:
                authors.remove(user_to_delete)
            else:
                idx = authors.index(user_to_delete)
                authors[idx] = self.generic_user
            idea.authors = authors
        user_to_delete.ideas_as_author = []

        # FI for other users
        for u in UserData.query.filter_by(fi=user_to_delete).all():
            u.fi = self.facilitator
        # user_to_delete.fi_for = []

        PointData.query.filter_by(user=user_to_delete).delete()

        # DI/FI ideas
        for wfcontext in IdeaWFContextData.query.filter_by(
                assignated_fi=user_to_delete).all():
            wfcontext.assignated_fi = self.facilitator
        for wfcontext in IdeaWFContextData.query.filter_by(
                assignated_di=user_to_delete).all():
            wfcontext.assignated_di = self.developer

        # Delete read ideas
        for read_idea in user_to_delete.read_ideas_association:
            session.delete(read_idea)
        user_to_delete.read_ideas_association = []

        # Votes for ideas
        for vote in VoteIdeaData.query.filter_by(user=user_to_delete).all():
            vote.user = self.generic_user

        # Votes for comments
        comments = set(e.comment for e in self.generic_user.votes_for_comments)
        for vote in user_to_delete.votes_for_comments:
            if vote.comment in comments:
                session.delete(vote)
            else:
                vote.user = self.generic_user
                comments.add(vote.comment)
        user_to_delete.votes_for_comments = []

        # Comments
        for e in CommentData.query.filter_by(created_by=user_to_delete).all():
            e.created_by = self.generic_user
        user_to_delete.comments = []

        # Votes for polls
        # Only one choice allowed per user and per poll, we need to check that
        choices = set(e.choice for e in self.generic_user.votes_for_polls)
        for vote in user_to_delete.votes_for_polls:
            if vote.choice in choices:
                session.delete(vote)
            else:
                vote.user = self.generic_user
                choices.add(vote.choice)
        user_to_delete.votes_for_polls = []

        # Tracked ideas
        ideas = list(
            set(self.generic_user.tracked_ideas)
            | set(user_to_delete.tracked_ideas))
        user_to_delete.tracked_ideas = []
        self.generic_user.tracked_ideas = ideas

        # DI for challenges
        self.generic_user.di_for_challenges = list(
            set(self.generic_user.di_for_challenges)
            | set(user_to_delete.di_for_challenges))
        user_to_delete.di_for_challenges = []

        for e in ChallengeData.query.filter_by(
                created_by=user_to_delete).all():
            e.created_by = self.generic_user

        # Domains
        self.developer.managed_domains = list(
            set(self.developer.managed_domains)
            | set(user_to_delete.managed_domains))
        user_to_delete.managed_domains = []

        # Comments in ideas' evaluation contexts
        for e in EvalCommentData.query.filter_by(created_by=user_to_delete):
            e.created_by = self.generic_user
        for e in EvalCommentData.query.filter_by(expert=user_to_delete):
            e.expert = self.generic_user

        # Workflow comments
        for e in WFCommentData.query.filter_by(created_by=user_to_delete):
            e.created_by = self.generic_user

        # Improvements
        for e in ImprovementData.query.filter_by(user=user_to_delete):
            e.user = self.generic_user

        # Delete photo
        user_to_delete._change_photo(None)

        # Home settings
        if user_to_delete._home_settings:
            # We need to manually delete the rows found in the ManyToMany tables used for domains and user filters
            # A better way would be to use cascade deletion
            user_to_delete._home_settings.domains = []
            user_to_delete._home_settings.users_filter = []
            session.delete(user_to_delete._home_settings)
            HomeSettingsData.query.filter_by(user=user_to_delete).delete()
            session.flush()

        session.delete(user_to_delete)