示例#1
0
def edit(request, option, id):
    if str(request.user) is 'AnonymousUser':
        return redirect('login')
    obj = None
    form = None
    context = {}
    if option == 'child':
        obj = get_object_or_404(Child, id=id)
        form = CreateChild(request.POST or None,
                           request.FILES or None,
                           instance=obj)
        context['image'] = obj.image
    elif option == 'donor':
        obj = get_object_or_404(Donor, id=id)
        form = CreateDonor(request.POST or None, instance=obj)
    elif option == 'donation_plan':
        obj = get_object_or_404(DonationPlan, id=id)
        form = CreateDonationPlan(request.POST or None, instance=obj)
    elif option == 'user' and request.user.is_superuser:
        form = forms.UserChangeForm(request.POST or None,
                                    instance=request.user)
    elif option == 'donate':
        form = Donate(request.POST or None, instance=obj)
    if form.is_valid():
        form.save()
        return redirect('index')
    context['option'] = option
    context['form'] = form
    return render(request, 'tool/edit.html', context)
示例#2
0
文件: resources.py 项目: sjl421/dagny
    def update(self, user_id):
        self.user = get_object_or_404(models.User, id=int(user_id))
        self.form = forms.UserChangeForm(self.request.POST, instance=self.user)
        if self.form.is_valid():
            self.form.save()
            return redirect('User#show', str(self.user.id))

        return self.edit.render(status=403)
示例#3
0
 def edit(self, user_id):
     self.user = get_object_or_404(models.User, id=int(user_id))
     self.form = forms.UserChangeForm(instance=self.user)