django-registration + ajax, user_registered signal randomly fails - ajax

I have "successfully" integrated django-registration with ajax in my project.
I'm using the user_registered signal to add additional information to the user upon registering.
Everything works whenever I test it personally. However, when I checked django-admin to see how many users have registered, I noticed that some users were created with only the default fields and does not include the fields created with the signal callback.
Is there a known reason why a django signal would fail?
Here's my user_registered callback:
def user_registered_callback(sender, user, request, **kwargs):
# Create a new instance of Registration form and bind the POST data
form = CustomRegistrationForm(request.POST)
form.full_clean()
# Generate new filename from timestamp and first name
fn = hashlib.md5()
fn.update( str(time.time()) + form.cleaned_data['first_name'] )
filename = fn.hexdigest() + '.jpg'
# Save additional details for the user
u = user
u.first_name = form.cleaned_data['first_name']
u.last_name = form.cleaned_data['last_name']
u.birthdate = form.cleaned_data['birthdate']
u.mobile = form.cleaned_data['mobile']
u.photo = 'photos/' + filename
u.save()

The user_registered signal is a custom signal introduced by django-registration, therefore I assume it would not be triggered if you use Django's original admin site. Also why should it be triggered, since adding a user in the admin is not a user registering himself.
Try registering your handler for post_save of your user class instead:
#receiver(post_save, sender=User)
def user_post_save(sender, instance, **kwargs):
if not instance.pk:
# instance was just created

I accidentally replicated the error and traced through Developer tools what it was.
As it turned out some users were adding strings to first_name that are longer than the maximum I set for that field in the database. However, I wasn't able to add a Form validation for this field that's why it was able to get past my form as valid. Hence, the app was able to create a new user, but when it comes to updating the user_profile it fails making it look like the signal callback didn't run.

Related

How to scrape the data using requests module only in python

I am actually trying to parse a website using the requests module, and extract some text out of it.
Url : https://www.icsi.in/student/Members/MemberSearch.aspx
after hitting the url in the Cp Number text field input : 16803
hit search,
on the bottom you can see some data, I want that data, let's say a name.
I am successfully able to get the data using selenium, but can't able to get it using requests module.
I have tried the requests module giving parameters, sessions, cookies etc.
but nothing worked.
url = "https://www.icsi.in/student/Members/MemberSearch.aspx"
ss = {'dnn$ctr410$MemberSearch$txtCpNumber':'16803',
'__EVENTTARGET':'dnn$ctr410$MemberSearch$btnSearch',
'__VIEWSTATEGENERATOR':'6A295697',
'dnn$ctlHeader$dnnSearch$Search':'SiteRadioButton'}
session = requests.Session()
cookies = session.cookies.get_dict()
for cookie in cookies:
session.cookies.set(cookie['name'], cookie['value'])
response = requests.post(url, data=ss)
print(response)
HTMLTree = html.fromstring(response.content)
name = HTMLTree.xpath('//div[#class="name_head"]//text()')
print(name)
I expect the output of the name of the person.
Anyone out there please help me.
If you don't mind using C# code I would be more than happy to help you otherwise it's a very lengthy process. If you choose that python is the only road you're willing to take then you should try grabbing the encrypted value within C:\User[USERNAME]\Appdata\Local\Google\Chrome\User Data\Default\Cookies You can change the file path accordingly to your OS. You can use SQLite to read and modify the encrypted values.
cookie = Decrypt(Encoding.Default.GetBytes(SQLDatabase1.GetValue(i, "encrypted_value")
if (cookie.Contains(".ASPXANONYMOUS")):
Step1 = cookie + "END"
Step2 = (step1 + ".ASPXANONYMOUS")
The following code above may help you with your journey.

Using DocuSign API and Ruby

I am getting started with Docusign, and even with Ruby. I am trying to get my head wrapped around something and I need your help.
I am trying in Ruby to create a helper in order to prefill a contract with the information I posses such as the client's information etc. And have that sent to the 2 people who need the contract. I am a little stuck in the steps I need to take in order to get the communication working and grabbing the information I need.
Any help or tips is appreciated.
I have installed the gem for the docusign API, I have the docusign-ruby-client code, I have also created my template, got my integrator key. I am stuck with the next step. How do I actually use in my project all these things together in order to automatically fill in the template with the information from the client ? –
EDITS:
I am unsure on how to use this below in order to get my template, fill it automatically with my client info, and when done, send the pre-filled contract to 2 people.
host = 'https://demo.docusign.net/restapi'
integrator_key = 'e5fdb0cd-a206-4934-91f1-5d00000000'
user_id = 'myemail#gmail.com'
expires_in_seconds = 3600 #1 hour
auth_server = 'account-d.docusign.com'
private_key_filename = '[REQUIRED]'
# STEP 1: Initialize API Client
configuration = DocuSign_eSign::Configuration.new
configuration.host = host
api_client = DocuSign_eSign::ApiClient.new(configuration)
api_client.configure_jwt_authorization_flow(private_key_filename, auth_server, integrator_key, user_id, expires_in_seconds)
# STEP 2: Initialize Authentication API using the API Client
authentication_api = DocuSign_eSign::AuthenticationApi.new(api_client)
# STEP 3: Make the login call
login_options = DocuSign_eSign::LoginOptions.new
login_information = authentication_api.login(login_options)
if !login_information.nil?
login_information.login_accounts.each do |login_account|
if login_account.is_default == "true"
# STEP 4: Extract the user information
base_url = login_account.base_url
account_id = login_account.account_id
puts base_url
puts account_id
# IMPORTANT: Use the base url from the login account to update the api client which will be used in future api calls
base_uri = URI.parse(base_url)
api_client.config.host = "%s://%s/restapi" % [base_uri.scheme, base_uri.host]

TestComplete_JavaScripting_how to hide web url path while performing any operation for any object in script

I'm new to use Testcomplete , i'm using javascripts to automate my code, below are sample script ( converted one recorded first then converted into jscript) and in this scripts what i observe that TestComplete identified and captured the object element by using complete web url path not on only object specific .
efunction Test_Login {var UserName, Password, TestEnv;UserName = "XYZ";Pwd = "XYZXYZ";TestEnv = "https://test.Env.com/";Browsers.Item(btChrome).Run("TestEnv",1);Aliases.browser.pageTestenvCom.formFrmlogincomponent.textboxUsername.SetText("UserName");Aliases.browser.pageTestenvCom.formFrmlogincomponent.passwordboxPassword.SetText("Pwd");Aliases.browser.pageTestenvCom.formFrmlogincomponent.buttonLogin.ClickButton();}e
what i means lets see below example of login page
thank you
Whenever we record any Test case in Test-Complete, it stores all the object in the Naming Repository and then access the same.
This helps test-complete in easily recognisation of object and can improve the speed of test-case, in case there are multiple objects visible on screen
You can go through following link for more info on Name Mapping.
https://support.smartbear.com/testcomplete/docs/testing-with/object-identification/name-mapping/overview.html

How to make locust load scripts run in sequence?

I'm trying to automate the following scenario with locust:
Login to application (put it in on_start, so it will login all the sessions first) and get token value from response of login call.
Create an organization
Create a user.
I need these calls to be executed in the order shown.
However, if I add #task for the 2nd and 3rd steps, it will pick these calls randomly, which causes my code to break.
Any suggestions?
Use Locust's TaskSequence class:
class SequentialTasks(TaskSequence):
def on_start(self):
# login to application and get token value from response of login call
#seq_task(1) # the first thing to do
#task(n) # do it n times
def create_org(self):
# create org
#seq_task(2) # the second thing to do
#task(n) # do it n times
def create_user(self):
# create user
You can just do it all in a single task. There is no limit to a single HTTP call within a single task (you could even put it all in on_start if you want to).
class MyTaskSet(TaskSet):
def on_start(self):
// do login
self.token = ...
#task
def create_task(self):
// create org
self.client.post(...)
// crete user
self.client.pos(...)

Devise: Is it possible to NOT send a confirmation email in specific cases ? (even when confirmable is active)

Here is my situation, I use devise to allow users to create account on
my site and manage their authentication.
During the registration process I allow customers to change some
options, leading to an actually different account being created but
still based on the same core user resource.
I would like to choose not to send a confirmation email for some of
those account types. I don't care if the account do not get confirmed
and user cannot log in, that's ok, no pb with that.
How would I go about doing that ?
Thanks,
Alex
Actually it's quite easy once I dig a little deeper.
Just override one method in your User model (or whatever you are using):
# Callback to overwrite if confirmation is required or not.
def confirmation_required?
!confirmed?
end
Put your conditions and job's done !
Alex
If you just want to skip sending the email but not doing confirmation, use:
# Skips sending the confirmation/reconfirmation notification email after_create/after_update. Unlike
# #skip_confirmation!, record still requires confirmation.
#user.skip_confirmation_notification!
If you don't want to call this in your model with a callback overwrite this method:
def send_confirmation_notification?
false
end
You can also simply add the following line of code in your controller before creating the new user:
#user.skip_confirmation!
I don't know if Devise added this after the other answers were submitted, but the code for this is right there in confirmable.rb:
# If you don't want confirmation to be sent on create, neither a code
# to be generated, call skip_confirmation!
def skip_confirmation!
self.confirmed_at = Time.now
end
I was able to do something similar with the functions:
registrations_controller.rb
def build_resource(*args)
super
if session[:omniauth] # TODO -- what about the case where they have a session, but are not logged in?
#user.apply_omniauth(session[:omniauth])
#user.mark_as_confirmed # we don't need to confirm the account if they are using external authentication
# #user.valid?
end
end
And then in my user model:
user.rb
def mark_as_confirmed
self.confirmation_token = nil
self.confirmed_at = Time.now
end

Resources