Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def user_edit(request, id):
p = Person.objects.get(pk=id)
if request.method == 'POST':
form = PersonForm(request.POST, request.FILES, instance=p)
if form.is_valid():
form.save()
return redirect(users)
else:
form = PersonForm(instance=p)
context = {
'title': 'Edit User',
'person': p,
'form': form,
'user_form': form.user_form,
}
return render(request, "manager/person/edit.html", context)
def user_edit(request, id):
p = Person.objects.get(pk=id)
if request.method == 'POST':
form = PersonForm(request.POST, request.FILES, instance=p)
if form.is_valid():
form.save()
return redirect(users)
else:
form = PersonForm(instance=p)
context = {
'title': 'Edit User',
'person': p,
'form': form,
'user_form': form.user_form,
}
return render(request, "manager/person/edit.html", context)
def __init__(self, *args, **kwargs):
super(ProfileForm, self).__init__(*args, **kwargs)
args = []
kwargs = {}
if self.data and self.instance.person:
self.person_form = PersonForm(self.data, user_form=False, instance=self.instance.person)
elif self.instance.person:
self.person_form = PersonForm(user_form=False, instance=self.instance.person)
elif self.data:
self.person_form = PersonForm(self.data, user_form=False)
else:
self.person_form = PersonForm(user_form=False)
def __init__(self, *args, **kwargs):
super(ProfileForm, self).__init__(*args, **kwargs)
args = []
kwargs = {}
if self.data and self.instance.person:
self.person_form = PersonForm(self.data, user_form=False, instance=self.instance.person)
elif self.instance.person:
self.person_form = PersonForm(user_form=False, instance=self.instance.person)
elif self.data:
self.person_form = PersonForm(self.data, user_form=False)
else:
self.person_form = PersonForm(user_form=False)
def __init__(self, *args, **kwargs):
super(ProfileForm, self).__init__(*args, **kwargs)
args = []
kwargs = {}
if self.data and self.instance.person:
self.person_form = PersonForm(self.data, user_form=False, instance=self.instance.person)
elif self.instance.person:
self.person_form = PersonForm(user_form=False, instance=self.instance.person)
elif self.data:
self.person_form = PersonForm(self.data, user_form=False)
else:
self.person_form = PersonForm(user_form=False)
def __init__(self, *args, **kwargs):
super(ProfileForm, self).__init__(*args, **kwargs)
args = []
kwargs = {}
if self.data and self.instance.person:
self.person_form = PersonForm(self.data, user_form=False, instance=self.instance.person)
elif self.instance.person:
self.person_form = PersonForm(user_form=False, instance=self.instance.person)
elif self.data:
self.person_form = PersonForm(self.data, user_form=False)
else:
self.person_form = PersonForm(user_form=False)
def is_valid(self):
if self.user_form:
return super(PersonForm, self).is_valid() and self.user_form.is_valid()
else:
return super(PersonForm, self).is_valid()
def user_add(request):
if request.method == 'POST':
form = PersonForm(request.POST, request.FILES, user_form=False)
if form.is_valid():
form.save()
return redirect(users)
else:
form = PersonForm(user_form=False)
context = {
'title': 'Add User',
'form': form,
'user_form': form.user_form,
}
return render(request, "manager/person/edit.html", context)