Commit 8d127da80ee900234d29ca180a5b92ead5736dae

Authored by Zambom
1 parent 9e08c780

Adding profile and fixing some html

amadeus/templates/base.html
1 1 <!DOCTYPE html>
2 2  
3 3 {% load static i18n %}
4   -{% load static i18n permission_tags %}
  4 +{% load static i18n permission_tags django_bootstrap_breadcrumbs %}
5 5 {% get_current_language as LANGUAGE_CODE %}
6 6  
7 7 <html>
8 8 <head>
9 9 <title>{{ title }} | Amadeus</title>
10 10  
11   - <!-- jQuery & jQuery UI -->
12   - <script type="text/javascript" src="{% static 'js/jquery-3.1.0.min.js' %}"></script>
13   - <script type="text/javascript" src="{% static 'js/jquery-ui.js' %}"></script>
  11 + <!-- jQuery & jQuery UI -->
  12 + <script type="text/javascript" src="{% static 'js/jquery-3.1.0.min.js' %}"></script>
  13 + <script type="text/javascript" src="{% static 'js/jquery-ui.js' %}"></script>
14 14  
15 15 <meta http-equiv="Cache-Control" content="no-cache, no-store" />
16 16 <link href="{% static 'img/topo-amadeus.png' %}" rel="shortcut icon" />
... ... @@ -35,7 +35,7 @@
35 35 <script type="text/javascript" src="{% static 'material/js/material.min.js' %}"></script>
36 36 <script type="text/javascript" src="{% static 'material/js/ripples.min.js' %}"></script>
37 37 <script type="text/javascript" src="{% static 'js/bootstrap-datepicker.js' %}"></script>
38   - {% with "js/vendor/locales/bootstrap-datepicker."|add:LANGUAGE_CODE|add:".js" as locale_datepicker %}
  38 + {% with "js/locales/bootstrap-datepicker."|add:LANGUAGE_CODE|add:".js" as locale_datepicker %}
39 39 <script type="text/javascript" src="{% static locale_datepicker %}"></script>
40 40 {% endwith %}
41 41 <script type="text/javascript" src="{% static 'js/alertify.min.js' %}"></script>
... ... @@ -45,12 +45,13 @@
45 45 <link rel="stylesheet" type="text/css" href="{% static 'font-awesome-4.6.3/css/font-awesome.min.css' %}">
46 46  
47 47 <!-- Custom styles -->
48   - <link rel="stylesheet" type="text/css" href="{% static 'css/base/amadeus.css' %}">
  48 + <link rel="stylesheet" type="text/css" href="{% static 'css/base/amadeus.css' %}">
49 49  
50 50 <!--Javascript block for specific-app ones -->
51 51 <script src="{% static 'js/base/amadeus.js' %}"></script>
52   - <script src="{% static 'js/main.js' %}"></script>
53   - {% block style %}
  52 + <script src="{% static 'js/main.js' %}"></script>
  53 +
  54 + {% block style %}
54 55 {% endblock %}
55 56 {% block javascript %}
56 57 {% endblock %}
... ... @@ -61,91 +62,114 @@
61 62  
62 63 </head>
63 64 <body>
64   - {% block nav %}
65   - <div class="navbar navbar-default">
66   - <div class="navbar-header">
67   - <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
68   - <span class="icon-bar"></span>
69   - <span class="icon-bar"></span>
70   - <span class="icon-bar"></span>
71   - </button>
72   - <a class="navbar-brand" href="#"><img class="logo" src="{% static 'img/topo-amadeus-white.png' %}" alt="Logo"/></a>
73   - </div>
74   - <div class="navbar-collapse collapse navbar-responsive-collapse">
75   - <div class="col-md-5 cards-content" id= 'NavBarSearch'>
76   - <form id="SearchForm" action="#" method="get" accept-charset="utf-8">
77   - <div class="input-group">
78   - <div class="form-group is-empty" >
79   - <input type="text" class="form-control" placeholder="{% trans 'Search Files (.pdf, others) and/or activities' %}" name="search">
  65 + {% block nav %}
  66 + <div class="navbar navbar-default">
  67 + <div class="navbar-header">
  68 + <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
  69 + <span class="icon-bar"></span>
  70 + <span class="icon-bar"></span>
  71 + <span class="icon-bar"></span>
  72 + </button>
  73 + <a class="navbar-brand" href="#"><img class="logo" src="{% static 'img/topo-amadeus-white.png' %}" alt="Logo"/></a>
80 74 </div>
81   - <span class="input-group-btn input-group-sm">
82   - <button type="submit" class="btn btn-primary" id="btn-search">
83   - <i class="fa fa-search fa-2x" aria-hidden="true" style="color:#93C741"></i>
84   - </button>
85   - </span>
86   - </div>
87   - </form>
88   - </div>
89   - <ul class="nav navbar-nav navbar-right notifications">
90   - <li class="" data-toggle="tooltip" data-placement="bottom" title data-original-title="notifications">
91   - <a class="dropdown-toggle" data-toggle="dropdown"> <span id="notification-count" class="badge notification-count">{{notifications.count}}</span><i class="fa fa-bell" aria-hidden="true"></i></a>
92   - <!--<ul id="notification-dropdown" class="dropdown-menu">
93   - <li class="dropdown-header"> {% trans 'Notifications' %}</li>
94   -
95   - <li>
96   - <a onclick="getNotifications(5)">
97   - <div id="notification-see-more" class="list-group-item">
98   - <div class="row-content">
99   - <p class="list-group-item-text">{% trans 'See More' %}</p>
100   - </div>
  75 + <div class="navbar-collapse collapse navbar-responsive-collapse">
  76 + <div class="col-md-5 cards-content" id= 'NavBarSearch'>
  77 + <form id="SearchForm" action="#" method="get" accept-charset="utf-8">
  78 + <div class="input-group">
  79 + <div class="form-group is-empty" >
  80 + <input type="text" class="form-control" placeholder="{% trans 'Search Files (.pdf, others) and/or activities' %}" name="search">
  81 + </div>
  82 + <span class="input-group-btn input-group-sm">
  83 + <button type="submit" class="btn btn-primary" id="btn-search">
  84 + <i class="fa fa-search fa-2x" aria-hidden="true" style="color:white"></i>
  85 + </button>
  86 + </span>
  87 + </div>
  88 + </form>
101 89 </div>
102   - </a>
103   - </li>
104   - </ul> -->
105   - </li>
106   - <li data-toggle="tooltip" data-placement="bottom" title data-original-title="{% trans 'messages' %}"> <a href="#"><i class="fa fa-comments" aria-hidden="true"></i></a> </li>
107   - <li>
108   - <a href="" data-toggle="dropdown">{{ user }}</a>
109   - <ul class="dropdown-menu pull-right">
110   - <li><a href="#">{% trans 'Perfil' %}</a></li>
111   - <li><a href="#">{% trans 'Edit Profile' %}</a></li>
112   - <li><a href="#">{% trans 'Change password' %}</a></li>
113   - <li><a href="#">{% trans 'Remove account' %}</a></li>
114   - </ul>
115   - </li>
116   - <li data-toggle="tooltip" data-placement="bottom" title data-original-title="log out"> <a href="#"><i class="fa fa-sign-out" aria-hidden="true"></i></a></li>
117   - </ul>
118   - </div>
119   - </div>
120   - {% endblock %}
121   - <div class="container-fluid">
122   - <div class="row">
123   - <div class="col-xs-2 col-sm-2 col-md-2 col-lg-2 col-xl-2">
124   - {% block test %}
125   - {% endblock %}
126   - {% block sidebar %}
127   - {% endblock %}
128   - </div>
129   - <div class="col-xs-10 col-sm-10 col-md-10 col-lg-10 col-xl-10">
130   - {% block breadcrumbs %}{% endblock %}
131   - {% block render_breadcrumbs %}{% endblock %}
132   - </div>
133   - <div class="col-xs-10 col-sm-10 col-md-10 col-lg-10 col-xl-10">
134   - {% block content %}{% endblock %}
135   - </div>
  90 + <ul class="nav navbar-nav navbar-right notifications">
  91 + <!--<li class="" data-toggle="tooltip" data-placement="bottom" title data-original-title="notifications">
  92 + <a class="dropdown-toggle" data-toggle="dropdown"> <span id="notification-count" class="badge notification-count">{{notifications.count}}</span><i class="fa fa-bell" aria-hidden="true"></i></a>-
  93 + <ul id="notification-dropdown" class="dropdown-menu">
  94 + <li class="dropdown-header"> {% trans 'Notifications' %}</li>
  95 +
  96 + <li>
  97 + <a onclick="getNotifications(5)">
  98 + <div id="notification-see-more" class="list-group-item">
  99 + <div class="row-content">
  100 + <p class="list-group-item-text">{% trans 'See More' %}</p>
  101 + </div>
  102 + </div>
  103 + </a>
  104 + </li>
  105 + </ul>
  106 + </li> -->
  107 + <li title data-original-title="{% trans 'settings' %}">
  108 + <a href="" data-toggle="dropdown"><i class="fa fa-cog" aria-hidden="true"></i></a>
  109 + <ul class="dropdown-menu pull-right">
  110 + <li><a href="#">{% trans 'Perfil' %}</a></li>
  111 + <li><a href="#">{% trans 'Edit Profile' %}</a></li>
  112 + <li><a href="#">{% trans 'Change password' %}</a></li>
  113 + <li><a href="#">{% trans 'Remove account' %}</a></li>
  114 + </ul>
  115 + </li>
  116 + <li>
  117 + <a href="{% url 'users:profile' %}" style="padding-top: 15px;padding-bottom:15px;">
  118 + <img src="{{ user.image_url }}" style="width:30px;height:30px" />
  119 + </a>
  120 + </li>
  121 + <li data-toggle="tooltip" data-placement="bottom" title data-original-title="log out">
  122 + <a href="{% url 'users:logout' %}"><i class="fa fa-sign-out" aria-hidden="true"></i></a>
  123 + </li>
  124 + </ul>
  125 + </div>
  126 + </div>
  127 + {% endblock %}
  128 + <div class="container-fluid">
  129 + <div class="row">
  130 + <div class="col-xs-2 col-sm-2 col-md-2 col-lg-2 col-xl-2">
  131 + {% block sidebar %}
  132 + <div class="panel panel-primary">
  133 + <div class="panel-heading">
  134 + <h4>{% trans 'Menu' %}</h4>
  135 + </div>
  136 + <div class="panel-body menu-lateral">
  137 + <ul class="nav nav-pills nav-stacked">
  138 + <li>
  139 + <a href="#menu_courses" class="accordion" data-toggle="collapse">{% trans 'Courses' %}<span class="pull-right glyphicon glyphicon-chevron-down"></span></a>
  140 + <div id="menu_courses" class="collapse">
  141 + <ul class="nav nav-pill nav-stacked accordion_list">
  142 + <li><a href="#"><i class="fa fa-book" aria-hidden="true"></i> {% trans 'My Courses' %} </a></li>
  143 + <li><a href="#"><i class="fa fa-globe" aria-hidden="true"></i> {% trans 'All Courses' %} </a></li>
  144 + {% if user|has_role:'system_admin' or user|has_role:'professor'%}
  145 + <li><a href="#"><i class="fa fa-list" aria-hidden="true"></i> {% trans 'List Category' %}</a></li>
  146 + <li><a href="#">{% trans 'Create Course' %}</a></li>
  147 + {% endif %}
  148 + </ul>
  149 + </div>
  150 + </li>
  151 + </ul>
  152 + </div>
  153 + </div>
  154 + {% endblock %}
  155 + </div>
  156 + <div class="col-xs-10 col-sm-10 col-md-10 col-lg-10 col-xl-10">
  157 + {% block breadcrumbs %}
  158 + {% breadcrumb 'Home' 'home' %}
  159 + {% endblock %}
  160 + {% block render_breadcrumbs %}
  161 + {% render_breadcrumbs %}
  162 + {% endblock %}
  163 + </div>
  164 + <div class="col-xs-10 col-sm-10 col-md-10 col-lg-10 col-xl-10">
  165 + {% block content %}
  166 + {% endblock %}
  167 + </div>
  168 + </div>
136 169 </div>
137   - </div>
138   -
139   - {% block script_file %}
140   -
141   - {% endblock script_file %}
142   -
143   - {% block script_link %}
144 170  
145   - {% endblock script_link %}
146   - <!-- Init material Bootstrap -->
147   - <script type="text/javascript" src="{% static 'js/home.js' %}"></script>
148   - <script type="text/javascript">$.material.init()</script>
  171 + <!-- Init material Bootstrap -->
  172 + <script type="text/javascript">$.material.init()</script>
149 173 </body>
150 174  
151 175 </html>
152 176 \ No newline at end of file
... ...
amadeus/urls.py
... ... @@ -24,7 +24,7 @@ from .views import index
24 24 urlpatterns = [
25 25 url(r'^users/', include('users.urls', namespace = 'users')),
26 26 url(r'^admin/', admin.site.urls),
27   - url(r'^$', index),
  27 + url(r'^$', index, name = 'home'),
28 28 url(r'^courses/', include('courses.urls', namespace = 'courses')),
29 29 #API
30 30 url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')),
... ...
amadeus/views.py
... ... @@ -3,6 +3,6 @@ from django.shortcuts import redirect
3 3  
4 4 def index(request):
5 5 if request.user.is_authenticated:
6   - raise Http404('<h1>Page not found</h1>')
  6 + return redirect('courses:index')
7 7 else:
8 8 return redirect('users:login')
9 9 \ No newline at end of file
... ...
courses/templates/courses/home.html
... ... @@ -14,59 +14,6 @@
14 14 {% render_breadcrumbs %}
15 15 {% endblock %}
16 16  
17   -{% block sidebar %}
18   - <div class="panel panel-primary">
19   - <div class="panel-heading">
20   - <h4>{% trans 'Menu' %}</h4>
21   - </div>
22   - <div class="panel-body menu-lateral">
23   - <ul class="nav nav-pills nav-stacked">
24   - <li>
25   - <a href="#menu_courses" class="accordion" data-toggle="collapse">{% trans 'Courses' %}<span class="pull-right glyphicon glyphicon-chevron-down"></span></a>
26   - <div id="menu_courses" class="collapse">
27   - <ul class="nav nav-pill nav-stacked accordion_list">
28   - <li><a href="#"><i class="fa fa-book" aria-hidden="true"></i> {% trans 'My Courses' %} </a></li>
29   - <li><a href="#"><i class="fa fa-globe" aria-hidden="true"></i> {% trans 'All Courses' %} </a></li>
30   - {% if user|has_role:'system_admin' or user|has_role:'professor'%}
31   - <li><a href="#"><i class="fa fa-list" aria-hidden="true"></i> {% trans 'List Category' %}</a></li>
32   - <li><a href="#">{% trans 'Create Course' %}</a></li>
33   - <li><a href="#">{% trans 'Create Category' %}</a></li>
34   - {% endif %}
35   - </ul>
36   - </div>
37   - </li>
38   - {% block menu %}
39   -
40   - {% endblock %}
41   - {% if user|has_role:'system_admin' %}
42   -
43   - <li>
44   - <a href="#menu_users" class="accordion" data-toggle="collapse">{% trans 'Users' %}<span class="pull-right glyphicon glyphicon-chevron-down"></span></a>
45   - <div id="menu_users" class="collapse">
46   - <ul class="nav nav-pill nav-stacked accordion_list">
47   - <li> <a href="#"><i class="fa fa-users" aria-hidden="true"></i> {% trans 'Manage Users' %}</a></li>
48   - <li> <a href="#"><i class="fa fa-user-plus" aria-hidden="true"></i> {% trans 'Create User' %}</a></li>
49   - </ul>
50   - </div>
51   - </li>
52   - <li>
53   - <a href="#menu_settings" class="accordion" data-toggle="collapse">{% trans 'Settings' %}<span class="pull-right glyphicon glyphicon-chevron-down"></span></a>
54   - <div id="menu_settings" class="collapse">
55   - <ul class="nav nav-pill nav-stacked accordion_list">
56   -
57   - <li> <a href="#"><i class="fa fa-cog" aria-hidden="true"></i> {% trans "System" %}</a></li>
58   -
59   - <li> <a href="#"><i class="fa fa-envelope" aria-hidden="true"></i> {% trans "Mail Sender" %}</a></li>
60   - <li> <a href="#"><i class="fa fa-shield" aria-hidden="true"></i> {% trans "Security" %}</a></li>
61   - </ul>
62   - </div>
63   - </li>
64   - {% endif %}
65   - </ul>
66   - </div>
67   - </div>
68   -{% endblock %}
69   -
70 17 {% block content %}
71 18 {% if user|has_role:'system_admin' %}
72 19 <h3>{% trans 'Courses' %}</h3>
... ...
users/forms.py
... ... @@ -8,6 +8,9 @@ class Validation(forms.ModelForm):
8 8 def clean_password(self):
9 9 password = self.cleaned_data.get('password')
10 10  
  11 + if self.is_edit and len(password) == 0:
  12 + return password
  13 +
11 14 # At least MIN_LENGTH long
12 15 if len(password) < self.MIN_LENGTH:
13 16 raise forms.ValidationError(_("The password must contain at least % d characters." % self.MIN_LENGTH))
... ... @@ -23,16 +26,20 @@ class Validation(forms.ModelForm):
23 26 password = self.cleaned_data.get("password")
24 27 password2 = self.cleaned_data.get("password2")
25 28  
  29 + if self.is_edit and len(password) == 0:
  30 + return password2
  31 +
26 32 if password and password2 and password != password2:
27 33 raise forms.ValidationError(_('The confirmation password is incorrect.'))
28 34  
29 35 return password2
30 36  
31 37 class RegisterUserForm(Validation):
32   - password = forms.CharField(label=_('Password'), widget=forms.PasswordInput)
  38 + password = forms.CharField(label=_('Password'), widget = forms.PasswordInput)
33 39 password2 = forms.CharField(label = _('Confirm Password'), widget = forms.PasswordInput)
34 40  
35 41 MIN_LENGTH = 8
  42 + is_edit = False
36 43  
37 44 def save(self, commit=True):
38 45 super(RegisterUserForm, self).save(commit=False)
... ... @@ -46,3 +53,27 @@ class RegisterUserForm(Validation):
46 53 class Meta:
47 54 model = User
48 55 fields = ['email', 'username', 'last_name', 'social_name',]
  56 +
  57 +class ProfileForm(Validation):
  58 + password = forms.CharField(label=_('Password'), widget = forms.PasswordInput, required = False)
  59 + password2 = forms.CharField(label = _('Confirm Password'), widget = forms.PasswordInput, required = False)
  60 +
  61 + MIN_LENGTH = 8
  62 + is_edit = True
  63 +
  64 + def save(self, commit=True):
  65 + super(ProfileForm, self).save(commit=False)
  66 +
  67 + if len(self.cleaned_data['password']) > 0:
  68 + self.instance.set_password(self.cleaned_data['password'])
  69 +
  70 + self.instance.save()
  71 +
  72 + return self.instance
  73 +
  74 + class Meta:
  75 + model = User
  76 + fields = ['social_name', 'description', 'show_email', 'image']
  77 + widgets = {
  78 + 'description': forms.Textarea,
  79 + }
49 80 \ No newline at end of file
... ...
users/models.py
... ... @@ -22,7 +22,7 @@ class User(AbstractBaseUser, PermissionsMixin):
22 22 image = models.ImageField(verbose_name = _('Photo'), null=True, blank = True, upload_to = 'users/')
23 23 date_created = models.DateTimeField(_('Create Date'), auto_now_add = True)
24 24 last_update = models.DateTimeField(_('Last Update'), auto_now = True)
25   - 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'))))
  25 + 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'))))
26 26 is_staff = models.BooleanField(_('Administrator'), default = False)
27 27 is_active = models.BooleanField(_('Active'), default = True)
28 28  
... ...
users/templates/users/edit_profile.html
... ... @@ -6,14 +6,8 @@
6 6 {% load django_bootstrap_breadcrumbs %}
7 7  
8 8 {% block breadcrumbs %}
9   - {% if user|has_role:'system_admin' %}
10   - {{ block.super }}
11   - {% breadcrumb 'Update User' 'users:update' %}
12   - {% else %}
13   - {{ block.super }}
14   - {% breadcrumb 'Update Profile' 'users:update' %}
15   - {% endif %}
16   -
  9 + {{ block.super }}
  10 + {% breadcrumb 'Update Profile' 'users:edit_profile' %}
17 11 {% endblock %}
18 12  
19 13  
... ... @@ -35,13 +29,8 @@
35 29 {% csrf_token %}
36 30 {% for field in form %}
37 31 <div class="form-group{% if form.has_error %} has-error {% endif %} is-fileinput">
38   - {% if not field.auto_id == 'id_is_staff' and not field.auto_id == 'id_is_active' and not field.auto_id == 'id_type_profile' %}
39   - <label for="{{ field.auto_id }}">{{ field.label }}</label>
40   - {% endif %}
41   - {% if field.auto_id == 'id_birth_date' %}
42   - <input type="text" class="form-control date-picker"name="{{field.name}}" value="{{field.value|date:'SHORT_DATE_FORMAT'}}" min="{{now|date:'SHORT_DATE_FORMAT'}}" id="{{ field.auto_id }}">
43   - <span id="helpBlock" class="help-block">{{ field.help_text }}</span>
44   - {% elif field.auto_id == 'id_image' or field.auto_id == 'id_curriculum'%}
  32 + <label for="{{ field.auto_id }}">{{ field.label }}</label>
  33 + {% if field.auto_id == 'id_image' %}
45 34 {% render_field field class='form-control input-sm' %}
46 35 <div class="input-group">
47 36 <input type="text" readonly="" class="form-control" placeholder="{% trans 'Choose your file...' %}">
... ... @@ -51,35 +40,11 @@
51 40 </button>
52 41 </span>
53 42 </div>
54   - {% elif field.auto_id == 'id_cpf' %}
55   - {% render_field field class='form-control' onkeypress='campoNumerico(this,event); formatarCpf(this,event);' %}
56   -
57   - {% elif field.auto_id == 'id_phone' %}
58   - {% render_field field class='form-control' onkeypress='campoNumerico(this,event); formatarTelefone(this,event);' %}
59   -
60   - {% elif field.auto_id == 'id_year_titration' %}
61   - {% render_field field class='form-control' onkeypress='campoNumerico(this,event);' %}
62   -
63   - {% elif field.auto_id == 'id_is_staff' or field.auto_id == 'id_is_active' %}
64   - {% if user|has_role:'system_admin' %}
65   - <label for="{{ field.auto_id }}">{{ field.label }}</label>
66   - <div class="checkbox">
67   - <label for="{{ field.auto_id }}">
68   - {% render_field field %} {{field.label}}
69   - </label>
70   - </div>
71   - {% endif %}
72   - {% elif field.auto_id == 'id_type_profile' %}
73   - {% if user|has_role:'system_admin' %}
74   - <label for="{{ field.auto_id }}">{{ field.label }}</label>
75   - {% render_field field class='form-control' %}
76   - <span id="helpBlock" class="help-block">{{ field.help_text }}</span>
77   - {% endif %}
  43 + {% elif field.auto_id == 'id_description' %}
  44 + {% render_field field class='form-control text_wysiwyg' %}
78 45 {% else %}
79   - {% if not field.auto_id == 'id_is_staff' and not field.auto_id == 'id_is_active' and not field.auto_id == 'id_type_profile' %}
80   - {% render_field field class='form-control' %}
81   - <span id="helpBlock" class="help-block">{{ field.help_text }}</span>
82   - {% endif %}
  46 + {% render_field field class='form-control' %}
  47 + <span id="helpBlock" class="help-block">{{ field.help_text }}</span>
83 48 {% endif %}
84 49 {% if field.errors %}
85 50 <div class="alert alert-danger alert-dismissible" role="alert">
... ... @@ -107,10 +72,8 @@
107 72 </div>
108 73 <br clear="all" />
109 74 <script type="text/javascript">
110   - var locale = navigator.language || navigator.userLanguage;
111   -
112   - $('.date-picker').datepicker({
113   - language: locale,
114   - });
  75 + $('.text_wysiwyg').summernote({
  76 + height: 200
  77 + });
115 78 </script>
116 79 {% endblock %}
... ...
users/templates/users/profile.html
1   -{% extends 'home.html' %}
  1 +{% extends 'base.html' %}
2 2  
3 3 {% load static i18n %}
4 4 {% load widget_tweaks %}
5 5 {% load django_bootstrap_breadcrumbs permission_tags%}
6 6  
7 7 {% block breadcrumbs %}
  8 + {{ block.super }}
  9 + {% breadcrumb 'Profile' 'users:profile' %}
  10 +{% endblock %}
8 11  
9   - {{ block.super }}
10   - {% breadcrumb 'Profile' 'users:profile' %}
11   -
  12 +{% block render_breadcrumbs %}
  13 + {% render_breadcrumbs %}
12 14 {% endblock %}
13 15  
14 16 {% block content %}
... ... @@ -24,120 +26,33 @@
24 26 {% endif %}
25 27 <div class="row">
26 28 <div class="col-lg-12">
27   - <div class="well well-lg">
28   - <div class="row">
29   -
30   - {% if user.image %}
31   - <div class="col-md-4" style="width: 200px;overflow:hidden;margin-left: 8em;height: 150px;background-image: url('{{user.image.url}}');background-position: center;background-size: cover;">
32   - {% else %}
33   - <div class="col-md-4">
34   - {% if user.gender == 'M' %}
35   - <img src="{% static 'img/male_avatar.png' %}" alt="Avatar" class="img-circle img-responsive img-list-user" style="margin-left: 8em;">
36   - {% else %}
37   - <img src="{% static 'img/female_avatar.png' %}" alt="Avatar" class="img-circle img-responsive img-list-user" style="margin-left: 8em;">
38   - {% endif %}
39   - {% endif %}
  29 + <div class="well well-lg container-fluid">
  30 + <div class="row-fluid">
  31 + <div class="col-md-3">
  32 + <span class="thumbnail">
  33 + <img src="{{ user.image_url }}" />
  34 + </span>
40 35 </div>
41   - <div class="col-md-8">
42   - <table class="table table-hover table-edited">
43   - <tbody>
44   - <tr>
45   - <td>{% trans "Status" %}:</td>
46   - {% if user %}
47   - <td> {% trans "Online" %}</td>
48   - {% else %}
49   - <td> {% trans "OffLine" %}</td>
50   - {% endif %}
51   -
52   - </tr>
53   - <tr>
54   - <td>{% trans "Name" %}:</td>
55   - <td>{{user}}</td>
56   - </tr>
57   - <tr>
58   - <td>{% trans "Login" %}</td>
59   - <td>{{user.username}}</td>
60   - </tr>
61   - <tr>
62   - <td>{% trans "Email" %}:</td>
63   - <td>{{user.email}}</td>
64   - </tr>
65   - </tbody>
66   - </table>
  36 + <div class="col-md-9">
  37 + <span><b>{% trans 'Name' %}: </b> {{ user.username }}</span><br />
  38 + <span><b>{% trans 'Last Name' %}: </b> {{ user.last_name }}</span><br />
  39 + <span><b>{% trans 'Social Name' %}: </b> {% if user.social_name is None %}{% trans 'Not informed' %}{% else %}{{ user.social_name }}{% endif %}</span><br />
  40 + <span><b>{% trans 'User since' %}: </b> {{ user.date_created|date }}</span><br />
67 41 </div>
68 42 </div>
69   - <div class="row">
70   - <div class="col-md-10 col-md-offset-1">
71   - <table class="table table-hover table-edited">
72   - <tbody>
73   - <tr>
74   - <td>{% trans "User role" %}:</td>
75   - {% if user.type_profile == 1 %}
76   - <td>{% trans "Teacher" %}</td>
77   - {% else %}
78   - <td>{% trans "Student" %}</td>
79   - {% endif %}
80   -
81   - </tr>
82   - <tr>
83   - <td>{% trans "CPF" %}:</td>
84   - {% if user.cpf %}
85   - <td>{{user.cpf}}</td>
86   -
87   - {% else %}
88   - <td>{% trans "doesn't possess CPF" %}</td>
89   - {% endif %}
90   -
91   - </tr>
92   - <tr>
93   - <td>{% trans "Phone Number" %}:</td>
94   - {% if user.phone %}
95   - <td>{{user.phone}}</td>
96   - {% else %}
97   - <td>{% trans "doesn't possess Phone" %}</td>
98   - {% endif %}
99   -
100   - </tr>
101   - <tr>
102   - <td>{% trans "Gender" %}:</td>
103   - <td>{{user.gender}}</td>
104   - </tr>
105   - <tr>
106   - <td>{% trans "Birth Date" %}:</td>
107   - <td>{{user.birth_date}}</td>
108   - </tr>
109   - <tr>
110   - <td>{% trans "State and City" %}:</td>
111   - <td>{{user.state}} - {{user.city}}</td>
112   - </tr>
113   - <tr>
114   - <td>{% trans "Title" %}:</td>
115   - <td>{{user.titration}}</td>
116   - </tr>
117   - <tr>
118   - <td>{% trans "Year" %}:</td>
119   - <td>{{user.year_titration}}</td>
120   - </tr>
121   - <tr>
122   - <td>{% trans "Institution" %}:</td>
123   - {% if user.institution %}
124   - <td>{{user.institution}}</td>
125   - {% else %}
126   - <td>{% trans "Didn't inform institution" %}</td>
127   - {% endif %}
128   - </tr>
129   - <tr>
130   - <td>{% trans "Curriculum" %}:</td>
131   - {% if user.curriculum %}
132   - <td>
133   - <a href="{{user.curriculum.url }}" target="_blank">link</a>
134   - </td>
135   - {% else %}
136   - <td>{% trans "Didn't upload any curriculum" %}</td>
137   - {% endif %}
138   - </tr>
139   - </tbody>
140   - </table>
  43 + <div class="row-fluid">
  44 + <div class="col-md-12">
  45 + {{ user.description|linebreaks }}
  46 + </div>
  47 + </div>
  48 + <div class="row-fluid">
  49 + <div class="col-md-12">
  50 + <a href="{% url 'users:edit_profile' %}" class="pull-left btn btn-raised btn-primary btn-sm">
  51 + <i class="fa fa-edit"></i> {% trans 'Edit Profile' %}
  52 + </a>
  53 + <a class="pull-right btn btn-raised btn-danger btn-sm">
  54 + <i class="fa fa-trash"></i> {% trans 'Delete Account' %}
  55 + </a>
141 56 </div>
142 57 </div>
143 58 </div>
... ...
users/urls.py
... ... @@ -7,4 +7,6 @@ urlpatterns = [
7 7 url(r'^login/$', views.login, name='login'),
8 8 url(r'^logout/$', auth_views.logout, {'next_page': 'users:login'}, name='logout'),
9 9 url(r'^signup/$', views.RegisterUser.as_view(), name = 'signup'),
  10 + url(r'^profile/$', views.Profile.as_view(), name = 'profile'),
  11 + url(r'^edit_profile/$', views.UpdateProfile.as_view(), name = 'edit_profile'),
10 12 ]
... ...
users/views.py
... ... @@ -14,7 +14,7 @@ from itertools import chain
14 14 from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
15 15  
16 16 from .models import User
17   -from .forms import RegisterUserForm
  17 +from .forms import RegisterUserForm, ProfileForm
18 18  
19 19 #API IMPORTS
20 20 from rest_framework import viewsets
... ... @@ -153,29 +153,7 @@ from rest_framework.permissions import IsAuthenticated, IsAuthenticatedOrReadOnl
153 153 # context['title'] = "Remove Account"
154 154 # return context
155 155  
156   -# class UpdateProfile(LoginRequiredMixin, generic.edit.UpdateView):
157   -# #login_url = reverse_lazy("core:home")
158   -# template_name = 'users/edit_profile.html'
159   -# form_class = UpdateProfileForm
160   -# success_url = reverse_lazy('users:profile')
161   -
162   -# def get_object(self):
163   -# user = get_object_or_404(User, username = self.request.user.username)
164   -# return user
165   -
166   -# def get_context_data(self, **kwargs):
167   -# context = super(UpdateProfile, self).get_context_data(**kwargs)
168   -# context['title'] = 'Update Profile'
169   -
170   -# context['form'] = UpdateProfileForm(instance = self.object)
171   -
172   -# return context
173   -
174   -# def form_valid(self, form):
175   -# form.save()
176   -# messages.success(self.request, _('Profile edited successfully!'))
177 156  
178   -# return super(UpdateProfile, self).form_valid(form)
179 157  
180 158 # class DeleteUser(LoginRequiredMixin, generic.edit.DeleteView):
181 159 # allowed_roles = ['student']
... ... @@ -189,23 +167,6 @@ from rest_framework.permissions import IsAuthenticated, IsAuthenticatedOrReadOnl
189 167 # user = get_object_or_404(User, username = self.request.user.username)
190 168 # return user
191 169  
192   -
193   -# class Profile(LoginRequiredMixin, generic.DetailView):
194   -
195   -# #login_url = reverse_lazy("core:home")
196   -# redirect_field_name = 'next'
197   -# context_object_name = 'user'
198   -# template_name = 'users/profile.html'
199   -
200   -# def get_object(self):
201   -# user = get_object_or_404(User, username = self.request.user.username)
202   -# return user
203   -
204   -# def get_context_data (self, **kwargs):
205   -# context = super(Profile, self).get_context_data(**kwargs)
206   -# context['title'] = "Profile"
207   -# return context
208   -
209 170 # class SearchView(LoginRequiredMixin, generic.ListView):
210 171  
211 172 # #login_url = reverse_lazy("core:home")
... ... @@ -221,6 +182,49 @@ from rest_framework.permissions import IsAuthenticated, IsAuthenticatedOrReadOnl
221 182  
222 183 # return context
223 184  
  185 +class Profile(LoginRequiredMixin, generic.DetailView):
  186 + login_url = reverse_lazy("users:login")
  187 + redirect_field_name = 'next'
  188 +
  189 + context_object_name = 'acc'
  190 + template_name = 'users/profile.html'
  191 +
  192 + def get_object(self):
  193 + user = get_object_or_404(User, username = self.request.user.username)
  194 +
  195 + return user
  196 +
  197 + def get_context_data (self, **kwargs):
  198 + context = super(Profile, self).get_context_data(**kwargs)
  199 + context['title'] = _("Profile")
  200 +
  201 + return context
  202 +
  203 +class UpdateProfile(LoginRequiredMixin, generic.edit.UpdateView):
  204 + login_url = reverse_lazy("users:login")
  205 + redirect_field_name = 'next'
  206 +
  207 + template_name = 'users/edit_profile.html'
  208 + form_class = ProfileForm
  209 + success_url = reverse_lazy('users:profile')
  210 +
  211 + def get_object(self):
  212 + user = get_object_or_404(User, email = self.request.user.email)
  213 +
  214 + return user
  215 +
  216 + def get_context_data(self, **kwargs):
  217 + context = super(UpdateProfile, self).get_context_data(**kwargs)
  218 + context['title'] = _('Update Profile')
  219 +
  220 + return context
  221 +
  222 + def form_valid(self, form):
  223 + form.save()
  224 + messages.success(self.request, _('Profile edited successfully!'))
  225 +
  226 + return super(UpdateProfile, self).form_valid(form)
  227 +
224 228 class RegisterUser(generic.edit.CreateView):
225 229 model = User
226 230 form_class = RegisterUserForm
... ... @@ -258,12 +262,12 @@ def login(request):
258 262 messages.add_message(request, messages.ERROR, _('E-mail or password are incorrect.'))
259 263 context["username"] = username
260 264 elif request.user.is_authenticated:
261   - return redirect('courses:index')
  265 + return redirect('home')
262 266  
263 267 return render(request,"users/login.html",context)
264 268  
265   -# API VIEWS
266 269  
  270 +# API VIEWS
267 271 class UserViewSet(viewsets.ModelViewSet):
268 272 queryset = User.objects.all()
269 273 serializer_class = UserSerializer
... ...