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-09 16:33:01 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
b6bfe00a0e6c9c09514b8f6102ea3e4cec85dd36
b6bfe00a
1 parent
d049fd1a
add file object_key upload
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
30 additions
and
34 deletions
dcloud/rest_mig.sh
dcloud/restful/models.py
dcloud/restful/serializers.py
dcloud/restful/tests.py
dcloud/restful/urls.py
dcloud/rest_mig.sh
0 → 100755
View file @
b6bfe00
#!/bin/bash
rm -f db.sqlite3
rm -r restful/migrations
python manage.py makemigrations restful
python manage.py migrate
dcloud/restful/models.py
View file @
b6bfe00
...
...
@@ -4,13 +4,11 @@ from django.db import models
# Create your models here.
class
File
(
models
.
Model
):
created
=
models
.
DateTimeField
(
auto_now_add
=
True
)
modified
=
models
.
DateTimeField
(
auto_now
=
True
)
title
=
models
.
CharField
(
max_length
=
100
)
updated
=
models
.
DateTimeField
(
auto_now
=
True
)
object_key
=
models
.
CharField
(
max_length
=
1025
)
size
=
models
.
IntegerField
()
# owner = models.ForeignKey('auth.User', related_name='snippets', on_delete=models.CASCADE)
class
Meta
:
ordering
=
(
'
title
'
,)
ordering
=
(
'
pk
'
,)
...
...
dcloud/restful/serializers.py
View file @
b6bfe00
...
...
@@ -3,30 +3,8 @@ from rest_framework import serializers
from
restful.models
import
File
class
FileSerializer
(
serializers
.
Serializer
):
pk
=
serializers
.
IntegerField
(
read_only
=
True
)
created
=
serializers
.
DateTimeField
(
read_only
=
True
)
modified
=
serializers
.
DateTimeField
(
read_only
=
True
)
title
=
serializers
.
CharField
(
max_length
=
100
)
object_key
=
serializers
.
CharField
(
max_length
=
1025
)
size
=
serializers
.
IntegerField
()
class
FileSerializer
(
serializers
.
ModelSerializer
):
def
create
(
self
,
validated_data
):
"""
Create and Return new `File` instance. Using validated_data.
"""
return
File
.
objects
.
create
(
**
validated_data
)
def
update
(
self
,
instance
,
validated_data
):
"""
Update and Return existing `File` instance. Using validated_data.
"""
instance
.
title
=
validated_data
.
get
(
'title'
,
instance
.
title
)
instance
.
object_key
=
validated_data
.
get
(
'object_key'
,
instance
.
object_key
)
instance
.
size
=
validated_data
.
get
(
'size'
,
instance
.
size
)
instance
.
language
=
validated_data
.
get
(
'language'
,
instance
.
language
)
instance
.
style
=
validated_data
.
get
(
'style'
,
instance
.
style
)
instance
.
save
()
return
instance
class
Meta
:
model
=
File
fields
=
(
'created'
,
'updated'
,
'object_key'
)
...
...
dcloud/restful/tests.py
View file @
b6bfe00
from
django.test
import
TestCase
from
rest_framework.test
import
APITestCase
from
django.urls
import
reverse
from
rest_framework
import
status
class
UploadFileTestCase
(
APITestCase
):
def
setup
(
self
):
self
.
tearDown
()
def
tearDown
(
self
):
pass
def
test_upload
(
self
):
url
=
reverse
(
'file-list'
)
data
=
{
'object_key'
:
'test_object_key'
}
response
=
self
.
client
.
post
(
url
,
data
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_201_CREATED
)
# Create your tests here.
...
...
dcloud/restful/urls.py
View file @
b6bfe00
...
...
@@ -3,8 +3,8 @@ from rest_framework.urlpatterns import format_suffix_patterns
from
restful
import
views
urlpatterns
=
[
url
(
r'^files/$'
,
views
.
FileList
.
as_view
()),
url
(
r'^files/(?P<pk>[0-9]+)/$'
,
views
.
FileDetail
.
as_view
()),
url
(
r'^files/$'
,
views
.
FileList
.
as_view
()
,
name
=
'file-list'
),
url
(
r'^files/(?P<pk>[0-9]+)/$'
,
views
.
FileDetail
.
as_view
()
,
name
=
'file-detail'
),
]
urlpatterns
=
format_suffix_patterns
(
urlpatterns
)
\ No newline at end of file
...
...
Please
register
or
login
to post a comment