Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/images on s3 #33

Merged
merged 20 commits into from
Oct 9, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
frontend build update
  • Loading branch information
erik-sn committed Oct 6, 2019
commit 1abbc08cf7c7a5575055ef867d4fdcbe9991477c
Binary file added media/1365f731-46e8-48c0-8272-84f3ce5695c9.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/2241d20e-867f-4c79-b59f-803d12360d67.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/2b129a61-6b45-4321-9a00-b727c4739107.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/2d331b93-c6ff-4bb5-9753-1d5b01c5c5d8.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/30477a8f-4345-43f4-b957-a729a67978c6.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/34f9830b-9d91-4995-b64c-ab1dbbc6e2e5.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/447d5dd6-aa73-42f3-b373-bc01e5f818bf.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/531fe35d-3533-4c37-b47b-0438268e98e2.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/57fa2153-e557-42f9-96ae-7d066d2d5f6f.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/9552af20-03d6-4309-afc5-0584c3ca8add.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/9d4f7074-0d20-4cf1-aad4-1be62cd9c2e2.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/cff5be2b-1e9a-4fad-8a49-f7ae371f0659.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/ed006120-0343-46d3-86b4-2a9c13723a75.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions scigym/config/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.contrib import admin

from .models import ImageConfig


@admin.register(ImageConfig)
class ImageAdmin(admin.ModelAdmin):
pass
3 changes: 2 additions & 1 deletion scigym/config/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ def load(self):
config, created = self.get_or_create(pk=1)
return config


class ImageConfig(models.Model):
valid_image_formats = ArrayField(models.CharField(max_length=10), default=list) #this should be a initial default
valid_image_formats = ArrayField(models.CharField(max_length=10), default=list) #this should be a initial default

objects = ConfigManager()

Expand Down
1 change: 1 addition & 0 deletions scigym/images/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from .models import Image


@admin.register(Image)
class ImageAdmin(admin.ModelAdmin):
date_hierarchy = 'created'
Expand Down
1 change: 1 addition & 0 deletions scigym/images/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from scigym.config.models import Base
from scigym.users.models import User


class Image(Base):
name = models.CharField(max_length=255)
file_path = models.TextField()
Expand Down
6 changes: 3 additions & 3 deletions scigym/images/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def save_image(uploaded_file: InMemoryUploadedFile, user) -> Image:

# check file extension
_, file_extension = os.path.splitext(file_name)
if not file_extension in valid_file_types:
raise TypeError #django error
if file_extension.lower() not in valid_file_types:
raise TypeError('Invalid image format. Valid image formats: {}'.format(valid_file_types_str))

uuid_name = f'{uuid.uuid4()}{file_extension}'
with storage.open(uuid_name, 'wb+') as destination:
Expand All @@ -47,7 +47,7 @@ def save_image(uploaded_file: InMemoryUploadedFile, user) -> Image:
# save image object
return Image.objects.create(
name=file_name,
file_path='',
file_path=storage.url(uuid_name),
owner=user,
)

Expand Down
12 changes: 4 additions & 8 deletions scigym/images/views.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
import logging
import os

from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework import viewsets, status
from rest_framework.permissions import AllowAny, IsAuthenticated
from rest_framework import mixins
from rest_framework.permissions import IsAuthenticated
from rest_framework.parsers import MultiPartParser
from rest_framework.decorators import action
from django import forms
from django.views.generic import View
from django.http import HttpResponse

from .permissions import IsOwnerOrReadOnly
from scigym.images.utils import save_image, delete_image
from scigym.images.utils import save_image
from scigym.images.models import Image
from scigym.images.serializers import ImageSerializer

logger = logging.getLogger('django')


class UploadImageForm(forms.Form):
file = forms.ImageField()


class ImageViewSet(viewsets.ModelViewSet):
"""
View to create images and save them to the filesystem
Expand Down Expand Up @@ -49,4 +46,3 @@ def create(self, request, *args, **kwargs):
return Response(serializer.data, status=201)

return Response(form.errors, status=400)

15 changes: 15 additions & 0 deletions static/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"main.css": "/static/css/main.2f8c4497.chunk.css",
"main.js": "/static/js/main.1da86a5f.chunk.js",
"main.js.map": "/static/js/main.1da86a5f.chunk.js.map",
"runtime~main.js": "/static/js/runtime~main.a8a9905a.js",
"runtime~main.js.map": "/static/js/runtime~main.a8a9905a.js.map",
"static/js/2.38c32710.chunk.js": "/static/js/2.38c32710.chunk.js",
"static/js/2.38c32710.chunk.js.map": "/static/js/2.38c32710.chunk.js.map",
"index.html": "/index.html",
"precache-manifest.6cbd73545782b12216d43983c781b62a.js": "/precache-manifest.6cbd73545782b12216d43983c781b62a.js",
"service-worker.js": "/service-worker.js",
"static/css/main.2f8c4497.chunk.css.map": "/static/css/main.2f8c4497.chunk.css.map",
"static/media/contribute.md": "/static/media/contribute.9b42cb7f.md",
"static/media/play.md": "/static/media/play.a860c2a7.md"
}
2 changes: 2 additions & 0 deletions static/css/main.2f8c4497.chunk.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions static/css/main.2f8c4497.chunk.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added static/favicon.ico
Binary file not shown.
Binary file added static/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion static/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="shortcut icon" href="https://scigym.s3.eu-central-1.amazonaws.com/client/images/favicon.png"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/><meta name="theme-color" content="#000000"/><link rel="manifest" href="/manifest.json"/><title>SciGym</title><link href="https://scigym.s3.eu-central-1.amazonaws.com/client/css/main.2f8c4497.chunk.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(l){function e(e){for(var r,t,n=e[0],o=e[1],u=e[2],f=0,i=[];f<n.length;f++)t=n[f],p[t]&&i.push(p[t][0]),p[t]=0;for(r in o)Object.prototype.hasOwnProperty.call(o,r)&&(l[r]=o[r]);for(s&&s(e);i.length;)i.shift()();return c.push.apply(c,u||[]),a()}function a(){for(var e,r=0;r<c.length;r++){for(var t=c[r],n=!0,o=1;o<t.length;o++){var u=t[o];0!==p[u]&&(n=!1)}n&&(c.splice(r--,1),e=f(f.s=t[0]))}return e}var t={},p={1:0},c=[];function f(e){if(t[e])return t[e].exports;var r=t[e]={i:e,l:!1,exports:{}};return l[e].call(r.exports,r,r.exports,f),r.l=!0,r.exports}f.m=l,f.c=t,f.d=function(e,r,t){f.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},f.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.t=function(r,e){if(1&e&&(r=f(r)),8&e)return r;if(4&e&&"object"==typeof r&&r&&r.__esModule)return r;var t=Object.create(null);if(f.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:r}),2&e&&"string"!=typeof r)for(var n in r)f.d(t,n,function(e){return r[e]}.bind(null,n));return t},f.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return f.d(r,"a",r),r},f.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},f.p="/";var r=window.webpackJsonp=window.webpackJsonp||[],n=r.push.bind(r);r.push=e,r=r.slice();for(var o=0;o<r.length;o++)e(r[o]);var s=n;a()}([])</script><script src="https://scigym.s3.eu-central-1.amazonaws.com/client/js/2.38c32710.chunk.js"></script><script src="https://scigym.s3.eu-central-1.amazonaws.com/client/js/main.414224f1.chunk.js"></script></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="shortcut icon" href="https://scigym.s3.eu-central-1.amazonaws.com/images/favicon.png"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/><meta name="theme-color" content="#000000"/><link rel="manifest" href="/manifest.json"/><title>SciGym</title><link href="https://scigym.s3.eu-central-1.amazonaws.com/css/main.2f8c4497.chunk.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(l){function e(e){for(var r,t,n=e[0],o=e[1],u=e[2],f=0,i=[];f<n.length;f++)t=n[f],p[t]&&i.push(p[t][0]),p[t]=0;for(r in o)Object.prototype.hasOwnProperty.call(o,r)&&(l[r]=o[r]);for(s&&s(e);i.length;)i.shift()();return c.push.apply(c,u||[]),a()}function a(){for(var e,r=0;r<c.length;r++){for(var t=c[r],n=!0,o=1;o<t.length;o++){var u=t[o];0!==p[u]&&(n=!1)}n&&(c.splice(r--,1),e=f(f.s=t[0]))}return e}var t={},p={1:0},c=[];function f(e){if(t[e])return t[e].exports;var r=t[e]={i:e,l:!1,exports:{}};return l[e].call(r.exports,r,r.exports,f),r.l=!0,r.exports}f.m=l,f.c=t,f.d=function(e,r,t){f.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},f.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.t=function(r,e){if(1&e&&(r=f(r)),8&e)return r;if(4&e&&"object"==typeof r&&r&&r.__esModule)return r;var t=Object.create(null);if(f.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:r}),2&e&&"string"!=typeof r)for(var n in r)f.d(t,n,function(e){return r[e]}.bind(null,n));return t},f.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return f.d(r,"a",r),r},f.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},f.p="/";var r=window.webpackJsonp=window.webpackJsonp||[],n=r.push.bind(r);r.push=e,r=r.slice();for(var o=0;o<r.length;o++)e(r[o]);var s=n;a()}([])</script><script src="https://scigym.s3.eu-central-1.amazonaws.com/js/2.38c32710.chunk.js"></script><script src="https://scigym.s3.eu-central-1.amazonaws.com/js/main.1da86a5f.chunk.js"></script></body></html>
2 changes: 2 additions & 0 deletions static/js/2.38c32710.chunk.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions static/js/2.38c32710.chunk.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions static/js/main.1da86a5f.chunk.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions static/js/main.1da86a5f.chunk.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions static/js/runtime~main.a8a9905a.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions static/js/runtime~main.a8a9905a.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions static/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "/static/images/favicon.png",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/png"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
Loading