Skip to content

Commit

Permalink
Upload papers to s3
Browse files Browse the repository at this point in the history
  • Loading branch information
valmack authored and v-stickykeys committed Oct 3, 2019
1 parent 59b9f7c commit 0029425
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
19 changes: 19 additions & 0 deletions src/paper/migrations/0005_paper_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 2.2.6 on 2019-10-03 19:48

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('paper', '0004_auto_20191002_1744'),
]

operations = [
migrations.AddField(
model_name='paper',
name='file',
field=models.FileField(default='paper.pdf', upload_to='papers/%Y/%m/%d'),
preserve_default=False,
),
]
3 changes: 1 addition & 2 deletions src/paper/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ class Paper(models.Model):
related_name='papers',
on_delete='SET NULL'
)
# TODO: Determine file upload path
# file = models.FileField(upload_to='uploads/papers/%Y/%m/%d')
file = models.FileField(upload_to='uploads/papers/%Y/%m/%d')

def __str__(self):
authors = list(self.authors.all())
Expand Down
5 changes: 4 additions & 1 deletion src/paper/tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.test import TestCase
from django.core.files.uploadedfile import SimpleUploadedFile

from utils.test_helpers import IntegrationTestHelper, TestHelper

Expand All @@ -22,9 +23,11 @@ def submit_paper_form(self):

def build_default_paper_form(self):
title = self.paper_title
file = SimpleUploadedFile('../config/paper.pdf', b'file_content')
form = {
'title': title,
'paper_publish_date': self.paper_publish_date
'paper_publish_date': self.paper_publish_date,
'file': file,
}
return form

Expand Down
27 changes: 24 additions & 3 deletions src/researchhub/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
'localhost',
]

# Cors

CORS_ORIGIN_WHITELIST = [
"http://localhost:3000",
]

# Application definition

Expand Down Expand Up @@ -60,6 +65,9 @@
'rest_auth',
'rest_auth.registration',

# Storage
'storages',

# Custom apps
'discussion',
'hub',
Expand Down Expand Up @@ -209,6 +217,19 @@

STATIC_URL = '/static/'

CORS_ORIGIN_WHITELIST = [
"http://localhost:3000",
]
# Storage

DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
AWS_STORAGE_BUCKET_NAME = 'researchhub-paper-dev'
AWS_S3_REGION_NAME = 'us-west-2'
AWS_ACCESS_KEY_ID = os.environ.get(
'AWS_ACCESS_KEY_ID',
keys.AWS_ACCESS_KEY_ID
)
AWS_SECRET_ACCESS_KEY = os.environ.get(
'AWS_SECRET_ACCESS_KEY',
keys.AWS_SECRET_ACCESS_KEY
)

AWS_S3_FILE_OVERWRITE = False
AWS_DEFAULT_ACL = None

0 comments on commit 0029425

Please sign in to comment.