Commit 525e272f8fc7702dc382776abcff4cbcde767e8b
1 parent
fa75a311
Exists in
master
and in
5 other branches
Adding form to create forum [Issue: #73]
Showing
6 changed files
with
100 additions
and
15 deletions
Show diff stats
courses/templates/subject/form_view_teacher.html
... | ... | @@ -2,20 +2,31 @@ |
2 | 2 | |
3 | 3 | {% block javascript %} |
4 | 4 | <script type="text/javascript"> |
5 | - var baseUrl = '{% url "forum:index" %}'; | |
5 | + var baseUrl = '{% url "forum:index" %}'; | |
6 | + var formUrl = '{% url "forum:create" %}'; | |
6 | 7 | |
7 | 8 | function showForum(topic) { |
8 | 9 | $.ajax({ |
9 | 10 | url: baseUrl, |
10 | 11 | data: {'topic': topic}, |
11 | 12 | success: function(data) { |
12 | - console.log(data); | |
13 | - $(".modal-body").html(data); | |
13 | + $(".forum_topics").html(data); | |
14 | 14 | } |
15 | 15 | }); |
16 | 16 | |
17 | 17 | $('#forumModal').modal(); |
18 | 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 | + } | |
19 | 30 | </script> |
20 | 31 | {% endblock %} |
21 | 32 | |
... | ... | @@ -43,10 +54,15 @@ |
43 | 54 | <div class="modal-content"> |
44 | 55 | <div class="modal-header"> |
45 | 56 | <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> |
46 | - <h4 class="modal-title" id="myModalLabel"></h4> | |
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> | |
47 | 60 | </div> |
48 | 61 | <div class="modal-body"> |
49 | - | |
62 | + <div class="forum_form" style="display:none"> | |
63 | + </div> | |
64 | + <div class="forum_topics"> | |
65 | + </div> | |
50 | 66 | </div> |
51 | 67 | </div> |
52 | 68 | </div> | ... | ... |
... | ... | @@ -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 | ... | ... |
... | ... | @@ -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 | ... | ... |
forum/templates/forum_list.html
1 | -<div class="page-header"> | |
2 | - <h1 id="timeline">Forum</h1> | |
3 | - <b>Descricao: </b>Learning Python<p> | |
4 | - <b>Abertura: </b>Sexta-feira, 10 Junho 2016 | |
5 | -</div> | |
6 | -<ul class="timeline"> | |
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"> | |
7 | 17 | <li> |
8 | 18 | <div class="timeline-badge"> |
9 | 19 | <img id="logo" src="https://uxdesign-html-japm94.c9users.io/atividades-amadeus/uxdesign-html/img/topo-amadeus.png"> |
... | ... | @@ -38,4 +48,4 @@ |
38 | 48 | <i class="fa fa-pencil-square-o fa-2x" aria-hidden="true"></i> |
39 | 49 | </div> |
40 | 50 | </li> |
41 | -</ul> | |
42 | 51 | \ No newline at end of file |
52 | +</ul> --> | |
43 | 53 | \ No newline at end of file | ... | ... |
forum/urls.py
forum/views.py
1 | 1 | from django.shortcuts import render, get_object_or_404 |
2 | 2 | from django.core.urlresolvers import reverse_lazy |
3 | 3 | from django.utils.translation import ugettext_lazy as _ |
4 | -from django.views.generic import ListView | |
4 | +from django.views import generic | |
5 | 5 | from django.contrib.auth.mixins import LoginRequiredMixin |
6 | 6 | |
7 | 7 | from .models import Forum |
8 | 8 | from courses.models import Topic |
9 | 9 | |
10 | -class ForumIndex(LoginRequiredMixin, ListView): | |
10 | +from .forms import ForumForm | |
11 | + | |
12 | +class ForumIndex(LoginRequiredMixin, generic.ListView): | |
11 | 13 | login_url = reverse_lazy("core:home") |
12 | 14 | redirect_field_name = 'next' |
13 | 15 | |
14 | 16 | template_name = "forum_list.html" |
15 | - context_object_name = 'forum' | |
17 | + context_object_name = 'foruns' | |
16 | 18 | |
17 | 19 | def get_queryset(self): |
18 | 20 | topic = get_object_or_404(Topic, slug = self.request.GET.get('topic', '')) |
... | ... | @@ -20,3 +22,9 @@ class ForumIndex(LoginRequiredMixin, ListView): |
20 | 22 | context = Forum.objects.filter(topic = topic) |
21 | 23 | |
22 | 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') | |
23 | 31 | \ No newline at end of file | ... | ... |