Commit 48521516aebbe53306a7984d11f283adc940b285

Authored by Felipe Henrique de Almeida Bormann
1 parent d25c5790

fixing runserver and settings for run

amadeus/settings.py
@@ -52,15 +52,7 @@ INSTALLED_APPS = [ @@ -52,15 +52,7 @@ INSTALLED_APPS = [
52 'django_summernote', 52 'django_summernote',
53 53
54 'users', 54 'users',
55 - 'core',  
56 - 'app',  
57 - 'courses',  
58 - 'forum',  
59 - 'poll',  
60 - 'exam',  
61 - 'links',  
62 - 'files',  
63 - 55 +
64 ] 56 ]
65 57
66 MIDDLEWARE_CLASSES = [ 58 MIDDLEWARE_CLASSES = [
@@ -75,7 +67,7 @@ MIDDLEWARE_CLASSES = [ @@ -75,7 +67,7 @@ MIDDLEWARE_CLASSES = [
75 'django.middleware.clickjacking.XFrameOptionsMiddleware', 67 'django.middleware.clickjacking.XFrameOptionsMiddleware',
76 'django.middleware.locale.LocaleMiddleware', 68 'django.middleware.locale.LocaleMiddleware',
77 69
78 - 'core.middleware.TimeSpentMiddleware', 70 + #'core.middleware.TimeSpentMiddleware',
79 #libs-middleware 71 #libs-middleware
80 72
81 ] 73 ]
amadeus/urls.py
@@ -20,11 +20,8 @@ from django.conf.urls.static import static @@ -20,11 +20,8 @@ from django.conf.urls.static import static
20 from django.contrib import admin 20 from django.contrib import admin
21 21
22 urlpatterns = [ 22 urlpatterns = [
23 - url(r'^home/', include('app.urls', namespace = 'app')),  
24 - url(r'^courses/', include('courses.urls', namespace = 'course')),  
25 url(r'^users/', include('users.urls', namespace = 'users')), 23 url(r'^users/', include('users.urls', namespace = 'users')),
26 url(r'^admin/', admin.site.urls), 24 url(r'^admin/', admin.site.urls),
27 - url(r'^', include('core.urls', namespace = 'core')),  
28 #API 25 #API
29 url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')), 26 url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')),
30 #S3Direct 27 #S3Direct
users/forms.py
@@ -7,7 +7,6 @@ from django import forms @@ -7,7 +7,6 @@ from django import forms
7 from django.utils.translation import ugettext_lazy as _ 7 from django.utils.translation import ugettext_lazy as _
8 from rolepermissions.shortcuts import assign_role 8 from rolepermissions.shortcuts import assign_role
9 from django.contrib.auth.forms import UserCreationForm 9 from django.contrib.auth.forms import UserCreationForm
10 -from core.forms import RegisterUserForm  
11 from .models import User 10 from .models import User
12 11
13 class AdminUserForm(forms.ModelForm): 12 class AdminUserForm(forms.ModelForm):
@@ -37,6 +36,79 @@ class AdminUserForm(forms.ModelForm): @@ -37,6 +36,79 @@ class AdminUserForm(forms.ModelForm):
37 'password':forms.PasswordInput 36 'password':forms.PasswordInput
38 } 37 }
39 38
  39 +class RegisterUserForm(forms.ModelForm):
  40 +
  41 + password = forms.CharField(label=_('Password'), widget=forms.PasswordInput)
  42 + password2 = forms.CharField(label = _('Confirm Password'), widget = forms.PasswordInput)
  43 + # birth_date = forms.DateField(widget=forms.SelectDateWidget())
  44 + MIN_LENGTH = 8
  45 +
  46 + def validate_cpf(self, cpf):
  47 + cpf = ''.join(re.findall('\d', str(cpf)))
  48 +
  49 + if cpfcnpj.validate(cpf):
  50 + return True
  51 + return False
  52 +
  53 + def clean_email(self):
  54 + email = self.cleaned_data['email']
  55 + if User.objects.filter(email = email).exists():
  56 + raise forms.ValidationError(_('There is already a registered User with this e-mail'))
  57 + return email
  58 +
  59 + def clean_birth_date(self):
  60 + birth_date = self.cleaned_data['birth_date']
  61 + if birth_date >= date.today():
  62 + raise forms.ValidationError(_('Please enter a valid date'))
  63 + return birth_date
  64 +
  65 +
  66 + def clean_cpf(self):
  67 + cpf = self.cleaned_data['cpf']
  68 + if (cpf == ""):
  69 + return cpf
  70 + if User.objects.filter(cpf = cpf).exists():
  71 + raise forms.ValidationError(_('There is already a registered User with this CPF'))
  72 + if not self.validate_cpf(cpf):
  73 + raise forms.ValidationError(_('Please enter a valid CPF'))
  74 + return cpf
  75 +
  76 + def clean_password(self):
  77 + password = self.cleaned_data.get('password')
  78 +
  79 + # At least MIN_LENGTH long
  80 + if len(password) < self.MIN_LENGTH:
  81 + raise forms.ValidationError(_("The password must contain at least % d characters." % self.MIN_LENGTH))
  82 +
  83 + # At least one letter and one non-letter
  84 + first_isalpha = password[0].isalpha()
  85 + if all(c.isalpha() == first_isalpha for c in password):
  86 + raise forms.ValidationError(_('The password must contain at least one letter and at least one digit or '\
  87 + "a punctuation character."))
  88 +
  89 + return password
  90 +
  91 + def clean_password2(self):
  92 + password = self.cleaned_data.get("password")
  93 + password2 = self.cleaned_data.get("password2")
  94 +
  95 + if password and password2 and password != password2:
  96 + raise forms.ValidationError(_('The confirmation password is incorrect.'))
  97 + return password2
  98 +
  99 + def save(self, commit=True):
  100 + super(RegisterUserForm, self).save(commit=False)
  101 + self.instance.set_password(self.cleaned_data['password'])
  102 +
  103 + self.instance.save()
  104 + return self.instance
  105 +
  106 + class Meta:
  107 + model = User
  108 + # exclude = ['is_staff', 'is_active']
  109 + fields = ['username', 'name', 'email', 'city', 'state', 'gender', 'cpf', 'birth_date', 'phone', 'image', 'titration',
  110 + 'year_titration', 'institution', 'curriculum',]
  111 +
40 class UserForm(RegisterUserForm): 112 class UserForm(RegisterUserForm):
41 113
42 class Meta: 114 class Meta:
@@ -71,6 +143,8 @@ class UpdateUserForm(forms.ModelForm): @@ -71,6 +143,8 @@ class UpdateUserForm(forms.ModelForm):
71 fields = ['username', 'name', 'email', 'birth_date', 'city', 143 fields = ['username', 'name', 'email', 'birth_date', 'city',
72 'state', 'gender', 'type_profile', 'cpf', 'phone', 'image', 'titration', 144 'state', 'gender', 'type_profile', 'cpf', 'phone', 'image', 'titration',
73 'year_titration', 'institution', 'curriculum', 'is_staff', 'is_active'] 145 'year_titration', 'institution', 'curriculum', 'is_staff', 'is_active']
  146 +
  147 +
74 148
75 class UpdateProfileFormAdmin(UpdateUserForm): 149 class UpdateProfileFormAdmin(UpdateUserForm):
76 150
users/views.py
@@ -13,12 +13,7 @@ from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger @@ -13,12 +13,7 @@ from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
13 13
14 from .models import User 14 from .models import User
15 from .forms import UserForm, UpdateProfileForm, UpdateUserForm, UpdateProfileFormAdmin 15 from .forms import UserForm, UpdateProfileForm, UpdateUserForm, UpdateProfileFormAdmin
16 -from links.models import Link  
17 -from poll.models import *  
18 -from forum.models import *  
19 -from files.models import *  
20 -from exam.models import *  
21 -from courses.models import * 16 +
22 17
23 #API IMPORTS 18 #API IMPORTS
24 from rest_framework import viewsets 19 from rest_framework import viewsets
@@ -214,61 +209,14 @@ class SearchView(LoginRequiredMixin, generic.ListView): @@ -214,61 +209,14 @@ class SearchView(LoginRequiredMixin, generic.ListView):
214 209
215 login_url = reverse_lazy("core:home") 210 login_url = reverse_lazy("core:home")
216 redirect_field_name = 'next' 211 redirect_field_name = 'next'
217 - queryset = Material.objects.all() 212 + queryset = None
218 template_name = 'users/search.html' 213 template_name = 'users/search.html'
219 paginate_by = 10 214 paginate_by = 10
220 215
221 def get_context_data(self, **kwargs): 216 def get_context_data(self, **kwargs):
222 context = super(SearchView, self).get_context_data(**kwargs) 217 context = super(SearchView, self).get_context_data(**kwargs)
223 search = self.request.GET.get('search', None) 218 search = self.request.GET.get('search', None)
224 - link_list = []  
225 - file_list = []  
226 - poll_list = []  
227 - exam_list = []  
228 - forum_list = []  
229 - qtd = 0  
230 -  
231 - if has_role(self.request.user,'system_admin'):  
232 - if search != '':  
233 - link_list = Link.objects.filter( Q(name__icontains=search)).order_by('name')  
234 - file_list = TopicFile.objects.filter(Q(name__icontains=search)).order_by('name')  
235 - poll_list = Poll.objects.filter(Q(name__icontains=search)).order_by('name')  
236 - exam_list = Exam.objects.filter(Q(name__icontains=search)).order_by('name')  
237 - forum_list = Forum.objects.filter(Q(name__icontains=search)).order_by('name')  
238 - qtd = len(link_list) + len(file_list) + len(poll_list) + len(exam_list) + len(forum_list)  
239 -  
240 - elif has_role(self.request.user,'professor'):  
241 - topics = Topic.objects.filter(owner = self.request.user)  
242 - links = Link.objects.all()  
243 - files = TopicFile.objects.all()  
244 - polls = Poll.objects.all()  
245 - exams = Exam.objects.all()  
246 - forums = Forum.objects.all()  
247 - if search != '':  
248 - link_list = sorted([link for link in links for topic in topics if (link.topic == topic) and ( search in link.name ) ],key = lambda x:x.name)  
249 - exam_list = sorted([exam for exam in exams for topic in topics if (exam.topic == topic) and ( search in exam.name ) ],key = lambda x:x.name)  
250 - file_list = sorted([arquivo for arquivo in files for topic in topics if (arquivo.topic == topic) and (search in arquivo.name ) ],key = lambda x:x.name)  
251 - poll_list = sorted([poll for poll in polls for topic in topics if (poll.topic == topic) and ( search in poll.name ) ],key = lambda x:x.name)  
252 - forum_list = sorted([forum for forum in forums for topic in topics if (forum.topic == topic) and ( search in forum.name ) ],key = lambda x:x.name)  
253 - qtd = len(link_list) + len(file_list) + len(poll_list) + len(exam_list) + len(forum_list)  
254 -  
255 - elif has_role(self.request.user, 'student'):  
256 - if search != '':  
257 - link_list = Link.objects.filter( Q(name__icontains=search) and Q(students__name = self.request.user.name)).order_by('name')  
258 - file_list = TopicFile.objects.filter(Q(name__icontains=search) and Q(students__name = self.request.user.name)).order_by('name')  
259 - poll_list = Poll.objects.filter(Q(name__icontains=search)and Q(students__name = self.request.user.name)).order_by('name')  
260 - exam_list = Exam.objects.filter(Q(name__icontains=search)and Q(students__name = self.request.user.name)).order_by('name')  
261 - forum_list = Forum.objects.filter(Q(name__icontains=search)and Q(students__name = self.request.user.name)).order_by('name')  
262 - qtd = len(link_list) + len(file_list) + len(poll_list) + len(exam_list) + len(forum_list)  
263 -  
264 - translated = _('You searched for... ')  
265 - context['link_list'] = link_list  
266 - context['file_list'] = file_list  
267 - context['poll_list'] = poll_list  
268 - context['exam_list'] = exam_list  
269 - context['forum_list'] = forum_list  
270 - context['qtd'] = qtd  
271 - context['search'] = translated + search 219 +
272 220
273 return context 221 return context
274 222