Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
style: Update source code to satisfy pep8 style guide
Browse files Browse the repository at this point in the history
  • Loading branch information
junghoon-vans committed Oct 9, 2022
1 parent 05d2be7 commit 7073483
Show file tree
Hide file tree
Showing 21 changed files with 146 additions and 101 deletions.
2 changes: 1 addition & 1 deletion account/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

from .models import Profile
# Register your models here.
admin.site.register(Profile)
admin.site.register(Profile)
10 changes: 7 additions & 3 deletions account/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from django.conf import settings
from django.db import models
# 유저 정보 import
from django.conf import settings


class Profile(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
image = models.ImageField(upload_to='profile/', blank=True)
user = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
)
image = models.ImageField(upload_to='profile/', blank=True)
3 changes: 1 addition & 2 deletions account/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from django.test import TestCase

# from django.test import TestCase
# Create your tests here.
3 changes: 2 additions & 1 deletion account/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.urls import path

from . import views

urlpatterns = [
Expand All @@ -7,4 +8,4 @@
path('logout/', views.logout, name='logout'),
path('userpage/<str:author_id>', views.userpage, name='userpage'),
path('changeprofile/', views.change_profile, name='change_profile'),
]
]
48 changes: 30 additions & 18 deletions account/views.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
from django.shortcuts import render, redirect, get_object_or_404
from django.http import HttpResponse
from django.contrib.auth.models import User
from django.contrib import auth
from page.models import Post
from account.models import Profile

# make circle image
from PIL import Image, ImageOps, ImageDraw
import os
from io import BytesIO

from django.contrib import auth
from django.contrib.auth.models import User
from django.core.files.uploadedfile import InMemoryUploadedFile
from django.http import HttpResponse
from django.shortcuts import redirect
from django.shortcuts import render
from PIL import Image
from PIL import ImageDraw
from PIL import ImageOps

from account.models import Profile
from page.models import Post
# make circle image
# default image path
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


def register(request):
if request.method == 'POST':
if request.POST['pw'] == request.POST['confirm-pw']:
user = User.objects.create_user(
request.POST['id'], password=request.POST['pw']
request.POST['id'], password=request.POST['pw'],
)
auth.login(request, user)
profile = Profile()
Expand All @@ -29,34 +33,42 @@ def register(request):
else:
return render(request, 'register.html')


def login(request):
if request.method == 'POST':
username = request.POST['id']
password = request.POST['pw']
user = auth.authenticate(request, username=username, password=password)
if user is not None:
auth.login(request, user)
return redirect ('home')
return redirect('home')
else:
return HttpResponse('입력 정보를 확인하세요.')
else:
return render(request, 'login.html')


def logout(request):
auth.logout(request)
return redirect('home')


def userpage(request, author_id):
# 유저 객체를 user에 저장
account = User.objects.get(username=author_id)
# 해당 유저의 포스트만 불러오기
posts = Post.objects.filter(author=account)
profile = Profile.objects.filter(user=account)
return render(request, 'userpage.html', {'posts':posts, 'account':account, 'profile':profile})
return render(
request, 'userpage.html', {
'posts': posts,
'account': account, 'profile': profile,
},
)


def change_profile(request):
# if profile_image exist, delete this image
# if profile_image exist, delete this image
if Profile.objects.filter(user=request.user):
Profile.objects.filter(user=request.user).delete()

Expand All @@ -65,17 +77,17 @@ def change_profile(request):
# save profile_image
if 'image' in request.FILES:
im = Image.open(request.FILES['image'])
im = im.resize((1920, 1920));
im = im.resize((1920, 1920))
bigsize = (im.size[0] * 3, im.size[1] * 3)
mask = Image.new('L', bigsize, 0)
draw = ImageDraw.Draw(mask)
draw = ImageDraw.Draw(mask)
draw.ellipse((0, 0) + bigsize, fill=255)
mask = mask.resize(im.size, Image.ANTIALIAS)
im.putalpha(mask)

output = ImageOps.fit(im, mask.size, centering=(0.5, 0.5))
output.putalpha(mask)

buffer = BytesIO()
output.save(buffer, format='png')

Expand All @@ -90,4 +102,4 @@ def change_profile(request):

profile.image = file
profile.save()
return redirect('/account/userpage/'+str(profile.user))
return redirect('/account/userpage/'+str(profile.user))
3 changes: 2 additions & 1 deletion comment/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.contrib import admin

from .models import Comment

# Register your models here.
admin.site.register(Comment)
admin.site.register(Comment)
4 changes: 3 additions & 1 deletion comment/forms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from django import forms

from .models import Comment


class CommentForm(forms.ModelForm):
class Meta:
model = Comment
fields = ['content']
fields = ['content']
17 changes: 12 additions & 5 deletions comment/models.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
from django.db import models
# 유저 정보 import
from django.conf import settings
from django.db import models

from page.models import Post
# 유저 정보 import

# Create your models here.


class Comment(models.Model):
# related_name
title = models.ForeignKey(Post, on_delete=models.CASCADE, related_name='comments')
author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
title = models.ForeignKey(
Post, on_delete=models.CASCADE, related_name='comments',
)
author = models.ForeignKey(
settings.AUTH_USER_MODEL, on_delete=models.CASCADE,
)
pub_date = models.DateTimeField('publish')
content = models.CharField(max_length=200)

def __str__(self):
return self.content
return self.content
3 changes: 1 addition & 2 deletions comment/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from django.test import TestCase

# from django.test import TestCase
# Create your tests here.
8 changes: 6 additions & 2 deletions comment/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from django.urls import path

from . import views

urlpatterns = [
path('new/<int:post_id>', views.comment_new, name='comment_new'),
path('delete/<int:post_id>/<int:comment_id>', views.comment_delete, name='comment_delete'),
]
path(
'delete/<int:post_id>/<int:comment_id>',
views.comment_delete, name='comment_delete',
),
]
8 changes: 6 additions & 2 deletions comment/views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from django.shortcuts import render, redirect, get_object_or_404
from django.shortcuts import get_object_or_404
from django.shortcuts import redirect
from django.utils import timezone
from .forms import CommentForm

from .models import Comment
from page.models import Post

# Create your views here.


def comment_new(request, post_id):
post = get_object_or_404(Post, pk=post_id)

Expand All @@ -17,6 +20,7 @@ def comment_new(request, post_id):
comment.save()
return redirect('post_detail', post_id)


def comment_delete(request, post_id, comment_id):
comment = get_object_or_404(Comment, pk=comment_id)

Expand Down
44 changes: 15 additions & 29 deletions lionstagram/settings.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,22 @@
"""
Django settings for lionstagram project.
Generated by 'django-admin startproject' using Django 2.1.5.
For more information on this file, see
https://docs.djangoproject.com/en/2.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.1/ref/settings/
"""

import os

import dj_database_url

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
# SECRET_KEY = 'mnu!)lvd7rkqcs21@esw7st%($-%*-k62-wrzhbjv*u^2#4_6s'
SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', 'mnu!)lvd7rkqcs21@esw7st%($-%*-k62-wrzhbjv*u^2#4_6s')
SECRET_KEY = os.environ.get(
'DJANGO_SECRET_KEY', 'mnu!)lvd7rkqcs21@esw7st%($-%*-k62-wrzhbjv*u^2#4_6s',
)

# SECURITY WARNING: don't run with debug turned on in production!
# DEBUG = True
DEBUG = bool( os.environ.get('DJANGO_DEBUG', True) )
DEBUG = bool(os.environ.get('DJANGO_DEBUG', True))

ALLOWED_HOSTS = ['*']


# Application definition

INSTALLED_APPS = [
Expand Down Expand Up @@ -75,37 +62,38 @@

WSGI_APPLICATION = 'lionstagram.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
},
}


# Password validation
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
'NAME': 'django.contrib.auth.password_validation.'
'UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
'NAME': 'django.contrib.auth.password_validation.'
'MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
'NAME': 'django.contrib.auth.password_validation.'
'CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
'NAME': 'django.contrib.auth.password_validation.'
'NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/2.1/topics/i18n/

Expand All @@ -119,7 +107,6 @@

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/

Expand All @@ -135,6 +122,5 @@
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

# Heroku: Update database configuration from $DATABASE_URL.
import dj_database_url
db_from_env = dj_database_url.config(conn_max_age=500)
DATABASES['default'].update(db_from_env)
10 changes: 6 additions & 4 deletions lionstagram/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path, include
from django.urls import include
from django.urls import path

import page.views
# media 경로
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
path('admin/', admin.site.urls),
path('', page.views.home, name='home'),
path('post/', include('page.urls')),
path('account/', include('account.urls')),
path('comment/', include('comment.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
1 change: 0 additions & 1 deletion lionstagram/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
For more information on this file, see
https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application
Expand Down
2 changes: 1 addition & 1 deletion manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
"forget to activate a virtual environment?",
) from exc
execute_from_command_line(sys.argv)
Loading

0 comments on commit 7073483

Please sign in to comment.