These are chat archives for django/django

10th
Jul 2015
Charles Javelona
@charlesjavelona
Jul 10 2015 14:49

Hi everyone,

What BDD tool are you using for Django?

Kamil Gałuszka
@galuszkak
Jul 10 2015 14:50
@charlesakio django-behave + behave + behaving
Mauro Oviedo
@moviedo
Jul 10 2015 14:51
@charlesakio I tried using lettuce a long time ago, about a year , but founf it’s gerkin language missing a full implementation for gerkins, so I stopped using it. Also, the docs weren’t the best
never tried behave
Charles Javelona
@charlesjavelona
Jul 10 2015 14:52
@galuszkak thanks for answering the question. I just installed django-behave.
@moviedo, what are you using now?
Mauro Oviedo
@moviedo
Jul 10 2015 14:54
I do a lot of angular and django so I use protractor, karma, and jasmine.js
then regular unit testing python code with nose
Charles Javelona
@charlesjavelona
Jul 10 2015 14:57
Ok, thanks for letting me now
Mauro Oviedo
@moviedo
Jul 10 2015 14:58
np
milad.kh
@iMilad
Jul 10 2015 15:17
I have problem to map the url. I used Geodjango, I've just created a model and used admin.OSMGeoAdmin. I don't have a problem to see the map in Administration page and also can draw a polygon and save it to the database BUT I do not know how to show it into the html instead of admin page.
does someone know any solution ?
also, you can generally create your own custom page using openlayers/ google maps js libraries with your spatial data
Volodymyr Rudyj
@volodymyrrudyi
Jul 10 2015 20:56
hey guys, I'm trying to implement a Post-Redirect-Get approach for form submission, but putting the django form to the session causes a pickle error. Is there some canonical way to save the form validation state to display after Post-Redirect-Get instead of just manually saving all errors to the session/get params?
I'm getting error message like this(obviously Django can't serialize some part of the form):
Django Version:    1.8
Exception Type:    PicklingError
Exception Value:    
Can't pickle <type 'function'>: attribute lookup __builtin__.function failed
Mir Nazim
@mnazim
Jul 10 2015 20:59
You should not have to manually store errors. Forms take care of that. If you want to set custom error messages use error_messages attribute of form.Meta. you should not have to change view code for this.
Or may be I understood the questiob in a different way. Share some code sample please.
Volodymyr Rudyj
@volodymyrrudyi
Jul 10 2015 21:00

def create_tour(request):
    if request.method == 'GET':
        return render(request, 'tours/create.html', {'form': CreateTourForm()})
    else:
        new_tour_form = CreateTourForm(request.POST)
        if new_tour_form.is_valid():
            return redirect('tour-created')
        else:
            request.session['form'] = new_tour_form  # This one will raise an PicklingError
            return redirect('create-tour')
        pass
not a big deal, just wondering how to correctly achieve this with Django
as you can see, in case if form is invalid I'd like to perform a redirect to a view and show an error there instead of just rendering the template, since I want to get rid of "Confirm page refresh" message
@mnazim does it make sense?
Mir Nazim
@mnazim
Jul 10 2015 21:05
Do not redirect on form invalid. Try this.
def create_tour(request):
    new_tour_form = CreateTourForm()
    if request.method == 'POST':
        new_tour_form = CreateTourForm(request.POST)
        if new_tour_form.is_valid():
            # Do whatever with new_tour_form
            return redirect('tour-created')
    return render(request, 'tours/create.html', {'form': new_tour_form })
Volodymyr Rudyj
@volodymyrrudyi
Jul 10 2015 21:06
@mnazim yeah, it's how it currently implemented, but it will force form submit on F5 and I don't want it :)
Mir Nazim
@mnazim
Jul 10 2015 21:12
def create_tour(request):
    new_tour_form = CreateTourForm()
    should_redirect = False
    if request.method == 'POST':
        new_tour_form = CreateTourForm(request.POST)
        if new_tour_form.is_valid():
            # Do whatever with new_tour_form
            return redirect('tour-created')
        else:
            should_redirect = True

    if should_redirect:
            return redirect('create-tour')

    return render(request, 'tours/create.html', {'form': new_tour_form })

`

Dont use sessions, let template context handle it.

That said, it would be the correct and intended behaivour to let refresh sumbit data if previous post resulted in error. Generally you want to redirect only on after processing å valid form, so that refreshing the page with same valid data again should not cause the action to be repeated.

Volodymyr Rudyj
@volodymyrrudyi
Jul 10 2015 21:14
@mnazim thanks a lot, got it