Exemplo n.º 1
0
 def create_partner(self,
                    org,
                    name,
                    description,
                    primary_contact,
                    labels=(),
                    restricted=True):
     return Partner.create(org, name, description, primary_contact,
                           restricted, labels, None)
Exemplo n.º 2
0
    def create_orgs(self, superuser, org_names, group_names, field_specs, partner_specs, password):
        """
        Creates the orgs
        """
        self._log(f"Creating {len(org_names)} orgs... ")

        orgs = []
        for o, org_name in enumerate(org_names):
            org = Org.objects.create(
                name=org_name,
                timezone=pytz.timezone(random.choice(pytz.all_timezones)),
                subdomain=org_name.lower(),
                created_on=timezone.now(),
                created_by=superuser,
                modified_by=superuser,
            )
            orgs.append(org)

            # create administrator user for this org
            Profile.create_org_user(
                org, "Adam", f"admin{o+1}@unicef.org", password, change_password=False, must_use_faq=False
            )

            for group_name in group_names:
                Group.objects.create(org=org, uuid=str(uuid4()), name=group_name)

            for field_spec in field_specs:
                Field.objects.create(
                    org=org, label=field_spec["label"], key=field_spec["key"], value_type=field_spec["value_type"]
                )

            label_names = set()
            for partner_spec in partner_specs:
                label_names.update(partner_spec["labels"])

            for label_name in sorted(label_names):
                tests = [ContainsTest([label_name.lower()], Quantifier.ANY)]
                Label.create(org, label_name, f"Messages about {label_name}", tests, is_synced=False)

            for p, partner_spec in enumerate(partner_specs):
                labels = Label.objects.filter(org=org, name__in=partner_spec["labels"])
                partner = Partner.create(
                    org,
                    partner_spec["name"],
                    partner_spec["description"],
                    primary_contact=None,
                    restricted=True,
                    labels=labels,
                )

                for user_spec in partner_spec["users"]:
                    email = f"{user_spec['name'].lower()}{o + 1}@{partner_spec['name'].lower()}.com"
                    Profile.create_partner_user(org, partner, user_spec["role"], user_spec["name"], email, password)

        self._log(self.style.SUCCESS("OK") + "\n")
        return orgs
Exemplo n.º 3
0
 def create_partner(self, org, name, labels=(), restricted=True):
     return Partner.create(org, name, restricted, labels, None)
Exemplo n.º 4
0
 def create_partner(self, org, name, labels=()):
     return Partner.create(org, name, labels, None)
Exemplo n.º 5
0
 def create_partner(self, org, name):
     return Partner.create(org, name, None)
Exemplo n.º 6
0
 def create_partner(self, org, name, description, primary_contact, labels=(), restricted=True):
     return Partner.create(org, name, description, primary_contact, restricted, labels, None)
Exemplo n.º 7
0
 def create_partner(self, org, name):
     return Partner.create(org, name, None)