Beispiel #1
0
def collaborator_add(request, collaborator_id, confirm):
    col = Collaborator.objects.filter(id=collaborator_id)
    c = {}
    if request.method == 'POST':
        ucform = UserCreateForm(request.POST)
        upform = UserProfileForm(request.POST)
        if ucform.is_valid() and upform.is_valid(
        ) and confirm == col[0].confirm:
            u = ucform.save()
            up = upform.save()
            up.doctors.add(col[0].doctor)
            up.current_doctor = col[0].doctor
            up.user = u
            up.save()
            col.delete()
            return render(request, 'valid.tpl')
        else:
            c['form'] = [ucform, upform]
            messages.error(request, "Error")
    else:
        if len(col):
            u = User.objects.filter(email=col[0].email_col)
            if len(u):
                u[0].doctors.add(col[0].doctor)
                return render(request, 'valid.tpl')
            else:
                c['form'] = [
                    UserCreateForm(email=col[0].email_col),
                    UserProfileForm()
                ]
    c['url'] = "/user/collaborator/add/%s/%s/" % (collaborator_id, confirm)
    c['title'] = _("New User")
    return render(request, 'form.tpl', c)
Beispiel #2
0
def add_user(request):
    c = {}
    if request.method == 'POST':
        ucform = UserCreateForm(request.POST)
        upform = UserProfileForm(request.POST)
        docform = DoctorForm(request.POST)
        invoiceform = MiniInvoiceForm(request.POST)
        if ucform.is_valid() and upform.is_valid() and docform.is_valid() and invoiceform.is_valid():
            i = invoiceform.save()
            u = ucform.save()
            up = upform.save()
            doc = docform.save()
            doc.refer_userprofile = up
            for st in settings.SLOT_TYPE:
                doc.get_colorslot(st[0])
            doc.invoices.add(i)
            doc.save()
            up.user = u
            up.doctors.add(doc)
            up.current_doctor = doc
            up.save()
            doc.set_slug()
            doc.save()
            mail_user_welcome(request, up, False)
            return HttpResponseRedirect('/')
        else:
            c['form'] = [ucform, upform, docform, invoiceform]
            messages.error(request, "Error")
    else:
        c['form'] = [UserCreateForm(), UserProfileForm(), DoctorForm(), MiniInvoiceForm()]
    c['url'] = "/user/add_user/"
    c['title'] = _("New doctor")
    return render(request, 'form.tpl', c)
Beispiel #3
0
def collaborator_add(request, collaborator_id, confirm):
    col = Collaborator.objects.filter(id=collaborator_id)
    c = {}
    if request.method == 'POST':
        ucform = UserCreateForm(request.POST)
        upform = UserProfileForm(request.POST)
        if ucform.is_valid() and upform.is_valid() and confirm == col[0].confirm:
            u = ucform.save()
            up = upform.save()
            up.doctors.add(col[0].doctor)
            up.current_doctor = col[0].doctor
            up.user = u
            up.save()
            col.delete()
            return render(request, 'valid.tpl')
        else:
            c['form'] = [ucform, upform]
            messages.error(request, "Error")
    else:
        if len(col):
            u = User.objects.filter(email=col[0].email_col)
            if len(u):
                u[0].doctors.add(col[0].doctor)
                return render(request, 'valid.tpl')
            else:
                c['form'] = [UserCreateForm(email=col[0].email_col), UserProfileForm()]
    c['url'] = "/user/collaborator/add/%s/%s/" % (collaborator_id, confirm)
    c['title'] = _("New User")
    return render(request, 'form.tpl', c)
Beispiel #4
0
def personal_data(request):
    results = {}
    if request.is_ajax():
        user_form = UserForm(request.POST, instance=request.user)
        userprofile_form = UserProfileForm(request.POST, instance=request.user.userprofile)
        if user_form.is_valid() and userprofile_form.is_valid():
            user_form.save()
            userprofile_form.save()
            results['return'] = True
        else:
            combo = userprofile_form.errors
            combo.update(user_form.errors)
            results['errors'] = combo
            results['return'] = False
    else:
        results['return'] = False
    return HttpResponse(json.dumps(results))
Beispiel #5
0
def register(request):
	# Redirect user if already logged in.
	if request.user:
		if request.user.is_authenticated():
			return HttpResponseRedirect('/home')

	# If it's a HTTP POST, we're interested in processing form data.
	if request.method == 'POST':
		# Attempt to grab information from the raw form information.
		# Note that we make use of both UserForm and UserProfileForm.
		user_form = UserForm(data=request.POST)
		profile_form = UserProfileForm(data=request.POST)

		# If the two forms are valid...
		if user_form.is_valid() and profile_form.is_valid():
			# Save the user's form data to the database.
			user = user_form.save()

			# Now we hash the password with the set_password method.
			# Once hashed, we can update the user object.
			user.set_password(user.password)
			user.save()

			# Now sort out the UserProfile instance.
			# Since we need to set the user attribute ourselves, we set commit=False.
			# This delays saving the model until we're ready to avoid integrity problems.
			profile = profile_form.save(commit=False)
			profile.user = user

			# Did the user provide a profile picture?
			# If so, we need to get it from the input form and put it in the UserProfile model.
			if 'picture' in request.FILES:
				 profile.picture = request.FILES['picture']

			# Now we save the UserProfile model instance.
			profile.save()

			return HttpResponseRedirect('/home')

		# Invalid form or forms - mistakes or something else?
		# Print problems to the terminal.
		# They'll also be shown to the user.
		else:
			context_dict = {
				'user_form': user_form,
				'profile_form': profile_form,
			}
			return render(request, 'index.html', context_dict)

	# Not a HTTP POST, this should never happen
	else:
		context_dict = {
			'user_form': UserForm(),
			'profile_form': UserProfileForm(),
			'error_messages': ['Invalid HTTP request.']
		}
		return render(request,'index.html',context_dict)
Beispiel #6
0
def add_company(request):
    form1 = UserProfileForm(request.POST)
    form2 = UserCreateForm(request.POST)
    form3 = CompanyForm(request.POST)
    if form1.is_valid() and form2.is_valid() and form3.is_valid():
        up = form1.save(commit=False)
        c = form3.save()
        c.active = True
        c.favorite = True
        c.save()
        u = form2.save()
        up.user = u
        up.save()
        up.companies.add(c)
        for user in User.objects.filter(is_superuser=True):
            user.userprofile.companies.add(c)
            user.userprofile.save()
        # add dossier global
        fy_init = FiscalYear.objects.filter(init=True)[0]
        y_init = Year(fiscal_year=fy_init, active=True, refer_company=c, favorite=False)
        y_init.save()
        c.years.add(y_init)
        tt_init = TemplateTrimester.objects.filter(year=fy_init, favorite=True)[0]
        tri_init = Trimester(template=tt_init, start_date=tt_init.start_date, active=True, refer_year=y_init, favorite=True)
        tri_init.save()
        y_init.trimesters.add(tri_init)
        tp_init = TypeCategory.objects.filter(priority=10)[0]
        cat_init = Category(cat=tp_init, refer_trimester=tri_init, active=True)
        cat_init.save()
        tri_init.categories.add(cat_init)
        # add favorite_year and favorite_trimester
        fy_fav = FiscalYear.objects.filter(favorite=True)[0]
        y_fav = Year(fiscal_year=fy_fav, active=True, refer_company=c, favorite=True)
        y_fav.save()
        c.years.add(y_fav)
        tt_fav = TemplateTrimester.objects.filter(year=fy_fav, favorite=True)[0]
        tri_fav = Trimester(template=tt_fav, start_date=tt_fav.start_date, active=True, refer_year=y_fav, favorite=True)
        tri_fav.save()
        y_fav.trimesters.add(tri_fav)
        for tp in TypeCategory.objects.filter(priority__lt=10).order_by('priority'):
            cat_fav = Category(cat=tp, refer_trimester=tri_fav, active=True)
            cat_fav.save()
            tri_fav.categories.add(cat_fav)
        c = {'return': True, 'list': Company.objects.all(), 'form': [UserProfileForm(), UserCreateForm(), CompanyForm()], 'url': '/company/add/'}
        return render(request, 'list.tpl', c)
    else:
        c = {'view_form': True, 'list': Company.objects.all(), 'form': [form1(), form2(), form3()]}
        return render(request, 'list.tpl', c)
Beispiel #7
0
def create_user(request):
    c = {}
    if request.method == 'POST':
        ucform = UserCreateForm(request.POST)
        upform = UserProfileForm(request.POST)
        docform = DoctorForm(request.POST)
        invoiceform = MiniInvoiceForm(request.POST)
        if ucform.is_valid() and upform.is_valid() and docform.is_valid(
        ) and invoiceform.is_valid():
            i = invoiceform.save()
            u = ucform.save()
            up = upform.save()
            u.is_active = False
            u.save()
            i.active = True
            i.save()
            up.confirm = string_random(32)
            doc = docform.save()
            doc.refer_userprofile = up
            for st in settings.SLOT_TYPE:
                doc.get_colorslot(st[0])
            doc.invoices.add(i)
            doc.save()
            up.user = u
            up.doctors.add(doc)
            # TODO regarder dans collaborator pour voir si il faut en rajouter
            up.current_doctor = doc
            up.save()
            doc.set_slug()
            doc.save()
            mail_user_welcome(request, up, True)
            c['mail'] = True
            return render(request, 'valid.tpl', c)
        else:
            c['form'] = [ucform, upform, docform, invoiceform]
            messages.error(request, "Error")
    else:
        c['form'] = [
            UserCreateForm(),
            UserProfileForm(),
            DoctorForm(),
            MiniInvoiceForm()
        ]
    c['url'] = "/user/create_user/"
    c['title'] = _("New doctor")
    return render(request, 'form.tpl', c)
Beispiel #8
0
def create_user(request):
    c = {}
    if request.method == 'POST':
        ucform = UserCreateForm(request.POST)
        upform = UserProfileForm(request.POST)
        docform = DoctorForm(request.POST)
        invoiceform = MiniInvoiceForm(request.POST)
        if ucform.is_valid() and upform.is_valid() and docform.is_valid() and invoiceform.is_valid():
            i = invoiceform.save()
            u = ucform.save()
            up = upform.save()
            u.is_active = False
            u.save()
            i.active = True
            i.save()
            up.confirm = string_random(32)
            doc = docform.save()
            doc.refer_userprofile = up
            for st in settings.SLOT_TYPE:
                doc.get_colorslot(st[0])
            doc.invoices.add(i)
            doc.save()
            up.user = u
            up.doctors.add(doc)
            # TODO regarder dans collaborator pour voir si il faut en rajouter
            up.current_doctor = doc
            up.save()
            doc.set_slug()
            doc.save()
            mail_user_welcome(request, up, True)
            c['mail'] = True
            return render(request, 'valid.tpl', c)
        else:
            c['form'] = [ucform, upform, docform, invoiceform]
            messages.error(request, "Error")
    else:
        c['form'] = [UserCreateForm(), UserProfileForm(), DoctorForm(), MiniInvoiceForm()]
    c['url'] = "/user/create_user/"
    c['title'] = _("New doctor")
    return render(request, 'form.tpl', c)
Beispiel #9
0
def add_user(request):
    c = {}
    if request.method == 'POST':
        ucform = UserCreateForm(request.POST)
        upform = UserProfileForm(request.POST)
        docform = DoctorForm(request.POST)
        invoiceform = MiniInvoiceForm(request.POST)
        if ucform.is_valid() and upform.is_valid() and docform.is_valid(
        ) and invoiceform.is_valid():
            i = invoiceform.save()
            u = ucform.save()
            up = upform.save()
            doc = docform.save()
            doc.refer_userprofile = up
            for st in settings.SLOT_TYPE:
                doc.get_colorslot(st[0])
            doc.invoices.add(i)
            doc.save()
            up.user = u
            up.doctors.add(doc)
            up.current_doctor = doc
            up.save()
            doc.set_slug()
            doc.save()
            mail_user_welcome(request, up, False)
            return HttpResponseRedirect('/')
        else:
            c['form'] = [ucform, upform, docform, invoiceform]
            messages.error(request, "Error")
    else:
        c['form'] = [
            UserCreateForm(),
            UserProfileForm(),
            DoctorForm(),
            MiniInvoiceForm()
        ]
    c['url'] = "/user/add_user/"
    c['title'] = _("New doctor")
    return render(request, 'form.tpl', c)
Beispiel #10
0
def register_social(request):
	if request.method == 'POST':
		# Attempt to grab information from the raw form information.
		# Note that we make use of both UserForm and UserProfileForm.
		user_form = UserForm(data=request.POST)
		profile_form = UserProfileForm(data=request.POST)

		# If the two forms are valid...
		if user_form.is_valid() and profile_form.is_valid():
			# Save the user's form data to the database.
			user = user_form.save()

			# Now we hash the password with the set_password method.
			# Once hashed, we can update the user object.
			user.set_password(user.password)
			user.save()

			# Now sort out the UserProfile instance.
			# Since we need to set the user attribute ourselves, we set commit=False.
			# This delays saving the model until we're ready to avoid integrity problems.
			profile = profile_form.save(commit=False)
			profile.user = user

			# Did the user provide a profile picture?
			# If so, we need to get it from the input form and put it in the UserProfile model.
			if 'picture' in request.FILES:
				 profile.picture = request.FILES['picture']

			# Now we save the UserProfile model instance.
			profile.save()

			user.backend = 'django.contrib.auth.backends.ModelBackend'
			login(request, user)

			backend = request.session['partial_pipeline']['backend']
			return redirect('social:complete', backend=backend)

		# Invalid form or forms - mistakes or something else?
		# Print problems to the terminal.
		# They'll also be shown to the user.
		else:
			print(user_form.errors, profile_form.errors)

			context_dict = {
				'user_form': user_form,
				'profile_form': profile_form,
				'backend': request.session['partial_pipeline']['backend'],
			}

			return render(request, 'register_social.html', context_dict)

	else:
		partial_user_data = request.session.get('partial_user_data')

		context_dict = {
			'user_form': UserForm(initial=partial_user_data),
			'profile_form': UserProfileForm(),
			'backend': request.session['partial_pipeline']['backend'],
		}

		request.session.pop('partial_user_data')

		return render(request, 'register_social.html', context_dict)