Commit 2fd277c4 authored by Gab De Jesus's avatar Gab De Jesus

Added courses app

parent ef96bdd8
...@@ -43,6 +43,7 @@ INSTALLED_APPS = [ ...@@ -43,6 +43,7 @@ INSTALLED_APPS = [
'reviews', 'reviews',
'profs', 'profs',
'accounts', 'accounts',
'courses',
] ]
MIDDLEWARE = [ MIDDLEWARE = [
......
...@@ -23,6 +23,8 @@ from reviews import views as reviews_views ...@@ -23,6 +23,8 @@ from reviews import views as reviews_views
from profs import views as profs_views from profs import views as profs_views
from courses import views as courses_views
from academe import views as academe_views from academe import views as academe_views
urlpatterns = [ urlpatterns = [
...@@ -37,4 +39,6 @@ urlpatterns = [ ...@@ -37,4 +39,6 @@ urlpatterns = [
url(r'reviews/$', reviews_views.index, name="reviews_index"), url(r'reviews/$', reviews_views.index, name="reviews_index"),
url(r'^prof/$', profs_views.index, name="profs_index"), url(r'^prof/$', profs_views.index, name="profs_index"),
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/(?P<course_id>[0-9]+)/$', courses_views.getCourse, name="courses_getCourse"),
] ]
from django.contrib import admin
from .models import Course
admin.site.register(Course)
\ No newline at end of file
from django.apps import AppConfig
class CoursesConfig(AppConfig):
name = 'courses'
from django.db import models
from profs.models import Prof
class Course(models.Model):
name = models.CharField(max_length = 20, unique = True)
prof = models.ManyToManyField(Prof)
def __str__ (self):
return self.name
\ No newline at end of file
{% extends 'templates/base.html' %}
{% block content %}
<center><h1>Courses</h1></center>
<!-- Create the table rows -->
{% for course in courses %}
<ul style="text-align: center; list-style: none; padding: 0">
<li><a href="">{{ course.name }}</a></li>
</ul>
{% endfor %}
<!-- Form for making a new review -->
<h1>New Review</h1>
<form method="POST">
{% csrf_token %}
<p>{{ review_form.message }}</p>d
<p>{{ review_form.rating }}</p>
<p>{{ review_form.prof }}</p>
<button type="submit">Save</button>
</form>
{% endblock %}
\ No newline at end of file
from django.test import TestCase
# Create your tests here.
from django.shortcuts import render, redirect
from django.urls import reverse
from profs.models import Prof
from profs.forms import ProfForm
from .models import Course
from django.contrib import messages
from django.contrib.auth.models import User
from reviews.models import Review
from reviews.forms import ReviewForm
from django.contrib.auth.decorators import login_required
def index(request):
"""Show all the courses"""
courses = Course.objects.all()
return render(request, 'courses/index.html', {'courses': courses})
No preview for this file type
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-11-16 10:04 # Generated by Django 1.11.5 on 2017-11-30 06:35
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models from django.db import migrations, models
...@@ -13,13 +13,6 @@ class Migration(migrations.Migration): ...@@ -13,13 +13,6 @@ class Migration(migrations.Migration):
] ]
operations = [ operations = [
migrations.CreateModel(
name='Course',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=20, unique=True)),
],
),
migrations.CreateModel( migrations.CreateModel(
name='Prof', name='Prof',
fields=[ fields=[
...@@ -28,9 +21,4 @@ class Migration(migrations.Migration): ...@@ -28,9 +21,4 @@ class Migration(migrations.Migration):
('last_name', models.CharField(max_length=20)), ('last_name', models.CharField(max_length=20)),
], ],
), ),
migrations.AddField(
model_name='course',
name='prof',
field=models.ManyToManyField(to='profs.Prof'),
),
] ]
...@@ -8,9 +8,3 @@ class Prof(models.Model): ...@@ -8,9 +8,3 @@ class Prof(models.Model):
def __str__ (self): def __str__ (self):
return self.first_name + " " + self.last_name return self.first_name + " " + self.last_name
class Course(models.Model):
name = models.CharField(max_length = 20, unique = True)
prof = models.ManyToManyField(Prof)
def __str__ (self):
return self.name
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
{% csrf_token %} {% csrf_token %}
<p>{{ review_form.message }}</p> <p>{{ review_form.message }}</p>
<p>{{ review_form.rating }}</p> <p>{{ review_form.rating }}</p>
<p>{{ review_form.course }}</p>
<button type="submit" class="btn btn-default">Submit Review</button> <button type="submit" class="btn btn-default">Submit Review</button>
</form> </form>
</div> </div>
......
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
from django.urls import reverse from django.urls import reverse
from profs.models import Prof, Course from profs.models import Prof
from courses.models import Course
from profs.forms import ProfForm from profs.forms import ProfForm
from django.contrib import messages from django.contrib import messages
from django.contrib.auth.models import User from django.contrib.auth.models import User
...@@ -50,7 +51,6 @@ def getProf(request, prof_id): ...@@ -50,7 +51,6 @@ def getProf(request, prof_id):
messages.error(request, "Error") messages.error(request, "Error")
return render(request, 'profs/prof.html') return render(request, 'profs/prof.html')
prof = Prof.objects.get(pk=prof_id) prof = Prof.objects.get(pk=prof_id)
# prof_course = Course.objects.filter(prof__id = prof_id)
reviews = Review.objects.filter(prof = prof) reviews = Review.objects.filter(prof = prof)
return render(request, 'profs/prof.html', {'review_form': ReviewForm, 'prof': prof, 'reviews': reviews}) return render(request, 'profs/prof.html', {'review_form': ReviewForm, 'prof': prof, 'reviews': reviews})
# return redirect(reverse('homepage')) # return redirect(reverse('homepage'))
from django.forms import ModelForm, CharField, TextInput from django.forms import ModelForm, CharField, TextInput
from reviews.models import Review from reviews.models import Review
from profs.models import Prof
from courses.models import Course
# Make a custom widget for rating so it can only be 0 - 5
from django.forms import widgets from django.forms import widgets
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
# class RatingWidget(widgets.TextInput):
# def render(self, name, value, attrs=None):
# return mark_safe(u'''<span>USD</span>%s''' % (super(RatingWidget, self).render(name, value, attrs)))
class ReviewForm(ModelForm): class ReviewForm(ModelForm):
# rating = CharField(label='Cost Price Per Unit', widget=RatingWidget, max_length=5)
rating = CharField(widget=TextInput(attrs={'type': 'number','value': 5, 'min': 0, 'max': 5})) rating = CharField(widget=TextInput(attrs={'type': 'number','value': 5, 'min': 0, 'max': 5}))
class Meta: class Meta:
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-11-16 10:04 # Generated by Django 1.11.5 on 2017-11-30 06:35
from __future__ import unicode_literals from __future__ import unicode_literals
from django.conf import settings from django.conf import settings
...@@ -15,6 +15,7 @@ class Migration(migrations.Migration): ...@@ -15,6 +15,7 @@ class Migration(migrations.Migration):
dependencies = [ dependencies = [
('profs', '0001_initial'), ('profs', '0001_initial'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL), migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('courses', '0001_initial'),
] ]
operations = [ operations = [
...@@ -26,7 +27,7 @@ class Migration(migrations.Migration): ...@@ -26,7 +27,7 @@ class Migration(migrations.Migration):
('created_at', models.DateTimeField(auto_now_add=True)), ('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(null=True)), ('updated_at', models.DateTimeField(null=True)),
('rating', models.IntegerField(default=5, validators=[django.core.validators.MaxValueValidator(5), django.core.validators.MinValueValidator(0)])), ('rating', models.IntegerField(default=5, validators=[django.core.validators.MaxValueValidator(5), django.core.validators.MinValueValidator(0)])),
('course', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='reviews', to='profs.Course')), ('course', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='reviews', to='courses.Course')),
('prof', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='reviews', to='profs.Prof')), ('prof', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='reviews', to='profs.Prof')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='reviews', to=settings.AUTH_USER_MODEL)), ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='reviews', to=settings.AUTH_USER_MODEL)),
], ],
......
...@@ -3,7 +3,8 @@ from django.core.validators import MaxValueValidator, MinValueValidator ...@@ -3,7 +3,8 @@ from django.core.validators import MaxValueValidator, MinValueValidator
from django.contrib.auth.models import User from django.contrib.auth.models import User
# Import profs # Import profs
from profs.models import Prof, Course from profs.models import Prof
from courses.models import Course
# Create your models here. # Create your models here.
class Review(models.Model): class Review(models.Model):
...@@ -16,7 +17,6 @@ class Review(models.Model): ...@@ -16,7 +17,6 @@ class Review(models.Model):
) )
prof = models.ForeignKey(Prof, related_name = 'reviews') prof = models.ForeignKey(Prof, related_name = 'reviews')
course = models.ForeignKey(Course, related_name = 'reviews') course = models.ForeignKey(Course, related_name = 'reviews')
# prof_course = models.ForeignKey(Course, related_name='reviews')
user = models.ForeignKey(User, related_name = 'reviews') user = models.ForeignKey(User, related_name = 'reviews')
def __str__ (self): def __str__ (self):
......
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="{% url 'profs_index' %}">Professors</a> <a class="nav-link" href="{% url 'profs_index' %}">Professors</a>
</li> </li>
<li class="nav-item">
<a class="nav-link" href="{% url 'course_index' %}">Courses</a>
</li>
</ul> </ul>
<form class="form-inline"> <form class="form-inline">
<input type="text" class="form-control" placeholder="Search"> <input type="text" class="form-control" placeholder="Search">
......
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