Example #1
0
    def parse_row(self, line, row):
        from openPLM.plmapp.forms import SponsorForm

        un, fn, ln, em, grps, la = self.get_values(row, *self.REQUIRED_HEADERS)
        groups = []
        for grp in grps.split("/"):
            try:
                groups.append(self.groups[grp])
            except KeyError:
                self.store_errors(line, u"Invalid group:%s" % grp)
                return
        data = {
            "sponsor": self.user.id,
            "username": un,
            "last_name": ln,
            "first_name": fn,
            "email": em,
            "groups": groups,
            "language": la,
            "warned": True,
        }
        form = SponsorForm(data, sponsor=self.user.id)
        if form.is_valid():
            new_user = form.save()
            new_user.profile.language = form.cleaned_data["language"]
            self.ctrl.sponsor(new_user)
            self.objects.append(new_user)
        else:
            items = (mark_safe(u"%s: %s" % item) for item in form.errors.iteritems())
            self.store_errors(line, *items)
Example #2
0
 def parse_row(self, line, row):
     from openPLM.plmapp.forms import SponsorForm
     un, fn, ln, em, grps,la = self.get_values(row, *self.REQUIRED_HEADERS)
     groups = []
     for grp in grps.split("/"):
         try:
             groups.append(self.groups[grp])
         except KeyError:
             self.store_errors(line, u"Invalid group:%s" % grp)
             return
     data = {
             "sponsor" : self.user.id,
             "username": un,
             "last_name": ln,
             "first_name": fn,
             "email" : em,
             "groups" : groups,
             "language" : la,
             "warned" : True,
             }
     form = SponsorForm(data, sponsor=self.user.id)
     if form.is_valid():
         new_user = form.save()
         new_user.profile.language = form.cleaned_data["language"]
         self.ctrl.sponsor(new_user)
         self.objects.append(new_user)
     else:
         items = (mark_safe(u"%s: %s" % item) for item
                 in form.errors.iteritems())
         self.store_errors(line, *items)
Example #3
0
 def handle(self, *args, **options):
     sponsor = User.objects.get(username=options.get('sponsor', None))
     obj = UserController(sponsor, sponsor)
     data = dict(options)
     data["sponsor"] = sponsor.id
     data["warned"] = True
     data["groups"] = list(GroupInfo.objects.filter(name__in=options["groups"]).values_list("id", flat=True))
     form = SponsorForm(data)
     if form.is_valid():
         new_user = form.save()
         new_user.profile.language = form.cleaned_data["language"]
         role = form.cleaned_data["role"]
         obj.sponsor(new_user, role=="contributor", role=="restricted")
     else:
         raise CommandError(form.errors.as_text())
Example #4
0
 def handle(self, *args, **options):
     sponsor = User.objects.get(username=options.get('sponsor', None))
     obj = UserController(sponsor, sponsor)
     data = dict(options)
     data["sponsor"] = sponsor.id
     data["warned"] = True
     data["groups"] = list(
         GroupInfo.objects.filter(name__in=options["groups"]).values_list(
             "id", flat=True))
     form = SponsorForm(data)
     if form.is_valid():
         new_user = form.save()
         new_user.profile.language = form.cleaned_data["language"]
         role = form.cleaned_data["role"]
         obj.sponsor(new_user, role == "contributor", role == "restricted")
     else:
         raise CommandError(form.errors.as_text())