text stringlengths 0 828 |
|---|
dob = self.profile.dob |
if dob: |
if 'dob_day' in self.fields: |
initial.update({ |
'dob_day': dob.day |
}) |
if 'dob_month' in self.fields: |
initial.update({ |
'dob_month': dob.month |
}) |
if 'dob_year' in self.fields: |
initial.update({ |
'dob_year': dob.year |
}) |
return initial" |
879,"def save(self, *args, **kwargs): |
"""""" |
This method should be called when is_valid is true to save |
relevant fields to user and profile models. |
"""""" |
for key, value in self.cleaned_data.items(): |
if value != None: |
if hasattr(self.user, key): |
setattr(self.user, key, value) |
if hasattr(self.profile, key): |
setattr(self.profile, key, value) |
# set password |
if 'password1' in self.cleaned_data: |
if self.cleaned_data['password1']: |
self.user.set_password(self.cleaned_data['password1']) |
# set dob |
if 'dob_day' in self.cleaned_data and 'dob_month' in self.\ |
cleaned_data and 'dob_year' in self.cleaned_data: |
self.profile.dob = self._gen_dob() |
self.user.save() |
self.profile.save()" |
880,"def clean_username(self): |
"""""" |
Validate that the username is alphanumeric and is not already |
in use. Don't fail if users username is provided. |
"""""" |
user = None |
try: |
user = User.objects.get(username__iexact=self.\ |
cleaned_data['username']) |
except User.DoesNotExist: |
return self.cleaned_data['username'] |
if user: |
if user.username == self.user.username: |
return self.cleaned_data['username'] |
raise forms.ValidationError(_(\ |
""A user with that username already exists.""))" |
881,"def clean(self): |
"""""" |
Verifiy that the values entered into the two password fields |
match. Note that an error here will end up in |
``non_field_errors()`` because it doesn't apply to a single |
field. |
"""""" |
if 'dob_day' in self.cleaned_data and 'dob_month' in \ |
self.cleaned_data and 'dob_year' in self.cleaned_data: |
try: |
self._gen_dob() |
except ValueError: |
self._errors['dob_day'] = (_(\ |
""You provided an invalid date.""),) |
if 'password1' in self.cleaned_data and 'password2' in \ |
self.cleaned_data: |
if self.cleaned_data['password1'] != \ |
self.cleaned_data['password2']: |
raise forms.ValidationError(_(\ |
""The two password fields didn't match."")) |
return self.cleaned_data" |
882,"def request(self,message,message_type): |
"""""" |
Send a request message of the given type |
Args: |
- message: the message to publish |
- message_type: the type of message being sent |
"""""" |
if message_type == MULTIPART: |
raise Exception(""Unsupported request type"") |
super(Requestor,self).send(message,message_type)" |
883,"def run_as_admin(command, cwd=None, environ=None): |
"""""" |
Runs a command as an admin in the specified *cwd* and *environ*. |
On Windows, this creates a temporary directory where this information |
is stored temporarily so that the new process can launch the proper |
subprocess. |
"""""" |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.