Toggle navigation
Toggle navigation
This project
Loading...
Sign in
신은섭(Shin Eun Seop)
/
2018-1-d.cloud
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
10
Merge Requests
0
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
신은섭(Shin Eun Seop)
2018-05-24 17:33:36 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
8131b6afdb92ba1091654663c1c51de31853ce20
8131b6af
1 parent
2aea18fe
add s3direct
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
83 additions
and
18 deletions
.gitignore
dcloud/dcloud/settings.py
dcloud/dcloud/urls.py
dcloud/website/forms.py
dcloud/website/models.py
dcloud/website/templates/website/s3direct.html
dcloud/website/urls.py
dcloud/website/views.py
.gitignore
View file @
8131b6a
...
...
@@ -105,3 +105,6 @@ ENV/
# mypy
.mypy_cache/
# aws configutation file
aws_conf.py
...
...
dcloud/dcloud/settings.py
View file @
8131b6a
"""
Django settings for dcloud project.
Generated by 'django-admin startproject' using Django 2.0.4.
For more information on this file, see
https://docs.djangoproject.com/en/2.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.0/ref/settings/
"""
import
os
import
aws_conf
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)))
...
...
@@ -39,7 +28,8 @@ INSTALLED_APPS = [
'django.contrib.staticfiles'
,
'rest_framework'
,
'restful.apps.RestfulConfig'
,
'website'
'website'
,
's3direct'
,
]
MIDDLEWARE
=
[
...
...
@@ -126,3 +116,53 @@ STATIC_URL = '/static/'
# Login redirect
LOGIN_REDIRECT_URL
=
'/'
# AWS
# If these are not defined, the EC2 instance profile and IAM role are used.
# This requires you to add boto3 (or botocore, which is a dependency of boto3)
# to your project dependencies.
AWS_ACCESS_KEY_ID
=
aws_conf
.
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
=
aws_conf
.
AWS_SECRET_ACCESS_KEY
AWS_STORAGE_BUCKET_NAME
=
aws_conf
.
AWS_STORAGE_BUCKET_NAME
# The region of your bucket, more info:
# http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
S3DIRECT_REGION
=
'ap-northeast-2'
# Destinations, with the following keys:
#
# key [required] Where to upload the file to, can be either:
# 1. '/' = Upload to root with the original filename.
# 2. 'some/path' = Upload to some/path with the original filename.
# 3. functionName = Pass a function and create your own path/filename.
# key_args [optional] Arguments to be passed to 'key' if it's a function.
# auth [optional] An ACL function to whether the current Django user can perform this action.
# allowed [optional] List of allowed MIME types.
# acl [optional] Give the object another ACL rather than 'public-read'.
# cache_control [optional] Cache control headers, eg 'max-age=2592000'.
# content_disposition [optional] Useful for sending files as attachments.
# bucket [optional] Specify a different bucket for this particular object.
# server_side_encryption [optional] Encryption headers for buckets that require it.
S3DIRECT_DESTINATIONS
=
{
'example_destination'
:
{
# REQUIRED
'key'
:
'/'
,
# OPTIONAL
#'auth': lambda u: u.is_staff, # Default allow anybody to upload
#'allowed': ['image/jpeg', 'image/png', 'video/mp4'], # Default allow all mime types
#'bucket': 'pdf-bucket', # Default is 'AWS_STORAGE_BUCKET_NAME'
'acl'
:
'private'
,
# Defaults to 'public-read'
'cache_control'
:
'max-age=2592000'
,
# Default no cache-control
#'content_disposition': 'attachment', # Default no content disposition
#'content_length_range': (5000, 20000000), # Default allow any size
#'server_side_encryption': 'AES256', # Default no encryption
},
'example_other'
:
{
'key'
:
lambda
filename
,
args
:
args
+
'/'
+
filename
,
'key_args'
:
'uploads/images'
,
# Only if 'key' is a function
}
}
\ No newline at end of file
...
...
dcloud/dcloud/urls.py
View file @
8131b6a
...
...
@@ -10,5 +10,6 @@ urlpatterns = [
url
(
r'^accounts/login/$'
,
views
.
login
,
name
=
'login'
),
url
(
r'^accounts/logout/$'
,
views
.
logout
,
name
=
'logout'
,
kwargs
=
{
'next_page'
:
'/'
}),
url
(
r'^s3direct/'
,
include
(
's3direct.urls'
)),
]
...
...
dcloud/website/forms.py
View file @
8131b6a
from
django
import
forms
from
s3direct.widgets
import
S3DirectWidget
# class PostForm(forms.ModelForm):
# class Meta:
# model = Post
# fields = ('title', 'text')
\ No newline at end of file
class
S3DirectUploadForm
(
forms
.
Form
):
images
=
forms
.
URLField
(
widget
=
S3DirectWidget
(
dest
=
'example_destination'
))
...
...
dcloud/website/models.py
View file @
8131b6a
from
django.db
import
models
from
django.utils
import
timezone
from
s3direct.fields
import
S3DirectField
class
Example
(
models
.
Model
):
video
=
S3DirectField
(
dest
=
'example_destination'
)
\ No newline at end of file
...
...
dcloud/website/templates/website/s3direct.html
0 → 100644
View file @
8131b6a
<html>
<head>
<meta
charset=
"utf-8"
>
<title>
s3direct
</title>
{{ form.media }}
</head>
<body>
<form
action=
""
method=
"post"
>
{% csrf_token %}
{{ form.as_p }}
</form>
</body>
</html>
\ No newline at end of file
dcloud/website/urls.py
View file @
8131b6a
...
...
@@ -11,4 +11,5 @@ urlpatterns = [
# blog
url
(
r'^$'
,
views
.
home
),
url
(
r'^files/'
,
views
.
file_list
,
name
=
'file_list'
),
url
(
r'^upload/'
,
views
.
upload
.
as_view
(),
name
=
'upload'
)
]
\ No newline at end of file
...
...
dcloud/website/views.py
View file @
8131b6a
from
django.shortcuts
import
render
,
get_object_or_404
,
redirect
,
Http404
from
django.utils
import
timezone
from
django.contrib.auth.decorators
import
login_required
from
django.views.generic
import
FormView
from
website.forms
import
S3DirectUploadForm
from
restful.models
import
File
import
requests
...
...
@@ -14,3 +16,8 @@ def file_list(request):
files
=
requests
.
get
(
'http://localhost:8000/restapi/files'
)
files
=
files
.
json
()
return
render
(
request
,
'website/file_list.html'
,
files
)
class
upload
(
FormView
):
template_name
=
'website/s3direct.html'
form_class
=
S3DirectUploadForm
\ No newline at end of file
...
...
Please
register
or
login
to post a comment