Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion ComSemApp/administrator/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django_select2.forms import Select2MultipleWidget

from django.contrib.auth.models import User
from ComSemApp.models import Course, CourseType, Session, SessionType, Teacher, Student, Institution
from ComSemApp.models import *



Expand Down Expand Up @@ -86,3 +86,16 @@ class StudentForm(ModelForm):
class Meta:
model = Student
fields = ['country', 'language']

class ReplyForm(ModelForm):
message = forms.CharField( widget=forms.Textarea(attrs={'style': "width:100%", 'placeholder': 'Enter reply here.'}))
class Meta:
model = Reply
fields = ["message"]

class TopicForm(ModelForm):
message = forms.CharField( widget=forms.Textarea(attrs={'style': "width:100%"}))
title = forms.CharField(widget=forms.TextInput(attrs={'style': "width:100%"}))
class Meta:
model = Reply
fields = ["title", "message"]
5 changes: 5 additions & 0 deletions ComSemApp/administrator/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from ComSemApp.administrator import views
from ComSemApp.corpus import views as corpus_views

from ComSemApp.discussionBoard import view as discussion_views

app_name = 'admin'
urlpatterns = [
url(r'^$', views.TeacherListView.as_view(), name='home'),
Expand Down Expand Up @@ -37,5 +39,8 @@
url(r'^session_type/(?P<pk>[0-9]+)/delete/$', views.SessionTypeDeleteView.as_view(), name='delete_session_type'),

url(r'^corpus/search$', corpus_views.corpus_search, name='corpus_search'),
url(r'^discussion_board$', discussion_views.TopicListView.as_view(), name='admin_discussion_board'),
url(r'^topic/(?P<topic_id>[0-9]+)/$', discussion_views.ReplyView.as_view(), name='admin_topic'),
url(r'^newtopic/$', discussion_views.CreateThreadView.as_view(),name='admin_create_topic')
]

2 changes: 1 addition & 1 deletion ComSemApp/discussionBoard/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
urlpatterns = [
url(r'^$', view.TopicListView.as_view(), name='topics'),
url(r'^topic/(?P<topic_id>[0-9]+)/$', view.ReplyView.as_view(), name='topic'),
url(r'^$', view.CreateThreadView.as_view(),name='create_topic')
url(r'^newtopic/$', view.CreateThreadView.as_view(),name='create_topic')
]
125 changes: 118 additions & 7 deletions ComSemApp/discussionBoard/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@
from django.contrib.auth.decorators import login_required
from django.contrib.auth.decorators import user_passes_test
from django.db.models import Q
from django.views.generic import ListView, DetailView, CreateView, UpdateView
from django.views.generic import ListView, DetailView, CreateView, UpdateView, FormView
from django.http import JsonResponse, HttpResponseRedirect
from django.urls import reverse
from django.contrib import messages
from django.urls import reverse_lazy
from django import forms
from django.urls import resolve
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin

from ComSemApp.teacher import constants as teacher_constants

from ComSemApp.models import *
from ComSemApp.libs.mixins import RoleViewMixin, CourseViewMixin, WorksheetViewMixin, SubmissionViewMixin
from ComSemApp.administrator.forms import ReplyForm, TopicForm


#This class deals with listing out all the topics within database
Expand All @@ -28,9 +32,18 @@ class TopicListView(LoginRequiredMixin,ListView):
context_object_name = 'topics'

def get_queryset(self):
return Topic.objects.filter()
return Topic.objects.filter().order_by("-id")

class ReplyMixin(LoginRequiredMixin, ListView, object):
context_object_name = 'replies'
template_name = 'ComSemApp/discussionBoard/add_reply.html'
fields = ["message", "personPosted", "topic", "hasMark"]
success_url = reverse_lazy("discussionBoard:topic")

def get_form_kwargs(self):
kwargs = super(ReplyMixin, self).get_form_kwargs()
return kwargs

class ReplyMixin(LoginRequiredMixin, object):
def dispatch(self, request, *args, **kwargs):
topic_id = kwargs.get('topic_id', None)
topics = Topic.objects.filter(id = topic_id)
Expand All @@ -41,20 +54,118 @@ def dispatch(self, request, *args, **kwargs):



class ReplyView(ReplyMixin, ListView):
class ReplyView(ReplyMixin, FormView):
model = Reply
template_name = 'ComSemApp/discussionBoard/reply_page.html'
context_object_name = 'replies'
fields = ["message", "personPosted", "topic", "hasMark"]

def get_queryset(self):
return Reply.objects.filter(topic = self.topic)

def get_context_data(self, **kwargs):
def get_context_data(self ,**kwargs):
self.object_list = self.get_queryset()
context = super(ReplyView, self).get_context_data(**kwargs)
context['topic_description'] = self.topic.topic
context['discussion_board'] = True
return context

class CreateThreadView(LoginRequiredMixin,CreateView):
print("Hello World")
def form_invalid(self, reply_form, **kwargs):
response = super().form_invalid(reply_form)
return JsonResponse(reply_form.errors, status=400)

def get(self, request, *args, **kwargs):
allow_empty = True
reply_form = ReplyForm()
reply_form.prefix = 'reply_form'
return self.render_to_response(self.get_context_data(form=reply_form))

def post(self, request, *args, **kwargs):
current_url = resolve(request.path_info).url_name
reply_form = ReplyForm(self.request.POST, prefix = 'reply_form')
likeButton = request.POST.get("like")
dislikeButton = request.POST.get("dislike")
if likeButton:
print(likeButton)
reply = Reply.objects.get(id = int(likeButton))
reply.hasMark = 1
reply.save()
if current_url == "admin_topic":
return HttpResponseRedirect(reverse("administrator:admin_topic", kwargs={'topic_id': self.topic.id }))
elif current_url == "teacher_topic":
return HttpResponseRedirect(reverse("teacher:teacher_topic", kwargs={'topic_id': self.topic.id }))
elif current_url == "student_topic":
return HttpResponseRedirect(reverse("student:student_topic", kwargs={'topic_id': self.topic.id }))
else:
return HttpResponseRedirect(reverse("discussion_board:topic", kwargs={'topic_id': self.topic.id }))
elif dislikeButton:
print(dislikeButton)
reply = Reply.objects.get(id = int(dislikeButton))
reply.hasMark = 0
reply.save()
if current_url == "admin_topic":
return HttpResponseRedirect(reverse("administrator:admin_topic", kwargs={'topic_id': self.topic.id }))
elif current_url == "teacher_topic":
return HttpResponseRedirect(reverse("teacher:teacher_topic", kwargs={'topic_id': self.topic.id }))
elif current_url == "student_topic":
return HttpResponseRedirect(reverse("student:student_topic", kwargs={'topic_id': self.topic.id }))
else:
return HttpResponseRedirect(reverse("discussion_board:topic", kwargs={'topic_id': self.topic.id }))
elif reply_form.is_valid():
print("it is giving this if statement a thing")
reply = reply_form.save(commit=False)
reply.personPosted = request.user
reply.topic = self.topic
reply.hasMark = 0
reply.save()

if current_url == "admin_topic":
return HttpResponseRedirect(reverse("administrator:admin_topic", kwargs={'topic_id': self.topic.id }))
elif current_url == "teacher_topic":
return HttpResponseRedirect(reverse("teacher:teacher_topic", kwargs={'topic_id': self.topic.id }))
elif current_url == "student_topic":
return HttpResponseRedirect(reverse("student:student_topic", kwargs={'topic_id': self.topic.id }))
else:
return HttpResponseRedirect(reverse("discussion_board:topic", kwargs={'topic_id': self.topic.id }))
else:
return self.form_invalid(reply_form, **kwargs)



class CreateThreadView(LoginRequiredMixin,FormView):
model = Reply
template_name = 'ComSemApp/discussionBoard/create_topic.html'
context_object_name = 'replies'
fields = ["message", "personPosted", "topic", "hasMark"]

def form_invalid(self, topic_form, **kwargs):
response = super().form_invalid(form)
return JsonResponse(form.errors, status=400)

def get(self, request, *args, **kwargs):
allow_empty = True
topic_form = TopicForm()
topic_form.prefix = "topic_form"
return self.render_to_response(self.get_context_data(form=topic_form))

def post(self, request, *args, **kwargs):
topic_form = TopicForm(self.request.POST, prefix = 'topic_form')
current_url = resolve(request.path_info).url_name
if topic_form.is_valid():
topic = Topic(personPosted = request.user, topic = topic_form.cleaned_data["title"])
topic.save()
reply = topic_form.save(commit=False)
reply.personPosted = request.user
reply.topic = topic
reply.hasMark = 0
reply.save()
if current_url == "admin_create_topic":
return HttpResponseRedirect(reverse("administrator:admin_topic", kwargs={'topic_id': topic.id }))
elif current_url == "teacher_create_topic":
return HttpResponseRedirect(reverse("teacher:teacher_topic", kwargs={'topic_id': topic.id }))
elif current_url == "student_create_topic":
return HttpResponseRedirect(reverse("student:student_topic", kwargs={'topic_id': topic.id }))
else:
return HttpResponseRedirect(reverse("discussion_board:topic", kwargs={'topic_id': topic.id }))
else:
return self.form_invalid(topic_form, **kwargs)
39 changes: 39 additions & 0 deletions ComSemApp/static/ComSemApp/Dyslexic/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@font-face{
font-family: "Open-Dyslexic";
src:url('../fonts/OpenDyslexic-Regular.eot');
src:url('../fonts/OpenDyslexic-Regular.woff') format('woff'),
url('../fonts/OpenDyslexic-Regular.ttf') format('truetype'),
url('../fonts/OpenDyslexic-Regular.svg') format('svg');
font-weight: normal;
font-style: normal;
}

@font-face{
font-family: "Open-Dyslexic";
src:url('../fonts/OpenDyslexic-Italic.eot');
src:url('../fonts/OpenDyslexic-Italic.woff') format('woff'),
url('../fonts/OpenDyslexic-Italic.ttf') format('truetype'),
url('../fonts/OpenDyslexic-Italic.svg') format('svg');
font-weight: normal;
font-style:italic;
}

@font-face{
font-family: "Open-Dyslexic";
src:url('../fonts/OpenDyslexic-Bold.eot');
src:url('../fonts/OpenDyslexic-Bold.woff') format('woff'),
url('../fonts/OpenDyslexic-Bold.ttf') format('truetype'),
url('../fonts/OpenDyslexic-Bold.svg') format('svg');
font-weight: bold;
font-style: normal;
}

@font-face{
font-family: "Open-Dyslexic";
src:url('../fonts/OpenDyslexic-BoldItalic.eot');
src:url('../fonts/OpenDyslexic-BoldItalic.woff') format('woff'),
url('../fonts/OpenDyslexic-BoldItalic.ttf') format('truetype'),
url('../fonts/OpenDyslexic-BoldItalic.svg') format('svg');
font-weight: bold;
font-style: italic;
}
Binary file not shown.
Loading