Commit 82bb8a2bbcffacd2c4e488080a13204d48d9c887
Exists in
master
and in
5 other branches
Fixing conflit
Showing
29 changed files
with
539 additions
and
481 deletions
Show diff stats
core/decorators.py
... | ... | @@ -14,7 +14,25 @@ def log_decorator(log_action = '', log_resource = ''): |
14 | 14 | action = Action.objects.filter(name = log_action) |
15 | 15 | resource = Resource.objects.filter(name = log_resource) |
16 | 16 | |
17 | - action_resource = Action_Resource.objects.filter(action = action, resource = resource)[0] | |
17 | + if not action: | |
18 | + action = Action(name = log_action) | |
19 | + action.save() | |
20 | + else: | |
21 | + action = action[0] | |
22 | + | |
23 | + if not resource: | |
24 | + resource = Resource(name = log_resource) | |
25 | + resource.save() | |
26 | + else: | |
27 | + resource = resource[0] | |
28 | + | |
29 | + action_resource = Action_Resource.objects.filter(action = action, resource = resource) | |
30 | + | |
31 | + if not action_resource: | |
32 | + action_resource = Action_Resource(action = action, resource = resource) | |
33 | + action_resource.save() | |
34 | + else: | |
35 | + action_resource = action_resource[0] | |
18 | 36 | |
19 | 37 | log = Log() |
20 | 38 | log.user = request.user |
... | ... | @@ -26,4 +44,4 @@ def log_decorator(log_action = '', log_resource = ''): |
26 | 44 | |
27 | 45 | return wraps(view_function)(_decorator) |
28 | 46 | |
29 | - return _log_decorator | |
30 | 47 | \ No newline at end of file |
48 | + return _log_decorator | ... | ... |
core/forms.py
... | ... | @@ -12,7 +12,7 @@ class RegisterUserForm(forms.ModelForm): |
12 | 12 | def clean_email(self): |
13 | 13 | email = self.cleaned_data['email'] |
14 | 14 | if User.objects.filter(email = email).exists(): |
15 | - raise forms.ValidationError('Já existe um usuário cadastrado com este E-mail') | |
15 | + raise forms.ValidationError('Ja existe um usuario cadastrado com este E-mail') | |
16 | 16 | return email |
17 | 17 | |
18 | 18 | def clean_password(self): |
... | ... | @@ -35,7 +35,7 @@ class RegisterUserForm(forms.ModelForm): |
35 | 35 | password2 = self.cleaned_data.get("password2") |
36 | 36 | |
37 | 37 | if password and password2 and password != password2: |
38 | - raise forms.ValidationError('A confirmacão da senha está incorreta') | |
38 | + raise forms.ValidationError('A confirmacao da senha esta incorreta') | |
39 | 39 | return password2 |
40 | 40 | |
41 | 41 | def save(self, commit=True): | ... | ... |
... | ... | @@ -0,0 +1,28 @@ |
1 | +# -*- coding: utf-8 -*- | |
2 | +# Generated by Django 1.10 on 2016-09-08 14:08 | |
3 | +from __future__ import unicode_literals | |
4 | + | |
5 | +from django.conf import settings | |
6 | +from django.db import migrations, models | |
7 | +import django.db.models.deletion | |
8 | + | |
9 | + | |
10 | +class Migration(migrations.Migration): | |
11 | + | |
12 | + dependencies = [ | |
13 | + migrations.swappable_dependency(settings.AUTH_USER_MODEL), | |
14 | + ('core', '0002_auto_20160907_0038'), | |
15 | + ] | |
16 | + | |
17 | + operations = [ | |
18 | + migrations.AddField( | |
19 | + model_name='notification', | |
20 | + name='actor', | |
21 | + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='notification_Performer', to=settings.AUTH_USER_MODEL, verbose_name='Perfomer'), | |
22 | + ), | |
23 | + migrations.AlterField( | |
24 | + model_name='notification', | |
25 | + name='user', | |
26 | + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='notification_Actor', to=settings.AUTH_USER_MODEL, verbose_name='User'), | |
27 | + ), | |
28 | + ] | ... | ... |
... | ... | @@ -0,0 +1,20 @@ |
1 | +# -*- coding: utf-8 -*- | |
2 | +# Generated by Django 1.10 on 2016-09-08 14:51 | |
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 | + ('core', '0003_auto_20160908_1108'), | |
12 | + ] | |
13 | + | |
14 | + operations = [ | |
15 | + migrations.AlterField( | |
16 | + model_name='resource', | |
17 | + name='name', | |
18 | + field=models.CharField(max_length=100, unique=True, verbose_name='Name'), | |
19 | + ), | |
20 | + ] | ... | ... |
core/mixins.py
1 | 1 | from django.conf import settings |
2 | -from .models import Action, Resource, Action_Resource, Log | |
2 | +from .models import Action, Resource, Action_Resource, Log, Notification | |
3 | 3 | |
4 | 4 | class LogMixin(object): |
5 | 5 | log_action = "" |
... | ... | @@ -9,7 +9,25 @@ class LogMixin(object): |
9 | 9 | action = Action.objects.filter(name = self.log_action) |
10 | 10 | resource = Resource.objects.filter(name = self.log_resource) |
11 | 11 | |
12 | - action_resource = Action_Resource.objects.filter(action = action, resource = resource)[0] | |
12 | + if not action: | |
13 | + action = Action(name = self.log_action) | |
14 | + action.save() | |
15 | + else: | |
16 | + action = action[0] | |
17 | + | |
18 | + if not resource: | |
19 | + resource = Resource(name = self.log_resource) | |
20 | + resource.save() | |
21 | + else: | |
22 | + resource = resource[0] | |
23 | + | |
24 | + action_resource = Action_Resource.objects.filter(action = action, resource = resource) | |
25 | + | |
26 | + if not action_resource: | |
27 | + action_resource = Action_Resource(action = action, resource = resource) | |
28 | + action_resource.save() | |
29 | + else: | |
30 | + action_resource = action_resource[0] | |
13 | 31 | |
14 | 32 | log = Log() |
15 | 33 | log.user = request.user |
... | ... | @@ -17,4 +35,21 @@ class LogMixin(object): |
17 | 35 | |
18 | 36 | log.save() |
19 | 37 | |
20 | - return super(LogMixin, self).dispatch(request, *args, **kwargs) | |
21 | 38 | \ No newline at end of file |
39 | + return super(LogMixin, self).dispatch(request, *args, **kwargs) | |
40 | + | |
41 | +class NotificationMixin(object): | |
42 | + message = "" | |
43 | + read = False | |
44 | + | |
45 | + def dispatch(self, request, *args, **kwargs): | |
46 | + action = Action.objects.filter(name = self.log_action) | |
47 | + resource = Resource.objects.filter(name = self.log_resource) | |
48 | + | |
49 | + action_resource = Action_Resource.objects.filter(action = action, resource = resource)[0] | |
50 | + | |
51 | + notification = Notification() | |
52 | + notification.action_resource = action_resource | |
53 | + notification.user = request.user #We still have to handle the notification to be sent to an amount of Users | |
54 | + | |
55 | + notification.read = read | |
56 | + notification.message = "" | ... | ... |
core/models.py
... | ... | @@ -24,9 +24,14 @@ class Resource(models.Model): |
24 | 24 | """ |
25 | 25 | It represents the resource where the action was applied on. |
26 | 26 | Example: Pool was answered (Resource: Pool), PDF was visualized(Resource: PDF). |
27 | + | |
28 | + Attributes: | |
29 | + @name: name of the resource affected, it will be unique because a resource can be affecte | |
30 | + by a huge amount of actions | |
31 | + @created_date: The date the resource was created | |
27 | 32 | """ |
28 | 33 | |
29 | - name = models.CharField(_('Name'), max_length =100) | |
34 | + name = models.CharField(_('Name'), max_length =100, unique=True) | |
30 | 35 | created_date = models.DateField(_('Created Date'), auto_now_add=True) |
31 | 36 | |
32 | 37 | class Meta: |
... | ... | @@ -51,12 +56,23 @@ class Action_Resource(models.Model): |
51 | 56 | |
52 | 57 | |
53 | 58 | class Notification(models.Model): |
59 | + """ | |
60 | + Attributes: | |
61 | + @message: The message that will be shown on the notification prompt | |
62 | + @user: The User that the notification will be sent to. | |
63 | + @read: Whether or not the user has read the notification. | |
64 | + @datetime: The time the notification was created | |
65 | + @action_resource: The Object that holds the information about which action was perfomed on the Resource | |
66 | + @actor: The user who applied the action | |
67 | + """ | |
68 | + | |
54 | 69 | message = models.TextField(_('Message')) |
55 | - user = models.ForeignKey(User, verbose_name = _('Actor')) | |
70 | + user = models.ForeignKey(User, related_name = _('%(class)s_Actor'), verbose_name= _('User')) | |
56 | 71 | read = models.BooleanField(_('Read'), default = False) |
57 | 72 | datetime = models.DateTimeField(_("Date and Time of action"), auto_now_add = True) |
58 | 73 | action_resource = models.ForeignKey(Action_Resource, verbose_name = _('Action_Resource')) |
59 | - | |
74 | + actor = models.ForeignKey(User, related_name = _('%(class)s_Performer'), verbose_name= _('Perfomer'), null = True) | |
75 | + | |
60 | 76 | class Meta: |
61 | 77 | verbose_name = _("Notification") |
62 | 78 | verbose_name_plural = _("Notifications") | ... | ... |
core/templates/base.html
... | ... | @@ -37,6 +37,7 @@ |
37 | 37 | </head> |
38 | 38 | <body> |
39 | 39 | {% block nav %} |
40 | + <div class="container-fluid"> | |
40 | 41 | <div class="row"> |
41 | 42 | <div class="navbar navbar-default"> |
42 | 43 | <div class="container-fluid"> |
... | ... | @@ -59,9 +60,10 @@ |
59 | 60 | </div> |
60 | 61 | </div> |
61 | 62 | </div> |
63 | + </div> | |
62 | 64 | {% endblock %} |
63 | 65 | |
64 | - <div class="container"> | |
66 | + <div class="container-fluid"> | |
65 | 67 | {% block breadcrumbs %} |
66 | 68 | |
67 | 69 | {% endblock %} | ... | ... |
core/templates/index.html
... | ... | @@ -6,15 +6,17 @@ |
6 | 6 | {% block nav %} |
7 | 7 | {% endblock %} |
8 | 8 | |
9 | +{% block sidebar %} | |
10 | + {% endblock sidebar %} | |
11 | + | |
9 | 12 | {% block content %} |
10 | 13 | <div class="row logo-row"> |
11 | 14 | <div class="col-lg-offset-2 col-lg-9"> |
12 | 15 | <img src="{% static 'img/amadeus.png' %}" class="img-responsive center-block " alt="logo amadeus" id="logo"> |
13 | - </div> | |
14 | 16 | </div> |
15 | 17 | |
16 | 18 | <div class="row "> |
17 | - <div class="col-lg-9 col-lg-offset-2"> | |
19 | + <div class="col-md-8 col-md-offset-2 col-sm-6 col-sm-offset-3"> | |
18 | 20 | <div class="card"> |
19 | 21 | {% if message %} |
20 | 22 | <div class="alert alert-danger fade in"> |
... | ... | @@ -23,7 +25,7 @@ |
23 | 25 | |
24 | 26 | {% endif %} |
25 | 27 | <div class="card-content"> |
26 | - <div class="card-body"> | |
28 | + | |
27 | 29 | <form id="form-login" class="form-group" method="post" action=""> |
28 | 30 | {% csrf_token %} |
29 | 31 | <div class="form-group is-empty"> |
... | ... | @@ -38,7 +40,7 @@ |
38 | 40 | <input form="form-login" type="password" name="password" class="form-control" id="inputPassword" placeholder="Password"> |
39 | 41 | </div> |
40 | 42 | </div> |
41 | - <div class="col-md-offset-2 col-md-10"> | |
43 | + <div class=" col-md-10"> | |
42 | 44 | <div class="checkbox"> |
43 | 45 | <label> |
44 | 46 | <input form="form-login" type="checkbox" name="checkbox"><span class="checkbox-material"><span class="check"></span></span> {% trans 'Remember Email' %} |
... | ... | @@ -46,23 +48,27 @@ |
46 | 48 | </div> |
47 | 49 | </div> |
48 | 50 | </form> |
49 | - </div> | |
51 | + | |
50 | 52 | |
51 | - <footer class="card-footer" style="display: -webkit-box;"> | |
52 | - <div class="col-md-6"> | |
53 | + | |
54 | + <div class="col-md-6 col-xs-6"> | |
53 | 55 | <button type="button" class="btn btn-flat" formaction="#" style="position: initial;">{% trans 'Guest' %}</button> |
54 | 56 | </div> |
55 | - <div class="col-md-6"> | |
57 | + <div class="col-md-6 col-xs-6"> | |
56 | 58 | <button type="submite" class="btn btn-flat btn-success" form="form-login" style="position: initial;">{% trans 'Login' %}</button> |
57 | 59 | </div> |
58 | - </footer> | |
60 | + | |
59 | 61 | </div> |
60 | 62 | </div> |
61 | 63 | </div> |
62 | 64 | </div> |
63 | 65 | <div class="row"> |
64 | - <div class="col-lg-offset-2 col-lg-9"> | |
66 | + <div class="col-lg-offset-2 col-lg-8 col-md-8 col-md-offset-2 col-sm-6 col-sm-offset-3"> | |
65 | 67 | <a class="btn btn-raised btn-primary btn-lg btn-block" href="{% url 'core:register' %}">{% trans 'Sign Up' %} </a> |
66 | 68 | </div> |
67 | 69 | </div> |
68 | 70 | {% endblock%} |
71 | + | |
72 | +{% block rightbar %} | |
73 | + | |
74 | +{% endblock rightbar %} | |
69 | 75 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,28 @@ |
1 | +# -*- coding: utf-8 -*- | |
2 | +# Generated by Django 1.10 on 2016-09-08 16:32 | |
3 | +from __future__ import unicode_literals | |
4 | + | |
5 | +from django.conf import settings | |
6 | +from django.db import migrations, models | |
7 | +import django.db.models.deletion | |
8 | + | |
9 | + | |
10 | +class Migration(migrations.Migration): | |
11 | + | |
12 | + dependencies = [ | |
13 | + migrations.swappable_dependency(settings.AUTH_USER_MODEL), | |
14 | + ('courses', '0007_topic'), | |
15 | + ] | |
16 | + | |
17 | + operations = [ | |
18 | + migrations.AddField( | |
19 | + model_name='subject', | |
20 | + name='professors', | |
21 | + field=models.ManyToManyField(related_name='subjects', to=settings.AUTH_USER_MODEL, verbose_name='Professors'), | |
22 | + ), | |
23 | + migrations.AddField( | |
24 | + model_name='topic', | |
25 | + name='owner', | |
26 | + field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, related_name='topics', to=settings.AUTH_USER_MODEL, verbose_name='Owner'), | |
27 | + ), | |
28 | + ] | ... | ... |
... | ... | @@ -0,0 +1,23 @@ |
1 | +# -*- coding: utf-8 -*- | |
2 | +# Generated by Django 1.10 on 2016-09-08 19:25 | |
3 | +from __future__ import unicode_literals | |
4 | + | |
5 | +from django.db import migrations | |
6 | + | |
7 | + | |
8 | +class Migration(migrations.Migration): | |
9 | + | |
10 | + dependencies = [ | |
11 | + ('courses', '0008_auto_20160908_1332'), | |
12 | + ] | |
13 | + | |
14 | + operations = [ | |
15 | + migrations.AlterModelOptions( | |
16 | + name='subject', | |
17 | + options={'ordering': ('create_date',), 'verbose_name': 'Subject', 'verbose_name_plural': 'Subjects'}, | |
18 | + ), | |
19 | + migrations.AlterModelOptions( | |
20 | + name='topic', | |
21 | + options={'ordering': ('create_date',), 'verbose_name': 'Topic', 'verbose_name_plural': 'Topics'}, | |
22 | + ), | |
23 | + ] | ... | ... |
courses/models.py
... | ... | @@ -49,10 +49,11 @@ class Subject(models.Model): |
49 | 49 | create_date = models.DateTimeField(_('Creation Date'), auto_now_add = True) |
50 | 50 | update_date = models.DateTimeField(_('Date of last update'), auto_now=True) |
51 | 51 | course = models.ForeignKey(Course, verbose_name = _('Course'), related_name="subjects") |
52 | + professors = models.ManyToManyField(User,verbose_name=_('Professors'), related_name='subjects') | |
52 | 53 | |
53 | 54 | |
54 | 55 | class Meta: |
55 | - | |
56 | + ordering = ('create_date',) | |
56 | 57 | verbose_name = _('Subject') |
57 | 58 | verbose_name_plural = _('Subjects') |
58 | 59 | |
... | ... | @@ -67,10 +68,10 @@ class Topic(models.Model): |
67 | 68 | create_date = models.DateTimeField(_('Creation Date'), auto_now_add = True) |
68 | 69 | update_date = models.DateTimeField(_('Date of last update'), auto_now=True) |
69 | 70 | subject = models.ForeignKey(Subject, verbose_name = _('Subject'), related_name="topics") |
70 | - | |
71 | + owner = models.ForeignKey(User, verbose_name = _('Owner'), related_name="topics",default=1) | |
71 | 72 | |
72 | 73 | class Meta: |
73 | - | |
74 | + ordering = ('create_date',) | |
74 | 75 | verbose_name = _('Topic') |
75 | 76 | verbose_name_plural = _('Topics') |
76 | 77 | ... | ... |
courses/templates/module/create.html
... | ... | @@ -1,80 +0,0 @@ |
1 | -{% extends 'app/base.html' %} | |
2 | - | |
3 | -{% load static i18n %} | |
4 | -{% load widget_tweaks %} | |
5 | - | |
6 | -{% block breadcrumbs %} | |
7 | - <ol class="breadcrumb"> | |
8 | - <li><a href="{% url 'app:index' %}">{% trans 'Home' %}</a></li> | |
9 | - <li><a href="{% url 'course:view' course.slug %}">{{ course }}</a></li> | |
10 | - <li class="active">{% trans 'Create Module' %}</li> | |
11 | - </ol> | |
12 | -{% endblock %} | |
13 | - | |
14 | -{% block sidebar %} | |
15 | - <div class="list-group"> | |
16 | - <a href="{% url 'course:manage' %}" class="list-group-item"> | |
17 | - {% trans 'Courses' %} | |
18 | - </a> | |
19 | - <a href="{% url 'course:create' %}" class="list-group-item"> | |
20 | - {% trans 'Create Course' %} | |
21 | - </a> | |
22 | - <a href="{% url 'course:view' course.slug %}" class="list-group-item active"> | |
23 | - {% trans 'Course Info' %} | |
24 | - </a> | |
25 | - <a href="{% url 'course:update' course.slug %}" class="list-group-item"> | |
26 | - {% trans 'Edit Course' %} | |
27 | - </a> | |
28 | - <a href="{% url 'course:manage_mods' course.slug %}" class="list-group-item"> | |
29 | - {% trans 'Manage Modules' %} | |
30 | - </a> | |
31 | - <a href="" class="list-group-item"> | |
32 | - {% trans 'Participants' %} | |
33 | - </a> | |
34 | - <a href="" class="list-group-item"> | |
35 | - {% trans 'Course avaliations' %} | |
36 | - </a> | |
37 | - <a href="" class="list-group-item"> | |
38 | - {% trans 'Duplicate Course' %} | |
39 | - </a> | |
40 | - <a href="" class="list-group-item"> | |
41 | - {% trans 'Delete Course' %} | |
42 | - </a> | |
43 | - </div> | |
44 | - | |
45 | -{% endblock %} | |
46 | - | |
47 | -{% block content %} | |
48 | - <div class="alert alert-info alert-dismissible" role="alert"> | |
49 | - <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
50 | - <span aria-hidden="true">×</span> | |
51 | - </button> | |
52 | - <p>{% trans 'All fields are required' %}</p> | |
53 | - </div> | |
54 | - | |
55 | - <form method="post" action="" enctype="multipart/form-data"> | |
56 | - {% csrf_token %} | |
57 | - {% for field in form %} | |
58 | - <div class="form-group{% if form.has_error %} has-error {% endif %}"> | |
59 | - <label for="{{ field.auto_id }}">{{ field.label }}</label> | |
60 | - {% render_field field class='form-control input-sm' %} | |
61 | - <span id="helpBlock" class="help-block">{{ field.help_text }}</span> | |
62 | - {% if field.errors.length > 0 %} | |
63 | - <div class="alert alert-danger alert-dismissible" role="alert"> | |
64 | - <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
65 | - <span aria-hidden="true">×</span> | |
66 | - </button> | |
67 | - <ul> | |
68 | - {% for error in field.errors %} | |
69 | - <li>{{ error }}</li> | |
70 | - {% endfor %} | |
71 | - </ul> | |
72 | - </div> | |
73 | - </div> | |
74 | - {% endif %} | |
75 | - </div> | |
76 | - {% endfor %} | |
77 | - <input type="submit" value="{% trans 'Save' %}" class="btn btn-sm btn-success" /> | |
78 | - </form> | |
79 | - <br clear="all" /> | |
80 | -{% endblock %} |
courses/templates/module/delete.html
... | ... | @@ -1,53 +0,0 @@ |
1 | -{% extends 'app/base.html' %} | |
2 | - | |
3 | -{% load static i18n %} | |
4 | - | |
5 | -{% block breadcrumbs %} | |
6 | - <ol class="breadcrumb"> | |
7 | - <li><a href="{% url 'app:index' %}">{% trans 'Home' %}</a></li> | |
8 | - <li><a href="{% url 'course:view' course.slug %}">{{ course }}</a></li> | |
9 | - <li class="active">{% trans 'Manage Modules' %}</li> | |
10 | - </ol> | |
11 | -{% endblock %} | |
12 | - | |
13 | -{% block sidebar %} | |
14 | - <div class="list-group"> | |
15 | - <a href="{% url 'course:manage' %}" class="list-group-item"> | |
16 | - {% trans 'Courses' %} | |
17 | - </a> | |
18 | - <a href="{% url 'course:create' %}" class="list-group-item"> | |
19 | - {% trans 'Create Course' %} | |
20 | - </a> | |
21 | - <a href="{% url 'course:view' course.slug %}" class="list-group-item active"> | |
22 | - {% trans 'Course Info' %} | |
23 | - </a> | |
24 | - <a href="{% url 'course:update' course.slug %}" class="list-group-item"> | |
25 | - {% trans 'Edit Course' %} | |
26 | - </a> | |
27 | - <a href="{% url 'course:manage_mods' course.slug %}" class="list-group-item"> | |
28 | - {% trans 'Manage Modules' %} | |
29 | - </a> | |
30 | - <a href="" class="list-group-item"> | |
31 | - {% trans 'Participants' %} | |
32 | - </a> | |
33 | - <a href="" class="list-group-item"> | |
34 | - {% trans 'Course avaliations' %} | |
35 | - </a> | |
36 | - <a href="" class="list-group-item"> | |
37 | - {% trans 'Duplicate Course' %} | |
38 | - </a> | |
39 | - <a href="" class="list-group-item"> | |
40 | - {% trans 'Delete Course' %} | |
41 | - </a> | |
42 | - </div> | |
43 | - | |
44 | -{% endblock %} | |
45 | - | |
46 | -{% block content %} | |
47 | - <form action="" method="post"> | |
48 | - {% csrf_token %} | |
49 | - <p>{% trans 'Are you sure you want to delete the module' %} "{{ object }}"?</p> | |
50 | - <input type="submit" class="btn btn-success btn-sm" value="{% trans 'Yes' %}" /> | |
51 | - <a href="{% url 'course:manage' %}" class="btn btn-danger btn-sm">{% trans 'No' %}</a> | |
52 | - </form> | |
53 | -{% endblock %} |
courses/templates/module/index.html
... | ... | @@ -1,128 +0,0 @@ |
1 | -{% extends 'app/base.html' %} | |
2 | - | |
3 | -{% load static i18n permission_tags %} | |
4 | - | |
5 | -{% block breadcrumbs %} | |
6 | - <ol class="breadcrumb"> | |
7 | - <li><a href="{% url 'app:index' %}">{% trans 'Home' %}</a></li> | |
8 | - <li><a href="{% url 'course:view' course.slug %}">{{ course }}</a></li> | |
9 | - <li class="active">{% trans 'Manage Modules' %}</li> | |
10 | - </ol> | |
11 | -{% endblock %} | |
12 | - | |
13 | -{% block sidebar %} | |
14 | - <div class="list-group"> | |
15 | - <a href="{% url 'course:manage' %}" class="list-group-item"> | |
16 | - {% trans 'Courses' %} | |
17 | - </a> | |
18 | - <a href="{% url 'course:view' course.slug %}" class="list-group-item active"> | |
19 | - {% trans 'Course Info' %} | |
20 | - </a> | |
21 | - <a href="{% url 'course:manage_mods' course.slug %}" class="list-group-item"> | |
22 | - {% trans 'Manage Modules' %} | |
23 | - </a> | |
24 | - {% if user|has_role:'professor, system_admin' %} | |
25 | - <a href="{% url 'course:create' %}" class="list-group-item"> | |
26 | - {% trans 'Create Course' %} | |
27 | - </a> | |
28 | - <a href="{% url 'course:update' course.slug %}" class="list-group-item"> | |
29 | - {% trans 'Edit Course' %} | |
30 | - </a> | |
31 | - <a href="" class="list-group-item"> | |
32 | - {% trans 'Participants' %} | |
33 | - </a> | |
34 | - <a href="" class="list-group-item"> | |
35 | - {% trans 'Course avaliations' %} | |
36 | - </a> | |
37 | - <a href="" class="list-group-item"> | |
38 | - {% trans 'Duplicate Course' %} | |
39 | - </a> | |
40 | - <a href="" class="list-group-item"> | |
41 | - {% trans 'Delete Course' %} | |
42 | - </a> | |
43 | - {% endif %} | |
44 | - </div> | |
45 | - | |
46 | -{% endblock %} | |
47 | - | |
48 | -{% block content %} | |
49 | - {% if messages %} | |
50 | - {% for message in messages %} | |
51 | - <div class="alert alert-success alert-dismissible" role="alert"> | |
52 | - <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
53 | - <span aria-hidden="true">×</span> | |
54 | - </button> | |
55 | - <p>{{ message }}</p> | |
56 | - </div> | |
57 | - {% endfor %} | |
58 | - {% endif %} | |
59 | - | |
60 | - <div class="row well well-inverse"> | |
61 | - <div class="col-md-2"> | |
62 | - <img src="{{ course.image.url }}" class="img-responsive" /> | |
63 | - </div> | |
64 | - <div class="col-md-10"> | |
65 | - <div class="row"> | |
66 | - <div class="col-md-12"> | |
67 | - {% if user|has_role:'professor, system_admin' %} | |
68 | - <div class="pull-right"> | |
69 | - <a href="{% url 'course:create_mods' course.slug %}" class="btn btn-sm btn-success"> | |
70 | - {% trans 'Create Module' %} | |
71 | - </a> | |
72 | - </div> | |
73 | - {% endif %} | |
74 | - <h4> | |
75 | - <a href="{% url 'course:view' course.slug %}"> | |
76 | - {{ course }} | |
77 | - </a> | |
78 | - </h4> | |
79 | - <span class="label label-info">{{ course.category }}</span> | |
80 | - <span class="label label-warning">{{ course.max_students }} {% trans 'students maximum' %}</span> | |
81 | - </div> | |
82 | - <div class="col-md-12"> | |
83 | - <strong>{% trans 'Period:' %} </strong> <em>de</em> <u>{{ course.init_date }}</u> <em>até</em> <u>{{ course.end_date }}</u> | |
84 | - </div> | |
85 | - </div> | |
86 | - </div> | |
87 | - </div> | |
88 | - | |
89 | - {% if modules|length > 0 %} | |
90 | - <div class="panel panel-default"> | |
91 | - <div class="panel-heading"> | |
92 | - <h3 class="panel-title">{% trans 'Modules' %}</h3> | |
93 | - </div> | |
94 | - <div class="panel-body"> | |
95 | - <ul class="list-group"> | |
96 | - {% for module in modules %} | |
97 | - <li class="list-group-item"> | |
98 | - <div class="media"> | |
99 | - <div class="col-sm-10"> | |
100 | - <div class="media-body"> | |
101 | - <h4 class="media-heading">{{ module }}</h4> | |
102 | - <p>{{ module.description|linebreaks }}</p> | |
103 | - </div> | |
104 | - </div> | |
105 | - <div class="col-sm-2" style="padding-top: 10px"> | |
106 | - {% if module.visible %} | |
107 | - <span class="label label-success">{% trans 'Visible' %}</span> | |
108 | - {% else %} | |
109 | - <span class="label label-danger">{% trans 'Invisible' %}</span> | |
110 | - {% endif %} | |
111 | - <a href="{% url 'course:update_mods' course.slug module.slug %}" class="btn btn-sm btn-primary" style="margin-top: 10px"> | |
112 | - <span class="glyphicon glyphicon-edit"></span> | |
113 | - </a> | |
114 | - <a href="{% url 'course:delete_mods' course.slug module.slug %}" class="btn btn-sm btn-danger" style="margin-top: 10px"> | |
115 | - <span class="glyphicon glyphicon-trash"></span> | |
116 | - </a> | |
117 | - </div> | |
118 | - </div> | |
119 | - </li> | |
120 | - {% endfor %} | |
121 | - </ul> | |
122 | - </div> | |
123 | - </div> | |
124 | - {% else %} | |
125 | - {% trans 'No modules found' %} | |
126 | - {% endif %} | |
127 | - | |
128 | -{% endblock %} |
courses/templates/module/update.html
... | ... | @@ -1,80 +0,0 @@ |
1 | -{% extends 'app/base.html' %} | |
2 | - | |
3 | -{% load static i18n %} | |
4 | -{% load widget_tweaks %} | |
5 | - | |
6 | -{% block breadcrumbs %} | |
7 | - <ol class="breadcrumb"> | |
8 | - <li><a href="{% url 'app:index' %}">{% trans 'Home' %}</a></li> | |
9 | - <li><a href="{% url 'course:view' course.slug %}">{{ course }}</a></li> | |
10 | - <li class="active">{% trans 'Edit Module' %}</li> | |
11 | - </ol> | |
12 | -{% endblock %} | |
13 | - | |
14 | -{% block sidebar %} | |
15 | - <div class="list-group"> | |
16 | - <a href="{% url 'course:manage' %}" class="list-group-item"> | |
17 | - {% trans 'Courses' %} | |
18 | - </a> | |
19 | - <a href="{% url 'course:create' %}" class="list-group-item"> | |
20 | - {% trans 'Create Course' %} | |
21 | - </a> | |
22 | - <a href="{% url 'course:view' course.slug %}" class="list-group-item active"> | |
23 | - {% trans 'Course Info' %} | |
24 | - </a> | |
25 | - <a href="{% url 'course:update' course.slug %}" class="list-group-item"> | |
26 | - {% trans 'Edit Course' %} | |
27 | - </a> | |
28 | - <a href="{% url 'course:manage_mods' course.slug %}" class="list-group-item"> | |
29 | - {% trans 'Manage Modules' %} | |
30 | - </a> | |
31 | - <a href="" class="list-group-item"> | |
32 | - {% trans 'Participants' %} | |
33 | - </a> | |
34 | - <a href="" class="list-group-item"> | |
35 | - {% trans 'Course avaliations' %} | |
36 | - </a> | |
37 | - <a href="" class="list-group-item"> | |
38 | - {% trans 'Duplicate Course' %} | |
39 | - </a> | |
40 | - <a href="" class="list-group-item"> | |
41 | - {% trans 'Delete Course' %} | |
42 | - </a> | |
43 | - </div> | |
44 | - | |
45 | -{% endblock %} | |
46 | - | |
47 | -{% block content %} | |
48 | - <div class="alert alert-info alert-dismissible" role="alert"> | |
49 | - <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
50 | - <span aria-hidden="true">×</span> | |
51 | - </button> | |
52 | - <p>{% trans 'All fields are required' %}</p> | |
53 | - </div> | |
54 | - | |
55 | - <form method="post" action="" enctype="multipart/form-data"> | |
56 | - {% csrf_token %} | |
57 | - {% for field in form %} | |
58 | - <div class="form-group{% if form.has_error %} has-error {% endif %}"> | |
59 | - <label for="{{ field.auto_id }}">{{ field.label }}</label> | |
60 | - {% render_field field class='form-control input-sm' %} | |
61 | - <span id="helpBlock" class="help-block">{{ field.help_text }}</span> | |
62 | - {% if field.errors.length > 0 %} | |
63 | - <div class="alert alert-danger alert-dismissible" role="alert"> | |
64 | - <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
65 | - <span aria-hidden="true">×</span> | |
66 | - </button> | |
67 | - <ul> | |
68 | - {% for error in field.errors %} | |
69 | - <li>{{ error }}</li> | |
70 | - {% endfor %} | |
71 | - </ul> | |
72 | - </div> | |
73 | - </div> | |
74 | - {% endif %} | |
75 | - </div> | |
76 | - {% endfor %} | |
77 | - <input type="submit" value="{% trans 'Save' %}" class="btn btn-sm btn-success" /> | |
78 | - </form> | |
79 | - <br clear="all" /> | |
80 | -{% endblock %} |
... | ... | @@ -0,0 +1,25 @@ |
1 | +{% extends 'subject/index.html' %} | |
2 | + | |
3 | +{% load static i18n permission_tags widget_tweaks %} | |
4 | + | |
5 | +{% block content %} | |
6 | + | |
7 | + <div class="panel panel-default"> | |
8 | + <div class="panel-body"> | |
9 | + <form class="form-group " method="post" action=""> | |
10 | + {% csrf_token %} | |
11 | + {% for field in form %} | |
12 | + <div class="form-group {% if field.errors %} has-error{% endif %}"> | |
13 | + <label for="{{ field.auto_id }}" class="control-label label-static"> {{ field.label }}</label> | |
14 | + | |
15 | + {% render_field field class='form-control' placeholder=field.label%} | |
16 | + <span class="help-block">{{ field.help_text }}</span> | |
17 | + </div> | |
18 | + {% endfor %} | |
19 | + <div class="col-lg-offset-4 col-lg-4"> | |
20 | + <button type="submite" class="btn btn-raised btn-primary btn-lg btn-block">{% trans 'Create' %}</button> | |
21 | + </div> | |
22 | + </form> | |
23 | + </div> | |
24 | + </div> | |
25 | +{% endblock content %} | ... | ... |
... | ... | @@ -0,0 +1,18 @@ |
1 | +{% extends 'subject/index.html' %} | |
2 | + | |
3 | +{% load static i18n permission_tags widget_tweaks %} | |
4 | + | |
5 | +{% block content %} | |
6 | + | |
7 | +<div class="panel panel-default"> | |
8 | + <div class="panel-body"> | |
9 | + <form action="" method="post"> | |
10 | + {% csrf_token %} | |
11 | + <h2>{% trans 'Are you sure you want to delete the category' %} "{{subject}}"?</h2> | |
12 | + <input type="submit" class="btn btn-raised btn-success btn-lg" value="{% trans 'Yes' %}" /> | |
13 | + <a href="{% url 'course:view_subject' subject.slug%}" class="btn btn-raised btn-danger btn-lg">{% trans 'No' %}</a> | |
14 | + </form> | |
15 | + </div> | |
16 | +</div> | |
17 | + | |
18 | +{% endblock content %} | ... | ... |
courses/templates/subject/form_view_student.html
courses/templates/subject/form_view_teacher.html
... | ... | @@ -7,11 +7,11 @@ |
7 | 7 | <h3>{{topic}}</h3> |
8 | 8 | </div> |
9 | 9 | <div class="col-md-3 col-sm-3"> |
10 | - <a href="#" class="btn">{% trans "edit" %}</a> | |
10 | + <a href="{% url 'course:update_topic' topic.slug%}" class="btn">{% trans "edit" %}</a> | |
11 | 11 | </div> |
12 | 12 | </div> |
13 | 13 | </div> |
14 | 14 | <div class="panel-body"> |
15 | - <p>{{topic.description}}</p> | |
15 | + <p>{{topic.description|linebreaks}}</p> | |
16 | 16 | </div> |
17 | 17 | </div> | ... | ... |
courses/templates/subject/index.html
... | ... | @@ -24,36 +24,54 @@ |
24 | 24 | <a href="{% url 'course:view_subject' subject.slug%}" class="btn btn-default">{{subject}}</a> |
25 | 25 | {% endfor %} |
26 | 26 | </div> |
27 | - | |
28 | 27 | </div> |
28 | + | |
29 | + {% if user|has_role:'system_admin' or user|has_role:'professor' %} | |
30 | + <a href="{% url 'course:create_subject' course.slug %}" class="btn btn-primary btn-md btn-block">{% trans "Create Subject" %}</a> | |
31 | + {% endif %} | |
29 | 32 | {% endblock %} |
30 | 33 | |
31 | 34 | {% block content %} |
32 | 35 | <div class="panel panel-info"> |
33 | 36 | <div class="panel-heading"> |
34 | - <h3 class="panel-title">{% trans "Presentation Subject" %}</h3> | |
37 | + <div class="row"> | |
38 | + <div class="col-md-7 col-sm-7"> | |
39 | + <h3>{% trans "Presentation Subject" %}</h3> | |
40 | + </div> | |
41 | + <div class="col-md-2 col-sm-2"> | |
42 | + {% if user|has_role:'system_admin' or user in subject.professors %} | |
43 | + <a href="{% url 'course:update_subject' subject.slug%}" class="btn">{% trans "edit" %}</a> | |
44 | + {% endif %} | |
45 | + </div> | |
46 | + <div class="col-md-3 col-sm-3"> | |
47 | + {% if user|has_role:'system_admin' or user in subject.professors %} | |
48 | + <a href="{% url 'course:delete_subject' subject.slug%}" class="btn">{% trans "delete" %}</a> | |
49 | + {% endif %} | |
50 | + </div> | |
51 | + </div> | |
35 | 52 | </div> |
36 | 53 | <div class="panel-body"> |
37 | 54 | <p> |
38 | - {{subject.description}} | |
55 | + {{subject.description|linebreaks}} | |
39 | 56 | </p> |
40 | 57 | </div> |
41 | 58 | </div> |
42 | 59 | {% for topic in topics %} |
43 | - {% if user|has_role:'professor' or user|has_role:'system_admin'%} | |
60 | + {% if user|has_role:'system_admin' or topic.owner == user%} | |
44 | 61 | {% include "subject/form_view_teacher.html" %} |
45 | 62 | {% else %} |
46 | 63 | {% include "subject/form_view_student.html" %} |
47 | 64 | {% endif %} |
48 | 65 | {% endfor %} |
49 | 66 | |
67 | + <a name="create_topic" class="btn btn-primary btn-md btn-block" href="{% url 'course:create_topic' subject.slug %}">{% trans "Create Topic" %}</a> | |
50 | 68 | {% endblock %} |
51 | 69 | |
52 | 70 | {% block rightbar %} |
53 | 71 | |
54 | 72 | <div class="panel panel-warning"> |
55 | 73 | <div class="panel-heading"> |
56 | - <h3 class="panel-title">Pending Stuffs</h3> | |
74 | + <h3 class="panel-title">{% trans "Pending Stuffs" %}</h3> | |
57 | 75 | </div> |
58 | 76 | <div class="panel-body"> |
59 | 77 | ... | ... |
... | ... | @@ -0,0 +1,25 @@ |
1 | +{% extends 'subject/index.html' %} | |
2 | + | |
3 | +{% load static i18n permission_tags widget_tweaks %} | |
4 | + | |
5 | +{% block content %} | |
6 | + | |
7 | + <div class="panel panel-default"> | |
8 | + <div class="panel-body"> | |
9 | + <form class="form-group " method="post" action=""> | |
10 | + {% csrf_token %} | |
11 | + {% for field in form %} | |
12 | + <div class="form-group {% if field.errors %} has-error{% endif %}"> | |
13 | + <label for="{{ field.auto_id }}" class="control-label label-static"> {{ field.label }}</label> | |
14 | + | |
15 | + {% render_field field class='form-control' placeholder=field.label%} | |
16 | + <span class="help-block">{{ field.help_text }}</span> | |
17 | + </div> | |
18 | + {% endfor %} | |
19 | + <div class="col-lg-offset-4 col-lg-4"> | |
20 | + <button type="submite" class="btn btn-raised btn-primary btn-lg btn-block">{% trans 'Update' %}</button> | |
21 | + </div> | |
22 | + </form> | |
23 | + </div> | |
24 | + </div> | |
25 | +{% endblock content %} | ... | ... |
... | ... | @@ -0,0 +1,26 @@ |
1 | +{% extends 'subject/index.html' %} | |
2 | + | |
3 | +{% load static i18n permission_tags widget_tweaks %} | |
4 | + | |
5 | +{% block content %} | |
6 | + | |
7 | + <div class="panel panel-default"> | |
8 | + <div class="panel-body"> | |
9 | + <form class="form-group " method="post" action=""> | |
10 | + {% csrf_token %} | |
11 | + {% for field in form %} | |
12 | + <div class="form-group {% if field.errors %} has-error{% endif %}"> | |
13 | + <label for="{{ field.auto_id }}" class="control-label label-static"> {{ field.label }}</label> | |
14 | + | |
15 | + {% render_field field class='form-control' placeholder=field.label%} | |
16 | + <span class="help-block">{{ field.help_text }}</span> | |
17 | + </div> | |
18 | + {% endfor %} | |
19 | + <div class="col-lg-offset-4 col-lg-4"> | |
20 | + <button type="submite" class="btn btn-raised btn-primary btn-lg btn-block">{% trans 'Create' %}</button> | |
21 | + | |
22 | + </div> | |
23 | + </form> | |
24 | + </div> | |
25 | + </div> | |
26 | +{% endblock content %} | ... | ... |
... | ... | @@ -0,0 +1,27 @@ |
1 | +{% extends 'subject/index.html' %} | |
2 | + | |
3 | +{% load static i18n permission_tags widget_tweaks %} | |
4 | + | |
5 | +{% block content %} | |
6 | + | |
7 | +<div class="panel panel-default"> | |
8 | + <div class="panel-body"> | |
9 | + <form class="form-group " method="post" action=""> | |
10 | + {% csrf_token %} | |
11 | + {% for field in form %} | |
12 | + <div class="form-group {% if field.errors %} has-error{% endif %}"> | |
13 | + <label for="{{ field.auto_id }}" class="control-label label-static"> {{ field.label }}</label> | |
14 | + | |
15 | + {% render_field field class='form-control' placeholder=field.label%} | |
16 | + <span class="help-block">{{ field.help_text }}</span> | |
17 | + </div> | |
18 | + {% endfor %} | |
19 | + <div class="col-lg-offset-4 col-lg-4"> | |
20 | + <button type="submite" class="btn btn-raised btn-primary btn-lg btn-block">{% trans 'Update' %}</button> | |
21 | + | |
22 | + </div> | |
23 | + </form> | |
24 | + </div> | |
25 | +</div> | |
26 | + | |
27 | +{% endblock content %} | ... | ... |
courses/urls.py
... | ... | @@ -14,9 +14,10 @@ urlpatterns = [ |
14 | 14 | url(r'^categories/edit/(?P<slug>[\w_-]+)/$', views.UpdateCatView.as_view(), name='update_cat'), |
15 | 15 | url(r'^categories/(?P<slug>[\w_-]+)/$', views.ViewCat.as_view(), name='view_cat'), |
16 | 16 | url(r'^categories/delete/(?P<slug>[\w_-]+)/$', views.DeleteCatView.as_view(), name='delete_cat'), |
17 | - url(r'^course/(?P<slug>[\w_-]+)/subjects/$', views.SubjectsView.as_view(), name='view_subject'), | |
18 | - # url(r'^course/(?P<slug>[\w_-]+)/modules/create/$', views.CreateModView.as_view(), name='create_mods'), | |
19 | - # url(r'^course/(?P<slug_course>[\w_-]+)/modules/edit/(?P<slug>[\w_-]+)/$', views.UpdateModView.as_view(), name='update_mods'), | |
20 | - # url(r'^course/(?P<slug_course>[\w_-]+)/modules/delete/(?P<slug>[\w_-]+)/$', views.DeleteModView.as_view(), name='delete_mods'), | |
21 | - # url(r'^course/(?P<slug>[\w_-]+)/subject$', views.ViewSubject.as_view(), name='view_subject'), | |
17 | + url(r'^course/subjects/(?P<slug>[\w_-]+)/$', views.SubjectsView.as_view(), name='view_subject'), | |
18 | + url(r'^course/topics/create/(?P<slug>[\w_-]+)/$', views.CreateTopicView.as_view(), name='create_topic'), | |
19 | + url(r'^course/topics/update/(?P<slug>[\w_-]+)/$', views.UpdateTopicView.as_view(), name='update_topic'), | |
20 | + url(r'^course/subjects/create/(?P<slug>[\w_-]+)/$', views.CreateSubjectView.as_view(), name='create_subject'), | |
21 | + url(r'^course/subjects/update/(?P<slug>[\w_-]+)/$', views.UpdateSubjectView.as_view(), name='update_subject'), | |
22 | + url(r'^course/subjects/delete/(?P<slug>[\w_-]+)/$', views.DeleteSubjectView.as_view(), name='delete_subject'), | |
22 | 23 | ] | ... | ... |
courses/views.py
... | ... | @@ -8,9 +8,11 @@ from rolepermissions.mixins import HasRoleMixin |
8 | 8 | from django.core.urlresolvers import reverse_lazy |
9 | 9 | from django.utils.translation import ugettext_lazy as _ |
10 | 10 | from slugify import slugify |
11 | +from rolepermissions.verifications import has_role | |
12 | +from django.db.models import Q | |
11 | 13 | |
12 | -from .forms import CourseForm, CategoryForm, SubjectForm | |
13 | -from .models import Course, Subject, Category | |
14 | +from .forms import CourseForm, CategoryForm, SubjectForm,TopicForm | |
15 | +from .models import Course, Subject, Category,Topic | |
14 | 16 | |
15 | 17 | |
16 | 18 | class IndexView(LoginRequiredMixin, generic.ListView): |
... | ... | @@ -193,116 +195,148 @@ class SubjectsView(LoginRequiredMixin, generic.ListView): |
193 | 195 | template_name = 'subject/index.html' |
194 | 196 | context_object_name = 'subjects' |
195 | 197 | model = Subject |
196 | - # paginate_by = 5 | |
197 | 198 | |
198 | 199 | def get_queryset(self): |
199 | 200 | subject = get_object_or_404(Subject, slug = self.kwargs.get('slug')) |
200 | 201 | course = subject.course |
201 | - return course.subjects.filter(visible=True) | |
202 | + context = course.subjects.filter(visible=True) | |
203 | + if (self.request.user in subject.professors.all() or has_role(self.request.user,'system_admin')): | |
204 | + context = course.subjects.all() | |
205 | + return context | |
202 | 206 | |
203 | 207 | def get_context_data(self, **kwargs): |
204 | - # print ("Deu Certo") | |
205 | 208 | subject = get_object_or_404(Subject, slug = self.kwargs.get('slug')) |
206 | - # print (course) | |
207 | - # print (course.slug) | |
208 | - # print (course.subjects.filter(visible=True)) | |
209 | 209 | context = super(SubjectsView, self).get_context_data(**kwargs) |
210 | 210 | context['course'] = subject.course |
211 | 211 | context['subject'] = subject |
212 | 212 | context['topics'] = subject.topics.all() |
213 | - # print (context) | |
214 | 213 | return context |
215 | 214 | |
216 | -# class CreateSubjectView(LoginRequiredMixin, HasRoleMixin, generic.edit.CreateView): | |
217 | -# | |
218 | -# allowed_roles = ['professor', 'system_admin'] | |
219 | -# login_url = reverse_lazy("core:home") | |
220 | -# redirect_field_name = 'next' | |
221 | -# template_name = 'module/create.html' | |
222 | -# form_class = SubjectForm | |
223 | -# | |
224 | -# def get_success_url(self): | |
225 | -# return reverse_lazy('course:manage_mods', kwargs={'slug' : self.object.course.slug}) | |
226 | -# | |
227 | -# def get_context_data(self, **kwargs): | |
228 | -# course = get_object_or_404(Course, slug = self.kwargs.get('slug')) | |
229 | -# context = super(CreateModView, self).get_context_data(**kwargs) | |
230 | -# context['course'] = course | |
231 | -# | |
232 | -# return context | |
233 | -# | |
234 | -# def form_valid(self, form): | |
235 | -# course = get_object_or_404(Course, slug = self.kwargs.get('slug')) | |
236 | -# | |
237 | -# self.object = form.save(commit = False) | |
238 | -# self.object.slug = slugify(self.object.name) | |
239 | -# self.object.course = course | |
240 | -# self.object.save() | |
241 | -# | |
242 | -# return super(CreateModView, self).form_valid(form) | |
243 | -# | |
244 | -# def render_to_response(self, context, **response_kwargs): | |
245 | -# messages.success(self.request, _('Module created successfully!')) | |
246 | -# | |
247 | -# return self.response_class(request=self.request, template=self.get_template_names(), context=context, using=self.template_engine) | |
248 | -# | |
249 | -# class UpdateModView(LoginRequiredMixin, HasRoleMixin, generic.UpdateView): | |
250 | -# | |
251 | -# allowed_roles = ['professor', 'system_admin'] | |
252 | -# login_url = reverse_lazy("core:home") | |
253 | -# redirect_field_name = 'next' | |
254 | -# template_name = 'module/update.html' | |
255 | -# model = Module | |
256 | -# form_class = ModuleForm | |
257 | -# | |
258 | -# def get_success_url(self): | |
259 | -# return reverse_lazy('course:manage_mods', kwargs={'slug' : self.object.course.slug}) | |
260 | -# | |
261 | -# def get_context_data(self, **kwargs): | |
262 | -# course = get_object_or_404(Course, slug = self.kwargs.get('slug_course')) | |
263 | -# context = super(UpdateModView, self).get_context_data(**kwargs) | |
264 | -# context['course'] = course | |
265 | -# | |
266 | -# return context | |
267 | -# | |
268 | -# def form_valid(self, form): | |
269 | -# self.object = form.save(commit = False) | |
270 | -# self.object.slug = slugify(self.object.name) | |
271 | -# self.object.save() | |
272 | -# | |
273 | -# return super(UpdateModView, self).form_valid(form) | |
274 | -# | |
275 | -# def render_to_response(self, context, **response_kwargs): | |
276 | -# messages.success(self.request, _('Module edited successfully!')) | |
277 | -# | |
278 | -# return self.response_class(request=self.request, template=self.get_template_names(), context=context, using=self.template_engine) | |
279 | -# | |
280 | -# class DeleteModView(LoginRequiredMixin, HasRoleMixin, generic.DeleteView): | |
281 | -# | |
282 | -# allowed_roles = ['professor', 'system_admin'] | |
283 | -# login_url = reverse_lazy("core:home") | |
284 | -# redirect_field_name = 'next' | |
285 | -# model = Module | |
286 | -# template_name = 'module/delete.html' | |
287 | -# | |
288 | -# def get_success_url(self): | |
289 | -# return reverse_lazy('course:manage_mods', kwargs={'slug' : self.object.course.slug}) | |
290 | -# | |
291 | -# def get_context_data(self, **kwargs): | |
292 | -# course = get_object_or_404(Course, slug = self.kwargs.get('slug_course')) | |
293 | -# context = super(DeleteModView, self).get_context_data(**kwargs) | |
294 | -# context['course'] = course | |
295 | -# | |
296 | -# return context | |
297 | -# | |
298 | -# def render_to_response(self, context, **response_kwargs): | |
299 | -# messages.success(self.request, _('Module deleted successfully!')) | |
300 | -# | |
301 | -# return self.response_class(request=self.request, template=self.get_template_names(), context=context, using=self.template_engine) | |
302 | - | |
303 | -# class ViewSubject(LoginRequiredMixin, generic.DetailView): | |
304 | -# login_url = reverse_lazy("core:home") | |
305 | -# redirect_field_name = 'next' | |
306 | -# model = Course | |
307 | -# template_name = 'subject/index.html' | |
308 | -# context_object_name = 'course' | |
215 | +class CreateTopicView(LoginRequiredMixin, HasRoleMixin, generic.edit.CreateView): | |
216 | + | |
217 | + allowed_roles = ['professor', 'system_admin','student'] | |
218 | + login_url = reverse_lazy("core:home") | |
219 | + redirect_field_name = 'next' | |
220 | + template_name = 'topic/create.html' | |
221 | + form_class = TopicForm | |
222 | + | |
223 | + def get_success_url(self): | |
224 | + return reverse_lazy('course:view_subject', kwargs={'slug' : self.object.subject.slug}) | |
225 | + | |
226 | + def get_context_data(self, **kwargs): | |
227 | + context = super(CreateTopicView, self).get_context_data(**kwargs) | |
228 | + subject = get_object_or_404(Subject, slug = self.kwargs.get('slug')) | |
229 | + context['course'] = subject.course | |
230 | + context['subject'] = subject | |
231 | + context['subjects'] = subject.course.subjects.filter(Q(visible=True) | Q(professors__in=[self.request.user])) | |
232 | + if (has_role(self.request.user,'system_admin')): | |
233 | + context['subjects'] = subject.course.subjects.all() | |
234 | + return context | |
235 | + | |
236 | + def form_valid(self, form): | |
237 | + subject = get_object_or_404(Subject, slug = self.kwargs.get('slug')) | |
238 | + | |
239 | + self.object = form.save(commit = False) | |
240 | + self.object.subject = subject | |
241 | + self.object.owner = self.request.user | |
242 | + self.object.save() | |
243 | + | |
244 | + return super(CreateTopicView, self).form_valid(form) | |
245 | + | |
246 | +class UpdateTopicView(LoginRequiredMixin, HasRoleMixin, generic.UpdateView): | |
247 | + | |
248 | + allowed_roles = ['professor', 'system_admin','student'] | |
249 | + login_url = reverse_lazy("core:home") | |
250 | + redirect_field_name = 'next' | |
251 | + template_name = 'topic/update.html' | |
252 | + form_class = TopicForm | |
253 | + | |
254 | + def get_object(self, queryset=None): | |
255 | + return get_object_or_404(Topic, slug = self.kwargs.get('slug')) | |
256 | + | |
257 | + def get_success_url(self): | |
258 | + return reverse_lazy('course:view_subject', kwargs={'slug' : self.object.subject.slug}) | |
259 | + | |
260 | + def get_context_data(self, **kwargs): | |
261 | + context = super(UpdateTopicView, self).get_context_data(**kwargs) | |
262 | + topic = get_object_or_404(Topic, slug = self.kwargs.get('slug')) | |
263 | + context['course'] = topic.subject.course | |
264 | + context['subject'] = topic.subject | |
265 | + context['subjects'] = topic.subject.course.subjects.filter(Q(visible=True) | Q(professors__in=[self.request.user])) | |
266 | + if (has_role(self.request.user,'system_admin')): | |
267 | + context['subjects'] = topic.subject.course.subjects.all() | |
268 | + return context | |
269 | + | |
270 | +class CreateSubjectView(LoginRequiredMixin, HasRoleMixin, generic.edit.CreateView): | |
271 | + | |
272 | + allowed_roles = ['professor', 'system_admin'] | |
273 | + login_url = reverse_lazy("core:home") | |
274 | + redirect_field_name = 'next' | |
275 | + template_name = 'subject/create.html' | |
276 | + form_class = SubjectForm | |
277 | + | |
278 | + def get_success_url(self): | |
279 | + return reverse_lazy('course:view_subject', kwargs={'slug' : self.object.slug}) | |
280 | + | |
281 | + def get_context_data(self, **kwargs): | |
282 | + context = super(CreateSubjectView, self).get_context_data(**kwargs) | |
283 | + course = get_object_or_404(Course, slug = self.kwargs.get('slug')) | |
284 | + context['course'] = course | |
285 | + context['subjects'] = course.subjects.filter(Q(visible=True) | Q(professors__in=[self.request.user])) | |
286 | + if (has_role(self.request.user,'system_admin')): | |
287 | + context['subjects'] = course.subjects.all() | |
288 | + return context | |
289 | + | |
290 | + def form_valid(self, form): | |
291 | + course = get_object_or_404(Course, slug = self.kwargs.get('slug')) | |
292 | + | |
293 | + self.object = form.save(commit = False) | |
294 | + self.object.course = course | |
295 | + self.object.professor = self.request.user | |
296 | + self.object.save() | |
297 | + | |
298 | + return super(CreateSubjectView, self).form_valid(form) | |
299 | + | |
300 | + | |
301 | +class UpdateSubjectView(LoginRequiredMixin, HasRoleMixin, generic.UpdateView): | |
302 | + | |
303 | + allowed_roles = ['professor', 'system_admin'] | |
304 | + login_url = reverse_lazy("core:home") | |
305 | + redirect_field_name = 'next' | |
306 | + template_name = 'subject/update.html' | |
307 | + form_class = SubjectForm | |
308 | + | |
309 | + def get_object(self, queryset=None): | |
310 | + return get_object_or_404(Subject, slug = self.kwargs.get('slug')) | |
311 | + | |
312 | + def get_success_url(self): | |
313 | + return reverse_lazy('course:view_subject', kwargs={'slug' : self.object.slug}) | |
314 | + | |
315 | + def get_context_data(self, **kwargs): | |
316 | + context = super(UpdateSubjectView, self).get_context_data(**kwargs) | |
317 | + context['course'] = self.object.course | |
318 | + context['subject'] = self.object | |
319 | + context['subjects'] = self.object.course.subjects.filter(Q(visible=True) | Q(professors__in=[self.request.user])) | |
320 | + if (has_role(self.request.user,'system_admin')): | |
321 | + context['subjects'] = self.object.course.subjects.all() | |
322 | + return context | |
323 | + | |
324 | +class DeleteSubjectView(LoginRequiredMixin, HasRoleMixin, generic.DeleteView): | |
325 | + | |
326 | + allowed_roles = ['professor', 'system_admin'] | |
327 | + login_url = reverse_lazy("core:home") | |
328 | + redirect_field_name = 'next' | |
329 | + model = Subject | |
330 | + template_name = 'subject/delete.html' | |
331 | + | |
332 | + def get_context_data(self, **kwargs): | |
333 | + context = super(DeleteSubjectView, self).get_context_data(**kwargs) | |
334 | + context['course'] = self.object.course | |
335 | + context['subject'] = self.object | |
336 | + context['subjects'] = self.object.course.subjects.filter(Q(visible=True) | Q(professors__in=[self.request.user])) | |
337 | + if (has_role(self.request.user,'system_admin')): | |
338 | + context['subjects'] = self.object.course.subjects.all() | |
339 | + return context | |
340 | + | |
341 | + def get_success_url(self): | |
342 | + return reverse_lazy('course:view_subject', kwargs={'slug' : self.object.course.subjects.all()[0].slug}) | ... | ... |
logs/log_file_06-09-2016.txt
... | ... | @@ -93,3 +93,8 @@ |
93 | 93 | 06/09/2016 21:34:11 - test - Acessou home |
94 | 94 | 06/09/2016 21:38:44 - test - Entrou no sistema |
95 | 95 | 06/09/2016 21:38:44 - test - Acessou home |
96 | +06/09/2016 21:58:49 - jailson - Entrou no sistema | |
97 | +06/09/2016 21:58:49 - jailson - Acessou home | |
98 | +06/09/2016 21:59:05 - jailson - Acessou home | |
99 | +06/09/2016 21:59:35 - jailson - Acessou home | |
100 | +06/09/2016 21:59:42 - jailson - Acessou home | ... | ... |
... | ... | @@ -0,0 +1,22 @@ |
1 | +# -*- coding: utf-8 -*- | |
2 | +# Generated by Django 1.10 on 2016-09-08 14:08 | |
3 | +from __future__ import unicode_literals | |
4 | + | |
5 | +import django.core.validators | |
6 | +from django.db import migrations, models | |
7 | +import re | |
8 | + | |
9 | + | |
10 | +class Migration(migrations.Migration): | |
11 | + | |
12 | + dependencies = [ | |
13 | + ('users', '0010_auto_20160906_2332'), | |
14 | + ] | |
15 | + | |
16 | + operations = [ | |
17 | + migrations.AlterField( | |
18 | + model_name='user', | |
19 | + name='username', | |
20 | + field=models.CharField(help_text='A short name that will be used to identify you in the platform and to access it', max_length=35, unique=True, validators=[django.core.validators.RegexValidator(re.compile(b'^[\\w.@+-]+$'), 'Type a valid username. This fields should only contain letters, numbers and the characteres: @/./+/-/_ .', b'invalid')], verbose_name='Login'), | |
21 | + ), | |
22 | + ] | ... | ... |
... | ... | @@ -0,0 +1,22 @@ |
1 | +# -*- coding: utf-8 -*- | |
2 | +# Generated by Django 1.10 on 2016-09-08 19:25 | |
3 | +from __future__ import unicode_literals | |
4 | + | |
5 | +import django.core.validators | |
6 | +from django.db import migrations, models | |
7 | +import re | |
8 | + | |
9 | + | |
10 | +class Migration(migrations.Migration): | |
11 | + | |
12 | + dependencies = [ | |
13 | + ('users', '0011_auto_20160908_1108'), | |
14 | + ] | |
15 | + | |
16 | + operations = [ | |
17 | + migrations.AlterField( | |
18 | + model_name='user', | |
19 | + name='username', | |
20 | + field=models.CharField(help_text='A short name that will be used to identify you in the platform and to access it', max_length=35, unique=True, validators=[django.core.validators.RegexValidator(re.compile('^[\\w.@+-]+$', 32), 'Type a valid username. This fields should only contain letters, numbers and the characteres: @/./+/-/_ .', 'invalid')], verbose_name='Login'), | |
21 | + ), | |
22 | + ] | ... | ... |
users/views.py