Skip to content

Commit

Permalink
Merge branch 'master' of github.com:znc-sistemas/python-people
Browse files Browse the repository at this point in the history
  • Loading branch information
cadu-leite committed Nov 26, 2012
2 parents ca5ba1c + 6a70a66 commit 2f175ee
Show file tree
Hide file tree
Showing 13 changed files with 267 additions and 78 deletions.
34 changes: 33 additions & 1 deletion python_people/people/forms.py
Expand Up @@ -7,7 +7,7 @@
#from django.utils.translation import ugettext_lazy as _
from django.db.models import Q

from people.models import UserProfile, PythonGroup
from people.models import UserProfile, PythonGroup, Survey


class UserRegisterForm(UserCreationForm):
Expand Down Expand Up @@ -87,3 +87,35 @@ def get_queryset(self):
object_list = object_list.filter(filter)

return object_list


class SurveyForm(forms.ModelForm):

def __init__(self, *args, **kargs):
self.user = kargs.pop('user', None)
self.commit = kargs.pop('commit', True)
super(SurveyForm, self).__init__(*args, **kargs)

def save(self, *args, **kargs):
if self.instance.pk:
if not self.instance.is_group_owner(self.user):
raise forms.ValidationError("the request user is not the survey owner")

self.instance.user = self.user
return super(SurveyForm, self).save(*args, **kargs)

class Meta:
model = Survey
exclude = ('user')
widgets = {
'date_add': forms.HiddenInput(),
}


class SurveySearchForm(forms.Form):
search_text = forms.CharField(required=False)

def get_queryset(self):
object_list = Survey.objects.all()

return object_list
60 changes: 60 additions & 0 deletions python_people/people/models.py
Expand Up @@ -86,3 +86,63 @@ def __unicode__(self):
def is_group_owner(self, user):
'''return true if user is the owner or if it has no owner.'''
return (self.user == user) or not self.user


class Survey(models.Model):
choices_degree = (
(1, "newbie"), (2, "novice"), (3, "apprentice"), (4, "expert"), (5, "master")
)

choices_user_type = (
(1, 'student'), (2, 'work as a developer'), (3, u'scientist / researcher'), (4, 'Other - (ex: geographer, lawyer ...)')
)

choices_main_context = (
(1, "commercial"), (2, "academic / scientific research"), (3, "gov"), (4, "ngos"), (5, "help open source projects")
)

choices_main_environment = (
(1, "web apps"), (2, "desktop apps"), (3, "scripts (server automation, small tools, plugins ...)"))

choices_main_problem = (
(1, u"as a glue language (ex: exchange data between applications, services ...)"),
(2, u"financial tools"),
(3, u"gis tools"),
(4, u"graphical tools"),
(5, u"IT Infrastructure (ex.:server automation, small tools)"),
(6, u"just have fun programming"),
(7, u"network tools"),
(8, u"plugin"),
(9, u"research"),
(10, u"testing software"),
(11, u"web applications development - workflow process"),
(12, u"web CMS"),
(13, u"other"),
)

user = models.ManyToManyField(User)
date_add = models.DateTimeField(u"Answers Date", auto_now_add=True)

when_start = models.DateField(u"when do you start using python", null=True, blank=True)
work = models.NullBooleanField(u"do you uses python at your work ?", null=True, blank=True)
first = models.NullBooleanField(u"is python your first language ? not you like most, but you use most.", null=True, blank=True)
degree = models.IntegerField(u"how much python do you know ? ", choices=choices_degree)
why = models.TextField(u"Why python", null=True, blank=True)

user_type = models.IntegerField(choices=choices_user_type, null=True, blank=True)
user_type_description = models.CharField(u"Description", max_length=50, null=True, blank=True)

context = models.IntegerField(u"main environment", choices=choices_main_context, null=True, blank=True)
environment = models.IntegerField(u"main environment", choices=choices_main_environment, null=True, blank=True)

problem = models.IntegerField(u"main environment", choices=choices_main_problem, null=True, blank=True)
problem_description = models.CharField(u"Description", max_length=50, null=True, blank=True)

def __unicode__(self):
return self.date

def is_survey_owner(self, user):
'''return true if user is the owner or if it has no owner.
to implement per user object check
'''
return (self.user == user) or not self.user
9 changes: 9 additions & 0 deletions python_people/people/templates/people/survey_form.html
@@ -0,0 +1,9 @@
{% extends "base.html" %}
{% load bootstrap_toolkit %}
{% block content %}
<form class="vertical">
{% csrf_token %}
{{ form|as_bootstrap:"vertical" }}
<button type="submit" class="btn btn-primary">Submit</button>
</form>
{% endblock %}
12 changes: 9 additions & 3 deletions python_people/people/urls.py
Expand Up @@ -2,19 +2,21 @@
from django.views.generic import DetailView

from people.models import PythonGroup, UserProfile
from people.views import (
from people.views import (
points,
user_profile_crud,
python_group_crud,
python_users_bounded,
profile_list,
group_list
group_list,
survey_list,
survey_crud,
)

urlpatterns = patterns('',
url(r'^kml/$', points, name='points'),
#url(r'^profile/(?P<id>\d+)/$', user_profile_upd, name='userprofile-upd'),
#url(r'^profile/list/$', ListView.as_view(queryset=UserProfile.objects.order_by("name"), template_name='people/userprofile_list.html',paginate_by=15) , name="user-profile-list"),
##url(r'^profile/list/$', ListView.as_view(queryset=UserProfile.objects.order_by("name"), template_name='people/userprofile_list.html',paginate_by=15) , name="user-profile-list"),
url(r'^profile/list/$', profile_list, name="user-profile-list"),
url(r'^profile/(?P<pk>\d+)/$', DetailView.as_view(model=UserProfile), name="user-profile"),
url(r'^profile/form/$', user_profile_crud, name="user-profile-form"),
Expand All @@ -25,5 +27,9 @@
url(r'^python_group/update/(?P<pk>\d+)/$', python_group_crud, name='python-group-crud'),
url(r'^python_group/delete/(?P<pk>\d+)/$', python_group_crud, name='python-group-crud'),

url(r'^survey/list/$', survey_list, name='survey-list'),
url(r'^survey/new/$', survey_crud, name='survey-new'),
url(r'^survey/edit/(?P<pk>\d+)/$', survey_crud, name="survey-edit"),

url(r'^list/bounded/(-?\d+\.\d+)/(-?\d+\.\d+)/(-?\d+\.\d+)/(-?\d+\.\d+)/$', python_users_bounded, name="python-user-list"),
)
39 changes: 36 additions & 3 deletions python_people/people/views.py
Expand Up @@ -16,16 +16,16 @@

from django.views.generic import ListView, CreateView, UpdateView

from people.forms import UserProfileForm, ProfileSearchForm, UserRegisterForm, PythonGroupForm, GroupSearchForm
from people.models import UserProfile, PythonFrameWorks, PythonGroup
from people.forms import UserProfileForm, ProfileSearchForm, UserRegisterForm, PythonGroupForm, GroupSearchForm, SurveySearchForm, SurveyForm
from people.models import UserProfile, PythonFrameWorks, PythonGroup, Survey


def gender_count():
profiles = list(UserProfile.objects.values('gender').annotate(Count('gender')))
l = list()
opts = {1: 'male', 2: 'female', 3: 'other'}
for i in profiles:
if (i['gender__count'] != None) and (i['gender'] != None):
if (i['gender__count'] != None) and (i['gender'] != None):
l.append([opts.get(i['gender']), i['gender__count']])
return (l)

Expand Down Expand Up @@ -199,3 +199,36 @@ class GroupListView(SearchListView):

group_list = GroupListView.as_view()


def survey_crud(request, pk=None):

try:
survey = Survey.objects.get(pk=pk)
if not group.is_group_owner(request.user):
group = None
messages.add_message(request, messages.INFO, 'You cannot update this python user group.')
return redirect(reverse('python-group-list'))
except:
survey = None

form = SurveyForm(request.POST or None, instance=survey, user=request.user)

if request.POST:
if form.is_valid():
form.save()
messages.add_message(request, messages.INFO, 'The survey was sucessfully updated')
return redirect(reverse('python-survey-detail', args=[group.pk]))
else:
messages.add_message(request, messages.ERROR, 'There are erros in your request. Please check the messages below.')
return render(request,
"people/survey_form.html",
{'form': form},
)


class SurveyListView(SearchListView):
form_class = SurveySearchForm
paginate_by = 20

survey_list = SurveyListView.as_view()

1 change: 1 addition & 0 deletions python_people/settings.py
Expand Up @@ -130,6 +130,7 @@
'django.contrib.comments',
'social_auth',
'bootstrap_tags',
'bootstrap_toolkit',

'voting',
'gravatar',
Expand Down

0 comments on commit 2f175ee

Please sign in to comment.