Commit 1e22e988 authored by Gab De Jesus's avatar Gab De Jesus

Reverted to old commit

parent 0034e011
...@@ -3,6 +3,9 @@ __pycache__/ ...@@ -3,6 +3,9 @@ __pycache__/
*.py[cod] *.py[cod]
*$py.class *$py.class
# C extensions
*.so
# Distribution / packaging # Distribution / packaging
.Python .Python
build/ build/
...@@ -22,12 +25,62 @@ wheels/ ...@@ -22,12 +25,62 @@ 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
...@@ -37,6 +90,15 @@ ENV/ ...@@ -37,6 +90,15 @@ ENV/
env.bak/ env.bak/
venv.bak/ venv.bak/
# Project specifics # Spyder project settings
*/__pycache__/ .spyderproject
migrations/ .spyproject
\ No newline at end of file
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
\ No newline at end of file
...@@ -23,8 +23,6 @@ from reviews import views as reviews_views ...@@ -23,8 +23,6 @@ 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'),
...@@ -33,7 +31,7 @@ urlpatterns = [ ...@@ -33,7 +31,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'^$', academe_views.index, name="homepage"), url(r'^$', reviews_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,15 +3,14 @@ from django.urls import reverse ...@@ -3,15 +3,14 @@ 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
# Homepage # Create your views here.
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.5 on 2017-11-05 05:15 # Generated by Django 1.11.6 on 2017-11-04 09:28
from __future__ import unicode_literals from __future__ import unicode_literals
from django.conf import settings from django.conf import settings
from django.db import migrations, models from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
class Migration(migrations.Migration): class Migration(migrations.Migration):
initial = True initial = True
dependencies = [ dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL), migrations.swappable_dependency(settings.AUTH_USER_MODEL),
] ]
operations = [ operations = [
migrations.CreateModel( migrations.CreateModel(
name='Profile', name='Profile',
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')),
('email_confirmed', models.BooleanField(default=False)), ('email_confirmed', models.BooleanField(default=False)),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
], ],
), ),
] ]
...@@ -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.site@gmail.com" MY_ADDRESS = "academe.obf@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-11-05 05:15 # Generated by Django 1.11.5 on 2017-10-24 01:47
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):
initial = True initial = True
dependencies = [ dependencies = [
] ]
operations = [ operations = [
migrations.CreateModel( migrations.CreateModel(
name='Prof', name='Prof',
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)), ('first_name', models.CharField(max_length=20)),
('last_name', models.CharField(max_length=20)), ('last_name', models.CharField(max_length=20)),
], ],
), ),
] ]
...@@ -12,9 +12,7 @@ ...@@ -12,9 +12,7 @@
<h1>New Review</h1> <h1>New Review</h1>
<form method="POST"> <form method="POST">
{% csrf_token %} {% csrf_token %}
<p>{{ review_form.message }}</p> {{ review_form.as_p }}
<p>{{ review_form.rating }}</p>
<p>{{ review_form.prof }}</p>
<button type="submit">Save</button> <button type="submit">Save</button>
</form> </form>
......
...@@ -26,21 +26,11 @@ ...@@ -26,21 +26,11 @@
{% 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>
<form method="POST"> <textarea class="form-control" rows="5" id="comment"></textarea>
{% csrf_token %} <button type="submit" class="btn btn-default">Submit Review</button>
<p>{{ review_form.message }}</p>
<p>{{ review_form.rating }}</p>
<button type="submit" class="btn btn-default">Submit Review</button>
</form>
</div> </div>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -2,13 +2,12 @@ from django.shortcuts import render, redirect ...@@ -2,13 +2,12 @@ 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'):
...@@ -20,15 +19,10 @@ def index(request): ...@@ -20,15 +19,10 @@ def index(request):
# Make a new review # Make a new review
if(request.method=='POST'): if(request.method=='POST'):
post_values = request.POST.copy() form = ReviewForm(request.POST)
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})
...@@ -36,19 +30,6 @@ def index(request): ...@@ -36,19 +30,6 @@ 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
[
{
"model":"reviews.Review",
"pk":1,
"fields":{
"message":"legendary",
"created_at":"2017-11-05 05:40:11.094971+08:00",
"rating":5,
"prof":1,
"user":1
}
},
{
"model":"reviews.Review",
"pk":2,
"fields":{
"message":"easy a",
"created_at":"2017-11-05 05:50:11.094971+08:00",
"rating":5,
"prof":2,
"user":2
}
},
{
"model":"reviews.Review",
"pk":3,
"fields":{
"message":"chill",
"created_at":"2017-11-05 06:00:11.094971+08:00",
"rating":5,
"prof":3,
"user":3
}
},
{
"model":"reviews.Review",
"pk":4,
"fields":{
"message":"load rev",
"created_at":"2017-11-05 06:10:11.094971+08:00",
"rating":1,
"prof":4,
"user":1
}
},
{
"model":"reviews.Review",
"pk":5,
"fields":{
"message":"Easy A prof",
"created_at":"2017-11-05 06:20:11.094971+08:00",
"rating":5,
"prof":1,
"user":2
}
},
{
"model":"reviews.Review",
"pk":6,
"fields":{
"message":"mabait",
"created_at":"2017-11-05 06:30:11.094971+08:00",
"rating":5,
"prof":2,
"user":3
}
},
{
"model":"reviews.Review",
"pk":7,
"fields":{
"message":"explains really well",
"created_at":"2017-11-05 06:40:11.094971+08:00",
"rating":4,
"prof":3,
"user":1
}
},
{
"model":"reviews.Review",
"pk":8,
"fields":{
"message":"makes a lot of jokes",
"created_at":"2017-11-05 06:50:11.094971+08:00",
"rating":4,
"prof":4,
"user":2
}
},
{
"model":"reviews.Review",
"pk":9,
"fields":{
"message":"friendly with students",
"created_at":"2017-11-05 7:00:11.094971+08:00",
"rating":4,
"prof":1,
"user":3
}
},
{
"model":"reviews.Review",
"pk":10,
"fields":{
"message":"fair in giving grades",
"created_at":"2017-11-05 07:10:11.094971+08:00",
"rating":4,
"prof":2,
"user":1
}
}
]
\ No newline at end of file
from django.forms import ModelForm, CharField, TextInput from django.forms import ModelForm
from reviews.models import Review from reviews.models import Review
# Make a custom widget for rating so it can only be 0 - 5 class ReviewForm(ModelForm):
from django.forms import widgets class Meta:
from django.utils.safestring import mark_safe model = Review
fields = ['message', 'rating', 'prof']
# class RatingWidget(widgets.TextInput): \ No newline at end of file
# 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):
# 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:
model = Review
fields = ['message', 'rating', 'prof', 'user']
\ No newline at end of file
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-11-05 05:16 # Generated by Django 1.11.6 on 2017-10-10 04:34
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
class Migration(migrations.Migration):
class Migration(migrations.Migration):
initial = True
initial = True
dependencies = [
dependencies = [ ]
('profs', '0001_initial'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL), operations = [
] migrations.CreateModel(
name='Prof',
operations = [ fields=[
migrations.CreateModel( ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
name='Course', ('first_name', models.CharField(max_length=20)),
fields=[ ('last_name', models.CharField(max_length=20)),
('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)), migrations.CreateModel(
], name='Review',
), fields=[
migrations.CreateModel( ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
name='Review', ('message', models.TextField(max_length=4000)),
fields=[ ('created_at', models.DateTimeField(auto_now_add=True)),
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('updated_at', models.DateTimeField(null=True)),
('message', models.TextField(max_length=4000)), ('rating', models.IntegerField(default=5, validators=[django.core.validators.MaxValueValidator(5), django.core.validators.MinValueValidator(0)])),
('created_at', models.DateTimeField(auto_now_add=True)), ('prof', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='reviews', to='reviews.Prof')),
('updated_at', models.DateTimeField(null=True)), ],
('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='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',
),
]
from django.db import models from django.db import models
from django.core.validators import MaxValueValidator, MinValueValidator 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 from profs.models import Prof
# Create your models here. # Create your models here.
class Course(models.Model): class Course(models.Model):
name = models.CharField(max_length = 15, unique = True) name = models.CharField(max_length = 15, unique = True)
description = models.CharField(max_length = 100) description = models.CharField(max_length = 100)
class Review(models.Model): class Review(models.Model):
message = models.TextField(max_length = 4000) message = models.TextField(max_length = 4000)
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( rating = models.IntegerField(
default = 5, default = 5,
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
...@@ -10,7 +9,6 @@ from .forms import ReviewForm ...@@ -10,7 +9,6 @@ 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