Beispiel #1
0
 def post(self, request):
     if not request.FILES:
         form = BioForm(request.POST, {'img': Bio.objects.get(pk=1).img})
     else:
         form = BioForm(request.POST, request.FILES)
     if form.is_valid():
         model = form.save(commit=False)
         model.id = 1
         model.save()
         return HttpResponse("Okay")
     else:
         return self.render(request, form, 'content.html')
Beispiel #2
0
def edit_bio(request, username):
    person = get_object_or_404(DjangoPerson, user__username = username)
    if request.method == 'POST':
        form = BioForm(request.POST)
        if form.is_valid():
            person.bio = form.cleaned_data['bio']
            person.save()
            return HttpResponseRedirect('/%s/' % username)
    else:
        form = BioForm(initial = {'bio': person.bio})
    return render(request, 'edit_bio.html', {
        'form': form,
    })
Beispiel #3
0
def edit_data(request, id=1, rev=False):
    """
    views for edit data
    """
    try:
        my_bio_edit = MyBio.objects.get(id=id)
    except:
        my_bio_edit = MyBio.objects.create()

    if request.POST:
        # 3 sec sleep for ajax submit
        if request.is_ajax():
            time.sleep(3)
        form = BioForm(request.POST, instance=my_bio_edit)
        if rev:
            form.fields.keyOrder.reverse()
        if form.is_valid():
            form.save()
            if request.is_ajax():
                json_result = simplejson.dumps({'status': "done_status"})
        else:
            if request.is_ajax():
                error_string = ''
                n = 0
                for err in form.errors:
                    n += 1
                    if n == len(form.errors):
                        error_string = error_string + " " + err + " "
                    else:
                        error_string = error_string + " " + err + ", "

                json_result = simplejson.dumps({'status': 'fail_status',
                                                'errors': error_string})
        if request.is_ajax():
            return HttpResponse(json_result, mimetype='application/javascript')
    else:
        form = BioForm(instance=my_bio_edit)
        if rev:
                form.fields.keyOrder.reverse()

    return render_to_response('bio/edit_data.html',
            {'form': form, 'id': id, 'reverse': rev, 'obj': my_bio_edit})
Beispiel #4
0
def edit_bio(request, pk):
    bio = get_object_or_404(Bio, pk=pk)
    if request.method == 'POST':
        form = BioForm(request.POST, instance=bio)
        user = request.user
        if form.is_valid():
            bio = form.save(commit=False)
            bio.save()
            return redirect('skills')
        else:
            HttpResponse('fill the form correctly')
    else:
        form = BioForm(instance=bio)
    return render(request, 'skills/bio.html', {'form': form})
Beispiel #5
0
def bio(request):
    if request.method == 'POST':
        form = BioForm(request.POST)
        user = request.user
        if form.is_valid():
            bio = form.save(commit=False)
            bio.user = user
            bio.save()
            return redirect('dashboard/skills')
        else:
            HttpResponse('please fill the form properly')
    else:
        form = BioForm()
    return render(request, 'skills/bio.html', {'form': form})