def register(request): """ New user applying for access """ form = RegistrationForm() data = {"title": _("Register")} if request.method == "POST": form = RegistrationForm(request.POST) if form.is_valid(): user = User(is_active=False) user.email = form.cleaned_data["email"] user.last_name = form.cleaned_data["last_name"] user.first_name = form.cleaned_data["first_name"] user.set_password(form.cleaned_data["password"]) user.save() messages.success(request, _(u"Your registration is now pending approval.")) return redirect(login) data["form"] = form return render(request, "accounts/register.html", data)
def register(request): """ New user applying for access """ form = RegistrationForm() data = {'title': _("Register")} if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): user = User(is_active=False) user.email = form.cleaned_data['email'] user.last_name = form.cleaned_data['last_name'] user.first_name = form.cleaned_data['first_name'] user.set_password(form.cleaned_data['password']) user.save() messages.success(request, _(u'Your registration is now pending approval.')) return redirect(login) data['form'] = form return render(request, 'accounts/register.html', data)
def save(self, **kwargs): users = [] string = u'' cd = self.cleaned_data data = cd['datafile'].read() for i in ( 'utf-8', 'latin-1', ): try: string = data.decode(i) except: pass if not string: raise ValueError(_('Unsupported file encoding')) sio = io.StringIO(string, newline=None) for l in sio.readlines(): cols = l.strip().split("\t") if len(cols) < 2: continue # Skip empty rows user = User(username=cols[2]) user.first_name = cols[0] user.last_name = cols[1] user.email = cols[3] user.set_password(cols[4]) user.save() user.location = cd['location'] user.timezone = user.location.timezone user.groups.add(cd['group']) user.queues = cd['queues'] user.save() users.append(user) return users
def save(self, **kwargs): users = [] string = u'' cd = self.cleaned_data data = cd['datafile'].read() for i in ('utf-8', 'latin-1',): try: string = data.decode(i) except: pass if not string: raise ValueError(_('Unsupported file encoding')) sio = io.StringIO(string, newline=None) for l in sio.readlines(): cols = l.strip().split("\t") if len(cols) < 2: continue # Skip empty rows user = User(username=cols[2]) user.first_name = cols[0] user.last_name = cols[1] user.email = cols[3] user.set_password(cols[4]) user.save() user.location = cd['location'] user.timezone = user.location.timezone user.groups.add(cd['group']) user.queues = cd['queues'] user.save() users.append(user) return users