How to Process Multi Step Forms in Django?

2015-05-01 Thread Ken Nguyen


I've made some attempted to use formwizard but there wasn't much 
documentation about it so I decided to stay with the basic. I've 
successfully obtained and display the data from the first form to the 
second form and added some checkbox next to the data to allow user to 
choose whether to overwrite or ignore the duplicate data found in the 
backend process. The problem I have is the second form doesn't know how 
retrieve the data of the first form after hitting "Confirm" button. The 
form2.html template invalidated the data completely since it called itself 
again by the form action after submitting the data. Is there a way to solve 
this or a better approach to this?

*forms.py*

class NameForm (forms.Form): 
first_name = forms.CharField (required = False)
last_name = forms.CharField (required = False)

class CheckBox (forms.Form):
overwrite = forms.BooleanField (required = False)

views.py

def form1 (request):

NameFormSet = formset_factory (NameForm, formset = BaseNodeFormSet, extra = 
2, max_num = 5)

if request.method == 'POST':

name_formset = NameFormSet (request.POST, prefix = 'nameform')

if name_formset.is_valid ():
data = name_formset.cleaned_data

context = {'data': data}
return render (request, 'nameform/form2.html', context)
else:
name_formset = NameFormSet (prefix = 'nameform')

 context = {..}

 return render (request, 'nameform/form1.html', context)

def form2 (request):

CheckBoxFormSet = formset_factory (CheckBox, extra = 2, max_num = 5)

if request.method == 'POST':

checkbox_formset = CheckBoxFormSet (request.POST, prefix = 'checkbox')

if checkbox_formset.is_valid ():
data = checkbox_formset.cleaned_data

context = {'data': data}
return render (request, 'nameform/success.html', context)

else:
checkbox_formset = CheckBoxFormSet (prefix = 'checkbox')

 return HttpResponse ('No overwrite data.')



*form2.html*






{% load staticfiles %}

User Information


User Information:




First Name
Last Name
Overwrite

{% for info in data %}

{{ info.first_name }}
{{ info.last_address }}


{% endfor %}





Cancel




-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/27760adf-7d0d-4544-a645-72a7969c58a9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Template syntax issues w dict

2015-05-01 Thread Lachlan Musicman
 .items

Damn.

Thanks
On May 1, 2015 17:48, "ADEWALE ADISA"  wrote:

> If I can understand your code, of seems you want a table of : Institution
> | Number of attendees
> So if am right u can achive it this way :
>
> {% for org, num in attendees_per_org.items() %}
> 
> {{ org }}
> {{ num }}
> 
>   {% endfor %}
>
> Since your dataset is a dictionary, u need to use key,value to get
> elements in both side. Also items() is also required.
> On May 1, 2015 8:22 AM, "Lachlan Musicman"  wrote:
>
>> Hola,
>>
>> Django shell gives right results, template doesn't: code here
>>
>> http://dpaste.com/1NJEKD8
>>
>> What am I doing wrong?
>>
>> L.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAGBeqiN78i37JA9UJov7%2BAVbJzRt4c5YCX3em2XvN-QmefxSvg%40mail.gmail.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAMGzuy_WwAKnYddxrYBL5P5O75--EP7Aqrn8a7Fg-5rUgQq02w%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGBeqiP8Kec8GN1wRabagCWasezMXF%3DHA0XBbXKUzswg9cWwPw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[ANNOUNCE] Django bugfix releases issued: 1.8.1 and 1.7.8

2015-05-01 Thread Tim Graham
Details are available on the Django project weblog:

https://www.djangoproject.com/weblog/2015/may/01/bugfix-releases-issued/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ad207640-a7ce-452e-b61f-a4d9ced57d62%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django admin does not show value of datetime field till seconds/miliseconds

2015-05-01 Thread Ankit Agrawal



Hi everyone,
   I have a model which has a datetime field. In the django admin, the 
value is shown only till minutes. How can it be configured to display the 
value in second/milisecond?




-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e5e6a71c-a5ee-43c8-9ae5-f4a8e673%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: The best way to mock querysets

2015-05-01 Thread Javier Guerra Giraldez
On Fri, May 1, 2015 at 5:17 AM, Avraham Serour  wrote:
> In my opinion you shouldn't, you should set the test data and make a real
> query then compare results, you shouldn't care how the function got the
> data, but that it got it correctly.


that's part of a much bigger religious war, with "unit tests" at one
extreme and "integration tests" at the other.

even without aiming for unittest purity, the "test only the code
you're testing" idea would clearly advise for mocking the database.
of course, that means many more tests for the database layer itself,
which in turn make the OP's wish for quick tests all much more
important.

but when doing TDD, the favored tests aren't necessarily of the
unittest variety; they lean somewhat more towards functional tests,
almost integration tests.  IOW: if it's a requirement for the code to
work decoupled from the database, then test it in isolation.  if not,
then the minimal test (and minimal code to pass it) is to assume the
database layer is already well tested by the framework (and it is!),
and you're free to assume it in the tests.

cheers,

-- 
Javier

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFkDaoR2nsDrqmEWmTGnKqbaEoci%2BoJ-%3Dy%2Byg2vdP6vue3ssdg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


DRF - Which Authentication to use?

2015-05-01 Thread Nabeel Valapra


I have prior experience in Django. Recently I got a project to build in 
REST architecture. I learned the basics of Django Rest Framework. But I am 
stuck with the authentication system.

I planned serve my frontend in anguarjs an host it on app.mydomain.com, and 
the DRF on api.mydomain.com. So all the end application (android, IOS) can 
pull the the data from api.mydomain.com 

Here I don't want to use session authentication system, it doesn't play 
nice with CORS. I am more interested on JSONWebToken than Token Based 
Authentication because its signed and allows refresh token option too.

But, 1. How do I invalidate the existing tokens on password change? 2. How 
to destroy the token in a mobile lost scenario? 

Is there any better authentication solution?
 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/fabc7ac3-7343-48dc-8cfe-db909a5d6795%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: The best way to mock querysets

2015-05-01 Thread Avraham Serour
It seems correct, but the question is if you should do it.

In my opinion you shouldn't, you should set the test data and make a real
query then compare results, you shouldn't care how the function got the
data, but that it got it correctly.

let's say tomorrow you add a prefetch_related to your query, you're still
getting the same data, but now your tests are failing because you are doing
it differently

On Thu, Apr 30, 2015 at 10:25 PM, Edgar Gabaldi  wrote:

> Who practices TDD (XP like) says that the tests need to run quickly. For
> this, we have to mock all external resources of the method that i want to
> test.
>
> In the case of queryset, i think so strange. Eg:
> https://gist.github.com/edgabaldi/ffdffa60f2add650f052
>
> Am i doing it wrong? Do i have better way to do that?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAGjPPHkvcPGusgTzddJ3SVtfeGhgQCZb4L9tOq8vWgY9OoP8zQ%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFWa6tLO-cr8g%3Df%2B%2BsntHr%2BHZpqbd%3DdtJWarfEeNEJEom-qqJA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Template syntax issues w dict

2015-05-01 Thread ADEWALE ADISA
If I can understand your code, of seems you want a table of : Institution |
Number of attendees
So if am right u can achive it this way :

{% for org, num in attendees_per_org.items() %}

{{ org }}
{{ num }}

  {% endfor %}

Since your dataset is a dictionary, u need to use key,value to get elements
in both side. Also items() is also required.
On May 1, 2015 8:22 AM, "Lachlan Musicman"  wrote:

> Hola,
>
> Django shell gives right results, template doesn't: code here
>
> http://dpaste.com/1NJEKD8
>
> What am I doing wrong?
>
> L.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAGBeqiN78i37JA9UJov7%2BAVbJzRt4c5YCX3em2XvN-QmefxSvg%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMGzuy_WwAKnYddxrYBL5P5O75--EP7Aqrn8a7Fg-5rUgQq02w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Template syntax issues w dict

2015-05-01 Thread Lachlan Musicman
Hola,

Django shell gives right results, template doesn't: code here

http://dpaste.com/1NJEKD8

What am I doing wrong?

L.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGBeqiN78i37JA9UJov7%2BAVbJzRt4c5YCX3em2XvN-QmefxSvg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Question on auto-generating username while using django registration

2015-05-01 Thread Babatunde Akinyanmi
Yes it is and very easy.

Create a form without a username field and do something like this:

def autogenerate_username ():
# some logic

new_user=User.objects.create_user(autogenerate_username (),
  self.cleaned_data['email'],
  self.cleaned_data['password1'])
new_user.first_name = self.cleaned_data['first_name']
new_user.last_name = self.cleaned_data['last_name']
new_user.save()

On 1 May 2015 01:48,  wrote:
>
> Hi there -
> I’m in the process of building a site with django, and I noticed that
username is a requirement for the django registration app.  I’m wondering
if it’s possible to auto generate the username after the user make entries
in the other fields (i.e. name, city, email, password)?
>
> OR does django registration necessarily require the username to be
created at the same time as the other fields?
>
> thanks in advance
>
> --
> You received this message because you are subscribed to the Google Groups
"Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/26e45341-aa13-4404-9f42-c3c38061b753%40googlegroups.com
.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BWjgXNEqitXLwjMufNntqwU-QoL72O-AhTBHJ5FizQ%3DQdv28A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.