diff options
-rw-r--r-- | workshop_app/forms.py | 15 | ||||
-rw-r--r-- | workshop_app/templates/workshop_app/add_workshop_type.html | 50 | ||||
-rw-r--r-- | workshop_app/templates/workshop_app/workshop_type_details.html | 33 | ||||
-rw-r--r-- | workshop_app/templates/workshop_app/workshop_type_list.html | 60 | ||||
-rw-r--r-- | workshop_app/urls.py | 3 | ||||
-rw-r--r-- | workshop_app/views.py | 23 |
6 files changed, 121 insertions, 63 deletions
diff --git a/workshop_app/forms.py b/workshop_app/forms.py index 334bd4e..fcb34c4 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, ProfileComments, department_choices, title, source, states, WorkshopType) try: from string import letters @@ -189,3 +189,16 @@ class ProfileCommentsForm(forms.ModelForm): widgets = { 'comments': forms.CharField(), } + + +class WorkshopTypeForm(forms.ModelForm): + def __init__(self, *args, **kwargs): + super(WorkshopTypeForm, self).__init__(*args, **kwargs) + for field in self.visible_fields(): + field.field.widget.attrs['class'] = 'form-control' + field.field.widget.attrs['placeholder'] = field.label + field.field.widget.attrs['rows'] = 6 + + class Meta: + model = WorkshopType + exclude = [] diff --git a/workshop_app/templates/workshop_app/add_workshop_type.html b/workshop_app/templates/workshop_app/add_workshop_type.html new file mode 100644 index 0000000..ed28b03 --- /dev/null +++ b/workshop_app/templates/workshop_app/add_workshop_type.html @@ -0,0 +1,50 @@ +{% extends 'workshop_app/base.html' %} + +{% block title %} + Add new Workshop type +{% endblock %} + +{% block content %} + <div class="container"> + <h2 class="text-center m-2">New Workshop Type</h2> + <br> + <form method="post"> + <div class="row my-3"> + <div class="col-3 font-weight-bold">Workshop Name :</div> + <div class="col text-left"> + <div class="row"><div class="col">{{ form.name }}</div></div> + <div class="row m-1 text-danger"><div class="col">{{ form.name.errors }}</div></div> + </div> + + </div> + <div class="row my-3"> + <div class="col-3 font-weight-bold">Duration :</div> + <div class="col text-left"> + <div class="row"><div class="col">{{ form.duration }}</div></div> + <div class="row m-1 text-muted"><div class="col">{{ form.duration.help_text }}</div></div> + <div class="row m-1 text-danger"><div class="col">{{ form.duration.errors }}</div></div> + </div> + </div> + <div class="row my-3"> + <div class="col-3 font-weight-bold">Description :</div> + <div class="col text-left"> + <div class="row"><div class="col">{{ form.description }}</div></div> + <div class="row m-1 text-danger"><div class="col">{{ form.description.errors }}</div></div> + </div> + </div> + <div class="row my-3"> + <div class="col-3 font-weight-bold">Terms and Conditions :</div> + <div class="col text-left"> + <div class="row"><div class="col">{{ form.terms_and_conditions }}</div></div> + <div class="row m-1 text-danger"><div class="col">{{ form.terms_and_conditions.errors }}</div></div> + </div> + </div> + + <div class="row my-3"> + <div class="col-12"> + <button type="submit" class="btn btn-md btn-primary float-right m-3">Create</button> + </div> + </div> + </form> + </div> +{% endblock %}
\ No newline at end of file diff --git a/workshop_app/templates/workshop_app/workshop_type_details.html b/workshop_app/templates/workshop_app/workshop_type_details.html index b8d6559..298d976 100644 --- a/workshop_app/templates/workshop_app/workshop_type_details.html +++ b/workshop_app/templates/workshop_app/workshop_type_details.html @@ -1,23 +1,40 @@ - {% extends 'workshop_app/base.html' %} {% block title %} - View Workshop details + View Workshop details {% endblock %} {% block extra %} - <!-- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> --> + <!-- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> --> - <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> - <script src="{{URL_ROOT}}/static/workshop_app/js/bootstrap-3.3.7.min.js"></script> + <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> + <script src="{{ URL_ROOT }}/static/workshop_app/js/bootstrap-3.3.7.min.js"></script> {% endblock %} {% block content %} - <div class="container"> - {{ workshop_type.description | safe }} - </div> + <div class="container"> + <h2 class="text-center m-3">Workshop Details</h2> + <table class="table table-hover"> + <tr class="d-flex"> + <th class="col-3">Workshop Name :</th> + <td class="col">{{ workshop_type.name }}</td> + </tr> + <tr class="d-flex"> + <th class="col-3">Duration :</th> + <td class="col">{{ workshop_type.duration }}</td> + </tr> + <tr class="d-flex"> + <th class="col-3">Description :</th> + <td class="col">{{ workshop_type.description }}</td> + </tr> + <tr class="d-flex"> + <th class="col-3">Terms and Conditions :</th> + <td class="col">{{ workshop_type.terms_and_conditions }}</td> + </tr> + </table> + </div> {% endblock %} diff --git a/workshop_app/templates/workshop_app/workshop_type_list.html b/workshop_app/templates/workshop_app/workshop_type_list.html index 0531864..a3d9c6e 100644 --- a/workshop_app/templates/workshop_app/workshop_type_list.html +++ b/workshop_app/templates/workshop_app/workshop_type_list.html @@ -4,55 +4,16 @@ View List of available Workshops {% endblock %} -{% block extra %} - - <!-- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> --> - <style> - /* The Modal (background) */ - .modal { - display: none; /* Hidden by default */ - position: fixed; /* Stay in place */ - z-index: 1; /* Sit on top */ - padding-top: 100px; /* Location of the box */ - left: 0; - top: 0; - width: 100%; /* Full width */ - height: 100%; /* Full height */ - overflow: auto; /* Enable scroll if needed */ - background-color: rgb(0,0,0); /* Fallback color */ - background-color: rgba(0,0,0,0.4); /* Black w/ opacity */ - } - - /* Modal Content */ - .modal-content { - background-color: #fefefe; - margin: auto; - padding: 20px; - border: 1px solid #888; - width: 80%; - } - - /* The Close Button */ - .close { - color: #aaaaaa; - float: right; - font-size: 28px; - font-weight: bold; - } - .close:hover, - .close:focus { - color: #000; - text-decoration: none; - cursor: pointer; - } - </style> - - <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> - <script src="{{URL_ROOT}}/static/workshop_app/js/bootstrap-3.3.7.min.js"></script> - {% endblock %} - {% block content %} - + <div class="container"> + <h2 class="text-center">Workshop Types</h2> + <br> + {% if request.user.profile.position == 'instructor' %} + <a href="{% url 'add_workshop_type' %}"> + <button class="btn btn-md btn-primary float-right mb-3 mx-4">Add Workshop Type</button> + </a> + <br> + {% endif %} <div class="container"> <table class="table table-hover"> <thead> @@ -60,6 +21,7 @@ <th>id</th> <th>Workshop Name</th> <th>Workshop Duration</th> + <th>Action</th> </tr> </thead> @@ -119,5 +81,5 @@ </nav> </div> </div> - +</div> {% endblock %} diff --git a/workshop_app/urls.py b/workshop_app/urls.py index 4bb140c..76a0be6 100644 --- a/workshop_app/urls.py +++ b/workshop_app/urls.py @@ -32,6 +32,7 @@ urlpatterns = [ url(r'^my_workshops/$', views.my_workshops), url(r'^propose_workshop/$', views.propose_workshop), url(r'^workshop_types/$', views.workshop_type_list), - url(r'^workshop_type_details/([1-9][0-9]*)$', views.workshop_type_details), + url(r'^workshop_type_details/([1-9][0-9]*)$', views.workshop_type_details, name='workshop_type_details'), + url(r'^add_workshop_type$', views.add_workshop_type, name='add_workshop_type'), url(r'^view_profile/([1-9][0-9]*)$', views.view_comment_profile), ] diff --git a/workshop_app/views.py b/workshop_app/views.py index 5d0525c..d71f066 100644 --- a/workshop_app/views.py +++ b/workshop_app/views.py @@ -1,3 +1,5 @@ +from django.urls import reverse + try: from StringIO import StringIO as string_io except ImportError: @@ -6,13 +8,13 @@ from datetime import datetime from django.contrib.auth import login, logout, authenticate from django.contrib.auth.decorators import login_required -from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger +from django.core.paginator import Paginator from django.shortcuts import render, redirect from django.utils import timezone from .forms import ( UserRegistrationForm, UserLoginForm, - ProfileForm, WorkshopForm + ProfileForm, WorkshopForm, WorkshopTypeForm ) from .models import ( Profile, User, @@ -360,14 +362,27 @@ def workshop_type_list(request): workshop_types = WorkshopType.objects.all() paginator = Paginator(workshop_types, 12) # Show upto 12 workshops per page - page = request.GET.get('page') - workshop_type = paginator.get_page(paginator.num_pages) + workshop_type = paginator.get_page(page) return render(request, 'workshop_app/workshop_type_list.html', {'workshop_type': workshop_type}) @login_required +def add_workshop_type(request): + if not is_instructor(request.user): + return redirect(get_landing_page(request.user)) + if request.method == 'POST': + form = WorkshopTypeForm(request.POST) + if form.is_valid(): + form_data = form.save() + return redirect(reverse('workshop_type_details', args=[form_data.id])) + else: + form = WorkshopTypeForm + return render(request, 'workshop_app/add_workshop_type.html', {'form': form}) + + +@login_required def view_comment_profile(request, user_id): """instructor can view/post comments on coordinator profile """ user = request.user |