コード例 #1
0
def brokerEditProfileLogic(request):
    if (request.method != 'POST'):
        return err_GE002()

    old_url = None
    broker = request.role_user
    if broker.user.photo:
        old_url = broker.user.photo.name

    broker_form = BrokerForm(request.POST, instance=broker)
    if not broker_form.is_valid():
        return err_GE031(broker_form)

    user_form = BrokerUserForm(request.POST,
                               request.FILES,
                               instance=broker.user)
    if not user_form.is_valid():
        return err_GE031(user_form)

    broker_form.save()
    user_form.save()

    new_url = None
    if broker.user.photo:
        new_url = broker.user.photo.name
    ImageHelper.generate_image(old_url, new_url)

    return HttpJSONSuccessResponse()
コード例 #2
0
ファイル: views.py プロジェクト: DongHuaLu/mdcom
def org_edit(request):
	context = get_context_for_organization(request)
	context['show_form_errors'] = True
	org = request.org
	context["save_success"] = False

	if 'organization_type' in request.REQUEST:
		organization_type = request.REQUEST['organization_type']
	else:
		organization_type = org.organization_type.id

	org_type = get_object_or_404(OrganizationType, id=organization_type)

	type_form = OrgTypeForm(data={\
			'organization_type': organization_type}, \
			user_id=request.user.id, org_id=request.org.id)
	context['pareorg_form'] = type_form

	old_display_in_contact_list_tab = org.get_setting_attr("display_in_contact_list_tab")

	if (request.method == 'POST'):
		old_url = None
		if org.practice_photo:
			old_url = org.practice_photo.name
		form = PracticeProfileForm(request.POST, request.FILES, instance=org)
		if form.is_valid() and type_form.is_valid():
			org = form.save(commit=False)
			org.practice_lat = form.cleaned_data['practice_lat']
			org.practice_longit = form.cleaned_data['practice_longit']
			org.organization_type = org_type
			org.save()

			update_staff_address_info_by_practice(org)
			new_url = None
			if org.practice_photo:
				new_url = org.practice_photo.name
			if old_url != new_url:
				ImageHelper.generate_image(old_url, new_url, 'img_size_practice')
			context["save_success"] = True

			new_display_in_contact_list_tab = \
				org.get_setting_attr("display_in_contact_list_tab")

			logger.debug("new display_in_contact_list_tab: %s, old display_in_contact_list_tab: %s"\
				% (str(new_display_in_contact_list_tab), str(old_display_in_contact_list_tab)))
			if not new_display_in_contact_list_tab == old_display_in_contact_list_tab:
				# send notification to related users
				thread.start_new_thread(notify_org_users_tab_chanaged,\
						(org.id,), {"include_member_org": True})

		context['form'] = form
		try:
			org.time_zone = OLD_TIME_ZONES_MIGRATION[org.time_zone]
		except:
			pass
	else:
		context['show_form_errors'] = False
		context['form'] = PracticeProfileForm(instance=org)
	context['type_form'] = type_form
	return render_to_response('MHLOrganization/Information/org_edit.html', context)
コード例 #3
0
ファイル: business_account.py プロジェクト: DongHuaLu/mdcom
def brokerEditProfileLogic(request):
	if (request.method != 'POST'):
		return err_GE002()

	old_url = None
	broker = request.role_user
	if broker.user.photo:
		old_url = broker.user.photo.name

	broker_form = BrokerForm(request.POST, instance=broker)
	if not broker_form.is_valid():
		return err_GE031(broker_form)

	user_form = BrokerUserForm(request.POST, request.FILES, instance=broker.user)
	if not user_form.is_valid():
		return err_GE031(user_form)

	broker_form.save()
	user_form.save()

	new_url = None
	if broker.user.photo:
		new_url = broker.user.photo.name
	ImageHelper.generate_image(old_url, new_url)

	return HttpJSONSuccessResponse()
コード例 #4
0
ファイル: views.py プロジェクト: DongHuaLu/mdcom
def profile_edit_broker(request):
	broker = request.session['MHL_Users']['Broker']
	context = get_context(request)
	#context['all_providers_box'] = box_all_providers()
	if (request.method == "POST"):
		old_url = None
		if broker.user.photo:
			old_url = broker.user.photo.name
		# First, deal with user form stuff
		if("old_password" in request.POST):
			password_form = ChangePasswordForm(broker.user, request.POST)
			broker_form = BrokerForm(instance=broker)
			user_form = BrokerUserForm(instance=broker.user)
		else:
			broker_form = BrokerForm(request.POST, instance=broker)
			user_form = BrokerUserForm(request.POST, request.FILES, instance=broker.user)
			password_form = ChangePasswordForm(broker.user)
			preference_form = PreferenceForm(request.POST, instance=broker.user)
			#user_form.save(commit=False)

		context['user'] = broker
		context['user_form'] = user_form
		context['broker_form'] = broker_form
		context['password_form'] = password_form
		context['preference_form'] = preference_form

		if(password_form.is_valid()):
			if(password_form.cleaned_data['old_password']):
				response = HttpResponseRedirect(reverse('MHLogin.MHLUsers.views.profile_view'))
				return change_pass(password_form, request, response)

		if (broker_form.is_valid() and user_form.is_valid() and preference_form.is_valid()):
			broker_form.save()
			user_form.save()
			mhluser = MHLUser.objects.get(id=broker.user.id)
			mhluser.time_setting = preference_form.cleaned_data['time_setting']
			mhluser.time_zone = preference_form.cleaned_data['time_zone']
			mhluser.save()

			context = get_context(request)
			new_url = None
			if broker.user.photo:
				new_url = broker.user.photo.name
			ImageHelper.generate_image(old_url, new_url)
			return HttpResponseRedirect(reverse('MHLogin.MHLUsers.views.profile_view'))
	else:
		context['user'] = broker
		context['user_form'] = BrokerUserForm(instance=broker.user)
		context['broker_form'] = BrokerForm(instance=broker)
		context['password_form'] = ChangePasswordForm(user=broker.user)
		context['preference_form'] = PreferenceForm(initial={'time_setting':
				broker.user.time_setting if broker.user.time_setting else 0,
						'time_zone': broker.user.time_zone})

	context['mobile_required'] = True
	from django import conf
	context['Language'] = LANGUAGE[conf.settings.FORCED_LANGUAGE_CODE]
	return render_to_response('Profile/profile_edit.html', context)
コード例 #5
0
def practice_profile_edit(request):
    """
	Practice profile edit page.
	"""
    # Permissions checks. We need to check to see if this user is a manager
    # for this office.
    if (not 'OfficeStaff' in request.session['MHL_UserIDs']):
        return err403(request)
    office_staff = request.session['MHL_Users']['OfficeStaff']
    office_mgr = Office_Manager.objects.filter(
        user=office_staff, practice=office_staff.current_practice)
    if (not office_mgr.exists()):
        return err403(request)

    context = get_context(request)
    if (request.method == 'POST'):
        old_url = None
        if office_staff.current_practice.practice_photo:
            old_url = office_staff.current_practice.practice_photo.name
        form = PracticeProfileForm(request.POST,
                                   request.FILES,
                                   instance=office_staff.current_practice)

        if (form.is_valid()):
            practice = form.save(commit=False)
            practice.practice_lat = form.cleaned_data['practice_lat']
            practice.practice_longit = form.cleaned_data['practice_longit']
            practice.save()
            update_staff_address_info_by_practice(practice)
            new_url = None
            if office_staff.current_practice.practice_photo:
                new_url = practice.practice_photo.name
            if old_url != new_url:
                ImageHelper.generate_image(old_url, new_url,
                                           'img_size_practice')
            if not form.non_field_warnings:
                return HttpResponseRedirect(reverse(practice_profile_view))
    else:
        practice = office_staff.current_practice
        try:
            if practice.time_zone:
                practice.time_zone = OLD_TIME_ZONES_MIGRATION[
                    practice.time_zone]
        except Exception as e:
            logger.critical("FIXME: Unexpected bug: %s" % str(e))

        form = PracticeProfileForm(instance=practice)

    context['form'] = form
    return render_to_response('Profile/practice_profile_edit.html', context)
コード例 #6
0
def providerEditProfileLogic(request):
    if (request.method != 'POST'):
        return err_GE002()
    provider = request.role_user
    phys = Physician.objects.filter(user=provider)
    if phys and len(phys):
        phys = phys[0]
    else:
        phys = None

    old_url = None
    if provider.photo:
        old_url = provider.photo.name
    provider_form = ProviderForm(data=request.POST,
                                 files=request.FILES,
                                 instance=provider)
    if (not provider_form.is_valid()):
        return err_GE031(provider_form)

    physician_form = None
    if (phys):
        physician_form = PhysicianForm(request.POST, instance=phys)
        if (not physician_form.is_valid()):
            return err_GE031(physician_form)

    provider = provider_form.save(commit=False)
    provider.lat = provider_form.cleaned_data['lat']
    provider.longit = provider_form.cleaned_data['longit']
    provider.licensure_states = provider_form.cleaned_data['licensure_states']
    #add by xlin in 20120611 for issue897 that add city, address, zip into database
    provider.address1 = provider_form.cleaned_data['address1']
    provider.address2 = provider_form.cleaned_data['address2']
    provider.city = provider_form.cleaned_data['city']
    provider.state = provider_form.cleaned_data['state']
    provider.zip = provider_form.cleaned_data['zip']
    provider.save()
    if (physician_form):
        physician_form.save()

    new_url = None
    if provider.photo:
        new_url = provider.photo.name

    #thumbnail creating code moved from here to save method of provider mode
    #use common method to generate
    ImageHelper.generate_image(old_url, new_url)

    return HttpJSONSuccessResponse()
コード例 #7
0
ファイル: views.py プロジェクト: DongHuaLu/mdcom
def practice_profile_edit(request):
	"""
	Practice profile edit page.
	"""
	# Permissions checks. We need to check to see if this user is a manager
	# for this office.
	if (not 'OfficeStaff' in request.session['MHL_UserIDs']):
		return err403(request)
	office_staff = request.session['MHL_Users']['OfficeStaff']
	office_mgr = Office_Manager.objects.filter(user=office_staff,
				practice=office_staff.current_practice)
	if (not office_mgr.exists()):
		return err403(request)

	context = get_context(request)
	if (request.method == 'POST'):
		old_url = None
		if office_staff.current_practice.practice_photo:
			old_url = office_staff.current_practice.practice_photo.name
		form = PracticeProfileForm(request.POST, request.FILES,
					instance=office_staff.current_practice)

		if (form.is_valid()):
			practice = form.save(commit=False)
			practice.practice_lat = form.cleaned_data['practice_lat']
			practice.practice_longit = form.cleaned_data['practice_longit']
			practice.save()
			update_staff_address_info_by_practice(practice)
			new_url = None
			if office_staff.current_practice.practice_photo:
				new_url = practice.practice_photo.name
			if old_url != new_url:
				ImageHelper.generate_image(old_url, new_url, 'img_size_practice')
			if not form.non_field_warnings:
				return HttpResponseRedirect(reverse(practice_profile_view))
	else:
		practice = office_staff.current_practice
		try:
			if practice.time_zone:
				practice.time_zone = OLD_TIME_ZONES_MIGRATION[practice.time_zone]
		except Exception as e:
			logger.critical("FIXME: Unexpected bug: %s" % str(e))

		form = PracticeProfileForm(instance=practice)

	context['form'] = form
	return render_to_response('Profile/practice_profile_edit.html', context)
コード例 #8
0
ファイル: business_account.py プロジェクト: DongHuaLu/mdcom
def providerEditProfileLogic(request):
	if (request.method != 'POST'):
		return err_GE002()
	provider = request.role_user
	phys = Physician.objects.filter(user=provider)
	if phys and len(phys):
		phys = phys[0]
	else:
		phys = None

	old_url = None
	if provider.photo:
		old_url = provider.photo.name
	provider_form = ProviderForm(data=request.POST, files=request.FILES, instance=provider)
	if (not provider_form.is_valid()):
		return err_GE031(provider_form)

	physician_form = None
	if (phys):
		physician_form = PhysicianForm(request.POST, instance=phys)
		if (not physician_form.is_valid()):
			return err_GE031(physician_form)
	
	provider = provider_form.save(commit=False)
	provider.lat = provider_form.cleaned_data['lat']
	provider.longit = provider_form.cleaned_data['longit']
	provider.licensure_states = provider_form.cleaned_data['licensure_states']
	#add by xlin in 20120611 for issue897 that add city, address, zip into database
	provider.address1 = provider_form.cleaned_data['address1']
	provider.address2 = provider_form.cleaned_data['address2']
	provider.city = provider_form.cleaned_data['city']
	provider.state = provider_form.cleaned_data['state']
	provider.zip = provider_form.cleaned_data['zip']
	provider.save()
	if (physician_form):
		physician_form.save()
	
	new_url = None
	if provider.photo:
		new_url = provider.photo.name
	
	#thumbnail creating code moved from here to save method of provider mode
	#use common method to generate
	ImageHelper.generate_image(old_url, new_url)

	return HttpJSONSuccessResponse()
コード例 #9
0
def officeStaffEditProfileLogic(request):
    if (request.method != 'POST'):
        return err_GE002()

    staff = request.role_user
    old_url = None
    if staff.user.photo:
        old_url = staff.user.photo.name

    staff_form = OfficeStaffForm(request.POST, instance=staff)
    if not staff_form.is_valid():
        return err_GE031(staff_form)

    user_form = UserForm(request.POST, request.FILES, instance=staff.user)
    if not user_form.is_valid():
        return err_GE031(user_form)

    user_form.save(commit=False)
    staff_form.save()
    new_url = None
    if staff.user.photo:
        new_url = staff.user.photo.name
    ImageHelper.generate_image(old_url, new_url)
    return HttpJSONSuccessResponse()
コード例 #10
0
ファイル: business_account.py プロジェクト: DongHuaLu/mdcom
def officeStaffEditProfileLogic(request):
	if (request.method != 'POST'):
		return err_GE002()

	staff = request.role_user
	old_url = None
	if staff.user.photo:
		old_url = staff.user.photo.name

	staff_form = OfficeStaffForm(request.POST, instance=staff)
	if not staff_form.is_valid():
		return err_GE031(staff_form)

	user_form = UserForm(request.POST, request.FILES, instance=staff.user)
	if not user_form.is_valid():
		return err_GE031(user_form)

	user_form.save(commit=False)
	staff_form.save()
	new_url = None
	if staff.user.photo:
		new_url = staff.user.photo.name
	ImageHelper.generate_image(old_url, new_url)
	return HttpJSONSuccessResponse()
コード例 #11
0
ファイル: views.py プロジェクト: DongHuaLu/mdcom
def profile_edit_office_staff(request):
	""" This function allows for ofice staff to edit their profiles.
	"""
	# First, get the relevant user's profile. Everything requires it.
	context = get_context(request)
	staff = request.session['MHL_Users']['OfficeStaff']

	if (not staff.vm_config.count()):
		config = VMBox_Config()
		config.owner = staff
		config.save()

	vmconfig_obj = staff.vm_config.get()
	#context['all_providers_box'] = box_all_providers()
	if (request.method == "POST"):
		old_url = None
		if staff.user.photo:
			old_url = staff.user.photo.name

		# First, deal with user form stuff
		if("old_password" in request.POST):
			password_form = ChangePasswordForm(staff.user, request.POST)
			# set these here so they still display properly when we get form errors 
			# in the password form
			staff_form = OfficeStaffForm(instance=staff)
			user_form = UserForm(instance=staff.user)
		else:
			staff_form = OfficeStaffForm(request.POST, instance=staff)
			user_form = UserForm(request.POST, request.FILES, instance=staff.user)
			password_form = ChangePasswordForm(staff.user)
			settings_form = VMBox_ConfigForm(request.POST, instance=vmconfig_obj)
			preference_form = PreferenceForm(request.POST, instance=staff.user)
		if user_form.is_valid():
			user_form.save(commit=False)
			context['user'] = staff
			context['user_form'] = user_form
			context['staff_form'] = staff_form
			context['password_form'] = password_form

			if(password_form.is_valid()):
				if(password_form.cleaned_data['old_password']):
					response = HttpResponseRedirect(reverse('MHLogin.MHLUsers.views.profile_view'))
					return change_pass(password_form, request, response)

			if (staff_form.is_valid() and user_form.is_valid() and settings_form.is_valid() \
					and preference_form.is_valid()):
				staff_form.save()
				user_form.save()
				settings_form.save()
				mhluser = MHLUser.objects.get(id=staff.user.id)
				mhluser.time_setting = preference_form.cleaned_data['time_setting']
				mhluser.time_zone = preference_form.cleaned_data['time_zone']
				mhluser.save()

				new_url = None
				if staff.user.photo:
					new_url = staff.user.photo.name
				ImageHelper.generate_image(old_url, new_url)

				return HttpResponseRedirect(reverse('MHLogin.MHLUsers.views.profile_view'))
		else:
			context['user_form'] = user_form
			context['staff_form'] = staff_form
			context['settings_form'] = settings_form
			context['preference_form'] = preference_form
	else:
		context['user'] = staff
		context['user_form'] = UserForm(instance=staff.user)
		context['staff_form'] = OfficeStaffForm(instance=staff)
		context['password_form'] = ChangePasswordForm(user=staff.user)
		context['settings_form'] = VMBox_ConfigForm(instance=vmconfig_obj, 
									initial={'pin': ''})
		context['preference_form'] = PreferenceForm(initial={'time_setting':
			staff.user.time_setting if staff.user.time_setting else 0,
					'time_zone': staff.user.time_zone})

	from django import conf
	context['Language'] = LANGUAGE[conf.settings.FORCED_LANGUAGE_CODE]
	context['mobile_required'] = False
	context['isStaff'] = True
	return render_to_response('Profile/profile_edit.html', context)
コード例 #12
0
ファイル: views.py プロジェクト: DongHuaLu/mdcom
def profile_edit_provider(request):
	""" This function allows for physicians to edit their profiles. Note that it displays 
		elements of two forms for a provider profile page:
		1. Provider form
		2. Provider type (Physician, Nurse, etc.) form
	"""
	context = get_context(request)

	# First, get the relevant user's profile. Everything requires it.
	provider = Provider.objects.filter(id=request.user.id)
	if (provider.count() != 1):
		raise Exception(_('Incorrect number of provider objects returned: ') + str(provider.count()))
	provider = provider[0]

	vmconfig_obj = provider.vm_config.get()

	phys = None
	if ('Physician' in request.session['MHL_Users']):
		phys = request.session['MHL_Users']['Physician']
	context['physician'] = phys

	if (request.method == "POST"):
		old_url = None
		if provider.photo:
			old_url = provider.photo.name
		settings_form = VMBox_ConfigForm(request.POST, instance=vmconfig_obj)
		provider_form = ProviderForm(data=request.POST, files=request.FILES, instance=provider)

		preference_form = PreferenceProviderForm(request.POST, instance=provider.user)

		if (phys):
			physician_form = PhysicianForm(request.POST, instance=phys)
		else:
			physician_form = None

		if (physician_form):
			physician_form_validity = physician_form.is_valid()
		else:
			physician_form_validity = True

		if (provider_form.is_valid() and physician_form_validity and \
				settings_form.is_valid() and preference_form.is_valid()):
			provider = provider_form.save(commit=False)
			provider.lat = provider_form.cleaned_data['lat']
			provider.longit = provider_form.cleaned_data['longit']
			provider.licensure_states = provider_form.cleaned_data['licensure_states']
			#add by xlin in 20120611 for issue897 that add city, address, zip into database
			provider.address1 = provider_form.cleaned_data['address1']
			provider.address2 = provider_form.cleaned_data['address2']
			provider.city = provider_form.cleaned_data['city']
			provider.state = provider_form.cleaned_data['state']
			provider.zip = provider_form.cleaned_data['zip']
			provider.save()
			mhluser = MHLUser.objects.get(id=provider.user.id)
			mhluser.time_setting = preference_form.cleaned_data['time_setting']
			mhluser.time_zone = preference_form.cleaned_data['time_zone']
			mhluser.refer_forward = preference_form.cleaned_data['refer_forward']
			mhluser.save()
			if (physician_form):
				physician_form.save()
			settings_form.save()

			new_url = provider.photo.name if provider.photo else None
			#thumbnail creating code moved from here to save method of provider mode
			#use common method to generate
			ImageHelper.generate_image(old_url, new_url)
			if not provider_form.non_field_warnings:
				return HttpResponseRedirect(reverse('MHLogin.MHLUsers.views.profile_view'))
			else:
				context['user_form'] = provider_form
				context['physician_form'] = physician_form
				context['settings_form'] = settings_form
				context['preference_form'] = preference_form
		else:  # if not (user_form.is_valid() and provider_form):
			context['user_form'] = provider_form
			context['physician_form'] = physician_form
			context['settings_form'] = settings_form
			context['preference_form'] = preference_form

	else:  # if (request.method != "POST"):
		context['user_form'] = ProviderForm(instance=Provider.objects.get(id=request.user.id))
		context['settings_form'] = VMBox_ConfigForm(instance=vmconfig_obj, initial={'pin': ''})
		context['preference_form'] = PreferenceProviderForm(initial={'time_setting':
				provider.user.time_setting if provider.user.time_setting else 0,
						'time_zone': provider.user.time_zone,
						'refer_forward': provider.user.refer_forward})
		if (phys):
			context['physician_form'] = PhysicianForm(instance=phys)

	from django import conf
	context['Language'] = LANGUAGE[conf.settings.FORCED_LANGUAGE_CODE]
	context['mobile_required'] = True
	context['isProvider'] = True
	return render_to_response('Profile/profile_edit.html', context)
コード例 #13
0
def profile_edit_office_staff(request):
    """ This function allows for ofice staff to edit their profiles.
	"""
    # First, get the relevant user's profile. Everything requires it.
    context = get_context(request)
    staff = request.session['MHL_Users']['OfficeStaff']

    if (not staff.vm_config.count()):
        config = VMBox_Config()
        config.owner = staff
        config.save()

    vmconfig_obj = staff.vm_config.get()
    #context['all_providers_box'] = box_all_providers()
    if (request.method == "POST"):
        old_url = None
        if staff.user.photo:
            old_url = staff.user.photo.name

        # First, deal with user form stuff
        if ("old_password" in request.POST):
            password_form = ChangePasswordForm(staff.user, request.POST)
            # set these here so they still display properly when we get form errors
            # in the password form
            staff_form = OfficeStaffForm(instance=staff)
            user_form = UserForm(instance=staff.user)
        else:
            staff_form = OfficeStaffForm(request.POST, instance=staff)
            user_form = UserForm(request.POST,
                                 request.FILES,
                                 instance=staff.user)
            password_form = ChangePasswordForm(staff.user)
            settings_form = VMBox_ConfigForm(request.POST,
                                             instance=vmconfig_obj)
            preference_form = PreferenceForm(request.POST, instance=staff.user)
        if user_form.is_valid():
            user_form.save(commit=False)
            context['user'] = staff
            context['user_form'] = user_form
            context['staff_form'] = staff_form
            context['password_form'] = password_form

            if (password_form.is_valid()):
                if (password_form.cleaned_data['old_password']):
                    response = HttpResponseRedirect(
                        reverse('MHLogin.MHLUsers.views.profile_view'))
                    return change_pass(password_form, request, response)

            if (staff_form.is_valid() and user_form.is_valid() and settings_form.is_valid() \
              and preference_form.is_valid()):
                staff_form.save()
                user_form.save()
                settings_form.save()
                mhluser = MHLUser.objects.get(id=staff.user.id)
                mhluser.time_setting = preference_form.cleaned_data[
                    'time_setting']
                mhluser.time_zone = preference_form.cleaned_data['time_zone']
                mhluser.save()

                new_url = None
                if staff.user.photo:
                    new_url = staff.user.photo.name
                ImageHelper.generate_image(old_url, new_url)

                return HttpResponseRedirect(
                    reverse('MHLogin.MHLUsers.views.profile_view'))
        else:
            context['user_form'] = user_form
            context['staff_form'] = staff_form
            context['settings_form'] = settings_form
            context['preference_form'] = preference_form
    else:
        context['user'] = staff
        context['user_form'] = UserForm(instance=staff.user)
        context['staff_form'] = OfficeStaffForm(instance=staff)
        context['password_form'] = ChangePasswordForm(user=staff.user)
        context['settings_form'] = VMBox_ConfigForm(instance=vmconfig_obj,
                                                    initial={'pin': ''})
        context['preference_form'] = PreferenceForm(
            initial={
                'time_setting':
                staff.user.time_setting if staff.user.time_setting else 0,
                'time_zone':
                staff.user.time_zone
            })

    from django import conf
    context['Language'] = LANGUAGE[conf.settings.FORCED_LANGUAGE_CODE]
    context['mobile_required'] = False
    context['isStaff'] = True
    return render_to_response('Profile/profile_edit.html', context)
コード例 #14
0
def profile_edit_provider(request):
    """ This function allows for physicians to edit their profiles. Note that it displays 
		elements of two forms for a provider profile page:
		1. Provider form
		2. Provider type (Physician, Nurse, etc.) form
	"""
    context = get_context(request)

    # First, get the relevant user's profile. Everything requires it.
    provider = Provider.objects.filter(id=request.user.id)
    if (provider.count() != 1):
        raise Exception(
            _('Incorrect number of provider objects returned: ') +
            str(provider.count()))
    provider = provider[0]

    vmconfig_obj = provider.vm_config.get()

    phys = None
    if ('Physician' in request.session['MHL_Users']):
        phys = request.session['MHL_Users']['Physician']
    context['physician'] = phys

    if (request.method == "POST"):
        old_url = None
        if provider.photo:
            old_url = provider.photo.name
        settings_form = VMBox_ConfigForm(request.POST, instance=vmconfig_obj)
        provider_form = ProviderForm(data=request.POST,
                                     files=request.FILES,
                                     instance=provider)

        preference_form = PreferenceProviderForm(request.POST,
                                                 instance=provider.user)

        if (phys):
            physician_form = PhysicianForm(request.POST, instance=phys)
        else:
            physician_form = None

        if (physician_form):
            physician_form_validity = physician_form.is_valid()
        else:
            physician_form_validity = True

        if (provider_form.is_valid() and physician_form_validity and \
          settings_form.is_valid() and preference_form.is_valid()):
            provider = provider_form.save(commit=False)
            provider.lat = provider_form.cleaned_data['lat']
            provider.longit = provider_form.cleaned_data['longit']
            provider.licensure_states = provider_form.cleaned_data[
                'licensure_states']
            #add by xlin in 20120611 for issue897 that add city, address, zip into database
            provider.address1 = provider_form.cleaned_data['address1']
            provider.address2 = provider_form.cleaned_data['address2']
            provider.city = provider_form.cleaned_data['city']
            provider.state = provider_form.cleaned_data['state']
            provider.zip = provider_form.cleaned_data['zip']
            provider.save()
            mhluser = MHLUser.objects.get(id=provider.user.id)
            mhluser.time_setting = preference_form.cleaned_data['time_setting']
            mhluser.time_zone = preference_form.cleaned_data['time_zone']
            mhluser.refer_forward = preference_form.cleaned_data[
                'refer_forward']
            mhluser.save()
            if (physician_form):
                physician_form.save()
            settings_form.save()

            new_url = provider.photo.name if provider.photo else None
            #thumbnail creating code moved from here to save method of provider mode
            #use common method to generate
            ImageHelper.generate_image(old_url, new_url)
            if not provider_form.non_field_warnings:
                return HttpResponseRedirect(
                    reverse('MHLogin.MHLUsers.views.profile_view'))
            else:
                context['user_form'] = provider_form
                context['physician_form'] = physician_form
                context['settings_form'] = settings_form
                context['preference_form'] = preference_form
        else:  # if not (user_form.is_valid() and provider_form):
            context['user_form'] = provider_form
            context['physician_form'] = physician_form
            context['settings_form'] = settings_form
            context['preference_form'] = preference_form

    else:  # if (request.method != "POST"):
        context['user_form'] = ProviderForm(instance=Provider.objects.get(
            id=request.user.id))
        context['settings_form'] = VMBox_ConfigForm(instance=vmconfig_obj,
                                                    initial={'pin': ''})
        context['preference_form'] = PreferenceProviderForm(
            initial={
                'time_setting':
                provider.user.time_setting if provider.user.
                time_setting else 0,
                'time_zone':
                provider.user.time_zone,
                'refer_forward':
                provider.user.refer_forward
            })
        if (phys):
            context['physician_form'] = PhysicianForm(instance=phys)

    from django import conf
    context['Language'] = LANGUAGE[conf.settings.FORCED_LANGUAGE_CODE]
    context['mobile_required'] = True
    context['isProvider'] = True
    return render_to_response('Profile/profile_edit.html', context)
コード例 #15
0
def profile_edit_broker(request):
    broker = request.session['MHL_Users']['Broker']
    context = get_context(request)
    #context['all_providers_box'] = box_all_providers()
    if (request.method == "POST"):
        old_url = None
        if broker.user.photo:
            old_url = broker.user.photo.name
        # First, deal with user form stuff
        if ("old_password" in request.POST):
            password_form = ChangePasswordForm(broker.user, request.POST)
            broker_form = BrokerForm(instance=broker)
            user_form = BrokerUserForm(instance=broker.user)
        else:
            broker_form = BrokerForm(request.POST, instance=broker)
            user_form = BrokerUserForm(request.POST,
                                       request.FILES,
                                       instance=broker.user)
            password_form = ChangePasswordForm(broker.user)
            preference_form = PreferenceForm(request.POST,
                                             instance=broker.user)
            #user_form.save(commit=False)

        context['user'] = broker
        context['user_form'] = user_form
        context['broker_form'] = broker_form
        context['password_form'] = password_form
        context['preference_form'] = preference_form

        if (password_form.is_valid()):
            if (password_form.cleaned_data['old_password']):
                response = HttpResponseRedirect(
                    reverse('MHLogin.MHLUsers.views.profile_view'))
                return change_pass(password_form, request, response)

        if (broker_form.is_valid() and user_form.is_valid()
                and preference_form.is_valid()):
            broker_form.save()
            user_form.save()
            mhluser = MHLUser.objects.get(id=broker.user.id)
            mhluser.time_setting = preference_form.cleaned_data['time_setting']
            mhluser.time_zone = preference_form.cleaned_data['time_zone']
            mhluser.save()

            context = get_context(request)
            new_url = None
            if broker.user.photo:
                new_url = broker.user.photo.name
            ImageHelper.generate_image(old_url, new_url)
            return HttpResponseRedirect(
                reverse('MHLogin.MHLUsers.views.profile_view'))
    else:
        context['user'] = broker
        context['user_form'] = BrokerUserForm(instance=broker.user)
        context['broker_form'] = BrokerForm(instance=broker)
        context['password_form'] = ChangePasswordForm(user=broker.user)
        context['preference_form'] = PreferenceForm(
            initial={
                'time_setting':
                broker.user.time_setting if broker.user.time_setting else 0,
                'time_zone':
                broker.user.time_zone
            })

    context['mobile_required'] = True
    from django import conf
    context['Language'] = LANGUAGE[conf.settings.FORCED_LANGUAGE_CODE]
    return render_to_response('Profile/profile_edit.html', context)