diff --git a/decide/census/census_utils.py b/decide/census/census_utils.py index 33c8cafe13..133101bbcc 100644 --- a/decide/census/census_utils.py +++ b/decide/census/census_utils.py @@ -2,20 +2,26 @@ from .models import Census def get_user_atributes(): - user = User.objects.all().values()[0] atributes_list = [] - counter = 0 - for atribute in user.keys(): - if not atribute == 'id' and not atribute == 'password': - atributes_list.append((counter, atribute)) - counter += 1 + if User.objects.all().values() != []: + user = User.objects.all().values()[0] + counter = 0 + for atribute in user.keys(): + if not atribute == 'id' and not atribute == 'password': + atributes_list.append((counter, atribute)) + counter += 1 return atributes_list # csvtext -> Header1,Header2,Header3/value1,value2,value3/value1,value2,value3/ def get_csvtext_and_data(form_values, census): atributes_list = get_user_atributes() + + if atributes_list == []: + atributes_list.append('id,username/None,NoUser') + return atributes_list + voters_data = [] headers = [] diff --git a/decide/census/forms.py b/decide/census/forms.py index 2a4aa70750..07e61112c7 100644 --- a/decide/census/forms.py +++ b/decide/census/forms.py @@ -2,13 +2,14 @@ from django.contrib.auth.models import User class AtributosUser(forms.Form): - user = User.objects.all().values()[0] atributes_list = [] - counter = 0 - for atribute in user.keys(): - if not atribute == 'id' and not atribute == 'password': - atributes_list.append((counter, atribute)) - counter += 1 + if User.objects.all().values() != []: + user = User.objects.all().values()[0] + counter = 0 + for atribute in user.keys(): + if not atribute == 'id' and not atribute == 'password': + atributes_list.append((counter, atribute)) + counter += 1 user_atributes = forms.MultipleChoiceField(label="", choices=atributes_list, widget=forms.CheckboxSelectMultiple) \ No newline at end of file