Skip to content
Snippets Groups Projects
Commit 465222a6 authored by BinBin's avatar BinBin
Browse files

first take

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 847 additions and 0 deletions
# Created by https://www.toptal.com/developers/gitignore/api/python,django,pycharm
# Edit at https://www.toptal.com/developers/gitignore?templates=python,django,pycharm
### Django ###
.idea
*.log
*.pot
*.pyc
__pycache__/
local_settings.py
db.sqlite3
db.sqlite3-journal
media
db.sqbpro
# If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/
# in your Git repository. Update and uncomment the following line accordingly.
# <django-project-name>/staticfiles/
### Django.Python Stack ###
# Byte-compiled / optimized / DLL files
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
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/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
# Django stuff:
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
### PyCharm ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# AWS User-specific
.idea/**/aws.xml
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
### PyCharm Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr
# Sonarlint plugin
# https://plugins.jetbrains.com/plugin/7973-sonarlint
.idea/**/sonarlint/
# SonarQube Plugin
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
.idea/**/sonarIssues.xml
# Markdown Navigator plugin
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
.idea/**/markdown-navigator.xml
.idea/**/markdown-navigator-enh.xml
.idea/**/markdown-navigator/
# Cache file creation bug
# See https://youtrack.jetbrains.com/issue/JBR-2257
.idea/$CACHE_FILE$
# CodeStream plugin
# https://plugins.jetbrains.com/plugin/12206-codestream
.idea/codestream.xml
### Python ###
# Byte-compiled / optimized / DLL files
# C extensions
# Distribution / packaging
# 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.
# Installer logs
# Unit test / coverage reports
# Translations
# Django stuff:
# Flask stuff:
# Scrapy stuff:
# Sphinx documentation
# PyBuilder
# Jupyter Notebook
# IPython
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
# Celery stuff
# SageMath parsed files
# Environments
# Spyder project settings
# Rope project settings
# mkdocs documentation
# mypy
# Pyre type checker
# pytype static type analyzer
# Cython debug symbols
# End of https://www.toptal.com/developers/gitignore/api/python,django,pycharm
\ No newline at end of file
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class ContentConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'content'
# Generated by Django 3.2.6 on 2021-10-03 06:33
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Feed',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('content', models.TextField()),
('image', models.TextField()),
('profile_image', models.TextField()),
('user_id', models.TextField()),
('like_count', models.IntegerField()),
],
),
]
# Generated by Django 3.2.6 on 2021-10-11 12:03
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('content', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='feed',
name='user_id',
field=models.CharField(blank=True, max_length=30, null=True),
),
]
# Generated by Django 3.2.6 on 2021-10-11 12:05
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('content', '0002_alter_feed_user_id'),
]
operations = [
migrations.AddField(
model_name='feed',
name='email',
field=models.EmailField(blank=True, max_length=100, null=True, verbose_name='email'),
),
]
# Generated by Django 3.2.6 on 2021-10-11 12:28
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('content', '0003_feed_email'),
]
operations = [
migrations.CreateModel(
name='FeedLike',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('feed_id', models.IntegerField()),
('email', models.CharField(blank=True, max_length=30, null=True)),
('is_like', models.BooleanField(default=False)),
('content', models.TextField()),
],
),
migrations.CreateModel(
name='Reply',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('feed_id', models.IntegerField()),
('created_at', models.DateTimeField(auto_now_add=True)),
('user_id', models.CharField(blank=True, max_length=30, null=True)),
('content', models.TextField()),
],
),
migrations.AddIndex(
model_name='reply',
index=models.Index(fields=['feed_id'], name='content_rep_feed_id_49ae3d_idx'),
),
migrations.AddIndex(
model_name='feedlike',
index=models.Index(fields=['feed_id'], name='content_fee_feed_id_1c82cf_idx'),
),
migrations.AddIndex(
model_name='feedlike',
index=models.Index(fields=['email'], name='content_fee_email_3901d6_idx'),
),
]
# Generated by Django 3.2.6 on 2021-10-11 12:31
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('content', '0004_auto_20211011_2128'),
]
operations = [
migrations.RemoveIndex(
model_name='feedlike',
name='content_fee_email_3901d6_idx',
),
]
# Generated by Django 3.2.6 on 2021-10-11 12:31
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('content', '0005_remove_feedlike_content_fee_email_3901d6_idx'),
]
operations = [
migrations.AddIndex(
model_name='feedlike',
index=models.Index(fields=['email'], name='content_fee_email_3901d6_idx'),
),
]
# Generated by Django 3.2.6 on 2021-10-11 15:07
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('content', '0006_feedlike_content_fee_email_3901d6_idx'),
]
operations = [
migrations.RemoveField(
model_name='feedlike',
name='content',
),
migrations.AddField(
model_name='reply',
name='email',
field=models.EmailField(blank=True, max_length=100, null=True, verbose_name='email'),
),
]
# Generated by Django 3.2.6 on 2021-10-14 12:46
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('content', '0007_auto_20211012_0007'),
]
operations = [
migrations.CreateModel(
name='Bookmark',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('email', models.EmailField(max_length=100, verbose_name='email')),
('feed_id', models.IntegerField()),
('is_bookmarked', models.BooleanField(default=True)),
],
),
migrations.AddIndex(
model_name='bookmark',
index=models.Index(fields=['email'], name='content_boo_email_03c3c8_idx'),
),
]
from django.db import models
# Create your models here.
class Feed(models.Model):
content = models.TextField()
image = models.TextField()
profile_image = models.TextField()
email = models.EmailField(verbose_name='email', max_length=100, blank=True, null=True)
user_id = models.CharField(max_length=30, blank=True, null=True)
like_count = models.IntegerField()
class Reply(models.Model):
feed_id = models.IntegerField()
created_at = models.DateTimeField(auto_now_add=True)
user_id = models.CharField(max_length=30, blank=True, null=True)
content = models.TextField()
email = models.EmailField(verbose_name='email', max_length=100, blank=True, null=True)
class Meta:
indexes = [
models.Index(fields=['feed_id'])
]
class FeedLike(models.Model):
feed_id = models.IntegerField()
email = models.CharField(max_length=30, blank=True, null=True)
is_like = models.BooleanField(default=False)
class Meta:
indexes = [
models.Index(fields=['feed_id']),
models.Index(fields=['email']),
]
class Bookmark(models.Model):
email = models.EmailField(verbose_name='email', max_length=100)
feed_id = models.IntegerField()
is_bookmarked = models.BooleanField(default=True)
class Meta:
indexes = [
models.Index(fields=['email'])
]
from django.test import TestCase
# Create your tests here.
from django.urls import path
from .views import UploadFeed, CreateReply, LikeFeed, BookmarkFeed
urlpatterns = [
path('upload', UploadFeed.as_view(), name='upload_feed'),
path('reply/create', CreateReply.as_view(), name='reply_create'),
path('like', LikeFeed.as_view(), name='like'),
path('bookmark', BookmarkFeed.as_view(), name='bookmark'),
]
from django.shortcuts import render
from rest_framework.views import APIView
from content.models import Feed, Reply, FeedLike, Bookmark
from rest_framework.response import Response
from user.models import User
from rest_framework.response import Response
import os
from jinstagram.settings import MEDIA_ROOT
from uuid import uuid4
from datetime import datetime
class UploadFeed(APIView):
def post(self, request):
file = request.FILES['file']
uuid_name = uuid4().hex
save_path = os.path.join(MEDIA_ROOT, uuid_name)
with open(save_path, 'wb+') as destination:
for chunk in file.chunks():
destination.write(chunk)
content = request.data.get('content')
image = uuid_name
profile_image = request.data.get('profile_image')
user_id = request.data.get('user_id')
email = request.data.get('email')
Feed.objects.create(content=content, image=image, profile_image=profile_image, user_id=user_id, email=email, like_count=0)
return Response(status=200)
class LikeFeed(APIView):
def post(self, request):
feed_id = request.data.get('feed_id')
email = request.data.get('email')
is_like = request.data.get('is_like', 'True')
if is_like.lower() == 'false':
is_like = False
else:
is_like = True
feed_like = FeedLike.objects.filter(feed_id=feed_id, email=email).first()
if feed_like is None:
FeedLike.objects.create(feed_id=feed_id,
email=email,
is_like=is_like,
)
else:
feed_like.is_like = is_like
feed_like.save()
return Response(status=200, data=dict(message='피드 좋아요 완료.'))
class CreateReply(APIView):
def post(self, request):
feed_id = request.data.get('feed_id')
user_id = request.data.get('user_id')
content = request.data.get('content')
email = request.data.get('email')
Reply.objects.create(feed_id=feed_id,
user_id=user_id,
content=content,
email=email
)
return Response(status=200, data=dict(message='댓글 작성 완료.'))
class DeleteReply(APIView):
def post(self, request):
reply_id = request.data.get('reply_id')
email = request.data.get('email')
reply = Reply.objects.filter(id=reply_id).first()
if reply is None:
return Response(status=500, data=dict(message='삭제 실패'))
if reply.email == email:
reply.delete()
return Response(status=200, data=dict(message='성공'))
else:
return Response(status=500, data=dict(message='삭제 실패'))
class BookmarkFeed(APIView):
def post(self, request):
feed_id = request.data.get('feed_id')
email = request.data.get('email')
is_bookmarked = request.data.get('is_bookmarked', 'True')
if is_bookmarked.lower() == 'false':
is_bookmarked = False
else:
is_bookmarked = True
bookmark = Bookmark.objects.filter(feed_id=feed_id, email=email).first()
if bookmark is None:
Bookmark.objects.create(feed_id=feed_id,
email=email,
is_bookmarked=is_bookmarked,
)
else:
bookmark.is_bookmarked = is_bookmarked
bookmark.save()
return Response(status=200, data=dict(message='북마크 설정 완료.'))
"""
ASGI config for jinstagram project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'jinstagram.settings')
application = get_asgi_application()
"""
Django settings for jinstagram project.
Generated by 'django-admin startproject' using Django 3.2.6.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""
from pathlib import Path
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-(ddgwrknj$82@u324e@$mhqx6w&+!3f$o+18de%kulzyo@ij01'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['*']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'content',
'user'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'jinstagram.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR / 'templates']
,
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'jinstagram.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/
STATIC_URL = '/static/'
# static 파일이 위치한 경로를 지정
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
AUTH_USER_MODEL = 'user.User'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment