Beispiel #1
0
    def add(cls, **kwargs):
        utype = kwargs.get('utype')
        users = SlackUser.objects.filter(user_type=utype).order_by('id')
        if kwargs.get("utype") != "guest":
            user = SlackUser(
                firstname=kwargs.get("firstname"),
                lastname=kwargs.get("lastname"),)
        else:
            last_guest = filter(lambda x: x.firstname.startswith("Guest"),
                                list(users))[-1] if len(users) else None

            if not last_guest:
                username = kwargs.get("name", "Guest 1")
            else:
                last_num = int(
                    re.match("^Guest ([\d]*)".format(), last_guest.firstname).groups()[0])

                username = '******'.format(last_num + 1)

            user = SlackUser(firstname=username)

        user.slack_id = cls.generate_unique(
            utype, [individual.slack_id for individual in users] if len(users) else [])
        user.user_type = utype

        try:
            user.save()
            return "{} ({}) was created successfully.".format(user.firstname, utype,), user.id

        except Exception, e:
            return "{0} user couldn't be created. Error: {1}".format(
                utype.upper(), type(e)), None
Beispiel #2
0
    def add(cls, **kwargs):
        utype = kwargs.get("utype")
        users = SlackUser.objects.filter(user_type=utype).order_by("id")
        if kwargs.get("utype").lower() != "guest":
            user = SlackUser(
                firstname=kwargs.get("firstname"), lastname=kwargs.get("lastname")
            )
        else:
            # for some reason filter object is not subscriptable
            # last_guest = (
            #     filter(lambda x: x.firstname.startswith("Guest"), list(users))[-1]
            #     if len(users)
            #     else None
            # )
            guests = [x for x in list(users) if x.firstname.startswith("Guest")]
            last_guest = guests[-1] if len(guests) else None

            if not guests:
                username = kwargs.get("name", "Guest 1")
            else:
                last_num = int(
                    re.match("^Guest ([\d]*)".format(), last_guest.firstname).groups()[
                        0
                    ]
                )

                username = "******".format(last_num + 1)

            user = SlackUser(firstname=username)

        user.slack_id = cls.generate_unique(
            utype, [individual.slack_id for individual in users] if len(users) else []
        )
        user.user_type = utype

        try:
            user.save()
            return (
                "{} ({}) was created successfully.".format(user.firstname, utype),
                user.id,
            )

        except Exception as e:
            user_type = utype.upper()
            error_type = type(e)
            return f"{user_type} user couldn't be created. Error: {error_type}"
Beispiel #3
0
    def add(cls, **kwargs):
        utype = kwargs.get('utype')
        users = SlackUser.objects.filter(user_type=utype).order_by('id')
        if kwargs.get("utype") != "guest":
            user = SlackUser(
                firstname=kwargs.get("firstname"),
                lastname=kwargs.get("lastname"),
            )
        else:
            last_guest = filter(lambda x: x.firstname.startswith("Guest"),
                                list(users))[-1] if len(users) else None

            if not last_guest:
                username = kwargs.get("name", "Guest 1")
            else:
                last_num = int(
                    re.match("^Guest ([\d]*)".format(),
                             last_guest.firstname).groups()[0])

                username = '******'.format(last_num + 1)

            user = SlackUser(firstname=username)

        user.slack_id = cls.generate_unique(
            utype, [individual.slack_id
                    for individual in users] if len(users) else [])
        user.user_type = utype

        try:
            user.save()
            return "{} ({}) was created successfully.".format(
                user.firstname,
                utype,
            ), user.id

        except Exception, e:
            return "{0} user couldn't be created. Error: {1}".format(
                utype.upper(), type(e)), None