diff --git a/amadeus/templates/base.html b/amadeus/templates/base.html
index f088b90..421240f 100644
--- a/amadeus/templates/base.html
+++ b/amadeus/templates/base.html
@@ -1,16 +1,16 @@
{% load static i18n %}
-{% load static i18n permission_tags %}
+{% load static i18n permission_tags django_bootstrap_breadcrumbs %}
{% get_current_language as LANGUAGE_CODE %}
-
-
-
- {% endblock %}
-
-
-
- {% block test %}
- {% endblock %}
- {% block sidebar %}
- {% endblock %}
-
-
- {% block breadcrumbs %}{% endblock %}
- {% block render_breadcrumbs %}{% endblock %}
-
-
- {% block content %}{% endblock %}
-
+
+
+ -
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+
+ {% endblock %}
+
+
+
+ {% block sidebar %}
+
+
+
{% trans 'Menu' %}
+
+
+
+ {% endblock %}
+
+
+ {% block breadcrumbs %}
+ {% breadcrumb 'Home' 'home' %}
+ {% endblock %}
+ {% block render_breadcrumbs %}
+ {% render_breadcrumbs %}
+ {% endblock %}
+
+
+ {% block content %}
+ {% endblock %}
+
+
-
-
- {% block script_file %}
-
- {% endblock script_file %}
-
- {% block script_link %}
- {% endblock script_link %}
-
-
-
+
+
\ No newline at end of file
diff --git a/amadeus/urls.py b/amadeus/urls.py
index 065d47c..7d46856 100644
--- a/amadeus/urls.py
+++ b/amadeus/urls.py
@@ -24,7 +24,7 @@ from .views import index
urlpatterns = [
url(r'^users/', include('users.urls', namespace = 'users')),
url(r'^admin/', admin.site.urls),
- url(r'^$', index),
+ url(r'^$', index, name = 'home'),
url(r'^courses/', include('courses.urls', namespace = 'courses')),
#API
url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')),
diff --git a/amadeus/views.py b/amadeus/views.py
index 9eadb59..1f6b34e 100644
--- a/amadeus/views.py
+++ b/amadeus/views.py
@@ -3,6 +3,6 @@ from django.shortcuts import redirect
def index(request):
if request.user.is_authenticated:
- raise Http404('
Page not found
')
+ return redirect('courses:index')
else:
return redirect('users:login')
\ No newline at end of file
diff --git a/courses/templates/courses/home.html b/courses/templates/courses/home.html
index f0842d6..af0e028 100755
--- a/courses/templates/courses/home.html
+++ b/courses/templates/courses/home.html
@@ -14,59 +14,6 @@
{% render_breadcrumbs %}
{% endblock %}
-{% block sidebar %}
-
-
-
{% trans 'Menu' %}
-
-
-
-{% endblock %}
-
{% block content %}
{% if user|has_role:'system_admin' %}
{% trans 'Courses' %}
diff --git a/users/forms.py b/users/forms.py
index a0056d0..80a54a2 100644
--- a/users/forms.py
+++ b/users/forms.py
@@ -8,6 +8,9 @@ class Validation(forms.ModelForm):
def clean_password(self):
password = self.cleaned_data.get('password')
+ if self.is_edit and len(password) == 0:
+ return password
+
# At least MIN_LENGTH long
if len(password) < self.MIN_LENGTH:
raise forms.ValidationError(_("The password must contain at least % d characters." % self.MIN_LENGTH))
@@ -23,16 +26,20 @@ class Validation(forms.ModelForm):
password = self.cleaned_data.get("password")
password2 = self.cleaned_data.get("password2")
+ if self.is_edit and len(password) == 0:
+ return password2
+
if password and password2 and password != password2:
raise forms.ValidationError(_('The confirmation password is incorrect.'))
return password2
class RegisterUserForm(Validation):
- password = forms.CharField(label=_('Password'), widget=forms.PasswordInput)
+ password = forms.CharField(label=_('Password'), widget = forms.PasswordInput)
password2 = forms.CharField(label = _('Confirm Password'), widget = forms.PasswordInput)
MIN_LENGTH = 8
+ is_edit = False
def save(self, commit=True):
super(RegisterUserForm, self).save(commit=False)
@@ -46,3 +53,27 @@ class RegisterUserForm(Validation):
class Meta:
model = User
fields = ['email', 'username', 'last_name', 'social_name',]
+
+class ProfileForm(Validation):
+ password = forms.CharField(label=_('Password'), widget = forms.PasswordInput, required = False)
+ password2 = forms.CharField(label = _('Confirm Password'), widget = forms.PasswordInput, required = False)
+
+ MIN_LENGTH = 8
+ is_edit = True
+
+ def save(self, commit=True):
+ super(ProfileForm, self).save(commit=False)
+
+ if len(self.cleaned_data['password']) > 0:
+ self.instance.set_password(self.cleaned_data['password'])
+
+ self.instance.save()
+
+ return self.instance
+
+ class Meta:
+ model = User
+ fields = ['social_name', 'description', 'show_email', 'image']
+ widgets = {
+ 'description': forms.Textarea,
+ }
\ No newline at end of file
diff --git a/users/models.py b/users/models.py
index 156ba51..edc44d6 100644
--- a/users/models.py
+++ b/users/models.py
@@ -22,7 +22,7 @@ class User(AbstractBaseUser, PermissionsMixin):
image = models.ImageField(verbose_name = _('Photo'), null=True, blank = True, upload_to = 'users/')
date_created = models.DateTimeField(_('Create Date'), auto_now_add = True)
last_update = models.DateTimeField(_('Last Update'), auto_now = True)
- show_email = models.IntegerField(_('Show email?'), null = True, choices = ((1, _('Allow everyone to see my address')), (2, _('Only classmates can see my address')), (3, _('Nobody can see my address'))))
+ show_email = models.IntegerField(_('Show email?'), null = True, blank = True, choices = ((1, _('Allow everyone to see my address')), (2, _('Only classmates can see my address')), (3, _('Nobody can see my address'))))
is_staff = models.BooleanField(_('Administrator'), default = False)
is_active = models.BooleanField(_('Active'), default = True)
diff --git a/users/templates/users/edit_profile.html b/users/templates/users/edit_profile.html
index b37bd30..98259c2 100644
--- a/users/templates/users/edit_profile.html
+++ b/users/templates/users/edit_profile.html
@@ -6,14 +6,8 @@
{% load django_bootstrap_breadcrumbs %}
{% block breadcrumbs %}
- {% if user|has_role:'system_admin' %}
- {{ block.super }}
- {% breadcrumb 'Update User' 'users:update' %}
- {% else %}
- {{ block.super }}
- {% breadcrumb 'Update Profile' 'users:update' %}
- {% endif %}
-
+ {{ block.super }}
+ {% breadcrumb 'Update Profile' 'users:edit_profile' %}
{% endblock %}
@@ -35,13 +29,8 @@
{% csrf_token %}
{% for field in form %}
- {% if not field.auto_id == 'id_is_staff' and not field.auto_id == 'id_is_active' and not field.auto_id == 'id_type_profile' %}
-
- {% endif %}
- {% if field.auto_id == 'id_birth_date' %}
-
-
{{ field.help_text }}
- {% elif field.auto_id == 'id_image' or field.auto_id == 'id_curriculum'%}
+
+ {% if field.auto_id == 'id_image' %}
{% render_field field class='form-control input-sm' %}
@@ -51,35 +40,11 @@
- {% elif field.auto_id == 'id_cpf' %}
- {% render_field field class='form-control' onkeypress='campoNumerico(this,event); formatarCpf(this,event);' %}
-
- {% elif field.auto_id == 'id_phone' %}
- {% render_field field class='form-control' onkeypress='campoNumerico(this,event); formatarTelefone(this,event);' %}
-
- {% elif field.auto_id == 'id_year_titration' %}
- {% render_field field class='form-control' onkeypress='campoNumerico(this,event);' %}
-
- {% elif field.auto_id == 'id_is_staff' or field.auto_id == 'id_is_active' %}
- {% if user|has_role:'system_admin' %}
-
-
-
-
- {% endif %}
- {% elif field.auto_id == 'id_type_profile' %}
- {% if user|has_role:'system_admin' %}
-
- {% render_field field class='form-control' %}
-
{{ field.help_text }}
- {% endif %}
+ {% elif field.auto_id == 'id_description' %}
+ {% render_field field class='form-control text_wysiwyg' %}
{% else %}
- {% if not field.auto_id == 'id_is_staff' and not field.auto_id == 'id_is_active' and not field.auto_id == 'id_type_profile' %}
- {% render_field field class='form-control' %}
-
{{ field.help_text }}
- {% endif %}
+ {% render_field field class='form-control' %}
+
{{ field.help_text }}
{% endif %}
{% if field.errors %}
@@ -107,10 +72,8 @@
{% endblock %}
diff --git a/users/templates/users/profile.html b/users/templates/users/profile.html
index e75cce2..c87237b 100644
--- a/users/templates/users/profile.html
+++ b/users/templates/users/profile.html
@@ -1,14 +1,16 @@
-{% extends 'home.html' %}
+{% extends 'base.html' %}
{% load static i18n %}
{% load widget_tweaks %}
{% load django_bootstrap_breadcrumbs permission_tags%}
{% block breadcrumbs %}
+ {{ block.super }}
+ {% breadcrumb 'Profile' 'users:profile' %}
+{% endblock %}
- {{ block.super }}
- {% breadcrumb 'Profile' 'users:profile' %}
-
+{% block render_breadcrumbs %}
+ {% render_breadcrumbs %}
{% endblock %}
{% block content %}
@@ -24,120 +26,33 @@
{% endif %}
-
-
-
- {% if user.image %}
-
- {% else %}
-
- {% if user.gender == 'M' %}
-

- {% else %}
-

- {% endif %}
- {% endif %}
+
+
+
+
+
+
-
-
-
-
- {% trans "Status" %}: |
- {% if user %}
- {% trans "Online" %} |
- {% else %}
- {% trans "OffLine" %} |
- {% endif %}
-
-
-
- {% trans "Name" %}: |
- {{user}} |
-
-
- {% trans "Login" %} |
- {{user.username}} |
-
-
- {% trans "Email" %}: |
- {{user.email}} |
-
-
-
+
+ {% trans 'Name' %}: {{ user.username }}
+ {% trans 'Last Name' %}: {{ user.last_name }}
+ {% trans 'Social Name' %}: {% if user.social_name is None %}{% trans 'Not informed' %}{% else %}{{ user.social_name }}{% endif %}
+ {% trans 'User since' %}: {{ user.date_created|date }}
-
-
-
-
-
- {% trans "User role" %}: |
- {% if user.type_profile == 1 %}
- {% trans "Teacher" %} |
- {% else %}
- {% trans "Student" %} |
- {% endif %}
-
-
-
- {% trans "CPF" %}: |
- {% if user.cpf %}
- {{user.cpf}} |
-
- {% else %}
- {% trans "doesn't possess CPF" %} |
- {% endif %}
-
-
-
- {% trans "Phone Number" %}: |
- {% if user.phone %}
- {{user.phone}} |
- {% else %}
- {% trans "doesn't possess Phone" %} |
- {% endif %}
-
-
-
- {% trans "Gender" %}: |
- {{user.gender}} |
-
-
- {% trans "Birth Date" %}: |
- {{user.birth_date}} |
-
-
- {% trans "State and City" %}: |
- {{user.state}} - {{user.city}} |
-
-
- {% trans "Title" %}: |
- {{user.titration}} |
-
-
- {% trans "Year" %}: |
- {{user.year_titration}} |
-
-
- {% trans "Institution" %}: |
- {% if user.institution %}
- {{user.institution}} |
- {% else %}
- {% trans "Didn't inform institution" %} |
- {% endif %}
-
-
- {% trans "Curriculum" %}: |
- {% if user.curriculum %}
-
- link
- |
- {% else %}
- {% trans "Didn't upload any curriculum" %} |
- {% endif %}
-
-
-
+
+
+ {{ user.description|linebreaks }}
+
+
+
diff --git a/users/urls.py b/users/urls.py
index b1575b0..40b241b 100644
--- a/users/urls.py
+++ b/users/urls.py
@@ -7,4 +7,6 @@ urlpatterns = [
url(r'^login/$', views.login, name='login'),
url(r'^logout/$', auth_views.logout, {'next_page': 'users:login'}, name='logout'),
url(r'^signup/$', views.RegisterUser.as_view(), name = 'signup'),
+ url(r'^profile/$', views.Profile.as_view(), name = 'profile'),
+ url(r'^edit_profile/$', views.UpdateProfile.as_view(), name = 'edit_profile'),
]
diff --git a/users/views.py b/users/views.py
index 6d7f92a..edfb629 100644
--- a/users/views.py
+++ b/users/views.py
@@ -14,7 +14,7 @@ from itertools import chain
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from .models import User
-from .forms import RegisterUserForm
+from .forms import RegisterUserForm, ProfileForm
#API IMPORTS
from rest_framework import viewsets
@@ -153,29 +153,7 @@ from rest_framework.permissions import IsAuthenticated, IsAuthenticatedOrReadOnl
# context['title'] = "Remove Account"
# return context
-# class UpdateProfile(LoginRequiredMixin, generic.edit.UpdateView):
-# #login_url = reverse_lazy("core:home")
-# template_name = 'users/edit_profile.html'
-# form_class = UpdateProfileForm
-# success_url = reverse_lazy('users:profile')
-
-# def get_object(self):
-# user = get_object_or_404(User, username = self.request.user.username)
-# return user
-
-# def get_context_data(self, **kwargs):
-# context = super(UpdateProfile, self).get_context_data(**kwargs)
-# context['title'] = 'Update Profile'
-
-# context['form'] = UpdateProfileForm(instance = self.object)
-
-# return context
-
-# def form_valid(self, form):
-# form.save()
-# messages.success(self.request, _('Profile edited successfully!'))
-# return super(UpdateProfile, self).form_valid(form)
# class DeleteUser(LoginRequiredMixin, generic.edit.DeleteView):
# allowed_roles = ['student']
@@ -189,23 +167,6 @@ from rest_framework.permissions import IsAuthenticated, IsAuthenticatedOrReadOnl
# user = get_object_or_404(User, username = self.request.user.username)
# return user
-
-# class Profile(LoginRequiredMixin, generic.DetailView):
-
-# #login_url = reverse_lazy("core:home")
-# redirect_field_name = 'next'
-# context_object_name = 'user'
-# template_name = 'users/profile.html'
-
-# def get_object(self):
-# user = get_object_or_404(User, username = self.request.user.username)
-# return user
-
-# def get_context_data (self, **kwargs):
-# context = super(Profile, self).get_context_data(**kwargs)
-# context['title'] = "Profile"
-# return context
-
# class SearchView(LoginRequiredMixin, generic.ListView):
# #login_url = reverse_lazy("core:home")
@@ -221,6 +182,49 @@ from rest_framework.permissions import IsAuthenticated, IsAuthenticatedOrReadOnl
# return context
+class Profile(LoginRequiredMixin, generic.DetailView):
+ login_url = reverse_lazy("users:login")
+ redirect_field_name = 'next'
+
+ context_object_name = 'acc'
+ template_name = 'users/profile.html'
+
+ def get_object(self):
+ user = get_object_or_404(User, username = self.request.user.username)
+
+ return user
+
+ def get_context_data (self, **kwargs):
+ context = super(Profile, self).get_context_data(**kwargs)
+ context['title'] = _("Profile")
+
+ return context
+
+class UpdateProfile(LoginRequiredMixin, generic.edit.UpdateView):
+ login_url = reverse_lazy("users:login")
+ redirect_field_name = 'next'
+
+ template_name = 'users/edit_profile.html'
+ form_class = ProfileForm
+ success_url = reverse_lazy('users:profile')
+
+ def get_object(self):
+ user = get_object_or_404(User, email = self.request.user.email)
+
+ return user
+
+ def get_context_data(self, **kwargs):
+ context = super(UpdateProfile, self).get_context_data(**kwargs)
+ context['title'] = _('Update Profile')
+
+ return context
+
+ def form_valid(self, form):
+ form.save()
+ messages.success(self.request, _('Profile edited successfully!'))
+
+ return super(UpdateProfile, self).form_valid(form)
+
class RegisterUser(generic.edit.CreateView):
model = User
form_class = RegisterUserForm
@@ -258,12 +262,12 @@ def login(request):
messages.add_message(request, messages.ERROR, _('E-mail or password are incorrect.'))
context["username"] = username
elif request.user.is_authenticated:
- return redirect('courses:index')
+ return redirect('home')
return render(request,"users/login.html",context)
-# API VIEWS
+# API VIEWS
class UserViewSet(viewsets.ModelViewSet):
queryset = User.objects.all()
serializer_class = UserSerializer
--
libgit2 0.21.2