권주희

Merge branch 'develop' into 'master'

Develop



See merge request !11
...@@ -26,3 +26,5 @@ __pycache__ ...@@ -26,3 +26,5 @@ __pycache__
26 npm-debug.log* 26 npm-debug.log*
27 yarn-debug.log* 27 yarn-debug.log*
28 yarn-error.log* 28 yarn-error.log*
29 +.idea
30 +secrets.json
......
1 +from django.contrib import admin
2 +
3 +from .models import Item, SharedItem, User
4 +
5 +admin.site.register(Item)
6 +admin.site.register(SharedItem)
7 +admin.site.register(User)
...\ No newline at end of file ...\ No newline at end of file
1 +# Generated by Django 3.0.6 on 2020-06-11 14:54
2 +
3 +from django.db import migrations, models
4 +
5 +
6 +class Migration(migrations.Migration):
7 +
8 + initial = True
9 +
10 + dependencies = [
11 + ]
12 +
13 + operations = [
14 + migrations.CreateModel(
15 + name='Item',
16 + fields=[
17 + ('item_id', models.AutoField(primary_key=True, serialize=False)),
18 + ('is_folder', models.BooleanField(default=False)),
19 + ('name', models.CharField(max_length=50)),
20 + ('file_type', models.CharField(max_length=100, null=True)),
21 + ('path', models.TextField()),
22 + ('parent', models.IntegerField()),
23 + ('user_id', models.IntegerField()),
24 + ('size', models.IntegerField()),
25 + ('is_deleted', models.BooleanField(default=False)),
26 + ('created_time', models.DateTimeField(auto_now=True)),
27 + ('updated_time', models.DateTimeField(null=True)),
28 + ('status', models.BooleanField()),
29 + ],
30 + options={
31 + 'ordering': ['item_id'],
32 + },
33 + ),
34 + migrations.CreateModel(
35 + name='SharedItem',
36 + fields=[
37 + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
38 + ('item_id', models.IntegerField()),
39 + ('expires', models.DateTimeField()),
40 + ('password', models.CharField(max_length=20)),
41 + ('created_time', models.DateTimeField(auto_now=True)),
42 + ],
43 + options={
44 + 'ordering': ['item_id'],
45 + },
46 + ),
47 + migrations.CreateModel(
48 + name='User',
49 + fields=[
50 + ('int_id', models.AutoField(primary_key=True, serialize=False)),
51 + ('user_id', models.CharField(max_length=50)),
52 + ('name', models.CharField(max_length=50)),
53 + ('password', models.CharField(max_length=20)),
54 + ('total_size', models.IntegerField()),
55 + ('current_size', models.IntegerField()),
56 + ('created_time', models.DateTimeField(auto_now=True)),
57 + ],
58 + options={
59 + 'ordering': ['int_id'],
60 + },
61 + ),
62 + ]
1 +# Generated by Django 3.0.6 on 2020-06-11 15:29
2 +
3 +from django.db import migrations, models
4 +
5 +
6 +class Migration(migrations.Migration):
7 +
8 + dependencies = [
9 + ('api', '0001_initial'),
10 + ]
11 +
12 + operations = [
13 + migrations.AddField(
14 + model_name='user',
15 + name='root_folder',
16 + field=models.IntegerField(null=True),
17 + ),
18 + migrations.AlterField(
19 + model_name='item',
20 + name='parent',
21 + field=models.IntegerField(null=True),
22 + ),
23 + ]
1 +from django.db import models
2 +
3 +# Create your models here.
4 +class Item(models.Model):
5 + item_id = models.AutoField(primary_key = True)
6 + is_folder = models.BooleanField(default = False)
7 + name = models.CharField(max_length = 50)
8 + file_type = models.CharField(max_length=100, null=True) # signed_url 생성을 위해 file type 세팅
9 + path = models.TextField()
10 + #parent = models.ForeignKey('Item', on_delete=models.CASCADE, null=True) #related_name
11 + parent = models.IntegerField(null=True) # root 폴더의 경우 null임
12 + user_id = models.IntegerField()
13 + size = models.IntegerField()
14 + is_deleted = models.BooleanField(default = False)
15 + created_time = models.DateTimeField(auto_now=True)
16 + updated_time = models.DateTimeField(null=True)
17 + status = models.BooleanField(default=False)
18 +
19 + #file = models.FileField(upload_to = \path)
20 +
21 + class Meta:
22 + ordering = ['item_id']
23 +
24 +
25 +class SharedItem(models.Model):
26 + item_id = models.IntegerField()
27 + #file_id?
28 + expires = models.DateTimeField()
29 + password = models.CharField(max_length = 20)
30 + created_time = models.DateTimeField(auto_now=True)
31 + class Meta:
32 + ordering = ['item_id']
33 +
34 +
35 +class User(models.Model):
36 + int_id = models.AutoField(primary_key = True)
37 + user_id = models.CharField(max_length = 50)
38 + name = models.CharField(max_length = 50)
39 + password = models.CharField(max_length = 20)
40 + root_folder = models.IntegerField(null=True)
41 + total_size = models.IntegerField()
42 + current_size = models.IntegerField()
43 + created_time = models.DateTimeField(auto_now=True)
44 + class Meta:
45 + ordering = ['int_id']
1 +from django.contrib.auth.models import Group
2 +from rest_framework import serializers
3 +from .models import Item, SharedItem,User
4 +
5 +
6 +class UserSerializer(serializers.HyperlinkedModelSerializer):
7 + class Meta:
8 + model = User
9 + fields = '__all__'
10 +
11 +class GroupSerializer(serializers.HyperlinkedModelSerializer):
12 + class Meta:
13 + model = Group
14 + fields = ['url', 'name']
15 +
16 +class ItemSerializer(serializers.ModelSerializer):
17 + class Meta:
18 + model = Item
19 + fields = '__all__'
20 +
This diff is collapsed. Click to expand it.
1 -from django.contrib import admin
2 -
3 -# Register your models here.
1 -from django.db import models
2 -
3 -# Create your models here.
1 -from django.shortcuts import render
2 -
3 -# Create your views here.
1 """ 1 """
2 Django settings for khudrive project. 2 Django settings for khudrive project.
3 3
4 -Generated by 'django-admin startproject' using Django 3.0.6. 4 +Generated by 'django-admin startproject' using Django 3.0.7.
5 5
6 For more information on this file, see 6 For more information on this file, see
7 https://docs.djangoproject.com/en/3.0/topics/settings/ 7 https://docs.djangoproject.com/en/3.0/topics/settings/
...@@ -11,16 +11,23 @@ https://docs.djangoproject.com/en/3.0/ref/settings/ ...@@ -11,16 +11,23 @@ https://docs.djangoproject.com/en/3.0/ref/settings/
11 """ 11 """
12 12
13 import os 13 import os
14 +import sys
15 +import json
14 16
15 # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 17 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
16 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 18 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17 19
20 +ROOT_DIR = os.path.dirname(BASE_DIR)
21 +# secrets.json의 경로
22 +SECRETS_PATH = os.path.join(ROOT_DIR, 'secrets.json')
23 +# json파일을 파이썬 객체로 변환
24 +secrets = json.loads(open(SECRETS_PATH).read())
18 25
19 # Quick-start development settings - unsuitable for production 26 # Quick-start development settings - unsuitable for production
20 # See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ 27 # See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
21 28
22 # SECURITY WARNING: keep the secret key used in production secret! 29 # SECURITY WARNING: keep the secret key used in production secret!
23 -SECRET_KEY = '3b=a99pdbz*48$9$kh@h3tkb*9w-m3vtf8ngyymdzwpl5$emwn' 30 +SECRET_KEY = ')i0_(*4t7k3=rcqp*_i0u((9zbk8q(2(3tk(%$woji-e-37=o*'
24 31
25 # SECURITY WARNING: don't run with debug turned on in production! 32 # SECURITY WARNING: don't run with debug turned on in production!
26 DEBUG = True 33 DEBUG = True
...@@ -38,6 +45,7 @@ INSTALLED_APPS = [ ...@@ -38,6 +45,7 @@ INSTALLED_APPS = [
38 'django.contrib.messages', 45 'django.contrib.messages',
39 'django.contrib.staticfiles', 46 'django.contrib.staticfiles',
40 'rest_framework', 47 'rest_framework',
48 + 'api.apps.ApiConfig',
41 ] 49 ]
42 50
43 MIDDLEWARE = [ 51 MIDDLEWARE = [
...@@ -73,11 +81,18 @@ WSGI_APPLICATION = 'khudrive.wsgi.application' ...@@ -73,11 +81,18 @@ WSGI_APPLICATION = 'khudrive.wsgi.application'
73 81
74 # Database 82 # Database
75 # https://docs.djangoproject.com/en/3.0/ref/settings/#databases 83 # https://docs.djangoproject.com/en/3.0/ref/settings/#databases
76 -
77 DATABASES = { 84 DATABASES = {
85 + # 'default': {
86 + # 'ENGINE': 'django.db.backends.sqlite3',
87 + # 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
88 + # }
78 'default': { 89 'default': {
79 - 'ENGINE': 'django.db.backends.sqlite3', 90 + 'ENGINE': 'django.db.backends.postgresql',
80 - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 91 + 'NAME': 'khuDrive',
92 + 'USER': 'root',
93 + 'PASSWORD': '1234',
94 + 'HOST': 'localhost',
95 + 'PORT': '',
81 } 96 }
82 } 97 }
83 98
...@@ -119,3 +134,11 @@ USE_TZ = True ...@@ -119,3 +134,11 @@ USE_TZ = True
119 # https://docs.djangoproject.com/en/3.0/howto/static-files/ 134 # https://docs.djangoproject.com/en/3.0/howto/static-files/
120 135
121 STATIC_URL = '/static/' 136 STATIC_URL = '/static/'
137 +
138 +
139 +#S3
140 +DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
141 +STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
142 +
143 +for key, value in secrets.items():
144 + setattr(sys.modules[__name__], key, value)
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -13,9 +13,29 @@ Including another URLconf ...@@ -13,9 +13,29 @@ Including another URLconf
13 1. Import the include() function: from django.urls import include, path 13 1. Import the include() function: from django.urls import include, path
14 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 14 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
15 """ 15 """
16 +from django.urls import include, path
17 +from rest_framework import routers
16 from django.contrib import admin 18 from django.contrib import admin
17 -from django.urls import path 19 +from api import views
20 +from django.conf.urls import url
18 21
22 +router = routers.DefaultRouter()
23 +router.register(r'users', views.UserViewSet)
24 +router.register(r'items', views.ItemViewSet)
25 +router.register(r'items', views.SharedItemViewSet)
26 +
27 +# Wire up our API using automatic URL routing.
28 +# Additionally, we include login URLs for the browsable API.
19 urlpatterns = [ 29 urlpatterns = [
20 path('admin/', admin.site.urls), 30 path('admin/', admin.site.urls),
31 + path('', include(router.urls)),
32 + url(r'^search/$', views.ItemViewSet.search, name='search'),
33 + url(r'^<int:pk>/share/$', views.SharedItemViewSet.share, name='share'),
34 + url(r'^<int:pk>/move/$', views.ItemViewSet.move, name='move'),
35 + url(r'^<int:pk>/copy/$', views.ItemViewSet.copy, name='copy'),
36 + url(r'^<int:pk>/children/$', views.ItemViewSet.children, name='children'),
37 + url(r'^signup/$', views.UserViewSet.signup, name='signup'),
38 + url(r'^login/$', views.UserViewSet.login, name='login'),
39 + url(r'^upload/$', views.ItemViewSet.upload, name='upload'),
40 + url(r'^status/$', views.ItemViewSet.status, name='status'),
21 ] 41 ]
......