Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignment 8 #17

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitignore

This file was deleted.

Binary file added blogging/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file added blogging/__pycache__/admin.cpython-39.pyc
Binary file not shown.
Binary file added blogging/__pycache__/apps.cpython-39.pyc
Binary file not shown.
Binary file added blogging/__pycache__/models.cpython-39.pyc
Binary file not shown.
Binary file added blogging/__pycache__/tests.cpython-39.pyc
Binary file not shown.
Binary file added blogging/__pycache__/urls.cpython-39.pyc
Binary file not shown.
Binary file added blogging/__pycache__/views.cpython-39.pyc
Binary file not shown.
11 changes: 8 additions & 3 deletions blogging/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from django.contrib import admin
from blogging.models import Post, Category
from .models import Post, Category

class PostAdmin(admin.ModelAdmin):
prepopulated_fields = {'title':('text',)}

admin.site.register(Post)
admin.site.register(Category)
class CatagoryAdmin(admin.ModelAdmin):
prepopulated_fields = {'name':('description',)}

admin.site.register(Post, PostAdmin)
admin.site.register(Category, CatagoryAdmin)
2 changes: 1 addition & 1 deletion blogging/fixtures/blogging_test_fixture.json
Original file line number Diff line number Diff line change
@@ -35,4 +35,4 @@
"date_joined": "2013-05-24T05:35:58.628Z"
}
}
]
]
2 changes: 1 addition & 1 deletion blogging/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 2.1.1 on 2019-10-29 01:39
# Generated by Django 2.1.1 on 2021-06-30 23:44

from django.conf import settings
from django.db import migrations, models
5 changes: 4 additions & 1 deletion blogging/migrations/0002_category.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 2.1.1 on 2019-11-05 03:35
# Generated by Django 2.1.1 on 2021-07-09 22:32

from django.db import migrations, models

@@ -18,5 +18,8 @@ class Migration(migrations.Migration):
('description', models.TextField(blank=True)),
('posts', models.ManyToManyField(blank=True, related_name='categories', to='blogging.Post')),
],
options={
'verbose_name_plural': 'Categories',
},
),
]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 2.1.1 on 2019-11-05 03:42
# Generated by Django 2.1.1 on 2021-08-11 00:28

from django.db import migrations

@@ -10,8 +10,8 @@ class Migration(migrations.Migration):
]

operations = [
migrations.AlterModelOptions(
name='category',
options={'verbose_name_plural': 'Categories'},
migrations.RemoveField(
model_name='category',
name='posts',
),
]
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 3 additions & 1 deletion blogging/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# blogging/models.py

from django.contrib import admin
from django.db import models
from django.contrib.auth.models import User

@@ -15,7 +18,6 @@ def __str__(self):
class Category(models.Model):
name = models.CharField(max_length=128)
description = models.TextField(blank=True)
posts = models.ManyToManyField(Post, blank=True, related_name='categories')

class Meta:
verbose_name_plural = 'Categories'
2 changes: 1 addition & 1 deletion blogging/static/django_blog.css
Original file line number Diff line number Diff line change
@@ -71,4 +71,4 @@ ul.categories {
}
ul.categories li {
display: inline;
}
}
3 changes: 1 addition & 2 deletions blogging/templates/blogging/detail.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% extends "base.html" %}

{% block content %}
<a class="backlink" href="/">Home</a>
<h1>{{ post }}</h1>
@@ -14,4 +13,4 @@ <h1>{{ post }}</h1>
<li>{{ category }}</li>
{% endfor %}
</ul>
{% endblock %}
{% endblock %}
4 changes: 2 additions & 2 deletions blogging/templates/blogging/list.html
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ <h1>Recent Posts</h1>
{% comment %} here is where the query happens {% endcomment %}
{% for post in posts %}
<div class="post">
<h2>
<h2>
<a href="{% url 'blog_detail' post.pk %}">{{ post }}</a>
</h2>
<p class="byline">
@@ -19,4 +19,4 @@ <h2>
</ul>
</div>
{% endfor %}
{% endblock %}
{% endblock %}
12 changes: 3 additions & 9 deletions blogging/tests.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import datetime

from django.utils.timezone import utc
from django.test import TestCase
from django.contrib.auth.models import User
from django.utils.timezone import utc

from blogging.models import Post
from blogging.models import Category

from blogging.models import Post, Category

class PostTestCase(TestCase):
fixtures = ['blogging_test_fixture.json', ]
@@ -20,7 +16,6 @@ def test_string_representation(self):
actual = str(p1)
self.assertEqual(expected, actual)


class CategoryTestCase(TestCase):

def test_string_representation(self):
@@ -29,7 +24,6 @@ def test_string_representation(self):
actual = str(c1)
self.assertEqual(expected, actual)


class FrontEndTestCase(TestCase):
"""test views provided in the front-end"""
fixtures = ['blogging_test_fixture.json', ]
@@ -69,4 +63,4 @@ def test_details_only_published(self):
self.assertEqual(resp.status_code, 200)
self.assertContains(resp, title)
else:
self.assertEqual(resp.status_code, 404)
self.assertEqual(resp.status_code, 404)
4 changes: 2 additions & 2 deletions blogging/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.urls import path
from blogging.views import list_view, detail_view
from blogging.views import stub_view, list_view, detail_view

urlpatterns = [
path('', list_view, name="blog_index"),
path('posts/<int:post_id>/', detail_view, name="blog_detail"),
]
]
24 changes: 16 additions & 8 deletions blogging/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
from django.shortcuts import render
from django.http import HttpResponse, HttpResponseRedirect, Http404
from django.template import loader

from blogging.models import Post

def stub_view(request, *args, **kwargs):
body = "Stub View\n\n"
if args:
body += "Args:\n"
body += "\n".join(["\t%s" % a for a in args])
if kwargs:
body += "Kwargs:\n"
body += "\n".join(["\t%s: %s" % i for i in kwargs.items()])
return HttpResponse(body, content_type="text/plain")

def list_view(request):
published = Post.objects.exclude(published_date__exact=None)
posts = published.order_by('-published_date')
context = {'posts': posts}
return render(request, 'blogging/list.html', context)

def detail_view(request, post_id):
published = Post.objects.exclude(published_date__exact=None)
@@ -13,10 +27,4 @@ def detail_view(request, post_id):
raise Http404
context = {'post': post}
return render(request, 'blogging/detail.html', context)


def list_view(request):
published = Post.objects.exclude(published_date__exact=None)
posts = published.order_by('-published_date')
context = {'posts': posts}
return render(request, 'blogging/list.html', context)

Binary file added db.sqlite3
Binary file not shown.
Binary file added mysite/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file added mysite/__pycache__/settings.cpython-39.pyc
Binary file not shown.
Binary file added mysite/__pycache__/urls.cpython-39.pyc
Binary file not shown.
Binary file added mysite/__pycache__/wsgi.cpython-39.pyc
Binary file not shown.
23 changes: 20 additions & 3 deletions mysite/settings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# mysite/settings.py
"""
Django settings for mysite project.

@@ -20,7 +21,7 @@
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'xak=ca*e6hvh8q5hgfz5l9ees)_pxjif0)ui!ikifg4!enjk+7'
SECRET_KEY = '0@3oddlht7%xzs2$)izd7e(kod(-+esmnr!z(ia*7+f$u11j4-'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
@@ -39,6 +40,13 @@
'django.contrib.staticfiles',
'polling',
'blogging',

'django.contrib.sites',

'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.facebook',
]

MIDDLEWARE = [
@@ -56,7 +64,7 @@
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'mysite/templates')],
'DIRS': [],#os.path.join(BASE_DIR, 'mysite/templates')], # <- Make DIRS look like this
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
@@ -101,6 +109,13 @@
},
]

AUTHENTICATION_BACKENDS = [
# Needed to login by username in Django admin, regardless of `allauth`
'django.contrib.auth.backends.ModelBackend',

# `allauth` specific authentication methods, such as login by e-mail
'allauth.account.auth_backends.AuthenticationBackend',
]

# Internationalization
# https://docs.djangoproject.com/en/2.1/topics/i18n/
@@ -120,6 +135,8 @@
# https://docs.djangoproject.com/en/2.1/howto/static-files/

STATIC_URL = '/static/'

LOGIN_URL = '/login/'
LOGIN_REDIRECT_URL = '/'
SITE_ID = 1

LOGIN_REDIRECT_URL = '/profile/'
3 changes: 2 additions & 1 deletion mysite/templates/base.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{# mysite/templates/base.html #}
{% load staticfiles %}
<!DOCTYPE html>
<html>
@@ -24,4 +25,4 @@
</div>
</div>
</body>
</html>
</html>
2 changes: 1 addition & 1 deletion mysite/templates/login.html
Original file line number Diff line number Diff line change
@@ -6,4 +6,4 @@ <h1>My Blog Login</h1>
{{ form.as_p }}
<p><input type="submit" value="Log In"></p>
</form>
{% endblock %}
{% endblock %}
13 changes: 8 additions & 5 deletions mysite/urls.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# mysite/urls.py
"""mysite URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
@@ -13,15 +14,17 @@
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""


from django.contrib import admin
from django.urls import path, include
from django.urls import path, include # <-- Make sure you have both of these imports.
from django.contrib.auth.views import LoginView, LogoutView


urlpatterns = [
path('', include('blogging.urls')),
path('polling/', include('polling.urls')),
path('admin/', admin.site.urls),
path('polling/', include('polling.urls')), # <-- Add this
path('admin/', admin.site.urls), # <- already there
path('login/', LoginView.as_view(template_name='login.html'), name="login"),
path('logout/', LogoutView.as_view(next_page='/'), name="logout"),
]
path('accounts/', include('allauth.urls')),
]
Binary file added polling/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file added polling/__pycache__/admin.cpython-39.pyc
Binary file not shown.
Binary file added polling/__pycache__/apps.cpython-39.pyc
Binary file not shown.
Binary file added polling/__pycache__/models.cpython-39.pyc
Binary file not shown.
Binary file added polling/__pycache__/urls.cpython-39.pyc
Binary file not shown.
Binary file added polling/__pycache__/views.cpython-39.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion polling/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.contrib import admin
from polling.models import Poll

admin.site.register(Poll)
admin.site.register(Poll)
2 changes: 1 addition & 1 deletion polling/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 2.1.1 on 2019-10-29 01:24
# Generated by Django 2.1.1 on 2021-06-30 22:56

from django.db import migrations, models

Binary file not shown.
Binary file not shown.
3 changes: 2 additions & 1 deletion polling/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# blogging/models.py
from django.db import models

class Poll(models.Model):
@@ -6,4 +7,4 @@ class Poll(models.Model):
score = models.IntegerField(default=0)

def __str__(self):
return self.title
return self.title
2 changes: 1 addition & 1 deletion polling/templates/polling/detail.html
Original file line number Diff line number Diff line change
@@ -16,4 +16,4 @@ <h1>{{ poll.title }}</h1>
<input type="submit" name="vote" value="No">
</form>
</div>
{% endblock %}
{% endblock %}
3 changes: 2 additions & 1 deletion polling/templates/polling/list.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{# polling/templates/polling/list.html #}
{% extends "base.html" %}
{% block content %}
<h1>Polls</h1>
@@ -8,4 +9,4 @@ <h2>
</h2>
</div>
{% endfor %}
{% endblock %}
{% endblock %}
4 changes: 3 additions & 1 deletion polling/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# polling/urls.py

from django.urls import path
from polling.views import list_view, detail_view

urlpatterns = [
path('', list_view, name="poll_index"),
path('polls/<int:poll_id>/', detail_view, name="poll_detail"),
]
]
4 changes: 3 additions & 1 deletion polling/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# polling/views.py

from django.shortcuts import render
from django.http import Http404
from polling.models import Poll
@@ -20,4 +22,4 @@ def detail_view(request, poll_id):
poll.save()

context = {'poll': poll}
return render(request, 'polling/detail.html', context)
return render(request, 'polling/detail.html', context)
2 changes: 0 additions & 2 deletions requirements.txt

This file was deleted.

Loading