Commit d6c1edea authored by Gab De Jesus's avatar Gab De Jesus

Fixed search when clicking a course, designed view for reviews, now has...

Fixed search when clicking a course, designed view for reviews, now has prefilled data with populatedb.txt
parent 59e9de5e
from profs.models import Prof
from courses.models import Course
from django.contrib.auth.models import User
from reviews.models import Review
import datetime
prof1=Prof(first_name="Marlene",last_name="De Leon")
prof1.save()
course1=Course(id=1,name="CS 123")
course1.save()
course1.prof.add(prof1)
user1=User(username="AceOfJayce",email="jayce@yahoo.com",password="FinalsChampions")
user1.save()
review1=Review(id=1, message="you will learn how to engineer software",created_at=datetime.datetime.now(),updated_at=datetime.datetime.now(),prof=prof1,course=course1, user=user1)
review1.save()
prof2=Prof(first_name="Patricia",last_name="Abu")
prof2.save()
course2=Course(id=2,name="CS 152")
course2.save()
course2.prof.add(prof2)
user2=User(username="GabCanDab",email="gab@yahoo.com",password="SafeExam")
user2.save()
review2=Review(message="i can organize computers now",created_at=datetime.datetime.now(),updated_at=datetime.datetime.now(),prof=prof2,course=course2, user=user2)
review2.save()
prof3=Prof(first_name="Raphael",last_name="Alampay")
prof3.save()
course3=Course(id=3,name="CS 129.18")
course3.save()
course3.prof.add(prof3)
user3=User(username="NateTheGreat",email="nate@yahoo.com",password="GetRektWithPattRekt")
user3.save()
review3=Review(message="recognizing patterns makes me happy",created_at=datetime.datetime.now(),updated_at=datetime.datetime.now(),prof=prof3,course=course3, user=user3)
review3.save()
prof4=Prof(first_name="Jessica",last_name="Sugay")
prof4.save()
course4=Course(id=4,name="CS 122")
course4.save()
course4.prof.add(prof4)
user4=User(username="JoshOshKosh",email="josh@yahoo.com",password="icantthinkofabetterrhyme")
user4.save()
review4=Review(message="databases are fun",created_at=datetime.datetime.now(),updated_at=datetime.datetime.now(),prof=prof4,course=course4, user=user4)
review4.save()
prof5=Prof(first_name="Alberto",last_name="Medalla")
prof5.save()
course5=Course(id=5,name="CS 21B")
course5.save()
course5.prof.add(prof5)
user5=User(username="Choob",email="choob@youtube.com",password="YouChoob")
user5.save()
review5=Review(message="I feel like the prof is also one of our classmates",created_at=datetime.datetime.now(),updated_at=datetime.datetime.now(),prof=prof5,course=course5, user=user5)
review5.save()
prof6=Prof(first_name="Ma. Mercedes",last_name="Rodrigo")
prof6.save()
course6=Course(id=6,name="CS 21A")
course6.save()
course6.prof.add(prof6)
user6=User(username="NateAgain",email="nate@gmail.com",password="Python>Java")
user6.save()
review6=Review(message="gives food after midterms and finals",created_at=datetime.datetime.now(),updated_at=datetime.datetime.now(),prof=prof6,course=course6, user=user6)
review6.save()
prof7=Prof(first_name="John Paul",last_name="Vergara")
prof7.save()
course7=Course(id=7,name="CS 110")
course7.save()
course7.prof.add(prof7)
user7=User(username="Aldrich",email="asuncion@gmail.com",password="iamgoodatcs")
user7.save()
review7=Review(message="good at teaching logarithms and how to structure data",created_at=datetime.datetime.now(),updated_at=datetime.datetime.now(),prof=prof7,course=course7, user=user7)
prof8=Prof(first_name="Hadrian",last_name="Ang")
prof8.save()
course8=Course(id=8,name="AMC 124")
course8.save()
course8.prof.add(prof8)
user8=User(username="Migee",email="migee@gmail.com",password="HadeAndIArePros")
user8.save()
review8=Review(message="creative problems, and he's such a pro",created_at=datetime.datetime.now(),updated_at=datetime.datetime.now(),prof=prof8,course=course8, user=user8)
review8.save()
prof9=Prof(first_name="Vernon",last_name="Gutierrez")
prof9.save()
course9=Course(id=9,name="AMC 125")
course9.save()
course9.prof.add(prof9)
user9=User(username="huffman",email="huffman@sortify.com",password="FreshieFriendlyTopic")
user9.save()
review9=Review(message="His topics are freshie friendly",created_at=datetime.datetime.now(),updated_at=datetime.datetime.now(),prof=prof9,course=course9, user=user9)
review9.save()
\ No newline at end of file
...@@ -45,5 +45,5 @@ urlpatterns = [ ...@@ -45,5 +45,5 @@ urlpatterns = [
url(r'^prof/(?P<prof_id>[0-9]+)/$', profs_views.getProf, name="profs_getProf"), url(r'^prof/(?P<prof_id>[0-9]+)/$', profs_views.getProf, name="profs_getProf"),
url(r'^course/$', courses_views.index, name="courses_index"), url(r'^course/$', courses_views.index, name="courses_index"),
url(r'^course/prof/(?P<prof_name>[A-Za-z ]+)/$', courses_views.json_prof_courses, name="courses_json_prof_courses"), url(r'^course/prof/(?P<prof_name>[A-Za-z ]+)/$', courses_views.json_prof_courses, name="courses_json_prof_courses"),
# url(r'^course/(?P<course_id>[0-9]+)/$', courses_views.getCourse, name="courses_getCourse"), url(r'^course/(?P<course_id>[0-9]+)/$', courses_views.getCourse, name="courses_getCourse"),
] ]
...@@ -5,6 +5,7 @@ from django.db.models.functions import Concat ...@@ -5,6 +5,7 @@ from django.db.models.functions import Concat
from django.db.models import Value from django.db.models import Value
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.contrib import messages from django.contrib import messages
import datetime
from courses import views as course_views from courses import views as course_views
from profs import views as prof_views from profs import views as prof_views
...@@ -40,7 +41,6 @@ def search(request): ...@@ -40,7 +41,6 @@ def search(request):
prof_set = Prof.objects.annotate(search_name=Concat('first_name', Value(' '), 'last_name')) prof_set = Prof.objects.annotate(search_name=Concat('first_name', Value(' '), 'last_name'))
profs = prof_set.filter(search_name__icontains=prof_query) profs = prof_set.filter(search_name__icontains=prof_query)
# profs = Prof.objects.filter(first_name__icontains=prof_query last_name__contains=prof_query)
return render(request, 'profs/index.html', {'profs': profs, 'message': message}) return render(request, 'profs/index.html', {'profs': profs, 'message': message})
except Prof.DoesNotExist: except Prof.DoesNotExist:
return HttpResponse('No such prof') return HttpResponse('No such prof')
...@@ -52,7 +52,7 @@ def search(request): ...@@ -52,7 +52,7 @@ def search(request):
except Course.DoesNotExist: except Course.DoesNotExist:
return HttpResponse('No such course') return HttpResponse('No such course')
else: else:
courses = course_views.all_course() courses = course_views.all_courses(request)
return render(request, 'templates/browse.html', {'courses': courses}) return render(request, 'templates/browse.html', {'courses': courses})
@login_required @login_required
...@@ -70,9 +70,9 @@ def review(request, prof_id=None): ...@@ -70,9 +70,9 @@ def review(request, prof_id=None):
if(form.is_valid()): if(form.is_valid()):
form.save() form.save()
prof_id = post_values['prof'] prof_id = post_values['prof']
return redirect(reverse('profs_getProf', args=(prof_id))) return redirect(reverse('profs_getProf', args=(prof_id,)))
else: else:
messages.error(request, "Error") print(form.errors)
return render(request, 'reviews/review_form.html') return render(request, 'reviews/review_form.html')
# If there's an input prof, return review page for that prof # If there's an input prof, return review page for that prof
if prof_id: if prof_id:
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
{% endif %} {% endif %}
{% for course in courses %} {% for course in courses %}
<ul style="text-align: center; list-style: none; padding: 0"> <ul style="text-align: center; list-style: none; padding: 0">
<li><a href="">{{ course.name }}</a></li> <li><a href="{% url 'courses_getCourse' course_id=course.id %}">{{ course.name }}</a></li>
</ul> </ul>
{% endfor %} {% endfor %}
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -32,6 +32,15 @@ def prof_courses(request, prof_id): ...@@ -32,6 +32,15 @@ def prof_courses(request, prof_id):
course = Course.objects.filter(prof=prof_id) course = Course.objects.filter(prof=prof_id)
return course return course
# Display the page of a prof using id passed through url
def getCourse(request, course_id):
course = Course.objects.get(pk=course_id)
profs = course.prof.all()
message = 'Showing professors under: ' + course.name
print(profs)
return render(request, 'profs/index.html', {'profs': profs, 'message': message})
def json_prof_courses(request, prof_name): def json_prof_courses(request, prof_name):
""" Returns the JSON of courses of a specific prof for xhr""" """ Returns the JSON of courses of a specific prof for xhr"""
prof_set = Prof.objects.annotate(search_name=Concat('first_name', Value(' '), 'last_name')) prof_set = Prof.objects.annotate(search_name=Concat('first_name', Value(' '), 'last_name'))
......
No preview for this file type
{% extends 'templates/base.html' %} {% extends 'templates/base.html' %}
{% load static %}
{% block css %}
<link rel="stylesheet" type="text/css" href="{% static 'css/reviews.css' %}">
{% endblock %}
{% block content %} {% block content %}
<div> <div>
<h1><center>{{prof.first_name}} {{prof.last_name}}</center></h1> <h1>{{prof.first_name}} {{prof.last_name}}</h1>
<h4><center>Reviews</center></h4> <p id="review_action" ><a href="{% url 'review_prof' prof_id=prof.id %}">Review {{ prof.first_name }} {{ prof.last_name }}</a></p>
</div>
<div class="reviews">
<h4>Reviews <span>{{ reviews.count }} total</span></h4>
{% for review in reviews %}
<div class="review">
<h3><img src="http://style.anu.edu.au/_anu/4/images/placeholders/person.png">{{review.user}} <span>Gave a rating of {{ review.rating }}/5</span></h3>
<p>&#8220;{{review.message}}&#8221;</p>
</div>
{% endfor %}
</div> </div>
<!--
<table class="table table-bordered"> <table class="table table-bordered">
<thead> <thead>
<tr> <tr>
...@@ -31,14 +45,14 @@ ...@@ -31,14 +45,14 @@
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table> -->
{% if messages %} {% if messages %}
{% for message in messages %} {% for message in messages %}
{{ message }} {{ message }}
{% endfor %} {% endfor %}
{% endif %} {% endif %}
<p><a href="{% url 'review_prof' prof_id=prof.id %}">Review {{ prof.first_name }} {{ prof.last_name }}</a></p>
<!-- <div class="form-group"> <!-- <div class="form-group">
<label for="comment">Review {{ prof.first_name }} {{ prof.last_name }}</label> <label for="comment">Review {{ prof.first_name }} {{ prof.last_name }}</label>
......
...@@ -21,7 +21,7 @@ def index(request): ...@@ -21,7 +21,7 @@ def index(request):
# Go to that profs page # Go to that profs page
prof_id = post_values['prof'] prof_id = post_values['prof']
return redirect(reverse('profs_getProf', args=(prof_id))) return redirect(reverse('profs_getProf', args=(prof_id,)))
profs = all_profs() profs = all_profs()
return render(request, 'profs/index.html', {'review_form': ReviewForm, 'profs': profs}) return render(request, 'profs/index.html', {'review_form': ReviewForm, 'profs': profs})
...@@ -38,7 +38,7 @@ def getProf(request, prof_id): ...@@ -38,7 +38,7 @@ def getProf(request, prof_id):
form = ReviewForm(post_values) form = ReviewForm(post_values)
if(form.is_valid()): if(form.is_valid()):
form.save() form.save()
return redirect(reverse('profs_getProf', args=(prof_id))) return redirect(reverse('profs_getProf', args=(prof_id,)))
else: else:
messages.error(request, "Error") messages.error(request, "Error")
return render(request, 'profs/prof.html') return render(request, 'profs/prof.html')
......
...@@ -24,6 +24,13 @@ ...@@ -24,6 +24,13 @@
<!-- AJAX --> <!-- AJAX -->
<script type="text/javascript"> <script type="text/javascript">
var profDropDown = document.getElementById('prof'); var profDropDown = document.getElementById('prof');
try {
document.getElementById('id_course').addEventListener("change", showSave);
}
catch(e) {
}
// Runs when a prof is selected from drop down // Runs when a prof is selected from drop down
function dropDownSelect() { function dropDownSelect() {
if(profDropDown.selectedIndex > 0) { if(profDropDown.selectedIndex > 0) {
...@@ -68,7 +75,7 @@ ...@@ -68,7 +75,7 @@
dropDown.appendChild(placeholder); dropDown.appendChild(placeholder);
} }
var option = document.createElement('option'); var option = document.createElement('option');
option.value = index; option.value = objectKey;
option.textContent = json[objectKey]; option.textContent = json[objectKey];
dropDown.appendChild(option); dropDown.appendChild(option);
} }
...@@ -76,21 +83,6 @@ ...@@ -76,21 +83,6 @@
document.querySelector("#show").style.display = "none"; document.querySelector("#show").style.display = "none";
document.getElementById('dropdown').addEventListener("change", showSave); document.getElementById('dropdown').addEventListener("change", showSave);
console.log("XHR Request done"); console.log("XHR Request done");
// for (var i = 1; course = json[i]; i++) {
// if (i == 1) {
// var placeholder = document.createElement('option');
// placeholder.value = "";
// placeholder.textContent = "Select a course";
// dropDown.appendChild(placeholder);
// }
// var option = document.createElement('option');
// option.value = i;
// option.textContent = course;
// dropDown.appendChild(option);
// }
// document.querySelector("#show").style.display = "none";
// document.getElementById('dropdown').addEventListener("change", showSave);
// console.log("XHR Request done");
} }
}; };
......
...@@ -5,8 +5,9 @@ from django.contrib.auth.models import User ...@@ -5,8 +5,9 @@ from django.contrib.auth.models import User
from .models import Review from .models import Review
from profs.models import Prof from profs.models import Prof
from .forms import ReviewForm from .forms import ReviewForm
from django.contrib.auth.decorators import user_passes_test
@login_required() @user_passes_test(lambda u: u.is_superuser)
def index(request): def index(request):
if(request.method=='POST'): if(request.method=='POST'):
form = ReviewForm(request.POST) form = ReviewForm(request.POST)
......
h1 {
margin-left: 1em;
padding: 1em;
padding-bottom: 0;
}
h4 {
margin-left: 6em;
font-weight: bold;
margin-bottom: 1em;
}
h4 span {
font-weight: normal;
color: grey;
margin-left: 1em;
}
h3 span {
font-weight: normal;
font-size: 0.5em;
color: grey;
}
h3 img {
width: 2em;
margin: 0.5em;
}
.review {
margin: 1em auto;
width: 80%;
background: white;
border: 1px solid #DDDDDD;
padding: 1em;
}
.review p {
margin-left: 2em;
}
.content {
margin: 0;
}
.reviews {
width: 100vw;
background: #EEEEEE;
border-top: 1px solid #DDDDDD;
margin: 0;
padding-top: 2em;
padding-bottom: 2em;
}
#review_action {
margin-left: 5em;
}
\ No newline at end of file
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<title>Academe</title> <title>Academe</title>
<link rel="stylesheet" type="text/css" href="{% static 'css/main.css' %}"> <link rel="stylesheet" type="text/css" href="{% static 'css/main.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'css/bootstrap.min.css' %}"> <link rel="stylesheet" type="text/css" href="{% static 'css/bootstrap.min.css' %}">
<link rel="stylesheet" type="text/css" href="123.css"> {% block css %}{% endblock %}
</head> </head>
<body> <body>
<nav class="navbar navbar-light navbar-toggleable-md bg-faded"> <nav class="navbar navbar-light navbar-toggleable-md bg-faded">
...@@ -20,6 +20,12 @@ ...@@ -20,6 +20,12 @@
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="{% url 'review' %}">Create Review</a> <a class="nav-link" href="{% url 'review' %}">Create Review</a>
</li> </li>
{% if user.is_superuser %}
<li class="nav-item">
<a class="nav-link" href="{% url 'reviews_index' %}">All Reviews</a>
</li>
{% endif %}
</ul> </ul>
<form class="form-inline"><ul class="navbar-nav mr-auto"> <form class="form-inline"><ul class="navbar-nav mr-auto">
{% if user.is_authenticated %} {% if user.is_authenticated %}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment