commit 351863b382d5bbcda0fe4f84f8c76a9a694c3275 Author: clemens Date: Thu Nov 30 12:37:58 2017 +0100 init diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..ecca6cc --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,12 @@ +version: "2" + +services: + db: + image: postgres:10-alpine + volumes: + - ./pgdata/:/var/lib/postgresql/data/ + environment: + - POSTGRES_PASSWORD=secret + - POSTGRES_USER=imageHost + ports: + - "127.0.0.1:5432:5432" \ No newline at end of file diff --git a/imageHost/__init__.py b/imageHost/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/imageHost/settings.py b/imageHost/settings.py new file mode 100644 index 0000000..a2acaac --- /dev/null +++ b/imageHost/settings.py @@ -0,0 +1,136 @@ +""" +Django settings for imageHost project. + +Generated by 'django-admin startproject' using Django 1.11.7. + +For more information on this file, see +https://docs.djangoproject.com/en/1.11/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.11/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'ox%di3+hzr@#p_!=l68m3ms(_en)ixd38m8u=p2*(p-*slume-' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'images.apps.ImagesConfig', + 'rest_framework' +] + +REST_FRAMEWORK = { + 'DEFAULT_PERMISSION_CLASSES':[ + 'rest_framework.permissions.IsAdminUser', + ] +} + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'imageHost.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [os.path.join(BASE_DIR, 'templates')] + , + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + 'django.template.context_processors.media', + ], + }, + }, +] + +WSGI_APPLICATION = 'imageHost.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.11/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': 'imageHost', + 'USER': 'imageHost', + 'PASSWORD': 'secret', + 'HOST': '127.0.0.1', + 'PORT': '5432', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + """{ + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + },""" +] + + +# Internationalization +# https://docs.djangoproject.com/en/1.11/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/1.11/howto/static-files/ +STATIC_ROOT = os.path.join(BASE_DIR, 'static/') +STATIC_URL = '/static/' +MEDIA_ROOT = "media/" +MEDIA_URL = "media/" \ No newline at end of file diff --git a/imageHost/urls.py b/imageHost/urls.py new file mode 100644 index 0000000..95d6ae4 --- /dev/null +++ b/imageHost/urls.py @@ -0,0 +1,36 @@ +"""imageHost URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/1.11/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.conf.urls import url, include + 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) +""" +from django.conf import settings +from django.conf.urls import url, include +from django.conf.urls.static import static +from django.contrib import admin + +from images.views import index,upload, ImageViewSet + +from rest_framework import routers + +router = routers.DefaultRouter() +router.register(r'images', ImageViewSet) + +urlpatterns = [ + url(r'^admin/', admin.site.urls), + url(r'^upload$', upload), + url(r'^$', index), + #url(r'^api', router.urls), + url(r'^api-auth/', include('rest_framework.urls', namespace="rest_framework")) +] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + +print(urlpatterns) \ No newline at end of file diff --git a/imageHost/wsgi.py b/imageHost/wsgi.py new file mode 100644 index 0000000..26dcf91 --- /dev/null +++ b/imageHost/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for imageHost project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "imageHost.settings") + +application = get_wsgi_application() diff --git a/images/__init__.py b/images/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/images/admin.py b/images/admin.py new file mode 100644 index 0000000..cba9e96 --- /dev/null +++ b/images/admin.py @@ -0,0 +1,5 @@ +from django.contrib import admin + +from .models import Image + +admin.site.register(Image) \ No newline at end of file diff --git a/images/apps.py b/images/apps.py new file mode 100644 index 0000000..a873d1a --- /dev/null +++ b/images/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class ImagesConfig(AppConfig): + name = 'images' diff --git a/images/forms.py b/images/forms.py new file mode 100644 index 0000000..940f81e --- /dev/null +++ b/images/forms.py @@ -0,0 +1,8 @@ +from django import forms +from .models import Image + + +class UploadImageForm(forms.ModelForm): + class Meta: + model = Image + fields = ['image', 'name'] diff --git a/images/migrations/0001_initial.py b/images/migrations/0001_initial.py new file mode 100644 index 0000000..fa5df19 --- /dev/null +++ b/images/migrations/0001_initial.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.7 on 2017-11-30 10:17 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Image', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('image', models.FileField(blank=True, null=True, upload_to='sketches/')), + ('name', models.CharField(max_length=256)), + ], + ), + ] diff --git a/images/migrations/0002_auto_20171130_1102.py b/images/migrations/0002_auto_20171130_1102.py new file mode 100644 index 0000000..50e6903 --- /dev/null +++ b/images/migrations/0002_auto_20171130_1102.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.7 on 2017-11-30 11:02 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('images', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='image', + name='image', + field=models.ImageField(blank=True, null=True, upload_to='sketches/'), + ), + ] diff --git a/images/migrations/__init__.py b/images/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/images/models.py b/images/models.py new file mode 100644 index 0000000..7f0a1db --- /dev/null +++ b/images/models.py @@ -0,0 +1,6 @@ +from django.db import models + + +class Image(models.Model): + image = models.ImageField(upload_to="image_uploads/", blank=True, null=True) + name = models.CharField(max_length=256) diff --git a/images/serializers.py b/images/serializers.py new file mode 100644 index 0000000..cd390fa --- /dev/null +++ b/images/serializers.py @@ -0,0 +1,8 @@ +from .models import Image +from rest_framework import serializers + + +class ImageSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = Image + fields = ('image', 'name') diff --git a/images/templates/images/index.html b/images/templates/images/index.html new file mode 100644 index 0000000..4b4253c --- /dev/null +++ b/images/templates/images/index.html @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/images/templates/images/upload.html b/images/templates/images/upload.html new file mode 100644 index 0000000..31c4c6d --- /dev/null +++ b/images/templates/images/upload.html @@ -0,0 +1,5 @@ +
+ {% csrf_token %} + {{ form }} + +
\ No newline at end of file diff --git a/images/tests.py b/images/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/images/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/images/views.py b/images/views.py new file mode 100644 index 0000000..e129cf9 --- /dev/null +++ b/images/views.py @@ -0,0 +1,31 @@ +from django.http import HttpResponseRedirect +from django.shortcuts import render + +from .models import Image +from .forms import UploadImageForm + + +def index(request): + context = {'images': Image.objects.all()} + return render(request, "images/index.html", context) + + +def upload(request): + print("asdf") + if request.method == 'POST': + print("POST") + form = UploadImageForm(request.POST, request.FILES) + print(form.is_valid()) + if form.is_valid(): + form.save() + return HttpResponseRedirect('/') + else: + form = UploadImageForm() + return render(request, "images/upload.html", {"form":form}) + +from rest_framework import viewsets +from .serializers import ImageSerializer + +class ImageViewSet(viewsets.ModelViewSet): + queryset = Image.objects.all() + serializer_class = ImageSerializer \ No newline at end of file diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..7293566 --- /dev/null +++ b/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "imageHost.settings") + try: + from django.core.management import execute_from_command_line + except ImportError: + # The above import may fail for some other reason. Ensure that the + # issue is really that Django is missing to avoid masking other + # exceptions on Python 2. + try: + import django + except ImportError: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) + raise + execute_from_command_line(sys.argv) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..9a33e8b --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +django +psycopg2 +djangorestframework \ No newline at end of file