summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--workshop_app/admin.py9
-rw-r--r--workshop_app/forms.py27
-rw-r--r--workshop_app/models.py16
-rw-r--r--workshop_app/templates/workshop_app/base.html7
-rw-r--r--workshop_app/templates/workshop_app/workshop_details.html83
-rw-r--r--workshop_app/templates/workshop_app/workshop_status_coordinator.html6
-rw-r--r--workshop_app/templates/workshop_app/workshop_status_instructor.html8
-rw-r--r--workshop_app/urls.py3
-rw-r--r--workshop_app/views.py33
9 files changed, 154 insertions, 38 deletions
diff --git a/workshop_app/admin.py b/workshop_app/admin.py
index 4e3d333..5182776 100644
--- a/workshop_app/admin.py
+++ b/workshop_app/admin.py
@@ -6,7 +6,7 @@ from django.http import HttpResponse
from .models import (
Profile, WorkshopType,
Workshop,
- Testimonial, ProfileComments, Banner, AttachmentFile
+ Testimonial, WorkshopComment, Banner, AttachmentFile
)
try:
@@ -117,8 +117,9 @@ class TestimonialAdmin(admin.ModelAdmin):
download_csv.short_description = "Download CSV file for selected stats."
-class ProfileCommentAdmin(admin.ModelAdmin):
- list_display = ['comment', 'created_date', 'coordinator', 'instructor']
+class WorkshopCommentAdmin(admin.ModelAdmin):
+ list_display = ['workshop', 'comment', 'created_date', 'author', 'public']
+ list_filter = ['workshop', 'author', 'created_date', 'public']
# Register your models here.
@@ -126,6 +127,6 @@ admin.site.register(Profile, ProfileAdmin)
admin.site.register(WorkshopType, WorkshopTypeAdmin)
admin.site.register(Workshop, WorkshopAdmin)
admin.site.register(Testimonial, TestimonialAdmin)
-admin.site.register(ProfileComments, ProfileCommentAdmin)
+admin.site.register(WorkshopComment, WorkshopCommentAdmin)
admin.site.register(Banner)
admin.site.register(AttachmentFile)
diff --git a/workshop_app/forms.py b/workshop_app/forms.py
index 334bd4e..6099a76 100644
--- a/workshop_app/forms.py
+++ b/workshop_app/forms.py
@@ -3,7 +3,7 @@ from string import punctuation, digits
from django import forms
from django.utils import timezone
-from .models import (Profile, Workshop, ProfileComments, department_choices, title, source, states)
+from .models import (Profile, Workshop, department_choices, title, source, states, WorkshopComment)
try:
from string import letters
@@ -170,22 +170,25 @@ class WorkshopForm(forms.ModelForm):
}
-class ProfileCommentsForm(forms.ModelForm):
+class WorkshopCommentsForm(forms.ModelForm):
"""
- Instructors will post comments on Coordinators profile
+ Users will post comments on workshops
"""
def __init__(self, *args, **kwargs):
- super(ProfileCommentsForm, self).__init__(*args, **kwargs)
- self.fields['comment'].label = ""
- self.fields['comment'].widget.attrs['rows'] = 5
- self.fields['comment'].widget.attrs['cols'] = 95
+ kwargs.setdefault('label_suffix', '')
+ super(WorkshopCommentsForm, self).__init__(*args, **kwargs)
+ self.fields['comment'].required = True
+ self.fields['public'].label = "Public"
class Meta:
- model = ProfileComments
- exclude = ['coordinator_profile', 'instructor_profile',
- 'created_date'
- ]
+ model = WorkshopComment
+ exclude = ['author', 'created_date', 'workshop']
widgets = {
- 'comments': forms.CharField(),
+ 'comment': forms.Textarea(attrs={
+ 'class': 'form-control',
+ }),
+ 'public': forms.CheckboxInput(attrs={
+ 'class': 'form-check-input',
+ })
}
diff --git a/workshop_app/models.py b/workshop_app/models.py
index b35d9a7..616e3de 100644
--- a/workshop_app/models.py
+++ b/workshop_app/models.py
@@ -200,26 +200,26 @@ class Testimonial(models.Model):
)
-class ProfileComments(models.Model):
+class WorkshopComment(models.Model):
"""
- Contains comments posted by instructors on coordinator profile
+ Contains comments posted by users on workshop instances
"""
- coordinator = models.ForeignKey(User,
- on_delete=models.CASCADE)
+ author = models.ForeignKey(User, on_delete=models.CASCADE)
comment = models.TextField()
- instructor = models.ForeignKey(User, related_name="%(app_label)s_%(class)s_related", on_delete=models.CASCADE)
+ public = models.BooleanField(default=True)
created_date = models.DateTimeField(default=timezone.now)
+ workshop = models.ForeignKey(Workshop, on_delete=models.CASCADE)
def __str__(self):
- return u"{0} | {1}".format(
+ return u"{0} | {1} | {2}".format(
self.comment,
self.created_date,
- self.coordinator,
- self.instructor
+ self.author,
)
+
class Banner(models.Model):
"""
Add HTML for banner display on homepage
diff --git a/workshop_app/templates/workshop_app/base.html b/workshop_app/templates/workshop_app/base.html
index c7a454e..88ee1a1 100644
--- a/workshop_app/templates/workshop_app/base.html
+++ b/workshop_app/templates/workshop_app/base.html
@@ -43,7 +43,7 @@
<ul class="navbar-nav mr-auto">
{% if request.user.profile.position == 'coordinator' %}
<li class="nav-item">
- <a class="nav-link" href="/my_workshops/">Workshop Status</a>
+ <a class="nav-link" href="{% url 'workshop_status_coordinator' %}">Workshop Status</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/propose_workshop/">Propose Workshop</a>
@@ -53,7 +53,7 @@
</li>
{% elif request.user.profile.position == 'instructor' %}
<li class="nav-item">
- <a class="nav-link" href="/my_workshops/">Workshop Status</a>
+ <a class="nav-link" href="{% url 'workshop_status_instructor' %}">Workshop Status</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/workshop_types/">Workshop Types</a>
@@ -91,10 +91,11 @@
</nav>
{% endblock %}
+<div class="container-fluid" style="margin-bottom: 44px">
{% block content %}
<h1>Base Template Content. Please override me</h1>
{% endblock %}
-
+</div>
</body>
<footer class="footer">
diff --git a/workshop_app/templates/workshop_app/workshop_details.html b/workshop_app/templates/workshop_app/workshop_details.html
new file mode 100644
index 0000000..3ca5a50
--- /dev/null
+++ b/workshop_app/templates/workshop_app/workshop_details.html
@@ -0,0 +1,83 @@
+{% extends 'workshop_app/base.html' %}
+
+{% block title %}
+ View Workshop details
+{% endblock %}
+
+{% block content %}
+ <div class="container">
+ <table class="table table-bordered">
+ <tr>
+ <th><label for="id_first_name">Workshop Type :</label></th>
+ <td><label for="id_first_name"><a
+ href="{% url 'workshop_type_details' workshop.workshop_type_id %}">{{ workshop.workshop_type }}</a></label>
+ </td>
+ </tr>
+ <tr>
+ <th><label for="id_last_name">Date :</label></th>
+ <td><label for="id_last_name">{{ workshop.date }}</label></td>
+ </tr>
+ <tr>
+ <th><label for="id_email">Coordinator :</label></th>
+ <td><label for="id_email"><a
+ href="{% url 'view_profile' workshop.coordinator_id %}">{{ workshop.coordinator }}</a></label>
+ </td>
+ </tr>
+ {% if workshop.status %}
+ <tr>
+ <th><label for="id_institute">Status :</label></th>
+ <td><span class="badge badge-success">{{ workshop.get_status }}</span></td>
+ </tr>
+ <tr>
+ <th><label for="id_phone_number">Instructor :</label></th>
+ <td><label for="id_email"><a
+ href="{% url 'view_profile' workshop.instructor_id %}">{{ workshop.instructor }}</a></label>
+ </td>
+ </tr>
+ {% else %}
+ <tr>
+ <th><label for="id_institute">Status :</label></th>
+ <td><span class="badge badge-warning">{{ workshop.get_status }}</span></td>
+ </tr>
+ {% endif %}
+ </table>
+ <br>
+ <div class="container">
+ <h2 class="text-center">Comments</h2>
+ <br>
+ {% for comment in workshop_comments %}
+ <div class="card my-2">
+ <div class="card-header">
+ <div class="row">
+ <div class="mx-3 font-weight-bold"><a
+ href="{% url 'view_profile' comment.author_id %}">{{ comment.author }}</a></div>
+ <div class="text-muted">{{ comment.created_date }}</div>
+ </div>
+ </div>
+ <div class="card-body">
+ <p>{{ comment.comment }}</p>
+ </div>
+ </div>
+ {% endfor %}
+ <br><br>
+ <div class="card mt-2 mb-5">
+ <form method="post">
+ <div class="card-header">
+ <div class="row">
+ <div class="mx-3 font-weight-bold">Post a comment</div>
+ {% if request.user.profile.position == 'instructor' %}
+ <div class="ml-5">{{ form.public }} Public</div>
+ <div class="ml-1 text-muted">(Non-public comments are visible only to instructors)</div>
+ {% endif %}
+ </div>
+ </div>
+ <div class="card-body">
+ {{ form.comment }}
+ </div>
+ <button type="submit" class="float-right btn btn-primary btn-md m-2">Post</button>
+ </form>
+ </div>
+ </div>
+ </div>
+
+{% endblock %} \ No newline at end of file
diff --git a/workshop_app/templates/workshop_app/workshop_status_coordinator.html b/workshop_app/templates/workshop_app/workshop_status_coordinator.html
index 00e28b3..e1c790a 100644
--- a/workshop_app/templates/workshop_app/workshop_status_coordinator.html
+++ b/workshop_app/templates/workshop_app/workshop_status_coordinator.html
@@ -33,8 +33,8 @@
<table class="table table-striped">
<thead>
<tr>
- <th>Instructor Name</th>
<th>Workshop Name</th>
+ <th>Instructor Name</th>
<th>Workshop Day</th>
<th>Status</th>
</tr>
@@ -44,8 +44,8 @@
<tbody>
<tr>
{% if workshop.status %}
+ <td><a href="{% url 'workshop_details' workshop.id %}" >{{ workshop.workshop_type |capfirst }}</a></td>
<td>{{ workshop.instructor.get_full_name }}</td>
- <td>{{ workshop.workshop_type |capfirst }}</td>
<td>{{ workshop.date | date }}</td>
<td><span class="badge badge-success">{{ workshop.get_status }}</span></td>
{% endif %}
@@ -73,7 +73,7 @@
<tbody>
<tr>
{% if not workshop.status and workshop.tnc_accepted %}
- <td>{{ workshop.workshop_type }}</td>
+ <td><a href="{% url 'workshop_details' workshop.id %}" >{{ workshop.workshop_type |capfirst }}</a></td>
<td>{{ workshop.date | date }}</td>
<td><span class="badge badge-warning">{{ workshop.get_status }}</span></td>
{% endif %}
diff --git a/workshop_app/templates/workshop_app/workshop_status_instructor.html b/workshop_app/templates/workshop_app/workshop_status_instructor.html
index ef64a70..8657b8d 100644
--- a/workshop_app/templates/workshop_app/workshop_status_instructor.html
+++ b/workshop_app/templates/workshop_app/workshop_status_instructor.html
@@ -42,9 +42,9 @@
<table class="table table-striped">
<thead>
<tr>
+ <th>Workshop Name</th>
<th>Coordinator Name</th>
<th>Institute</th>
- <th>Workshop Name</th>
<th>Workshop Day</th>
<th>Status</th>
</tr>
@@ -53,12 +53,12 @@
<tbody>
<tr>
{% if workshop.status %}
+ <td><a href="{% url 'workshop_details' workshop.id %}" >{{ workshop.workshop_type |capfirst }}</a></td>
<td>
<a href="{% url 'view_profile' workshop.coordinator.profile.user.id %}">
{{ workshop.coordinator.get_full_name }}</a>
</td>
<td>{{ workshop.coordinator.profile.institute }}</td>
- <td>{{ workshop.workshop_type |capfirst }}</td>
<td>{{ workshop.date | date }}
{% if workshop.date > today %}
@@ -97,9 +97,9 @@
<table class="table table-striped">
<thead>
<tr>
+ <th>Workshop Name</th>
<th>Coordinator Name</th>
<th>Institute</th>
- <th>Workshop Name</th>
<th>Workshop Day</th>
<th>Status</th>
<th>Action</th>
@@ -110,12 +110,12 @@
<tbody>
<tr>
{% if not workshop.status and workshop.tnc_accepted %}
+ <td><a href="{% url 'workshop_details' workshop.id %}" >{{ workshop.workshop_type |capfirst }}</a></td>
<td>
<a href="{% url 'view_profile' workshop.coordinator.profile.user.id %}">
{{ workshop.coordinator.get_full_name }}</a>
</td>
<td>{{ workshop.coordinator.profile.institute }}</td>
- <td>{{ workshop.workshop_type }}</td>
<td>{{ workshop.date | date }}</td>
<td><span class="badge badge-warning">{{ workshop.get_status }}</span></td>
<td>
diff --git a/workshop_app/urls.py b/workshop_app/urls.py
index 4c63c4c..eb101c3 100644
--- a/workshop_app/urls.py
+++ b/workshop_app/urls.py
@@ -31,7 +31,8 @@ urlpatterns = [
url(r'^change_workshop_date/(?P<workshop_id>\d+)$', views.change_workshop_date, name='change_workshop_date'),
url(r'^propose_workshop/$', views.propose_workshop),
url(r'^workshop_types/$', views.workshop_type_list),
+ url(r'^workshops/(?P<workshop_id>\d+)$', views.workshop_details, name='workshop_details'),
+ url(r'^workshop_type_details/(?P<workshop_type_id>\d+)$', views.workshop_type_details, name='workshop_type_details'),
url(r'^workshop_type_tnc/(?P<workshop_type_id>\d+)$', views.workshop_type_tnc, name='workshop_type_tnc'),
- url(r'^workshop_type_details/(?P<workshop_type_id>\d+)$', views.workshop_type_details),
url(r'^view_profile/(?P<workshop_type_id>\d+)$', views.view_comment_profile, name='view_profile'),
]
diff --git a/workshop_app/views.py b/workshop_app/views.py
index ab59795..b2f56cc 100644
--- a/workshop_app/views.py
+++ b/workshop_app/views.py
@@ -1,5 +1,5 @@
-from django.http import JsonResponse, Http404
from django.db.models import Q
+from django.http import JsonResponse, Http404
from django.urls import reverse
try:
@@ -16,12 +16,12 @@ from django.utils import timezone
from .forms import (
UserRegistrationForm, UserLoginForm,
- ProfileForm, WorkshopForm
+ ProfileForm, WorkshopForm, WorkshopCommentsForm
)
from .models import (
Profile, User,
Workshop,
- WorkshopType
+ WorkshopType, WorkshopComment
)
from .send_mails import send_email
@@ -376,6 +376,33 @@ def workshop_type_list(request):
@login_required
+def workshop_details(request, workshop_id):
+ workshop = Workshop.objects.filter(id=workshop_id)
+ if not workshop.exists():
+ raise Http404
+ workshop = workshop.first()
+ if request.method == 'POST':
+ form = WorkshopCommentsForm(request.POST)
+ if form.is_valid():
+ form_data = form.save(commit=False)
+ if not is_instructor(request.user):
+ form_data.public = True
+ form_data.author = request.user
+ form_data.created_date = timezone.now()
+ form_data.workshop = workshop
+ form.save()
+ else:
+ print(form.errors)
+ if is_instructor(request.user):
+ workshop_comments = WorkshopComment.objects.filter(workshop=workshop)
+ else:
+ workshop_comments = WorkshopComment.objects.filter(workshop=workshop, public=True)
+ return render(request, 'workshop_app/workshop_details.html',
+ {'workshop': workshop, 'workshop_comments': workshop_comments,
+ 'form': WorkshopCommentsForm(initial={'public': True})})
+
+
+@login_required
def view_comment_profile(request, user_id):
"""Instructor can view coordinator profile """
user = request.user