Exemple #1
0
    def create_series(self, name, desc, team_id, tags=None, series_id=None):
        """
        Adds a new series to the database

        :type name: str
        :param name: Name of the Series

        :type desc: str
        :param desc: Description of the Series

        :type team_id: str
        :param team_id: Team Id to which this Series belongs to

        :type tags: str
        :param tags: Tags for a Series

        :type series_id: str
        :param series_id: ID of the Series
        """

        if not series_id:
            series_id = convert_name_to_id(name)

        if not self.series_exists(series_id):
            new_series = Series(id=series_id,
                                name=name,
                                description=desc,
                                tags=tags,
                                team_id=team_id)

            self.session.add(new_series)
            self.session.flush()
        return series_id
Exemple #2
0
    def create_team(self, name, team_id=None):
        """
        Adds a new team to the database

        :type name: str
        :param name: Name of the team
        """

        if not team_id:
            team_id = convert_name_to_id(name)

        if not self.team_exists(team_id):
            new_team = Team(id=team_id,
                            name=name)

            self.session.add(new_team)
            self.session.flush()
        return team_id
Exemple #3
0
    def add_badge(self, name, image, desc, criteria, issuer_id,
                  tags=None, badge_id=None):
        """
        Add a new badge to the database

        :type name: str
        :param name: Name of the Badge

        :type image: str
        :param image: URL of the image for this Badge

        :type criteria: str
        :param criteria: The criteria of this Badge

        :type issuer_id: int
        :param issuer_id: The ID of the issuer who issues this Badge

        :type tags: str
        :param tags: Comma-delimited list of badge tags.
        """

        if not badge_id:
            badge_id = convert_name_to_id(name)

        if not self.badge_exists(badge_id):
            # Make sure the tags string has a trailing
            # comma at the end. The tags view in Tahrir
            # depends on that comma when matching all
            # tags.
            if tags and not tags.endswith(','):
                tags = tags + ','

            # Actually add the badge.
            new_badge = Badge(id=badge_id,
                              name=name,
                              image=image,
                              description=desc,
                              criteria=criteria,
                              issuer_id=issuer_id,
                              tags=tags)
            self.session.add(new_badge)
            self.session.flush()
        return badge_id