Commit 6c698491 authored by Gab De Jesus's avatar Gab De Jesus

Added different reviews add options depending on which prof page you're on,...

Added different reviews add options depending on which prof page you're on, Added admin support, rating is now from 0-5 only
parent caa09bab
...@@ -3,9 +3,6 @@ __pycache__/ ...@@ -3,9 +3,6 @@ __pycache__/
*.py[cod] *.py[cod]
*$py.class *$py.class
# C extensions
*.so
# Distribution / packaging # Distribution / packaging
.Python .Python
build/ build/
...@@ -25,62 +22,12 @@ wheels/ ...@@ -25,62 +22,12 @@ wheels/
*.egg *.egg
MANIFEST MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
# Translations
*.mo
*.pot
# Django stuff: # Django stuff:
*.log *.log
.static_storage/ .static_storage/
.media/ .media/
local_settings.py local_settings.py
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# Environments # Environments
.env .env
.venv .venv
...@@ -90,15 +37,6 @@ ENV/ ...@@ -90,15 +37,6 @@ ENV/
env.bak/ env.bak/
venv.bak/ venv.bak/
# Spyder project settings # Project specifics
.spyderproject */__pycache__/
.spyproject migrations/
\ No newline at end of file
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
\ No newline at end of file
...@@ -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 academe import views as academe_views
urlpatterns = [ urlpatterns = [
url(r'^signup/$', accounts_views.signup, name='signup'), url(r'^signup/$', accounts_views.signup, name='signup'),
url(r'^account_activation_sent/$', accounts_views.account_activation_sent, name='account_activation_sent'), url(r'^account_activation_sent/$', accounts_views.account_activation_sent, name='account_activation_sent'),
...@@ -31,7 +33,7 @@ urlpatterns = [ ...@@ -31,7 +33,7 @@ urlpatterns = [
url(r'^login/$', auth_views.LoginView.as_view(template_name='templates/login.html'), name='login'), url(r'^login/$', auth_views.LoginView.as_view(template_name='templates/login.html'), name='login'),
url(r'^logout/$', auth_views.LogoutView.as_view(), name='logout'), url(r'^logout/$', auth_views.LogoutView.as_view(), name='logout'),
url(r'^admin/', admin.site.urls), url(r'^admin/', admin.site.urls),
url(r'^$', reviews_views.index, name="homepage"), url(r'^$', academe_views.index, name="homepage"),
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"),
......
...@@ -3,14 +3,15 @@ from django.urls import reverse ...@@ -3,14 +3,15 @@ from django.urls import reverse
from profs.models import Prof from profs.models import Prof
from profs.forms import ProfForm from profs.forms import ProfForm
# Create your views here. # Homepage
def index(request): def index(request):
if(request.method=='POST'): # if(request.method=='POST'):
form = ProfForm(request.POST) # form = ProfForm(request.POST)
if(form.is_valid()): # if(form.is_valid()):
form.save() # form.save()
# Return to profs_index using reverse so only need to change url in settings.py # # Return to profs_index using reverse so only need to change url in settings.py
return redirect(reverse('profs_index')) # return redirect(reverse('profs_index'))
profs = Prof.objects.all() # profs = Prof.objects.all()
return render(request, 'profs/index.html', {'prof_form':ProfForm, 'profs': profs}) # return render(request, 'profs/index.html', {'prof_form':ProfForm, 'profs': profs})
return render(request, 'templates/index.html')
\ No newline at end of file
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2017-11-04 09:28 # Generated by Django 1.11.5 on 2017-11-05 05:15
from __future__ import unicode_literals from __future__ import unicode_literals
from django.conf import settings from django.conf import settings
......
...@@ -41,7 +41,7 @@ def signup(request): ...@@ -41,7 +41,7 @@ def signup(request):
#set up smtp #set up smtp
s = smtplib.SMTP(host='smtp.gmail.com', port=587) s = smtplib.SMTP(host='smtp.gmail.com', port=587)
s.starttls() s.starttls()
MY_ADDRESS = "academe.obf@gmail.com" MY_ADDRESS = "academe.site@gmail.com"
s.login(MY_ADDRESS, "Thisisthetester") s.login(MY_ADDRESS, "Thisisthetester")
with open("templates/account_activation_email.txt", encoding="utf-8") as template_file: with open("templates/account_activation_email.txt", encoding="utf-8") as template_file:
......
No preview for this file type
from django.contrib import admin from django.contrib import admin
from .models import Prof
# Register your models here. # Register your models here.
admin.site.register(Prof)
\ No newline at end of file
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-10-24 01:47 # Generated by Django 1.11.5 on 2017-11-05 05:15
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models from django.db import migrations, models
......
...@@ -12,7 +12,9 @@ ...@@ -12,7 +12,9 @@
<h1>New Review</h1> <h1>New Review</h1>
<form method="POST"> <form method="POST">
{% csrf_token %} {% csrf_token %}
{{ review_form.as_p }} <p>{{ review_form.message }}</p>
<p>{{ review_form.rating }}</p>
<p>{{ review_form.prof }}</p>
<button type="submit">Save</button> <button type="submit">Save</button>
</form> </form>
......
...@@ -26,11 +26,21 @@ ...@@ -26,11 +26,21 @@
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
{% if messages %}
{% for message in messages %}
{{ message }}
{% endfor %}
{% endif %}
<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>
<textarea class="form-control" rows="5" id="comment"></textarea> <form method="POST">
{% csrf_token %}
<p>{{ review_form.message }}</p>
<p>{{ review_form.rating }}</p>
<button type="submit" class="btn btn-default">Submit Review</button> <button type="submit" class="btn btn-default">Submit Review</button>
</form>
</div> </div>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -2,12 +2,13 @@ from django.shortcuts import render, redirect ...@@ -2,12 +2,13 @@ from django.shortcuts import render, redirect
from django.urls import reverse from django.urls import reverse
from profs.models import Prof from profs.models import Prof
from profs.forms import ProfForm from profs.forms import ProfForm
from django.contrib import messages
from django.contrib.auth.models import User
from reviews.models import Review from reviews.models import Review
from reviews.forms import ReviewForm from reviews.forms import ReviewForm
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
# Create your views here.
def index(request): def index(request):
# Make a prof # Make a prof
# if(request.method=='POST'): # if(request.method=='POST'):
...@@ -19,10 +20,15 @@ def index(request): ...@@ -19,10 +20,15 @@ def index(request):
# Make a new review # Make a new review
if(request.method=='POST'): if(request.method=='POST'):
form = ReviewForm(request.POST) post_values = request.POST.copy()
post_values['user'] = request.user.id
form = ReviewForm(post_values)
if(form.is_valid()): if(form.is_valid()):
form.save() form.save()
return redirect(reverse('profs_index'))
# Go to that profs page
prof_id = post_values['prof']
return redirect(reverse('profs_getProf', args=(prof_id)))
profs = Prof.objects.all() profs = Prof.objects.all()
return render(request, 'profs/index.html', {'review_form': ReviewForm, 'profs': profs}) return render(request, 'profs/index.html', {'review_form': ReviewForm, 'profs': profs})
...@@ -30,6 +36,19 @@ def index(request): ...@@ -30,6 +36,19 @@ def index(request):
# Display the page of a prof using id passed through url # Display the page of a prof using id passed through url
@login_required @login_required
def getProf(request, prof_id): def getProf(request, prof_id):
# Make a new review for the specific prof
if(request.method=='POST'):
# Insert the current user, and the prof with the id
post_values = request.POST.copy()
post_values['prof'] = prof_id
post_values['user'] = request.user.id
form = ReviewForm(post_values)
if(form.is_valid()):
form.save()
return redirect(reverse('profs_getProf', args=(prof_id)))
else:
messages.error(request, "Error")
return render(request, 'profs/prof.html')
prof = Prof.objects.get(pk=prof_id) prof = Prof.objects.get(pk=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})
......
from django.contrib import admin from django.contrib import admin
# Register your models here. # Register your models here.
from .models import Course, Review
admin.site.register(Course)
admin.site.register(Review)
\ No newline at end of file
from django.forms import ModelForm from django.forms import ModelForm, CharField, TextInput
from reviews.models import Review from reviews.models import Review
# Make a custom widget for rating so it can only be 0 - 5
from django.forms import widgets
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}))
class Meta: class Meta:
model = Review model = Review
fields = ['message', 'rating', 'prof'] fields = ['message', 'rating', 'prof', 'user']
\ No newline at end of file \ No newline at end of file
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2017-10-10 04:34 # Generated by Django 1.11.5 on 2017-11-05 05:16
from __future__ import unicode_literals from __future__ import unicode_literals
from django.conf import settings
import django.core.validators import django.core.validators
from django.db import migrations, models from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
...@@ -12,15 +13,17 @@ class Migration(migrations.Migration): ...@@ -12,15 +13,17 @@ class Migration(migrations.Migration):
initial = True initial = True
dependencies = [ dependencies = [
('profs', '0001_initial'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
] ]
operations = [ operations = [
migrations.CreateModel( migrations.CreateModel(
name='Prof', name='Course',
fields=[ fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('first_name', models.CharField(max_length=20)), ('name', models.CharField(max_length=15, unique=True)),
('last_name', models.CharField(max_length=20)), ('description', models.CharField(max_length=100)),
], ],
), ),
migrations.CreateModel( migrations.CreateModel(
...@@ -31,7 +34,8 @@ class Migration(migrations.Migration): ...@@ -31,7 +34,8 @@ 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)])),
('prof', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='reviews', to='reviews.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)),
], ],
), ),
] ]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-10-12 04:12
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('reviews', '0001_initial'),
]
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=15, unique=True)),
('description', models.CharField(max_length=100)),
],
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-10-24 01:47
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('reviews', '0002_course'),
]
operations = [
migrations.AlterField(
model_name='review',
name='prof',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='reviews', to='profs.Prof'),
),
migrations.DeleteModel(
name='Prof',
),
]
...@@ -20,6 +20,7 @@ class Review(models.Model): ...@@ -20,6 +20,7 @@ class Review(models.Model):
validators = [MaxValueValidator(5), MinValueValidator(0)] validators = [MaxValueValidator(5), MinValueValidator(0)]
) )
prof = models.ForeignKey(Prof, related_name = 'reviews') prof = models.ForeignKey(Prof, related_name = 'reviews')
user = models.ForeignKey(User, related_name = 'reviews')
def __str__ (self): def __str__ (self):
return self.message return self.message
\ No newline at end of file
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.urls import reverse from django.urls import reverse
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
...@@ -9,6 +10,7 @@ from .forms import ReviewForm ...@@ -9,6 +10,7 @@ from .forms import ReviewForm
def index(request): def index(request):
if(request.method=='POST'): if(request.method=='POST'):
form = ReviewForm(request.POST) form = ReviewForm(request.POST)
form['user'] = User.objects.get(pk=request.user.id)
if(form.is_valid()): if(form.is_valid()):
form.save() form.save()
# Return to reviews index so that no more post on refresh # Return to reviews index so that no more post on refresh
......
{% extends 'templates/base.html' %}
{% block content %}
<h1><center>Welcome to Academe</center></h1>
{% endblock %}
\ No newline at end of file
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