Commit 3894ffb66e232b74144139b3f2f2d6aef8e1b5ee
Exists in
master
and in
5 other branches
Merge branch 'master' of https://github.com/amadeusproject/amadeuslms
Showing
9 changed files
with
92 additions
and
15 deletions
Show diff stats
amadeus/settings.py
... | ... | @@ -79,6 +79,7 @@ TEMPLATES = [ |
79 | 79 | 'django.contrib.messages.context_processors.messages', |
80 | 80 | |
81 | 81 | 'core.context_processors.notifications', |
82 | + 'courses.context_processors.courses', | |
82 | 83 | ], |
83 | 84 | }, |
84 | 85 | }, |
... | ... | @@ -94,8 +95,8 @@ DATABASES = { |
94 | 95 | 'default': { |
95 | 96 | 'ENGINE': 'django.db.backends.postgresql', |
96 | 97 | 'NAME': 'amadeus', |
97 | - 'USER': 'postgres', | |
98 | - 'PASSWORD': 'felipe', | |
98 | + 'USER': 'amadeus_admin', | |
99 | + 'PASSWORD': 'amadeus', | |
99 | 100 | 'HOST': '127.0.0.1', |
100 | 101 | 'PORT': '5432', |
101 | 102 | } | ... | ... |
app/templates/home.html
... | ... | @@ -64,7 +64,7 @@ |
64 | 64 | {% block sidebar %} |
65 | 65 | <div class="panel panel-primary"> |
66 | 66 | <div class="panel-heading"> |
67 | - <img src="{{ user.image.url }}" id="img" class="img-rounded"> | |
67 | + <img src="{{ user.image_url }}" id="img" class="img-rounded"> | |
68 | 68 | <p></p> |
69 | 69 | <div class="row"> |
70 | 70 | <div class="col-xs-3 col-md-3"> |
... | ... | @@ -86,14 +86,24 @@ |
86 | 86 | <li> <a href="{% url 'app:index' %}">{% trans 'Home' %}</a></li> |
87 | 87 | <li> <a href="{% url 'users:profile' %}">{% trans 'Profile' %}</a></li> |
88 | 88 | <li> <a href="#">{% trans 'Pending Tasks' %}</a></li> |
89 | - {% if user|has_role:'student' %} | |
89 | + {% if user|has_role:'student' and not user.is_staff %} | |
90 | 90 | <li> <a href="#">{% trans 'My courses' %}</a></li> |
91 | 91 | {% endif %} |
92 | 92 | {% if user|has_role:'system_admin' %} |
93 | 93 | <li> <a href="{% url 'users:manage' %}">{% trans 'Manage Users' %}</a></li> |
94 | 94 | {% endif %} |
95 | - {% if user|has_role:'system_admin, professor' %} | |
96 | - <li> <a href="{% url 'course:manage' %}">{% trans 'Manage Courses' %}</a></li> | |
95 | + {% if user|has_role:'system_admin' or user|has_role:'professor' %} | |
96 | + <li> | |
97 | + <a href="#courses_list" data-toggle="collapse">{% trans 'Manage Courses' %}</a> | |
98 | + | |
99 | + <div id="courses_list" class="collapse"> | |
100 | + <ul class="nav nav-pill nav-stacked"> | |
101 | + {% for course in courses_list %} | |
102 | + <li><a href="{% url 'course:view' course.slug %}">{{ course }}</a></li> | |
103 | + {% endfor %} | |
104 | + </ul> | |
105 | + </div> | |
106 | + </li> | |
97 | 107 | {% endif %} |
98 | 108 | </ul> |
99 | 109 | </div> | ... | ... |
app/templates/home_teacher_student_content.html
1 | -{% load i18n %} | |
1 | +{% load static i18n %} | |
2 | 2 | |
3 | 3 | {% for notification in objects %} |
4 | 4 | <li {% if not notification.read %}class="not_read"{% endif %}> |
5 | 5 | <div class="avatar"> |
6 | - <img src="{{ notification.user.image.url }}"> | |
6 | + <img src="{{ notification.user.image_url }}"> | |
7 | 7 | </div> |
8 | 8 | <div class="bubble-container"> |
9 | 9 | <div class="bubble"> | ... | ... |
2.99 KB
... | ... | @@ -0,0 +1,14 @@ |
1 | +from .models import Course | |
2 | + | |
3 | +def courses(request): | |
4 | + if request.user.is_authenticated: | |
5 | + context = {} | |
6 | + | |
7 | + if request.user.is_staff: | |
8 | + context['courses_list'] = Course.objects.all() | |
9 | + else: | |
10 | + context['courses_list'] = Course.objects.filter(professors__in = [request.user]) | |
11 | + | |
12 | + return context | |
13 | + else: | |
14 | + return request | |
0 | 15 | \ No newline at end of file | ... | ... |
users/admin.py
1 | 1 | from django.contrib import admin |
2 | 2 | from .models import User |
3 | -from .forms import ProfileForm | |
3 | +from .forms import UserForm | |
4 | 4 | |
5 | 5 | class UserAdmin(admin.ModelAdmin): |
6 | 6 | list_display = ['username', 'name', 'email', 'is_staff', 'is_active'] |
7 | 7 | search_fields = ['username', 'name', 'email'] |
8 | - form = ProfileForm | |
8 | + form = UserForm | |
9 | 9 | |
10 | 10 | admin.site.register(User, UserAdmin) |
11 | 11 | \ No newline at end of file | ... | ... |
users/forms.py
1 | 1 | # coding=utf-8 |
2 | - | |
2 | +import os | |
3 | +from django.conf import settings | |
3 | 4 | from django import forms |
4 | 5 | from django.utils.translation import ugettext_lazy as _ |
6 | +from rolepermissions.shortcuts import assign_role | |
5 | 7 | from .models import User |
6 | 8 | |
7 | 9 | |
... | ... | @@ -25,10 +27,32 @@ class ProfileForm(forms.ModelForm): |
25 | 27 | } |
26 | 28 | |
27 | 29 | class UserForm(forms.ModelForm): |
30 | + def save(self, commit=True): | |
31 | + super(UserForm, self).save(commit=False) | |
32 | + | |
33 | + #if not self.instance.image: | |
34 | + # self.instance.image = os.path.join(os.path.dirname(settings.BASE_DIR), 'uploads', 'no_image.jpg') | |
35 | + | |
36 | + self.instance.set_password(self.cleaned_data['password']) | |
37 | + self.instance.save() | |
38 | + | |
39 | + if self.instance.is_staff: | |
40 | + assign_role(self.instance, 'system_admin') | |
41 | + elif self.instance.type_profile == 2: | |
42 | + assign_role(self.instance, 'student') | |
43 | + elif self.instance.type_profile == 1: | |
44 | + assign_role(self.instance, 'professor') | |
45 | + | |
46 | + self.instance.save() | |
47 | + | |
48 | + return self.instance | |
28 | 49 | |
29 | 50 | class Meta: |
30 | 51 | model = User |
31 | - fields = ['username', 'name', 'email', 'birth_date', 'city', 'state', 'gender', 'type_profile', 'cpf', 'phone', 'image', 'is_staff', 'is_active'] | |
52 | + fields = ['username', 'name', 'email', 'password', 'birth_date', 'city', 'state', 'gender', 'type_profile', 'cpf', 'phone', 'image', 'is_staff', 'is_active'] | |
53 | + widgets = { | |
54 | + 'password':forms.PasswordInput | |
55 | + } | |
32 | 56 | |
33 | 57 | class EditUserForm(forms.ModelForm): |
34 | 58 | ... | ... |
... | ... | @@ -0,0 +1,20 @@ |
1 | +# -*- coding: utf-8 -*- | |
2 | +# Generated by Django 1.10 on 2016-09-16 02:34 | |
3 | +from __future__ import unicode_literals | |
4 | + | |
5 | +from django.db import migrations, models | |
6 | + | |
7 | + | |
8 | +class Migration(migrations.Migration): | |
9 | + | |
10 | + dependencies = [ | |
11 | + ('users', '0012_auto_20160908_1625'), | |
12 | + ] | |
13 | + | |
14 | + operations = [ | |
15 | + migrations.AlterField( | |
16 | + model_name='user', | |
17 | + name='image', | |
18 | + field=models.ImageField(blank=True, upload_to='users/', verbose_name='Image'), | |
19 | + ), | |
20 | + ] | ... | ... |
users/models.py
... | ... | @@ -4,6 +4,7 @@ from django.db import models |
4 | 4 | from django.core import validators |
5 | 5 | from django.utils.translation import ugettext_lazy as _ |
6 | 6 | from django.contrib.auth.models import AbstractBaseUser, UserManager, PermissionsMixin |
7 | +from django.contrib.staticfiles.templatetags.staticfiles import static | |
7 | 8 | |
8 | 9 | class User(AbstractBaseUser, PermissionsMixin): |
9 | 10 | |
... | ... | @@ -19,7 +20,7 @@ class User(AbstractBaseUser, PermissionsMixin): |
19 | 20 | city = models.CharField(_('City'), max_length = 90, blank = True) |
20 | 21 | state = models.CharField(_('State'), max_length = 30, blank = True) |
21 | 22 | gender = models.CharField(_('Gender'), max_length = 1, choices = (('M', _('Male')), ('F', _('Female')))) |
22 | - image = models.ImageField(verbose_name = _('Image'), blank = True, upload_to = 'users/', default = 'no_image.jpg') | |
23 | + image = models.ImageField(verbose_name = _('Image'), blank = True, upload_to = 'users/') | |
23 | 24 | birth_date = models.DateField(_('Birth Date'), null = True, blank = True) |
24 | 25 | phone = models.CharField(_('Phone'), max_length = 30, blank = True) |
25 | 26 | cpf = models.CharField(_('Cpf'), max_length = 15, blank = True) |
... | ... | @@ -40,8 +41,15 @@ class User(AbstractBaseUser, PermissionsMixin): |
40 | 41 | def __str__(self): |
41 | 42 | return self.name or self.username |
42 | 43 | |
43 | - def det_full_name(self): | |
44 | + def get_full_name(self): | |
44 | 45 | return str(self) |
45 | 46 | |
46 | 47 | def get_short_name(self): |
47 | - return str(self).split(" ")[0] | |
48 | 48 | \ No newline at end of file |
49 | + return str(self).split(" ")[0] | |
50 | + | |
51 | + @property | |
52 | + def image_url(self): | |
53 | + if self.image and hasattr(self.image, 'url'): | |
54 | + return self.image.url | |
55 | + else: | |
56 | + return static('img/no_image.jpg') | |
49 | 57 | \ No newline at end of file | ... | ... |