Commit 80e6a9ec2939bb94509c61a041811af8303c7e01

Authored by Jailson Dias
2 parents e5987f89 f9504c73

Merge branch 'dev' of https://github.com/amadeusproject/amadeuslms into dev

courses/templates/subject/form_view_teacher.html
@@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
4 <script type="text/javascript" src="{% static 'js/forum.js' %}"></script> 4 <script type="text/javascript" src="{% static 'js/forum.js' %}"></script>
5 <script src="{% static 'js/file.js' %}"></script> 5 <script src="{% static 'js/file.js' %}"></script>
6 <script type="text/javascript" src="{% static 'js/material.js' %}"></script> 6 <script type="text/javascript" src="{% static 'js/material.js' %}"></script>
  7 + <script type = "text/javascript" src="{% static 'link.js' %}"></script>
7 {% endblock %} 8 {% endblock %}
8 9
9 <div class="panel-group accordion ui-accordion ui-widget ui-helper-reset ui-sortable" role="tablist" aria-multiselectable="false"> 10 <div class="panel-group accordion ui-accordion ui-widget ui-helper-reset ui-sortable" role="tablist" aria-multiselectable="false">
@@ -54,7 +55,7 @@ @@ -54,7 +55,7 @@
54 <div class="dropdown"> 55 <div class="dropdown">
55 <a href="#" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-plus-circle fa-lg" aria-hidden="true"></i></a> 56 <a href="#" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-plus-circle fa-lg" aria-hidden="true"></i></a>
56 <ul class="dropdown-menu" aria-labelledby="dLabel"> 57 <ul class="dropdown-menu" aria-labelledby="dLabel">
57 - <li><a href="javascript:void(0)" data-toggle="modal" data-target="#createLinksModal">Create a Link<div class="ripple-container"><div class="ripple ripple-on ripple-out" style="left: 54.5312px; top: 22px; background-color: rgb(0, 150, 136); transform: scale(20);"></div></div></a></li> 58 + <li><a href=" javascript:get_modal_link('{% url 'course:links:create_link' %}', '#createLinksModal','#divModalLink') ">Create a Link<div class="ripple-container"><div class="ripple ripple-on ripple-out" style="left: 54.5312px; top: 22px; background-color: rgb(0, 150, 136); transform: scale(20);"></div></div></a></li>
58 <li> 59 <li>
59 <a href="javascript:get_modal_file('{% url 'course:file:create_file' topic.slug %}', '#fileModal', '#divModalFile')"> 60 <a href="javascript:get_modal_file('{% url 'course:file:create_file' topic.slug %}', '#fileModal', '#divModalFile')">
60 {% trans "Create a file" %} 61 {% trans "Create a file" %}
@@ -69,7 +70,7 @@ @@ -69,7 +70,7 @@
69 </div> 70 </div>
70 <ul> 71 <ul>
71 {% list_topic_file request topic %} 72 {% list_topic_file request topic %}
72 - <li><i class="fa fa-link" aria-hidden="true"></i> <a href="#" data-toggle="modal" data-target="#linksModal">Link 1</a></li> 73 + {% list_topic_link request topic%}
73 <li><i class="fa fa-file-code-o" aria-hidden="true"></i> <a href="#" data-toggle="modal" data-target="#embedModal">EMBED Material</a></li> 74 <li><i class="fa fa-file-code-o" aria-hidden="true"></i> <a href="#" data-toggle="modal" data-target="#embedModal">EMBED Material</a></li>
74 </ul> 75 </ul>
75 </div> 76 </div>
@@ -115,12 +116,13 @@ @@ -115,12 +116,13 @@
115 <div class="dropdown"> 116 <div class="dropdown">
116 <a href="#" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-plus-circle fa-lg" aria-hidden="true"></i></a> 117 <a href="#" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-plus-circle fa-lg" aria-hidden="true"></i></a>
117 <ul class="dropdown-menu" aria-labelledby="dLabel"> 118 <ul class="dropdown-menu" aria-labelledby="dLabel">
118 - <li><a href="javascript:void(0)" data-toggle="modal" data-target="#createLinksModal">Create a Link</a></li> 119 + <li><a href=" javascript:get_modal_link('{% url 'course:links:create_link' %}', '#createLinksModal','#divModalLink') ">Create a Link</a></li>
119 <li><a href="javascript:void(0)" data-toggle="modal" data-target="#fileModal">Create a file</a></li> 120 <li><a href="javascript:void(0)" data-toggle="modal" data-target="#fileModal">Create a file</a></li>
120 </ul> 121 </ul>
121 </div> 122 </div>
122 </div> 123 </div>
123 <ul> 124 <ul>
  125 + {% list_topic_link_edit request topic%}
124 {% list_topic_file_edit request topic %} 126 {% list_topic_file_edit request topic %}
125 </ul> 127 </ul>
126 </div> 128 </div>
@@ -175,31 +177,6 @@ @@ -175,31 +177,6 @@
175 </div> 177 </div>
176 </div> 178 </div>
177 <!-- END --> 179 <!-- END -->
178 - <!--MODAL VIEW LINK-->  
179 - <div class="modal fade" id="linksModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">  
180 - <div class="modal-dialog" role="document">  
181 - <div class="modal-content">  
182 - <div class="modal-header">  
183 - <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>  
184 - <h4 class="modal-title" id="myModalLabel">Links</h4>  
185 - </div>  
186 - <div class="modal-body">  
187 - <!-- Card -->  
188 - <article class="card animated fadeInLeft">  
189 - <img class="card-img-top img-responsive" src="https://www.python.org/static/opengraph-icon-200x200.png" align="left">  
190 - <div class="card-block">  
191 - <b class="card-title">Python</b><p></p>  
192 - <b class="text-muted">Guido van Rossum</b>  
193 - <p class="card-text"> </p><p>Python is a widely used high-level, general-purpose, interpreted, dynamic programming language. Its design philosophy emphasizes code readability, and its syntax allows programmers to express concepts in fewer lines of code than possible in languages such as C++ or Java.</p>  
194 - <a href="https://www.python.org/" class="btn btn-primary">Read more</a>  
195 - </div>  
196 - </article>  
197 - <!-- .end Card -->  
198 - </div>  
199 - </div>  
200 - </div>  
201 - </div>  
202 - <!-- EndModal -->  
203 {% professor_subject topic.subject user as professor_links %} 180 {% professor_subject topic.subject user as professor_links %}
204 {% if professor_links%} 181 {% if professor_links%}
205 {% include "links/create_link.html" %} 182 {% include "links/create_link.html" %}
courses/templates/topic/link_topic_list.html 0 → 100644
@@ -0,0 +1,27 @@ @@ -0,0 +1,27 @@
  1 +{% load static i18n list_topic_foruns permission_tags %}
  2 +{% for link in links%}
  3 + <li><i class="fa fa-link" aria-hidden="true"></i> <a href="#" data-toggle="modal" data-target="#linksModal{{slug}}{{ forloop.counter }}">{{link}}</a></li>
  4 + <!--MODAL VIEW LINK-->
  5 + <div class="modal fade" id="linksModal{{slug}}{{ forloop.counter}}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  6 + <div class="modal-dialog" role="document">
  7 + <div class="modal-content">
  8 + <div class="modal-header">
  9 + <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
  10 + <h4 class="modal-title" id="myModalLabel">Link</h4>
  11 + </div>
  12 + <div class="modal-body">
  13 + <!-- Card -->
  14 + <article class="card animated fadeInLeft">
  15 + <div class="card-block">
  16 + <b class="card-title">{{link.name}}</b><p></p>
  17 + <p class="card-text"> </p><p>{{link.link_description}}</p>
  18 + <a href="{{ link.link_url }}" class="btn btn-primary">Read more</a>
  19 + </div>
  20 + </article>
  21 + <!-- .end Card -->
  22 + </div>
  23 + </div>
  24 + </div>
  25 + </div>
  26 + <!-- EndModal -->
  27 +{% endfor %}
courses/templates/topic/link_topic_list_edit.html 0 → 100644
@@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
  1 +{% load static i18n list_topic_foruns permission_tags %}
  2 +{% for link in links%}
  3 + <li class="icon_edit_remove"> <a href="#" data-toggle="modal" data-target="#linksModalEdit"><i class="fa fa-pencil fa-lg" aria-hidden="true"></i></a> <a href="#" data-toggle="modal" data-target="#removeLink"><i class="fa fa-trash fa-lg" aria-hidden="true"></i></a></li>
  4 + <li><i class="fa fa-link" aria-hidden="true"></i> <a href="#" data-toggle="modal" data-target="#linksModal{{slug}}{{ forloop.counter }}">{{link}}</a></li>
  5 +
  6 + <!--MODAL VIEW LINK-->
  7 + <div class="modal fade" id="linksModal{{slug}}{{ forloop.counter}}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  8 + <div class="modal-dialog" role="document">
  9 + <div class="modal-content">
  10 + <div class="modal-header">
  11 + <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
  12 + <h4 class="modal-title" id="myModalLabel">Link</h4>
  13 + </div>
  14 + <div class="modal-body">
  15 + <!-- Card -->
  16 + <article class="card animated fadeInLeft">
  17 + <div class="card-block">
  18 + <b class="card-title">{{link.name}}</b><p></p>
  19 + <p class="card-text"> </p><p>{{link.link_description}}</p>
  20 + <a href="{{ link.link_url }}" class="btn btn-primary">Read more</a>
  21 + </div>
  22 + </article>
  23 + <!-- .end Card -->
  24 + </div>
  25 + </div>
  26 + </div>
  27 + </div>
  28 + <!-- EndModal -->
  29 +{% endfor %}
  30 + <div class = "row" id="divModalLink">
  31 + </div>
courses/templatetags/list_topic_foruns.py
1 from django import template 1 from django import template
2 2
  3 +from links.models import Link
3 from forum.models import Forum 4 from forum.models import Forum
4 from poll.models import Poll 5 from poll.models import Poll
5 from files.models import TopicFile 6 from files.models import TopicFile
@@ -51,3 +52,21 @@ def list_topic_file_edit(request, topic): @@ -51,3 +52,21 @@ def list_topic_file_edit(request, topic):
51 context['topic'] = topic 52 context['topic'] = topic
52 53
53 return context 54 return context
  55 +
  56 +@register.inclusion_tag('topic/link_topic_list_edit.html')
  57 +def list_topic_link_edit(request,topic):
  58 + context = {
  59 + 'request':request
  60 + }
  61 + context['links'] = Link.objects.filter(topic = topic)
  62 + context['slug'] = topic.slug
  63 + return context
  64 +
  65 +@register.inclusion_tag('topic/link_topic_list.html')
  66 +def list_topic_link(request,topic):
  67 + context = {
  68 + 'request':request
  69 + }
  70 + context['links'] = Link.objects.filter(topic = topic)
  71 + context['slug'] = topic.slug
  72 + return context
courses/urls.py
@@ -30,6 +30,7 @@ urlpatterns = [ @@ -30,6 +30,7 @@ urlpatterns = [
30 url(r'^exam/', include('exam.urls', namespace = 'exam')), 30 url(r'^exam/', include('exam.urls', namespace = 'exam')),
31 url(r'^files/', include('files.urls', namespace = 'file')), 31 url(r'^files/', include('files.urls', namespace = 'file')),
32 url(r'^upload-material/$', views.UploadMaterialView.as_view(), name='upload_material'), 32 url(r'^upload-material/$', views.UploadMaterialView.as_view(), name='upload_material'),
  33 + url(r'^links/',include('links.urls',namespace = 'links')),
33 34
34 35
35 36
forum/tests/test_model_answer.py
@@ -93,16 +93,26 @@ class PostAnswerTestCase (TestCase): @@ -93,16 +93,26 @@ class PostAnswerTestCase (TestCase):
93 ) 93 )
94 self.post_student.save() 94 self.post_student.save()
95 95
96 - self.answer = PostAnswer.objects.create( 96 + self.answerStudent = PostAnswer.objects.create(
97 user = self.user_student, 97 user = self.user_student,
98 post = self.post_professor, 98 post = self.post_professor,
99 message = 'testing a post answer', 99 message = 'testing a post answer',
100 modification_date = '2016-10-05', 100 modification_date = '2016-10-05',
101 answer_date = '2016-10-04', 101 answer_date = '2016-10-04',
102 ) 102 )
103 - self.answer.save() 103 + self.answerStudent.save()
  104 +
  105 + self.answerProfessor = PostAnswer.objects.create(
  106 + user = self.user_professor,
  107 + post = self.post_student,
  108 + message = 'testing a post answer',
  109 + modification_date = '2016-10-05',
  110 + answer_date = '2016-10-04',
  111 + )
  112 + self.answerProfessor.save()
104 113
105 def test_create_answer_post (self): 114 def test_create_answer_post (self):
  115 + list_answers = PostAnswer.objects.filter(user=self.user_professor).count()
106 answer = PostAnswer.objects.create( 116 answer = PostAnswer.objects.create(
107 user = self.user_professor, 117 user = self.user_professor,
108 post = self.post_student, 118 post = self.post_student,
@@ -112,19 +122,46 @@ class PostAnswerTestCase (TestCase): @@ -112,19 +122,46 @@ class PostAnswerTestCase (TestCase):
112 ) 122 )
113 answer.save() 123 answer.save()
114 124
115 - self.assertEquals (answer, PostAnswer.objects.get(user=self.user_professor, post=self.post_student)) 125 + self.assertEquals (list_answers+1, PostAnswer.objects.filter(user=self.user_professor, post=self.post_student).count())
  126 +
  127 + list_answers = PostAnswer.objects.filter(user=self.user_student).count()
  128 + answer = PostAnswer.objects.create(
  129 + user = self.user_student,
  130 + post = self.post_professor,
  131 + message = 'testing a post answer2',
  132 + modification_date = '2016-10-05',
  133 + answer_date = '2016-10-04',
  134 + )
  135 + answer.save()
  136 +
  137 + self.assertEquals (list_answers+1, PostAnswer.objects.filter(user=self.user_student, post=self.post_professor).count())
116 138
117 def test_update_answer_post (self): 139 def test_update_answer_post (self):
118 - self.answer.message = 'updating a answer post'  
119 - self.answer.save() 140 + self.answerStudent.message = 'updating a student answer post'
  141 + self.answerStudent.save()
  142 + answer = PostAnswer.objects.get(message='updating a student answer post')
120 143
121 - self.assertEquals(self.answer, PostAnswer.objects.all()[0]) 144 + self.assertEquals(self.answerStudent, answer)
122 145
123 - def test_delete_answer_post (self):  
124 - answer = PostAnswer.objects.get(user=self.user_student, post=self.post_professor)  
125 - self.answer.delete()  
126 146
127 - try:  
128 - answer = PostAnswer.objects.get(user=self.user_student, post=self.post_professor)  
129 - except:  
130 - pass  
131 \ No newline at end of file 147 \ No newline at end of file
  148 + self.answerProfessor.message = 'updating a professor answer post'
  149 + self.answerProfessor.save()
  150 + answer = PostAnswer.objects.get(message='updating a professor answer post')
  151 +
  152 + self.assertEquals(self.answerProfessor, answer)
  153 +
  154 + def test_delete_answer_post (self):
  155 + list_studentAnswers = PostAnswer.objects.filter(user=self.user_student).count()
  156 + self.assertEquals(list_studentAnswers, 1)
  157 +
  158 + self.answerStudent.delete()
  159 + list_studentAnswers = PostAnswer.objects.filter(user=self.user_student).count()
  160 + self.assertEquals(list_studentAnswers, 0)
  161 +
  162 + list_professorAnswers = PostAnswer.objects.filter(user=self.user_professor).count()
  163 + self.assertEquals(list_professorAnswers, 1)
  164 +
  165 + self.answerProfessor.delete()
  166 + list_professorAnswers = PostAnswer.objects.filter(user=self.user_professor).count()
  167 + self.assertEquals(list_professorAnswers, 0)
  168 +
132 \ No newline at end of file 169 \ No newline at end of file
forum/tests/test_model_forum.py
@@ -77,6 +77,8 @@ class ForumTestCase (TestCase): @@ -77,6 +77,8 @@ class ForumTestCase (TestCase):
77 self.forum.save() 77 self.forum.save()
78 78
79 def test_create_forum (self): 79 def test_create_forum (self):
  80 + list_forum = Forum.objects.all().count()
  81 +
80 forum = Forum.objects.create( 82 forum = Forum.objects.create(
81 topic=self.topic, 83 topic=self.topic,
82 name = 'forum test2', 84 name = 'forum test2',
@@ -87,20 +89,18 @@ class ForumTestCase (TestCase): @@ -87,20 +89,18 @@ class ForumTestCase (TestCase):
87 ) 89 )
88 forum.save() 90 forum.save()
89 91
90 - self.assertEquals(forum, Forum.objects.filter(name='forum test2')[0]) 92 + self.assertEquals(list_forum+1, Forum.objects.all().count())
91 93
92 - def test_update_forum(self): 94 + def test_update_forum(self):
  95 + list_forum = Forum.objects.all().count()
93 self.forum.name = 'forum test updated' 96 self.forum.name = 'forum test updated'
94 self.forum.save() 97 self.forum.save()
95 98
96 self.assertEquals(self.forum, Forum.objects.get(name='forum test updated')) 99 self.assertEquals(self.forum, Forum.objects.get(name='forum test updated'))
  100 + self.assertEquals(list_forum, Forum.objects.all().count())
97 101
98 def test_delete_forum (self): 102 def test_delete_forum (self):
99 - forum = Forum.objects.get(name='forum test') 103 + list_forum = Forum.objects.all().count()
100 self.forum.delete() 104 self.forum.delete()
101 105
102 - try:  
103 - forum = Forum.objects.get(name='forum test')  
104 - except:  
105 - pass  
106 -  
107 \ No newline at end of file 106 \ No newline at end of file
  107 + self.assertEquals(list_forum-1, Forum.objects.all().count())
108 \ No newline at end of file 108 \ No newline at end of file
links/admin.py
@@ -3,8 +3,8 @@ from django.contrib import admin @@ -3,8 +3,8 @@ from django.contrib import admin
3 from .models import Link 3 from .models import Link
4 4
5 class LinkAdmin(admin.ModelAdmin): 5 class LinkAdmin(admin.ModelAdmin):
6 - list_display = ['name', 'link','description']  
7 - search_fields = ['name', 'link','description'] 6 + list_display = ['name', 'link_url','link_description']
  7 + search_fields = ['name', 'link_url','link_description']
8 8
9 9
10 admin.site.register(Link, LinkAdmin) 10 admin.site.register(Link, LinkAdmin)
links/forms.py
@@ -5,16 +5,16 @@ import validators @@ -5,16 +5,16 @@ import validators
5 class CreateLinkForm(forms.ModelForm): 5 class CreateLinkForm(forms.ModelForm):
6 6
7 def clean_link(self): 7 def clean_link(self):
8 - link = self.cleaned_data['link']  
9 - if not validators.url(link): 8 + link_url = self.cleaned_data['link_url']
  9 + if not validators.url(link_url):
10 raise forms.ValidationError(_('Please enter a valid URL')) 10 raise forms.ValidationError(_('Please enter a valid URL'))
11 - return link 11 + return link_url
12 12
13 class Meta: 13 class Meta:
14 model = Link 14 model = Link
15 - fields = ['name','link','description'] 15 + fields = ['name','link_url','link_description']
16 16
17 class UpdateLinkForm(forms.ModelForm): 17 class UpdateLinkForm(forms.ModelForm):
18 class Meta: 18 class Meta:
19 model = Link 19 model = Link
20 - fields = ['name','link','description'] 20 + fields = ['name','link_url','link_description']
links/models.py
1 -  
2 from django.db import models 1 from django.db import models
3 from courses.models import Material 2 from courses.models import Material
4 from autoslug.fields import AutoSlugField 3 from autoslug.fields import AutoSlugField
5 # Create your models here. 4 # Create your models here.
6 -class Link(models.Model):  
7 - name = models.CharField(max_length=100)  
8 - link = models.URLField()  
9 - description = models.CharField(max_length=200) 5 +class Link(Material):
  6 + link_url = models.URLField()
  7 + link_description = models.CharField(max_length=200)
10 class Meta: 8 class Meta:
11 verbose_name = 'Link' 9 verbose_name = 'Link'
12 verbose_name_plural = "Links" 10 verbose_name_plural = "Links"
links/static/links.js 0 → 100644
@@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
  1 +function get_modal_link(url, id,div_content){
  2 + $.get(url, function (data) {
  3 + //alert(data);
  4 + // $(div_content).empty();
  5 + // $(div_content).append(data);
  6 + $(id).modal('show');
  7 + });
  8 +
  9 +}
@@ -2,5 +2,7 @@ from django.conf.urls import url, include @@ -2,5 +2,7 @@ from django.conf.urls import url, include
2 from . import views 2 from . import views
3 3
4 urlpatterns = [ 4 urlpatterns = [
5 - url(r'^$', views.CreateLink.as_view(), name='teste') 5 + url(r'^$', views.CreateLink.as_view(), name='create_link'),
  6 + url(r'^deletelink/(?P<linkname>[\w_-]+)/$', views.deleteLink,name = 'delete_link'),
  7 + url(r'^updatelink/(?P<linkname>[\w_-]+)/$', views.UpdateLink.as_view(),name = 'update_link'),
6 ] 8 ]
links/views.py
@@ -13,7 +13,7 @@ class CreateLink(generic.CreateView): @@ -13,7 +13,7 @@ class CreateLink(generic.CreateView):
13 template_name = 'links/create_link.html' 13 template_name = 'links/create_link.html'
14 form_class = CreateLinkForm 14 form_class = CreateLinkForm
15 success_url = reverse_lazy('course:manage') 15 success_url = reverse_lazy('course:manage')
16 - context_object_name = 'links' 16 + context_object_name = 'form'
17 17
18 def form_valid(self, form): 18 def form_valid(self, form):
19 form.save() 19 form.save()
@@ -26,7 +26,6 @@ class CreateLink(generic.CreateView): @@ -26,7 +26,6 @@ class CreateLink(generic.CreateView):
26 context['form'] = CreateLinkForm 26 context['form'] = CreateLinkForm
27 return context 27 return context
28 28
29 -  
30 def deleteLink(request,linkname): 29 def deleteLink(request,linkname):
31 link = get_object_or_404(Link,name = linkname) 30 link = get_object_or_404(Link,name = linkname)
32 link.delete() 31 link.delete()