summaryrefslogtreecommitdiff
path: root/workshop_app
diff options
context:
space:
mode:
Diffstat (limited to 'workshop_app')
-rw-r--r--workshop_app/admin.py5
-rw-r--r--workshop_app/forms.py127
-rw-r--r--workshop_app/models.py28
-rw-r--r--workshop_app/static/workshop_app/css/modal.css20
-rw-r--r--workshop_app/static/workshop_app/css/sticky-footer.css10
-rw-r--r--workshop_app/static/workshop_app/js/overlay.js7
-rw-r--r--workshop_app/templates/workshop_app/base.html52
-rw-r--r--workshop_app/templates/workshop_app/booking.html22
-rw-r--r--workshop_app/templates/workshop_app/create_workshop.html48
-rw-r--r--workshop_app/templates/workshop_app/edit_profile.html37
-rw-r--r--workshop_app/templates/workshop_app/index.html10
-rw-r--r--workshop_app/templates/workshop_app/login.html20
-rw-r--r--workshop_app/templates/workshop_app/logout.html16
-rw-r--r--workshop_app/templates/workshop_app/manage.html35
-rw-r--r--workshop_app/templates/workshop_app/profile_updated.html28
-rw-r--r--workshop_app/templates/workshop_app/register.html18
-rw-r--r--workshop_app/templates/workshop_app/view_course_details.html26
-rw-r--r--workshop_app/templates/workshop_app/view_course_list.html101
-rw-r--r--workshop_app/templates/workshop_app/view_profile.html57
-rw-r--r--workshop_app/views.py64
20 files changed, 714 insertions, 17 deletions
diff --git a/workshop_app/admin.py b/workshop_app/admin.py
index 5a4da13..b980438 100644
--- a/workshop_app/admin.py
+++ b/workshop_app/admin.py
@@ -1,6 +1,7 @@
from django.contrib import admin
-from .models import Profile, Courses
+from .models import Profile, Course, Workshop
# Register your models here.
admin.site.register(Profile)
-admin.site.register(Courses) \ No newline at end of file
+admin.site.register(Course)
+admin.site.register(Workshop) \ No newline at end of file
diff --git a/workshop_app/forms.py b/workshop_app/forms.py
new file mode 100644
index 0000000..3cc0021
--- /dev/null
+++ b/workshop_app/forms.py
@@ -0,0 +1,127 @@
+from django import forms
+from .models import Profile, Course, Workshop
+from string import punctuation, digits, letters
+from django.contrib.auth.models import User
+from django.contrib.auth import authenticate
+
+
+
+UNAME_CHARS = letters + "._" + digits
+PWD_CHARS = letters + punctuation + digits
+
+position_choices = (
+ ("coordinator", "Coordinator"),
+ ("instructor", "Instructor")
+ )
+
+class UserRegistrationForm(forms.Form):
+ """A Class to create new form for User's Registration.
+ It has the various fields and functions required to register
+ a new user to the system"""
+
+ username = forms.CharField(max_length=32, help_text='''Letters, digits,
+ period only.''')
+ email = forms.EmailField()
+ password = forms.CharField(max_length=32, widget=forms.PasswordInput())
+ confirm_password = forms.CharField\
+ (max_length=32, widget=forms.PasswordInput())
+ first_name = forms.CharField(max_length=32)
+ last_name = forms.CharField(max_length=32)
+ institute = forms.CharField\
+ (max_length=128, help_text='Institute/Organization')
+ department = forms.CharField\
+ (max_length=64, help_text='Department you work/study at')
+ position = forms.ChoiceField\
+ (help_text='If you are an instructor please mail us at python[at]fossee[dot]in', choices=position_choices)
+
+ def clean_username(self):
+ u_name = self.cleaned_data["username"]
+ if u_name.strip(UNAME_CHARS):
+ msg = "Only letters, digits, period are"\
+ " allowed in username"
+ raise forms.ValidationError(msg)
+ try:
+ User.objects.get(username__exact=u_name)
+ raise forms.ValidationError("Username already exists.")
+ except User.DoesNotExist:
+ return u_name
+
+ def clean_password(self):
+ pwd = self.cleaned_data['password']
+ if pwd.strip(PWD_CHARS):
+ raise forms.ValidationError("Only letters, digits and punctuation\
+ are allowed in password")
+ return pwd
+
+ def clean_confirm_password(self):
+ c_pwd = self.cleaned_data['confirm_password']
+ pwd = self.data['password']
+ if c_pwd != pwd:
+ raise forms.ValidationError("Passwords do not match")
+
+ return c_pwd
+
+ def save(self):
+ u_name = self.cleaned_data["username"]
+ u_name = u_name.lower()
+ pwd = self.cleaned_data["password"]
+ email = self.cleaned_data['email']
+ new_user = User.objects.create_user(u_name, email, pwd)
+
+ new_user.first_name = self.cleaned_data["first_name"]
+ new_user.last_name = self.cleaned_data["last_name"]
+ new_user.save()
+
+ cleaned_data = self.cleaned_data
+ new_profile = Profile(user=new_user)
+ new_profile.institute = cleaned_data["institute"]
+ new_profile.department = cleaned_data["department"]
+ new_profile.position = cleaned_data["position"]
+
+ new_profile.save()
+
+ return u_name, pwd
+
+class UserLoginForm(forms.Form):
+ """Creates a form which will allow the user to log into the system."""
+
+ username = forms.CharField(max_length=32)
+ password = forms.CharField(max_length=32, widget=forms.PasswordInput())
+
+ def clean(self):
+ super(UserLoginForm, self).clean()
+ try:
+ u_name, pwd = self.cleaned_data["username"],\
+ self.cleaned_data["password"]
+ user = authenticate(username=u_name, password=pwd)
+ except Exception:
+ raise forms.ValidationError\
+ ("Username and/or Password is not entered")
+ if not user:
+ raise forms.ValidationError("Invalid username/password")
+ return user
+
+class ProfileForm(forms.ModelForm):
+ """ profile form for coordinator and instructor """
+
+ class Meta:
+ model = Profile
+ fields = ['first_name', 'last_name', 'institute', 'department',
+ 'position']
+
+ first_name = forms.CharField(max_length=32)
+ last_name = forms.CharField(max_length=32)
+
+ def __init__(self, *args, **kwargs):
+ if 'user' in kwargs:
+ user = kwargs.pop('user')
+ super(ProfileForm, self).__init__(*args, **kwargs)
+ self.fields['first_name'].initial = user.first_name
+ self.fields['last_name'].initial = user.last_name
+
+class CreateWorkshop(forms.ModelForm):
+ """Instructors can create Workshops based on the courses available."""
+
+ class Meta:
+ model = Workshop
+ fields = ['workshop_title', 'date', 'start_time', 'end_time'] \ No newline at end of file
diff --git a/workshop_app/models.py b/workshop_app/models.py
index 0dbff06..9aceb57 100644
--- a/workshop_app/models.py
+++ b/workshop_app/models.py
@@ -8,6 +8,12 @@ position_choices = (
("instructor", "Instructor")
)
+
+
+def has_profile(user):
+ """ check if user has profile """
+ return True if hasattr(user, 'profile') else False
+
class Profile(models.Model):
"""Profile for users(instructors and coordinators)"""
@@ -20,11 +26,7 @@ class Profile(models.Model):
return u"{0} {1} | {2}".format(self.user.first_name, self.user.last_name, self.user.email)
-def has_profile(user):
- """ check if user has profile """
- return True if hasattr(user, 'profile') else False
-
-class Courses(models.Model):
+class Course(models.Model):
""""Admin creates courses which can be used by the instructor to create workshops.
"""
@@ -32,7 +34,21 @@ class Courses(models.Model):
course_description = models.TextField()
course_duration = models.CharField(max_length=12)
-
def __str__(self):
return u"{0} {1}".format(self.course_name, self.course_duration)
+
+class Workshop(models.Model):
+ """Instructor Creates workshop based on
+ Courses available"""
+
+ workshop_creator = models.ForeignKey(Profile, on_delete=models.CASCADE)
+ workshop_title = models.ForeignKey(Course, on_delete=models.CASCADE,\
+ help_text='Select the course you would like to create a workshop for')
+ date = models.DateField()
+ start_time = models.TimeField()
+ end_time = models.TimeField()
+ status = models.BooleanField()
+
+ def __str__(self):
+ return u"{0} | {1}".format(self.workshop_title, self.date)
diff --git a/workshop_app/static/workshop_app/css/modal.css b/workshop_app/static/workshop_app/css/modal.css
new file mode 100644
index 0000000..dc767a0
--- /dev/null
+++ b/workshop_app/static/workshop_app/css/modal.css
@@ -0,0 +1,20 @@
+#overlay {
+ visibility: hidden;
+ position: absolute;
+ left: 0px;
+ top: 0px;
+ width:100%;
+ height:100%;
+ text-align:center;
+ z-index: 1000;
+}
+
+#overlay div {
+ width:900px;
+ height: 450px;
+ margin: 100px auto;
+ background-color: #fff;
+ border:1px solid #000;
+ padding:15px;
+ text-align:center;
+}
diff --git a/workshop_app/static/workshop_app/css/sticky-footer.css b/workshop_app/static/workshop_app/css/sticky-footer.css
new file mode 100644
index 0000000..42471ee
--- /dev/null
+++ b/workshop_app/static/workshop_app/css/sticky-footer.css
@@ -0,0 +1,10 @@
+.footer {
+ position: absolute;
+ bottom: 0;
+ padding-left: 75px;
+
+}
+
+.hiddenRow {
+ padding: 0 !important;
+} \ No newline at end of file
diff --git a/workshop_app/static/workshop_app/js/overlay.js b/workshop_app/static/workshop_app/js/overlay.js
new file mode 100644
index 0000000..6563c0d
--- /dev/null
+++ b/workshop_app/static/workshop_app/js/overlay.js
@@ -0,0 +1,7 @@
+function overlay(course_no) {
+ el = document.getElementById("overlay");
+ course_id = document.getElementById("course_id");
+ el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible";
+
+ console.log(course_no);
+} \ No newline at end of file
diff --git a/workshop_app/templates/workshop_app/base.html b/workshop_app/templates/workshop_app/base.html
new file mode 100644
index 0000000..cebab31
--- /dev/null
+++ b/workshop_app/templates/workshop_app/base.html
@@ -0,0 +1,52 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <title>
+ {% block title %}
+ HomePage
+ {% endblock %}
+ </title>
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
+
+ <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js">
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js">
+ <link href="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js">
+
+
+ <link rel="stylesheet" href="{{ URL_ROOT }}/static/workshop_app/css/sticky-footer.css" type="text/css" />
+</head>
+
+ {% block extra %}
+ {% endblock %}
+
+<body>
+
+ {% block header %}
+ <nav class="navbar navbar-inverse">
+ <div class="container-fluid">
+ <div class="navbar-header">
+ <a class="navbar-brand" href="#">Booking</a>
+ </div>
+ <ul class="nav navbar-nav">
+ <li class="active"><a href="#">Home</a></li>
+ </ul>
+ <ul class="nav navbar-nav navbar-right">
+ <li><a href="{{ URL_ROOT }}/register"><span class="glyphicon glyphicon-user"></span> Register</a></li>
+ <li><a href="{{ URL_ROOT }}/login"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
+ </ul>
+ </div>
+ </nav>
+ {% endblock %}
+
+ {% block content %}
+ <h1>Base Template Content. Please override me</h1>
+ {% endblock %}
+
+<footer class="footer">
+ <div class="container">
+ <p align="center">Developed by FOSSEE group, IIT Bombay</p>
+ </div>
+</footer>
+</body>
+</html> \ No newline at end of file
diff --git a/workshop_app/templates/workshop_app/booking.html b/workshop_app/templates/workshop_app/booking.html
new file mode 100644
index 0000000..05ddbb6
--- /dev/null
+++ b/workshop_app/templates/workshop_app/booking.html
@@ -0,0 +1,22 @@
+{% extends './base.html' %}
+
+{% block title %}
+ Booking
+{% endblock %}
+
+{% block header %}
+ <nav class="navbar navbar-inverse">
+ <div class="container-fluid">
+ <div class="navbar-header">
+ <a class="navbar-brand" href="#">WebSiteName</a>
+ </div>
+ <ul class="nav navbar-nav">
+ <li class="active"><a href="#">Home</a></li>
+ </ul>
+ <ul class="nav navbar-nav navbar-right">
+ <li><a href="{{ URL_ROOT }}/view_profile"><span class="glyphicon glyphicon-user"></span> Profile </a></li>
+ <li><a href="{{ URL_ROOT }}/logout"><span class="glyphicon glyphicon-log-in"></span> Logout</a></li>
+ </ul>
+ </div>
+ </nav>
+{% endblock %} \ No newline at end of file
diff --git a/workshop_app/templates/workshop_app/create_workshop.html b/workshop_app/templates/workshop_app/create_workshop.html
new file mode 100644
index 0000000..64727ad
--- /dev/null
+++ b/workshop_app/templates/workshop_app/create_workshop.html
@@ -0,0 +1,48 @@
+{% extends "./base.html" %}
+
+{% block title %}
+ Create Event
+{% endblock %}
+
+ {% block extra %}
+
+ <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
+
+ <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
+ <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
+ <script>
+ $( function() {
+ $( "#id_date" ).datepicker();
+ } );
+ </script>
+
+ {% endblock %}
+
+{% block header %}
+ <nav class="navbar navbar-inverse">
+ <div class="container-fluid">
+ <div class="navbar-header">
+ <a class="navbar-brand" href="{{ URL_ROOT}}/manage/">WebSiteName</a>
+ </div>
+ <ul class="nav navbar-nav">
+ <li class="active"><a href="{{ URL_ROOT }}/view_course_list">View Course List</a></li>
+
+ </ul>
+ <ul class="nav navbar-nav navbar-right">
+ <li><a href="{{ URL_ROOT }}/view_profile"><span class="glyphicon glyphicon-user"></span> Profile </a></li>
+ <li><a href="{{ URL_ROOT }}/logout"><span class="glyphicon glyphicon-log-in"></span> Logout</a></li>
+ </ul>
+ </div>
+ </nav>
+{% endblock %}
+
+{% block content %}
+ <div class="container">
+ <form method="post">
+ {% csrf_token %}
+ {{ form.as_p }}
+ <br>
+ <button class="btn btn-success" type="submit">Save</button>
+ </form>
+ </div>
+{% endblock %} \ No newline at end of file
diff --git a/workshop_app/templates/workshop_app/edit_profile.html b/workshop_app/templates/workshop_app/edit_profile.html
new file mode 100644
index 0000000..d2c5655
--- /dev/null
+++ b/workshop_app/templates/workshop_app/edit_profile.html
@@ -0,0 +1,37 @@
+{% extends "./base.html" %}
+
+{% block title %}
+ Edit Profile
+{% endblock %}
+
+{% block header %}
+ <nav class="navbar navbar-inverse">
+ <div class="container-fluid">
+ <div class="navbar-header">
+ <a class="navbar-brand" href="#">WebSiteName</a>
+ </div>
+ <ul class="nav navbar-nav">
+ <li class="active"><a href="#">Home</a></li>
+ </ul>
+ <ul class="nav navbar-nav navbar-right">
+ <li><a href="{{ URL_ROOT }}/view_profile"><span class="glyphicon glyphicon-user"></span> Profile </a></li>
+ <li><a href="{{ URL_ROOT }}/logout"><span class="glyphicon glyphicon-log-in"></span> Logout</a></li>
+ </ul>
+ </div>
+ </nav>
+{% endblock %}
+
+{% block content %}
+ <div class="container">
+ <form action="{{URL_ROOT}}/edit_profile/" method="post" >
+ {% csrf_token %}
+ <center>
+ <table class="table table-bordered">
+ {{ form.as_table }}
+ </table>
+ </center>
+ <br>
+ <button class="btn btn-primary pull-right" type="submit">Save Profile</button>
+ </form>
+ </div>
+{% endblock %} \ No newline at end of file
diff --git a/workshop_app/templates/workshop_app/index.html b/workshop_app/templates/workshop_app/index.html
new file mode 100644
index 0000000..7e163c8
--- /dev/null
+++ b/workshop_app/templates/workshop_app/index.html
@@ -0,0 +1,10 @@
+{% extends "./base.html" %}
+
+<!DOCTYPE html>
+<html>
+ <head>
+ {% block title %}
+ Welcome
+ {% endblock %}
+ </head>
+</html> \ No newline at end of file
diff --git a/workshop_app/templates/workshop_app/login.html b/workshop_app/templates/workshop_app/login.html
new file mode 100644
index 0000000..fa505ab
--- /dev/null
+++ b/workshop_app/templates/workshop_app/login.html
@@ -0,0 +1,20 @@
+{% extends './base.html' %}
+
+ {% block title %}
+ Login
+ {% endblock %}
+
+ {% block content %}
+ <div class="container" align="center">
+ <br>
+ <form method="post">
+ {% csrf_token %}
+ {{ form.as_table }}
+ <br>
+ <br>
+ <button class="btn btn-default" type="submit">Login</button>
+ <br>
+ </form>
+ <br>
+ </div>
+ {% endblock %}
diff --git a/workshop_app/templates/workshop_app/logout.html b/workshop_app/templates/workshop_app/logout.html
new file mode 100644
index 0000000..70a7862
--- /dev/null
+++ b/workshop_app/templates/workshop_app/logout.html
@@ -0,0 +1,16 @@
+{% extends './base.html' %}
+
+ {% block title %}
+ Logged out
+ {% endblock %}
+
+
+ {% block content %}
+ <div class="container" align="center">
+ <br>
+ <h3>You have logged out successfully.</h3>
+ <h4>If you want to Login again please <a href="{{ URL_ROOT}}/login">click here</a></h4>
+ <br>
+ </div>
+
+ {% endblock %} \ No newline at end of file
diff --git a/workshop_app/templates/workshop_app/manage.html b/workshop_app/templates/workshop_app/manage.html
new file mode 100644
index 0000000..a161ec2
--- /dev/null
+++ b/workshop_app/templates/workshop_app/manage.html
@@ -0,0 +1,35 @@
+{% extends './base.html' %}
+
+{% block header %}
+ <nav class="navbar navbar-inverse">
+ <div class="container-fluid">
+ <div class="navbar-header">
+ <a class="navbar-brand" href="#">WebSiteName</a>
+ </div>
+ <ul class="nav navbar-nav">
+ <li class="active"><a href="{{ URL_ROOT }}/create_workshop">Create Event</a></li>
+ <li class="active"><a href="{{ URL_ROOT }}/view_course_list">View Course List</a></li>
+ </ul>
+ <ul class="nav navbar-nav navbar-right">
+ <li><a href="{{ URL_ROOT }}/view_profile"><span class="glyphicon glyphicon-user"></span> Profile </a></li>
+ <li><a href="{{ URL_ROOT }}/logout"><span class="glyphicon glyphicon-log-in"></span> Logout</a></li>
+ </ul>
+ </div>
+ </nav>
+{% endblock %}
+
+{% block content %}
+
+<div class="container">
+ {% csrf_token %}
+ {% for w in workshop_details %}
+ {{ w.date }}<br>
+ {{ w.start_time }}<br>
+ {{ w.end_time }}<br>
+ {{ w.workshop_creator }}<br>
+ {{ w.workshop_title }}
+ {{ w.status }}
+ {% endfor %}
+</div>
+
+{% endblock %} \ No newline at end of file
diff --git a/workshop_app/templates/workshop_app/profile_updated.html b/workshop_app/templates/workshop_app/profile_updated.html
new file mode 100644
index 0000000..e9a0d54
--- /dev/null
+++ b/workshop_app/templates/workshop_app/profile_updated.html
@@ -0,0 +1,28 @@
+{% extends "./base.html" %}
+
+{% block title %}
+ Profile Changing
+{% endblock %}
+
+{% block header %}
+ <nav class="navbar navbar-inverse">
+ <div class="container-fluid">
+ <div class="navbar-header">
+ <a class="navbar-brand" href="#">WebSiteName</a>
+ </div>
+ <ul class="nav navbar-nav">
+ <li class="active"><a href="#">Home</a></li>
+ </ul>
+ <ul class="nav navbar-nav navbar-right">
+ <li><a href="{{ URL_ROOT }}/view_profile"><span class="glyphicon glyphicon-user"></span> Profile </a></li>
+ <li><a href="{{ URL_ROOT }}/logout"><span class="glyphicon glyphicon-log-in"></span> Logout</a></li>
+ </ul>
+ </div>
+ </nav>
+{% endblock %}
+
+{% block content %}
+{% dinesh akshen %}
+ <h3>Your Profile has changed {{ user.first_name }}</h3>
+{% endblock content %}
+
diff --git a/workshop_app/templates/workshop_app/register.html b/workshop_app/templates/workshop_app/register.html
new file mode 100644
index 0000000..fdb8bf8
--- /dev/null
+++ b/workshop_app/templates/workshop_app/register.html
@@ -0,0 +1,18 @@
+{% extends './base.html' %}
+
+ {% block title %}
+ Register
+ {% endblock %}
+
+ {% block content %}
+ <div class="container" >
+ <br>
+ <form action="" method="post">
+ {% csrf_token %}
+ <div class="form-group">
+ {{ form.as_p }}
+ <button class="btn btn-primary" type="submit">Register</button>
+ </div>
+ </form>
+ </div>
+ {% endblock %}
diff --git a/workshop_app/templates/workshop_app/view_course_details.html b/workshop_app/templates/workshop_app/view_course_details.html
new file mode 100644
index 0000000..58004da
--- /dev/null
+++ b/workshop_app/templates/workshop_app/view_course_details.html
@@ -0,0 +1,26 @@
+{% extends './base.html' %}
+
+{% block title %}
+ View Course Details
+{% endblock %}
+
+{% block header %}
+ <nav class="navbar navbar-inverse">
+ <div class="container-fluid">
+ <div class="navbar-header">
+ <a class="navbar-brand" href="#">WebSiteName</a>
+ </div>
+ <ul class="nav navbar-nav">
+ <li class="active"><a href="#">Home</a></li>
+ </ul>
+ <ul class="nav navbar-nav navbar-right">
+ <li><a href="{{ URL_ROOT }}/view_profile"><span class="glyphicon glyphicon-user"></span> Profile </a></li>
+ <li><a href="{{ URL_ROOT }}/logout"><span class="glyphicon glyphicon-log-in"></span> Logout</a></li>
+ </ul>
+ </div>
+ </nav>
+{% endblock %}
+
+{% block content %}
+
+{% endblock %} \ No newline at end of file
diff --git a/workshop_app/templates/workshop_app/view_course_list.html b/workshop_app/templates/workshop_app/view_course_list.html
new file mode 100644
index 0000000..4348a0d
--- /dev/null
+++ b/workshop_app/templates/workshop_app/view_course_list.html
@@ -0,0 +1,101 @@
+{% extends './base.html' %}
+
+{% block title %}
+ View Course List
+{% endblock %}
+
+
+{% block header %}
+ <nav class="navbar navbar-inverse">
+ <div class="container-fluid">
+ <div class="navbar-header">
+ <a class="navbar-brand" href="{{ URL_ROOT}}/manage/">WebSiteName</a>
+ </div>
+ <ul class="nav navbar-nav">
+ <li class="active"><a href="{{ URL_ROOT }}/create_workshop">Create Workshop</a></li>
+ </ul>
+ <ul class="nav navbar-nav navbar-right">
+ <li><a href="{{ URL_ROOT }}/view_profile"><span class="glyphicon glyphicon-user"></span> Profile </a></li>
+ <li><a href="{{ URL_ROOT }}/logout"><span class="glyphicon glyphicon-log-in"></span> Logout</a></li>
+ </ul>
+ </div>
+ </nav>
+{% endblock %}
+
+{% block extra %}
+ <!-- <script src="{{ URL_ROOT }}/static/workshop_app/js/overlay.js"></script> -->
+
+ <!-- <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="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
+{% endblock %}
+
+{% block content %}
+
+ <div class="container">
+
+ <table class="table table-hover" style="border-collapse:collapse;">
+ <thead>
+ <tr>
+ <th>id</th>
+ <th>Course Name</th>
+ <th>Course Duration</th>
+ </tr>
+ </thead>
+
+ {% for course in courses %}
+ <tbody>
+ <tr >
+ <td scope="row" id="{{ forloop.counter }}">{{ forloop.counter }}</td>
+ <td>{{ course.course_name }}</td>
+ <td>{{ course.course_duration }}</td>
+ <td><button class="btn btn-default btn-sm" class="accordion-toggle" data-toggle="collapse" href="#collapseOne{{ forloop.counter }}">View Course Details</button></td>
+ </tr>
+
+ <tr>
+ <td colspan="12" class="hiddenRow">
+ <div id="collapseOne{{ forloop.counter }}" class="accordion-body collapse">
+ <table class="table table-striped">
+ <tbody>
+ <tr>
+ <td>{{ course.course_description|safe }}</td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ </td>
+ </tr>
+ </tbody>
+ {% endfor %}
+ </table>
+
+ </div>
+
+ <div class="container">
+
+ <div class="Page-Nav" align="center">
+ <nav aria-label="Page navigation">
+ <ul class="pagination pagination-sm">
+ <li class="page-item">
+ {% if courses.has_previous %}
+ <a class="page-link" tabindex="-1"
+ href="?page={{ courses.previous_page_number }}">Previous</a>
+ {% endif %}
+ </li>
+ <li class="page-item">
+ <span class="current">
+ Page {{ courses.number }} of {{ courses.paginator.num_pages }}
+ </span>
+ </li>
+ <li class="page-item">
+ {% if courses.has_next %}
+ <a class="page-link" href="?page={{ courses.next_page_number }}">Next
+ </a>
+ {% endif %}
+ </li>
+ </ul>
+ </nav>
+ </div>
+ </div>
+{% endblock %} \ No newline at end of file
diff --git a/workshop_app/templates/workshop_app/view_profile.html b/workshop_app/templates/workshop_app/view_profile.html
new file mode 100644
index 0000000..546af88
--- /dev/null
+++ b/workshop_app/templates/workshop_app/view_profile.html
@@ -0,0 +1,57 @@
+{% extends './base.html' %}
+
+{% block title %}
+ View Profile
+{% endblock %}
+
+{% block header %}
+ <nav class="navbar navbar-inverse">
+ <div class="container-fluid">
+ <div class="navbar-header">
+ <a class="navbar-brand" href="#">WebSiteName</a>
+ </div>
+ <ul class="nav navbar-nav">
+ <li class="active"><a href="#">Home</a></li>
+ </ul>
+ <ul class="nav navbar-nav navbar-right">
+ <li><a href="{{ URL_ROOT }}/view_profile"><span class="glyphicon glyphicon-user"></span> Profile </a></li>
+ <li><a href="{{ URL_ROOT }}/logout"><span class="glyphicon glyphicon-log-in"></span> Logout</a></li>
+ </ul>
+ </div>
+ </nav>
+{% endblock %}
+
+{% block content %}
+
+ <div class="container">
+ {% csrf_token %}
+ <table class="table table-bordered">
+ <tr>
+ <th><label for="id_first_name"><h5>First name:</h5></label></th>
+ <th><label for="id_first_name"><h5>{{ user.first_name }}</h5></label></th>
+ </tr>
+ <tr>
+ <th><label for="id_last_name"><h5>Last name:</h5></label></th>
+ <th><label for="id_last_name"><h5>{{ user.last_name }}</h5></label></th>
+ </tr>
+ <tr>
+ <th><label for="id_email"><h5>Email:</h5></label></th>
+ <th><label for="id_email"><h5>{{ user.email }}</h5></label></th>
+ </tr>
+ <tr>
+ <th><label for="id_institute"><h5>Institute:</h5></label></th>
+ <th><label for="id_institute"><h5>{{ user.profile.institute }}</h5></label></th>
+ </tr>
+ <tr>
+ <th><label for="id_department"><h5>Department:</h5></label></th>
+ <th><label for="id_department"><h5>{{ user.profile.department }}</h5></label></th>
+ </tr>
+ <tr>
+ <th><label for="id_position"><h5>Position:</h5></label></th>
+ <th><label for="id_position"><h5>{{ user.profile.position }}</h5></label></th>
+ </tr>
+ </table>
+ <br>
+ <a class="btn btn-primary pull-right" href="{{ URL_ROOT }}/edit_profile/">Edit Profile</a>
+ </div>
+{% endblock %}
diff --git a/workshop_app/views.py b/workshop_app/views.py
index 54dc43d..2cb805e 100644
--- a/workshop_app/views.py
+++ b/workshop_app/views.py
@@ -1,10 +1,11 @@
from django.shortcuts import render, redirect
-from forms import UserRegistrationForm, UserLoginForm, ProfileForm
-from .models import Profile, User, has_profile
+from .forms import UserRegistrationForm, UserLoginForm, ProfileForm, CreateWorkshop
+from .models import Profile, User, has_profile, Workshop, Course
from django.template import RequestContext
from django.contrib.auth import login, logout, authenticate
from django.contrib.auth.decorators import login_required
from django.contrib import messages
+from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
@@ -23,7 +24,7 @@ def user_login(request):
if user.is_authenticated():
if user.groups.filter(name='instructor').count() > 0:
return redirect('/manage/')
- return redirect('/view_profile/')
+ return redirect('/book/')
if request.method == "POST":
form = UserLoginForm(request.POST)
@@ -32,7 +33,7 @@ def user_login(request):
login(request, user)
if user.groups.filter(name='instructor').count() > 0:
return redirect('/manage/')
- return redirect('/view_profile/')
+ return redirect('/book/')
else:
return render(request, 'workshop_app/login.html', {"form": form})
else:
@@ -53,12 +54,11 @@ def user_register(request):
username, password = form.save()
new_user = authenticate(username=username, password=password)
login(request, new_user)
- return redirect('/home')
+ return redirect('/view_profile/')
else:
return render(request, "workshop_app/register.html", {"form": form})
else:
form = UserRegistrationForm()
-
return render(request, "workshop_app/register.html", {"form": form})
@@ -71,18 +71,21 @@ def book(request):
else:
return redirect('/login/')
+@login_required
def manage(request):
user = request.user
if user.is_authenticated():
+ print user.id, user
if user.groups.filter(name='instructor').count() > 0:
- return render(request, "workshop_app/manage.html")
+ workshop_details = Workshop.objects.all()
+ return render(request, "workshop_app/manage.html", {"workshop_details": workshop_details})
return redirect('/book/')
else:
return redirect('/login/')
@login_required
def view_profile(request):
- """ view moderators and users profile """
+ """ view instructor and coordinator profile """
return render(request, "workshop_app/view_profile.html")
@login_required
@@ -125,6 +128,49 @@ def create_workshop(request):
user = request.user
if is_instructor(user):
- return render(request, 'workshop_app/create_workshop.html')
+ if request.method == 'POST':
+ form = CreateWorkshop(request.POST)
+ if form.is_valid():
+ form.save()
+ return redirect('/manage/')
+ else:
+ form = CreateWorkshop()
+ return render(request, 'workshop_app/create_workshop.html', {"form": form })
+ else:
+ return redirect('/book/')
+
+@login_required
+def view_course_list(request):
+ '''Gives the course details '''
+ user = request.user
+ if is_instructor(user):
+ course_list = Course.objects.all()
+ paginator = Paginator(course_list, 9) #Show upto 12 Courses per page
+
+ page = request.GET.get('page')
+ try:
+ courses = paginator.page(page)
+ except PageNotAnInteger:
+ #If page is not an integer, deliver first page.
+ courses = paginator.page(1)
+ except EmptyPage:
+ #If page is out of range(e.g 999999), deliver last page.
+ courses = paginator.page(paginator.num_pages)
+
+ return render(request, 'workshop_app/view_course_list.html', \
+ {'courses': courses})
+
else:
return redirect('/book/')
+
+@login_required
+def view_course_details(request):
+ '''Gives the course details '''
+
+ user = request.user
+ if is_instructor(user):
+
+ return redirect('/')
+
+ else:
+ return redirect('/book/') \ No newline at end of file