Commit ad507672d604d5e9bbc1f00d8e7683dd46e5deae
Exists in
master
and in
5 other branches
Fixing conflit
Showing
23 changed files
with
460 additions
and
150 deletions
Show diff stats
amadeus/settings.py
... | ... | @@ -47,6 +47,7 @@ INSTALLED_APPS = [ |
47 | 47 | 'app', |
48 | 48 | 'courses', |
49 | 49 | 'users', |
50 | + 'forum', | |
50 | 51 | ] |
51 | 52 | |
52 | 53 | MIDDLEWARE_CLASSES = [ |
... | ... | @@ -78,8 +79,8 @@ TEMPLATES = [ |
78 | 79 | 'django.contrib.auth.context_processors.auth', |
79 | 80 | 'django.contrib.messages.context_processors.messages', |
80 | 81 | |
81 | - # 'core.context_processors.notifications', | |
82 | - # 'courses.context_processors.courses', | |
82 | + 'core.context_processors.notifications', | |
83 | + 'courses.context_processors.courses', | |
83 | 84 | ], |
84 | 85 | }, |
85 | 86 | }, | ... | ... |
amadeus/urls.py
... | ... | @@ -23,6 +23,7 @@ urlpatterns = [ |
23 | 23 | url(r'^home/', include('app.urls', namespace = 'app')), |
24 | 24 | url(r'^course/', include('courses.urls', namespace = 'course')), |
25 | 25 | url(r'^users/', include('users.urls', namespace = 'users')), |
26 | + url(r'^forum/', include('forum.urls', namespace = 'forum')), | |
26 | 27 | url(r'^admin/', admin.site.urls), |
27 | 28 | url(r'^', include('core.urls', namespace = 'core')), |
28 | 29 | ] | ... | ... |
app/views.py
... | ... | @@ -42,7 +42,7 @@ class AppIndex(LoginRequiredMixin, LogMixin, ListView, NotificationMixin): |
42 | 42 | else: |
43 | 43 | self.template_name = "home_teacher_student_content.html" |
44 | 44 | |
45 | - #super(AppIndex, self).createNotification("testando notificacao de login", resource_name="home", resource_link="/") | |
45 | + super(AppIndex, self).createNotification("testando notificacao de login", resource_name="home", resource_link="/") | |
46 | 46 | return self.response_class(request = self.request, template = self.template_name, context = context, using = self.template_engine, **response_kwargs) |
47 | 47 | |
48 | 48 | ... | ... |
core/context_processors.py
... | ... | @@ -3,9 +3,8 @@ from .models import Notification |
3 | 3 | def notifications(request): |
4 | 4 | context = {} |
5 | 5 | context['notifications'] = None |
6 | - if not request.user is None: | |
7 | - if request.user.is_authenticated: | |
8 | - return { | |
9 | - 'notifications': Notification.objects.filter(user= request.user, read=False).order_by('-datetime') | |
10 | - } | |
6 | + if request.user.is_authenticated: | |
7 | + return { | |
8 | + 'notifications': Notification.objects.filter(user= request.user, read=False).order_by('-datetime') | |
9 | + } | |
11 | 10 | return context | ... | ... |
... | ... | @@ -0,0 +1,50 @@ |
1 | +# -*- coding: utf-8 -*- | |
2 | +# Generated by Django 1.10 on 2016-09-20 21:15 | |
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 | + initial = True | |
13 | + | |
14 | + dependencies = [ | |
15 | + ('core', '0001_initial'), | |
16 | + migrations.swappable_dependency(settings.AUTH_USER_MODEL), | |
17 | + ] | |
18 | + | |
19 | + operations = [ | |
20 | + migrations.AddField( | |
21 | + model_name='notification', | |
22 | + name='actor', | |
23 | + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='notification_Performer', to=settings.AUTH_USER_MODEL, verbose_name='Perfomer'), | |
24 | + ), | |
25 | + migrations.AddField( | |
26 | + model_name='notification', | |
27 | + name='user', | |
28 | + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='notification_Actor', to=settings.AUTH_USER_MODEL, verbose_name='User'), | |
29 | + ), | |
30 | + migrations.AddField( | |
31 | + model_name='log', | |
32 | + name='action_resource', | |
33 | + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.Action_Resource', verbose_name='Action_Resource'), | |
34 | + ), | |
35 | + migrations.AddField( | |
36 | + model_name='log', | |
37 | + name='user', | |
38 | + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='Actor'), | |
39 | + ), | |
40 | + migrations.AddField( | |
41 | + model_name='action_resource', | |
42 | + name='action', | |
43 | + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.Action', verbose_name='Action_Applied'), | |
44 | + ), | |
45 | + migrations.AddField( | |
46 | + model_name='action_resource', | |
47 | + name='resource', | |
48 | + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.Resource', verbose_name='Resource'), | |
49 | + ), | |
50 | + ] | ... | ... |
core/static/css/base/amadeus.css
courses/migrations/0001_initial.py
... | ... | @@ -34,8 +34,8 @@ class Migration(migrations.Migration): |
34 | 34 | ('create_date', models.DateField(auto_now_add=True, verbose_name='Creation Date')), |
35 | 35 | ], |
36 | 36 | options={ |
37 | - 'verbose_name': 'Category', | |
38 | 37 | 'verbose_name_plural': 'Categories', |
38 | + 'verbose_name': 'Category', | |
39 | 39 | }, |
40 | 40 | ), |
41 | 41 | migrations.CreateModel( |
... | ... | @@ -55,9 +55,15 @@ class Migration(migrations.Migration): |
55 | 55 | ('image', models.ImageField(blank=True, upload_to='courses/', verbose_name='Image')), |
56 | 56 | ], |
57 | 57 | options={ |
58 | +<<<<<<< HEAD | |
58 | 59 | 'ordering': ('create_date', 'name'), |
59 | 60 | 'verbose_name': 'Course', |
60 | 61 | 'verbose_name_plural': 'Courses', |
62 | +======= | |
63 | + 'verbose_name_plural': 'Courses', | |
64 | + 'verbose_name': 'Course', | |
65 | + 'ordering': ('create_date', 'name'), | |
66 | +>>>>>>> 21b49d36360d4f362742aa6527193cb3e0270c36 | |
61 | 67 | }, |
62 | 68 | ), |
63 | 69 | migrations.CreateModel( |
... | ... | @@ -82,9 +88,15 @@ class Migration(migrations.Migration): |
82 | 88 | ('update_date', models.DateTimeField(auto_now=True, verbose_name='Date of last update')), |
83 | 89 | ], |
84 | 90 | options={ |
91 | +<<<<<<< HEAD | |
85 | 92 | 'ordering': ('create_date', 'name'), |
86 | 93 | 'verbose_name': 'Subject', |
87 | 94 | 'verbose_name_plural': 'Subjects', |
95 | +======= | |
96 | + 'verbose_name_plural': 'Subjects', | |
97 | + 'verbose_name': 'Subject', | |
98 | + 'ordering': ('create_date', 'name'), | |
99 | +>>>>>>> 21b49d36360d4f362742aa6527193cb3e0270c36 | |
88 | 100 | }, |
89 | 101 | ), |
90 | 102 | migrations.CreateModel( |
... | ... | @@ -99,9 +111,15 @@ class Migration(migrations.Migration): |
99 | 111 | ('visible', models.BooleanField(default=False, verbose_name='Visible')), |
100 | 112 | ], |
101 | 113 | options={ |
114 | +<<<<<<< HEAD | |
102 | 115 | 'ordering': ('create_date', 'name'), |
103 | 116 | 'verbose_name': 'Topic', |
104 | 117 | 'verbose_name_plural': 'Topics', |
118 | +======= | |
119 | + 'verbose_name_plural': 'Topics', | |
120 | + 'verbose_name': 'Topic', | |
121 | + 'ordering': ('create_date', 'name'), | |
122 | +>>>>>>> 21b49d36360d4f362742aa6527193cb3e0270c36 | |
105 | 123 | }, |
106 | 124 | ), |
107 | 125 | ] | ... | ... |
... | ... | @@ -0,0 +1,75 @@ |
1 | +# -*- coding: utf-8 -*- | |
2 | +# Generated by Django 1.10 on 2016-09-20 21:15 | |
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 | + initial = True | |
13 | + | |
14 | + dependencies = [ | |
15 | + ('courses', '0001_initial'), | |
16 | + migrations.swappable_dependency(settings.AUTH_USER_MODEL), | |
17 | + ] | |
18 | + | |
19 | + operations = [ | |
20 | + migrations.AddField( | |
21 | + model_name='topic', | |
22 | + name='owner', | |
23 | + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='Owner'), | |
24 | + ), | |
25 | + migrations.AddField( | |
26 | + model_name='topic', | |
27 | + name='subject', | |
28 | + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='courses.Subject', verbose_name='Subject'), | |
29 | + ), | |
30 | + migrations.AddField( | |
31 | + model_name='subject', | |
32 | + name='course', | |
33 | + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='subjects', to='courses.Course', verbose_name='Course'), | |
34 | + ), | |
35 | + migrations.AddField( | |
36 | + model_name='subject', | |
37 | + name='professors', | |
38 | + field=models.ManyToManyField(related_name='subjects', to=settings.AUTH_USER_MODEL, verbose_name='Professors'), | |
39 | + ), | |
40 | + migrations.AddField( | |
41 | + model_name='material', | |
42 | + name='student', | |
43 | + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='student'), | |
44 | + ), | |
45 | + migrations.AddField( | |
46 | + model_name='material', | |
47 | + name='topic', | |
48 | + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='courses.Topic', verbose_name='Topic'), | |
49 | + ), | |
50 | + migrations.AddField( | |
51 | + model_name='course', | |
52 | + name='category', | |
53 | + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='courses.Category', verbose_name='Category'), | |
54 | + ), | |
55 | + migrations.AddField( | |
56 | + model_name='course', | |
57 | + name='professors', | |
58 | + field=models.ManyToManyField(related_name='courses', to=settings.AUTH_USER_MODEL, verbose_name='Professors'), | |
59 | + ), | |
60 | + migrations.AddField( | |
61 | + model_name='course', | |
62 | + name='students', | |
63 | + field=models.ManyToManyField(related_name='courses_student', to=settings.AUTH_USER_MODEL, verbose_name='Students'), | |
64 | + ), | |
65 | + migrations.AddField( | |
66 | + model_name='activity', | |
67 | + name='student', | |
68 | + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='student'), | |
69 | + ), | |
70 | + migrations.AddField( | |
71 | + model_name='activity', | |
72 | + name='topic', | |
73 | + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='courses.Topic', verbose_name='Topic'), | |
74 | + ), | |
75 | + ] | ... | ... |
courses/templates/course/view.html
... | ... | @@ -17,7 +17,7 @@ |
17 | 17 | {% block sidebar %} |
18 | 18 | <div class="panel panel-primary"> |
19 | 19 | <div class="panel-heading"> |
20 | - <img src="{{ user.image.url }}" id="img" class="img-circle img-responsive"> | |
20 | + <img src="{{ user.image_url }}" id="img" class="img-circle img-responsive"> | |
21 | 21 | </br> |
22 | 22 | <div class="row"> |
23 | 23 | <div class="col-xs-3 col-md-3"> | ... | ... |
courses/templates/subject/form_view_student.html
1 | 1 | {% load i18n %} |
2 | 2 | |
3 | 3 | <div class="panel panel-default"> |
4 | - <a href="{% url 'course:view_topic' topic.slug %}"> | |
5 | - <div class="panel-heading"> | |
6 | - <div class="row"> | |
7 | - <div class="col-md-9 col-sm-9"> | |
8 | - <h3>{{topic}}</h3> | |
9 | - </div> | |
10 | - </div> | |
11 | - </div> | |
12 | - </a> | |
13 | - </div> | |
14 | - | |
15 | - <div class="panel-body"> | |
16 | - <p>{{topic.description|linebreaks}}</p> | |
17 | - </div> | |
4 | + <a href="{% url 'course:view_topic' topic.slug %}"> | |
5 | + <div class="panel-heading"> | |
6 | + <div class="row"> | |
7 | + <div class="col-md-9 col-sm-9"> | |
8 | + <h3>{{topic}}</h3> | |
9 | + </div> | |
10 | + </div> | |
11 | + </div> | |
12 | + </a> | |
18 | 13 | </div> |
14 | +<div class="panel-body"> | |
15 | + <p>{{topic.description|linebreaks}}</p> | |
16 | +</div> | |
19 | 17 | \ No newline at end of file | ... | ... |
courses/templates/subject/form_view_teacher.html
1 | -{% load i18n %} | |
1 | +{% load static i18n %} | |
2 | + | |
3 | +{% block javascript %} | |
4 | + <script type="text/javascript"> | |
5 | + var baseUrl = '{% url "forum:index" %}'; | |
6 | + var formUrl = '{% url "forum:create" %}'; | |
7 | + | |
8 | + function showForum(topic) { | |
9 | + $.ajax({ | |
10 | + url: baseUrl, | |
11 | + data: {'topic': topic}, | |
12 | + success: function(data) { | |
13 | + $(".forum_topics").html(data); | |
14 | + } | |
15 | + }); | |
16 | + | |
17 | + $('#forumModal').modal(); | |
18 | + } | |
19 | + | |
20 | + function getForm() { | |
21 | + $.ajax({ | |
22 | + url: formUrl, | |
23 | + success: function(data) { | |
24 | + $(".forum_form").html(data); | |
25 | + } | |
26 | + }); | |
27 | + | |
28 | + $(".forum_form").show(); | |
29 | + } | |
30 | + </script> | |
31 | +{% endblock %} | |
2 | 32 | |
3 | 33 | <div class="panel panel-default"> |
4 | - <a href="{% url 'course:view_topic' topic.slug %}"> | |
5 | - <div class="panel-heading"> | |
6 | - <div class="row"> | |
7 | - <div class="col-md-9 col-sm-9"> | |
8 | - <h3>{{topic}}</h3> | |
9 | - </div> | |
10 | - <div class="col-md-3 col-sm-3"> | |
11 | - <a href="{% url 'course:update_topic' topic.slug%}" class="btn">{% trans "edit" %}</a> | |
12 | - </div> | |
34 | + <a href="{% url 'course:view_topic' topic.slug %}"> | |
35 | + <div class="panel-heading"> | |
36 | + <div class="row"> | |
37 | + <div class="col-md-9 col-sm-9"> | |
38 | + <h3>{{topic}}</h3> | |
39 | + </div> | |
40 | + <div class="col-md-3 col-sm-3"> | |
41 | + <a href="{% url 'course:update_topic' topic.slug%}" class="btn">{% trans "edit" %}</a> | |
42 | + </div> | |
43 | + </div> | |
44 | + </div> | |
45 | + </a> | |
46 | + <div class="panel-body"> | |
47 | + <p>{{topic.description|linebreaks}}</p> | |
48 | + <a href="javascript:showForum('{{topic.slug}}')">Forum</a> | |
13 | 49 | </div> |
14 | - </div> | |
15 | - </a> | |
16 | - <div class="panel-body"> | |
17 | - <p>{{topic.description|linebreaks}}</p> | |
18 | - </div> | |
19 | 50 | </div> |
51 | + | |
52 | +<div class="modal fade" id="forumModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> | |
53 | + <div class="modal-dialog" role="document"> | |
54 | + <div class="modal-content"> | |
55 | + <div class="modal-header"> | |
56 | + <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> | |
57 | + <h4 class="modal-title" id="myModalLabel"> | |
58 | + <button type="button" class="btn btn-primary btn-sm" onclick="getForm();"><i class="fa fa-plus"></i> {% trans 'Create Forum' %}</button> | |
59 | + </h4> | |
60 | + </div> | |
61 | + <div class="modal-body"> | |
62 | + <div class="forum_form" style="display:none"> | |
63 | + </div> | |
64 | + <div class="forum_topics"> | |
65 | + </div> | |
66 | + </div> | |
67 | + </div> | |
68 | + </div> | |
69 | +</div> | |
20 | 70 | \ No newline at end of file | ... | ... |
courses/templates/subject/index.html
... | ... | @@ -41,37 +41,39 @@ |
41 | 41 | {% endblock %} |
42 | 42 | |
43 | 43 | {% block content %} |
44 | - <div class="panel panel-info"> | |
45 | - <div class="panel-heading"> | |
44 | + <div class="panel panel-info"> | |
45 | + <div class="panel-heading"> | |
46 | 46 | <div class="row"> |
47 | - <div class="col-md-7 col-sm-7"> | |
48 | - <h3>{{subject}}</h3> | |
49 | - </div> | |
50 | - <div class="col-md-2 col-sm-2"> | |
47 | + <div class="col-md-7 col-sm-7"> | |
48 | + <h3>{{subject}}</h3> | |
49 | + </div> | |
50 | + <div class="col-md-2 col-sm-2"> | |
51 | 51 | {% if user|has_role:'system_admin' or user in subject.professors %} |
52 | - <a href="{% url 'course:update_subject' subject.slug%}" class="btn">{% trans "edit" %}</a> | |
52 | + <a href="{% url 'course:update_subject' subject.slug%}" class="btn">{% trans "edit" %}</a> | |
53 | 53 | {% endif %} |
54 | - </div> | |
54 | + </div> | |
55 | 55 | <div class="col-md-3 col-sm-3"> |
56 | 56 | {% if user|has_role:'system_admin' or user in subject.professors %} |
57 | - <a href="{% url 'course:delete_subject' subject.slug%}" class="btn">{% trans "delete" %}</a> | |
57 | + <a href="{% url 'course:delete_subject' subject.slug%}" class="btn">{% trans "delete" %}</a> | |
58 | 58 | {% endif %} |
59 | - </div> | |
60 | - </div> | |
61 | - </div> | |
62 | - <div class="panel-body"> | |
63 | - <p> | |
64 | - {{subject.description|linebreaks}} | |
65 | - </p> | |
66 | - </div> | |
67 | - </div> | |
68 | -{% for topic in topics %} | |
69 | - {% if user|has_role:'system_admin' or topic.owner == user%} | |
70 | - {% include "subject/form_view_teacher.html" %} | |
71 | - {% else %} | |
72 | - {% include "subject/form_view_student.html" %} | |
73 | - {% endif %} | |
74 | -{% endfor %} | |
59 | + </div> | |
60 | + </div> | |
61 | + </div> | |
62 | + <div class="panel-body"> | |
63 | + <p> | |
64 | + {{subject.description|linebreaks}} | |
65 | + </p> | |
66 | + </div> | |
67 | + </div> | |
68 | + | |
69 | + {% for topic in topics %} | |
70 | + {% if user|has_role:'system_admin' or topic.owner == user%} | |
71 | + {% include "subject/form_view_teacher.html" %} | |
72 | + {% else %} | |
73 | + {% include "subject/form_view_student.html" %} | |
74 | + {% endif %} | |
75 | + {% endfor %} | |
76 | + | |
75 | 77 | {% if user|has_role:'system_admin' or topic.owner == user%} |
76 | 78 | <a name="create_topic" class="btn btn-primary btn-md btn-block" href="{% url 'course:create_topic' subject.slug %}">{% trans "Create Topic" %}</a> |
77 | 79 | {% endif %} | ... | ... |
courses/urls.py
... | ... | @@ -9,7 +9,7 @@ urlpatterns = [ |
9 | 9 | url(r'^(?P<slug>[\w_-]+)/$', views.CourseView.as_view(), name='view'), |
10 | 10 | url(r'^delete/(?P<slug>[\w_-]+)/$', views.DeleteCourseView.as_view(), name='delete'), |
11 | 11 | url(r'^category/(?P<slug>[\w_-]+)/$', views.FilteredView.as_view(), name='filter'), |
12 | - url(r'^categories/$', views.IndexCatView.as_view(), name='manage_cat'), | |
12 | + url(r'^categories/view/view/$', views.IndexCatView.as_view(), name='manage_cat'), | |
13 | 13 | url(r'^categories/create/$', views.CreateCatView.as_view(), name="create_cat"), |
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'), | ... | ... |
courses/views.py
... | ... | @@ -7,7 +7,6 @@ from django.contrib.auth.mixins import LoginRequiredMixin |
7 | 7 | 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 | -from slugify import slugify | |
11 | 10 | from rolepermissions.verifications import has_role |
12 | 11 | from django.db.models import Q |
13 | 12 | from rolepermissions.verifications import has_object_permission |
... | ... | @@ -31,7 +30,7 @@ class IndexView(LoginRequiredMixin, NotificationMixin, generic.ListView): |
31 | 30 | def get_context_data(self, **kwargs): |
32 | 31 | context = super(IndexView, self).get_context_data(**kwargs) |
33 | 32 | context['categories'] = Category.objects.all() |
34 | - super.createNotification(users= User.obejcts.all(), message="testando a notificacao em login") | |
33 | + # super.createNotification(users= User.obejcts.all(), message="testando a notificacao em login") | |
35 | 34 | return context |
36 | 35 | |
37 | 36 | class CreateCourseView(LoginRequiredMixin, HasRoleMixin, NotificationMixin,generic.edit.CreateView): |
... | ... | @@ -44,21 +43,12 @@ class CreateCourseView(LoginRequiredMixin, HasRoleMixin, NotificationMixin,gener |
44 | 43 | success_url = reverse_lazy('course:manage') |
45 | 44 | |
46 | 45 | def form_valid(self, form): |
47 | - self.object = form.save(commit = False) | |
48 | - self.object.slug = slugify(self.object.name) | |
49 | - self.object.save() | |
50 | - messages.success(self.request, _('Course created successfully!')) | |
51 | - | |
52 | - def form_invalid(self, form): | |
53 | - print(form) | |
54 | - return self.render_to_response(self.get_context_data(form=form)) | |
55 | - | |
56 | - def render_to_responssse(self, context, **response_kwargs): | |
57 | - return self.response_class(request=self.request, template=self.get_template_names(), context=context, using=self.template_engine) | |
46 | + self.object = form.save() | |
47 | + self.object.professors.add(self.request.user) | |
48 | + return super(CreateCourseView, self).form_valid(form) | |
58 | 49 | |
59 | 50 | def get_context_data(self, **kwargs): |
60 | 51 | context = super(CreateCourseView, self).get_context_data(**kwargs) |
61 | - | |
62 | 52 | if has_role(self.request.user,'system_admin'): |
63 | 53 | courses = Course.objects.all() |
64 | 54 | elif has_role(self.request.user,'professor'): |
... | ... | @@ -140,6 +130,8 @@ class CourseView(LoginRequiredMixin, NotificationMixin, generic.DetailView): |
140 | 130 | template_name = 'course/view.html' |
141 | 131 | |
142 | 132 | def get_context_data(self, **kwargs): |
133 | + subjects = None | |
134 | + courses = None | |
143 | 135 | context = super(CourseView, self).get_context_data(**kwargs) |
144 | 136 | course = get_object_or_404(Course, slug = self.kwargs.get('slug')) |
145 | 137 | if has_role(self.request.user,'system_admin'): |
... | ... | @@ -213,13 +205,6 @@ class CreateCatView(LoginRequiredMixin, HasRoleMixin, generic.edit.CreateView): |
213 | 205 | form_class = CategoryForm |
214 | 206 | success_url = reverse_lazy('course:manage_cat') |
215 | 207 | |
216 | - def form_valid(self, form): | |
217 | - self.object = form.save(commit = False) | |
218 | - self.object.slug = slugify(self.object.name) | |
219 | - self.object.save() | |
220 | - | |
221 | - return super(CreateCatView, self).form_valid(form) | |
222 | - | |
223 | 208 | def render_to_response(self, context, **response_kwargs): |
224 | 209 | messages.success(self.request, _('Category created successfully!')) |
225 | 210 | |
... | ... | @@ -235,13 +220,6 @@ class UpdateCatView(LoginRequiredMixin, HasRoleMixin, generic.UpdateView): |
235 | 220 | form_class = CategoryForm |
236 | 221 | success_url = reverse_lazy('course:manage_cat') |
237 | 222 | |
238 | - def form_valid(self, form): | |
239 | - self.object = form.save(commit = False) | |
240 | - self.object.slug = slugify(self.object.name) | |
241 | - self.object.save() | |
242 | - | |
243 | - return super(UpdateCatView, self).form_valid(form) | |
244 | - | |
245 | 223 | def render_to_response(self, context, **response_kwargs): |
246 | 224 | messages.success(self.request, _('Category edited successfully!')) |
247 | 225 | |
... | ... | @@ -289,7 +267,7 @@ class SubjectsView(LoginRequiredMixin, generic.ListView): |
289 | 267 | context = super(SubjectsView, self).get_context_data(**kwargs) |
290 | 268 | context['course'] = subject.course |
291 | 269 | context['subject'] = subject |
292 | - context['topics'] = subject.topics.all() | |
270 | + context['topics'] = Topic.objects.filter(subject = subject) | |
293 | 271 | return context |
294 | 272 | |
295 | 273 | class TopicsView(LoginRequiredMixin, generic.ListView): |
... | ... | @@ -303,7 +281,7 @@ class TopicsView(LoginRequiredMixin, generic.ListView): |
303 | 281 | def get_queryset(self): |
304 | 282 | topic = get_object_or_404(Topic, slug = self.kwargs.get('slug')) |
305 | 283 | subject = topic.subject |
306 | - context = subject.topics.filter(visible=True) | |
284 | + context = Topic.objects.filter(subject = subject, visible=True) | |
307 | 285 | #if (self.request.user in subject.professors.all() or has_role(self.request.user,'system_admin')): |
308 | 286 | #context = subject.topics.all() <- Change it By Activities |
309 | 287 | return context | ... | ... |
... | ... | @@ -0,0 +1,20 @@ |
1 | +from django import forms | |
2 | +from django.utils.translation import ugettext_lazy as _ | |
3 | +from .models import Forum | |
4 | + | |
5 | +class ForumForm(forms.ModelForm): | |
6 | + | |
7 | + class Meta: | |
8 | + model = Forum | |
9 | + fields = ('title', 'description') | |
10 | + labels = { | |
11 | + 'title': _('Title'), | |
12 | + 'description': _('Description') | |
13 | + } | |
14 | + help_texts = { | |
15 | + 'title': _('Forum title'), | |
16 | + 'description': _('What is this forum about?') | |
17 | + } | |
18 | + widgets = { | |
19 | + 'description': forms.Textarea(attrs={'cols': 80, 'rows': 5}), | |
20 | + } | |
0 | 21 | \ No newline at end of file | ... | ... |
forum/models.py
... | ... | @@ -13,11 +13,11 @@ It works like a 'topic' of forum, which users can post to it and answer posts of |
13 | 13 | class Forum(Activity): |
14 | 14 | title = models.CharField(_('Title'), max_length = 100) |
15 | 15 | description = models.TextField(_('Description'), blank = True) |
16 | - create_date = models.DateTimeField(_('Create Date'), auto_now_add = True) | |
17 | 16 | |
18 | 17 | class Meta: |
19 | 18 | verbose_name = _('Forum') |
20 | 19 | verbose_name_plural = _('Foruns') |
20 | + app_label = 'forum' | |
21 | 21 | |
22 | 22 | def __str__(self): |
23 | 23 | return self.title |
... | ... | @@ -33,6 +33,7 @@ class Post(models.Model): |
33 | 33 | class Meta: |
34 | 34 | verbose_name = _('Post') |
35 | 35 | verbose_name_plural = _('Posts') |
36 | + app_label = 'forum' | |
36 | 37 | |
37 | 38 | def __str__(self): |
38 | 39 | return ''.join([self.user.name, " / ", self.post_date]) |
... | ... | @@ -49,6 +50,7 @@ class PostAnswer(models.Model): |
49 | 50 | class Meta: |
50 | 51 | verbose_name = _('Post Answer') |
51 | 52 | verbose_name_plural = _('Post Answers') |
53 | + app_label = 'forum' | |
52 | 54 | |
53 | 55 | def __str__(self): |
54 | 56 | return ''.join([self.user.name, " / ", self.answer_date]) |
55 | 57 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,30 @@ |
1 | +{% load static i18n %} | |
2 | +{% load widget_tweaks %} | |
3 | + | |
4 | +<form method="post" action="" enctype="multipart/form-data"> | |
5 | + {% csrf_token %} | |
6 | + {% for field in form %} | |
7 | + <div class="form-group {% if form.has_error %} has-error {% endif %} is-fileinput"> | |
8 | + <label for="{{ field.auto_id }}">{{ field.label }}</label> | |
9 | + {% render_field field class='form-control' %} | |
10 | + <span class="help-block">{{ field.help_text }}</span> | |
11 | + {% if field.errors %} | |
12 | + <div class="row"> | |
13 | + <br /> | |
14 | + <div class="alert alert-danger alert-dismissible" role="alert"> | |
15 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
16 | + <span aria-hidden="true">×</span> | |
17 | + </button> | |
18 | + <ul> | |
19 | + {% for error in field.errors %} | |
20 | + <li>{{ error }}</li> | |
21 | + {% endfor %} | |
22 | + </ul> | |
23 | + </div> | |
24 | + </div> | |
25 | + {% endif %} | |
26 | + </div> | |
27 | + {% endfor %} | |
28 | + | |
29 | + <input type="submit" value="{% trans 'Create' %}" class="btn btn-primary" /> | |
30 | +</form> | |
0 | 31 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,51 @@ |
1 | +{% load i18n %} | |
2 | + | |
3 | +{% if foruns|length > 0 %} | |
4 | + {% for forum in foruns %} | |
5 | + <div class="page-header"> | |
6 | + <h1 id="timeline">{{ forum }}</h1> | |
7 | + <b>Descricao: </b>{{ forum.description }}<p> | |
8 | + <b>Abertura: </b>{{ forum.create_date }} | |
9 | + </div> | |
10 | + {% endfor %} | |
11 | +{% else %} | |
12 | + <div class="page-header"> | |
13 | + <p>{% trans 'No forum created yet.' %}</p> | |
14 | + </div> | |
15 | +{% endif %} | |
16 | +<!-- <ul class="timeline"> | |
17 | + <li> | |
18 | + <div class="timeline-badge"> | |
19 | + <img id="logo" src="https://uxdesign-html-japm94.c9users.io/atividades-amadeus/uxdesign-html/img/topo-amadeus.png"> | |
20 | + </div> | |
21 | + <p></p> | |
22 | + <div class="timeline-panel"> | |
23 | + <div class="timeline-heading"> | |
24 | + <h4 class="timeline-title">Python is insteresting</h4> | |
25 | + <p><small class="text-muted"><i class="glyphicon glyphicon-time"></i> 11 hours ago by </small>Carlos </p> | |
26 | + </div> | |
27 | + <div class="timeline-body"> | |
28 | + <p>Who knows how working a String in python?</p> | |
29 | + </div> | |
30 | + <hr> | |
31 | + <i class="fa fa-pencil-square-o fa-2x" aria-hidden="true"></i> | |
32 | + </div> | |
33 | + </li> | |
34 | + <li> | |
35 | + <div class="timeline-badge"> | |
36 | + <img id="logo" src="https://uxdesign-html-japm94.c9users.io/atividades-amadeus/uxdesign-html/img/topo-amadeus.png"> | |
37 | + </div> | |
38 | + <p></p> | |
39 | + <div class="timeline-panel"> | |
40 | + <div class="timeline-heading"> | |
41 | + <h4 class="timeline-title">Ruby's doubt</h4> | |
42 | + <p><small class="text-muted"><i class="glyphicon glyphicon-time"></i> 5 hours ago by </small>Jurandi</p> | |
43 | + </div> | |
44 | + <div class="timeline-body"> | |
45 | + <p>How works the Gems?</p> | |
46 | + </div> | |
47 | + <hr> | |
48 | + <i class="fa fa-pencil-square-o fa-2x" aria-hidden="true"></i> | |
49 | + </div> | |
50 | + </li> | |
51 | +</ul> --> | |
0 | 52 | \ No newline at end of file | ... | ... |
forum/views.py
1 | -from django.shortcuts import render | |
1 | +from django.shortcuts import render, get_object_or_404 | |
2 | +from django.core.urlresolvers import reverse_lazy | |
3 | +from django.utils.translation import ugettext_lazy as _ | |
4 | +from django.views import generic | |
5 | +from django.contrib.auth.mixins import LoginRequiredMixin | |
2 | 6 | |
3 | -# Create your views here. | |
7 | +from .models import Forum | |
8 | +from courses.models import Topic | |
9 | + | |
10 | +from .forms import ForumForm | |
11 | + | |
12 | +class ForumIndex(LoginRequiredMixin, generic.ListView): | |
13 | + login_url = reverse_lazy("core:home") | |
14 | + redirect_field_name = 'next' | |
15 | + | |
16 | + template_name = "forum_list.html" | |
17 | + context_object_name = 'foruns' | |
18 | + | |
19 | + def get_queryset(self): | |
20 | + topic = get_object_or_404(Topic, slug = self.request.GET.get('topic', '')) | |
21 | + | |
22 | + context = Forum.objects.filter(topic = topic) | |
23 | + | |
24 | + return context | |
25 | + | |
26 | +class CreateForumView(LoginRequiredMixin, generic.edit.CreateView): | |
27 | + | |
28 | + template_name = 'forum_form.html' | |
29 | + form_class = ForumForm | |
30 | + success_url = reverse_lazy('forum:index') | |
4 | 31 | \ No newline at end of file | ... | ... |
requirements.txt
users/forms.py
... | ... | @@ -4,6 +4,7 @@ from django.conf import settings |
4 | 4 | from django import forms |
5 | 5 | from django.utils.translation import ugettext_lazy as _ |
6 | 6 | from rolepermissions.shortcuts import assign_role |
7 | +from django.contrib.auth.forms import UserCreationForm | |
7 | 8 | from .models import User |
8 | 9 | |
9 | 10 | |
... | ... | @@ -22,35 +23,32 @@ class ProfileForm(forms.ModelForm): |
22 | 23 | fields = ['username', 'name', 'email', 'password', 'birth_date', 'city', 'state', 'gender', 'cpf', 'phone', 'image'] |
23 | 24 | widgets = { |
24 | 25 | 'password':forms.PasswordInput |
25 | - } | |
26 | - | |
27 | -class UserForm(forms.ModelForm): | |
28 | - def save(self, commit=True): | |
29 | - super(UserForm, self).save(commit=False) | |
30 | - | |
31 | - #if not self.instance.image: | |
32 | - # self.instance.image = os.path.join(os.path.dirname(settings.BASE_DIR), 'uploads', 'no_image.jpg') | |
33 | - | |
34 | - self.instance.set_password(self.cleaned_data['password']) | |
35 | - self.instance.save() | |
36 | - | |
37 | - if self.instance.is_staff: | |
38 | - assign_role(self.instance, 'system_admin') | |
39 | - elif self.instance.type_profile == 2: | |
40 | - assign_role(self.instance, 'student') | |
41 | - elif self.instance.type_profile == 1: | |
42 | - assign_role(self.instance, 'professor') | |
43 | - | |
44 | - self.instance.save() | |
26 | + } | |
45 | 27 | |
46 | - return self.instance | |
28 | +class UserForm(UserCreationForm): | |
29 | + # def save(self, commit=True): | |
30 | + # super(UserForm, self).save() | |
31 | + # | |
32 | + # #if not self.instance.image: | |
33 | + # # self.instance.image = os.path.join(os.path.dirname(settings.BASE_DIR), 'uploads', 'no_image.jpg') | |
34 | + # | |
35 | + # # self.instance.set_password(self.cleaned_data['password']) | |
36 | + # # self.instance.save() | |
37 | + # | |
38 | + # if self.instance.is_staff: | |
39 | + # assign_role(self.instance, 'system_admin') | |
40 | + # elif self.instance.type_profile == 2: | |
41 | + # assign_role(self.instance, 'student') | |
42 | + # elif self.instance.type_profile == 1: | |
43 | + # assign_role(self.instance, 'professor') | |
44 | + # | |
45 | + # self.instance.save() | |
46 | + # | |
47 | + # return self.instance | |
47 | 48 | |
48 | 49 | class Meta: |
49 | 50 | model = User |
50 | - fields = ['username', 'name', 'email', 'password', 'birth_date', 'city', 'state', 'gender', 'type_profile', 'cpf', 'phone', 'image', 'is_staff', 'is_active'] | |
51 | - widgets = { | |
52 | - 'password':forms.PasswordInput | |
53 | - } | |
51 | + fields = ['username', 'name', 'email', 'birth_date', 'city', 'state', 'gender', 'type_profile', 'cpf', 'phone', 'image', 'is_staff', 'is_active'] | |
54 | 52 | |
55 | 53 | class EditUserForm(forms.ModelForm): |
56 | 54 | ... | ... |
users/templates/users/create.html
... | ... | @@ -32,30 +32,31 @@ |
32 | 32 | {% csrf_token %} |
33 | 33 | {% for field in form %} |
34 | 34 | <div class="form-group{% if form.has_error %} has-error {% endif %} is-fileinput"> |
35 | - <label for="{{ field.auto_id }}">{{ field.label }}</label> | |
36 | 35 | {% if field.auto_id == 'id_birth_date' %} |
37 | - {% render_field field class='form-control input-sm' type='date' %} | |
38 | - <span id="helpBlock" class="help-block">{{ field.help_text }}</span> | |
36 | + <label for="{{ field.auto_id }}">{{ field.label }}</label> | |
37 | + <input type="date" class="form-control"name="{{field.name}}" value="{% if field.value.year %}{{field.value|date:'Y-m-d'}}{% else %}{{field.value}}{% endif %}"> | |
39 | 38 | {% elif field.auto_id == 'id_image' %} |
40 | - {% render_field field class='form-control input-sm' %} | |
39 | + <label for="{{ field.auto_id }}">{{ field.label }}</label> | |
40 | + {% render_field field class='form-control' %} | |
41 | 41 | <div class="input-group"> |
42 | - <input type="text" readonly="" class="form-control" placeholder="{% trans 'Choose your photo...' %}"> | |
43 | - <span class="input-group-btn input-group-sm"> | |
44 | - <button type="button" class="btn btn-fab btn-fab-mini"> | |
45 | - <i class="material-icons">attach_file</i> | |
46 | - </button> | |
47 | - </span> | |
48 | - </div> | |
49 | - {% elif field.auto_id == 'id_is_staff' or field.auto_id == 'id_is_active' %} | |
50 | - <div class="checkbox"> | |
51 | - <label> | |
52 | - {% render_field field type='checkbox' %} | |
53 | - </label> | |
54 | - </div> | |
42 | + <input type="text" readonly="" class="form-control" placeholder="{% trans 'Choose your photo...' %}"> | |
43 | + <span class="input-group-btn input-group-sm"> | |
44 | + <button type="button" class="btn btn-fab btn-fab-mini"> | |
45 | + <i class="material-icons">attach_file</i> | |
46 | + </button> | |
47 | + </span> | |
48 | + </div> | |
49 | + {% elif field.auto_id == 'id_is_staff' or field.auto_id == 'id_is_active' %} | |
50 | + <div class="checkbox"> | |
51 | + <label> | |
52 | + <input type="checkbox" name="checkbox"><span class="checkbox-material"><span class="check"></span></span> {{field.label}} | |
53 | + </label> | |
54 | + </div> | |
55 | 55 | {% else %} |
56 | - {% render_field field class='form-control input-sm' %} | |
57 | - <span id="helpBlock" class="help-block">{{ field.help_text }}</span> | |
56 | + <label for="{{ field.auto_id }}">{{ field.label }}</label> | |
57 | + {% render_field field class='form-control' %} | |
58 | 58 | {% endif %} |
59 | + <span id="helpBlock" class="help-block">{{ field.help_text }}</span> | |
59 | 60 | {% if field.errors.length > 0 %} |
60 | 61 | <div class="alert alert-danger alert-dismissible" role="alert"> |
61 | 62 | <button type="button" class="close" data-dismiss="alert" aria-label="Close"> |
... | ... | @@ -67,20 +68,20 @@ |
67 | 68 | {% endfor %} |
68 | 69 | </ul> |
69 | 70 | </div> |
70 | - </div> | |
71 | 71 | {% endif %} |
72 | 72 | </div> |
73 | 73 | {% endfor %} |
74 | 74 | <div class="col-md-offset-2 col-md-2 col-sm-2 col-xs-2"> |
75 | - <input type="submit" value="{% trans 'Save' %}" class="btn btn-sm btn-success" /> | |
75 | + <input type="submit" value="{% trans 'Save' %}" class="btn btn-sm btn-success" /> | |
76 | 76 | </div> |
77 | 77 | <div class="col-md-offset-3 col-md-2 col-sm-2 col-xs-2"> |
78 | - <a href="{% url 'users:manage' %}" class="btn btn-sm btn-success" >{% trans 'Cancel' %}</a> | |
78 | + <a href="{% url 'users:manage' %}" class="btn btn-sm btn-default" >{% trans 'Cancel' %}</a> | |
79 | 79 | </div> |
80 | 80 | </form> |
81 | 81 | </div> |
82 | 82 | </div> |
83 | - </div> | |
84 | - | |
85 | - <br clear="all" /> | |
83 | + </div> | |
84 | +</br> | |
85 | +</br> | |
86 | +</br> | |
86 | 87 | {% endblock %} | ... | ... |