commit f8fdb07ad941834132401150b4dc7d6666142d61 Author: Piotr Dobrowolski Date: Thu Sep 29 22:20:10 2016 +0200 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9dfa28c --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.py[co] +db.sqlite3 +*.swp diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4a70a5e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.5 +ENV PYTHONUNBUFFERED 1 +RUN mkdir /code +WORKDIR /code +ADD requirements.txt /code/ +RUN pip install -r requirements.txt +ADD . /code/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..ea919f1 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +spejstore +========= + +Because there is not enough general inventory software invented here yet. +Please use Python3, for the love of `$deity`... diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..7fde322 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,14 @@ +version: '2' +services: + db: + image: aidanlister/postgres-hstore + + web: + build: . + command: /bin/bash -c "python manage.py migrate && python manage.py runserver 0.0.0.0:8000" + volumes: + - .:/code + ports: + - "8000:8000" + depends_on: + - db diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..1bb9343 --- /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", "spejstore.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..74b2b4a --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +Django==1.10.1 +git+https://github.com/djangonauts/django-hstore@61427e474cb2f4be8fdfce225d78a5330bc77eb0#egg=django-hstore +Pillow==3.3.1 +psycopg2==2.6.2 diff --git a/spejstore/__init__.py b/spejstore/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/spejstore/settings.py b/spejstore/settings.py new file mode 100644 index 0000000..a14206d --- /dev/null +++ b/spejstore/settings.py @@ -0,0 +1,127 @@ +""" +Django settings for spejstore project. + +Generated by 'django-admin startproject' using Django 1.10.1. + +For more information on this file, see +https://docs.djangoproject.com/en/1.10/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.10/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.10/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '#hjthi7_udsyt*9eeyb&nwgw5x=%pk_lnz3+u2tg9@=w3p1m*k' + +# 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', + + 'django_hstore', + + 'storage', +] + +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 = 'spejstore.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + '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', + ], + }, + }, +] + +WSGI_APPLICATION = 'spejstore.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.10/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': 'postgres', + 'USER': 'postgres', + 'HOST': 'db', + 'PORT': 5432, + } +} + + +# Password validation +# https://docs.djangoproject.com/en/1.10/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.10/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.10/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/spejstore/urls.py b/spejstore/urls.py new file mode 100644 index 0000000..c3e00af --- /dev/null +++ b/spejstore/urls.py @@ -0,0 +1,21 @@ +"""spejstore URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/1.10/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.urls import url +from django.contrib import admin + +urlpatterns = [ + url(r'^admin/', admin.site.urls), +] diff --git a/spejstore/wsgi.py b/spejstore/wsgi.py new file mode 100644 index 0000000..e520260 --- /dev/null +++ b/spejstore/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for spejstore 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.10/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "spejstore.settings") + +application = get_wsgi_application() diff --git a/storage/__init__.py b/storage/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/storage/admin.py b/storage/admin.py new file mode 100644 index 0000000..6d16a18 --- /dev/null +++ b/storage/admin.py @@ -0,0 +1,24 @@ +from django import forms +from django.contrib import admin +from .models import Item, ItemImage, Category + +class ItemForm(forms.ModelForm): + name = forms.CharField(widget=forms.TextInput()) + + class Meta: + model = Item + exclude = [] + +class ItemImageInline(admin.TabularInline): + model = ItemImage + extra = 1 + +class ItemAdmin(admin.ModelAdmin): + list_display = ('name', 'uuid', 'props') + list_filter = ('categories',) + form = ItemForm + inlines = [ItemImageInline] + + +admin.site.register(Item, ItemAdmin) +admin.site.register(Category) diff --git a/storage/apps.py b/storage/apps.py new file mode 100644 index 0000000..a9bfb2c --- /dev/null +++ b/storage/apps.py @@ -0,0 +1,7 @@ +from __future__ import unicode_literals + +from django.apps import AppConfig + + +class StorageConfig(AppConfig): + name = 'storage' diff --git a/storage/migrations/0001_initial.py b/storage/migrations/0001_initial.py new file mode 100644 index 0000000..5dcdccb --- /dev/null +++ b/storage/migrations/0001_initial.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.1 on 2016-09-29 20:18 +from __future__ import unicode_literals + +from django.db import migrations, models +import django_hstore.fields + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Item', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.TextField()), + ('description', models.TextField()), + ('props', django_hstore.fields.DictionaryField()), + ], + ), + ] diff --git a/storage/migrations/0001_squashed_0008_item_state.py b/storage/migrations/0001_squashed_0008_item_state.py new file mode 100644 index 0000000..be99617 --- /dev/null +++ b/storage/migrations/0001_squashed_0008_item_state.py @@ -0,0 +1,82 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.1 on 2016-09-29 22:03 +from __future__ import unicode_literals + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion +import django_hstore.fields +import uuid + + +class Migration(migrations.Migration): + + replaces = [('storage', '0001_initial'), ('storage', '0002_auto_20160929_2125'), ('storage', '0003_auto_20160929_2134'), ('storage', '0004_auto_20160929_2143'), ('storage', '0005_auto_20160929_2151'), ('storage', '0006_auto_20160929_2153'), ('storage', '0007_auto_20160929_2153'), ('storage', '0008_item_state')] + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='Item', + fields=[ + ('name', models.TextField()), + ('description', models.TextField(blank=True)), + ('props', django_hstore.fields.DictionaryField()), + ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), + ], + ), + migrations.CreateModel( + name='ItemImage', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('image', models.ImageField(upload_to='')), + ('item', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='images', to='storage.Item')), + ], + ), + migrations.CreateModel( + name='Category', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=127)), + ], + ), + migrations.AddField( + model_name='item', + name='categories', + field=models.ManyToManyField(to='storage.Category'), + ), + migrations.AddField( + model_name='item', + name='owner', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='owned_items', to=settings.AUTH_USER_MODEL), + ), + migrations.AddField( + model_name='item', + name='taken_by', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='taken_items', to=settings.AUTH_USER_MODEL), + ), + migrations.AddField( + model_name='item', + name='taken_on', + field=models.DateTimeField(blank=True, null=True), + ), + migrations.AddField( + model_name='item', + name='taken_until', + field=models.DateTimeField(blank=True, null=True), + ), + migrations.AlterField( + model_name='item', + name='description', + field=models.TextField(blank=True, null=True), + ), + migrations.AddField( + model_name='item', + name='state', + field=models.CharField(choices=[('present', 'Present'), ('taken', 'Taken'), ('broken', 'Broken'), ('missing', 'Missing')], default='present', max_length=31), + ), + ] diff --git a/storage/migrations/__init__.py b/storage/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/storage/models.py b/storage/models.py new file mode 100644 index 0000000..d4f5b10 --- /dev/null +++ b/storage/models.py @@ -0,0 +1,46 @@ +from __future__ import unicode_literals + +from django.db import models +from django.contrib.auth.models import User +from django_hstore import hstore +import uuid + +STATES = ( + ('present', 'Present'), + ('taken', 'Taken'), + ('broken', 'Broken'), + ('missing', 'Missing'), +) + + +# Create your models here. +class Category(models.Model): + name = models.CharField(max_length=127) + + def __str__(self): + return self.name + + +class Item(models.Model): + uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) + name = models.TextField() + description = models.TextField(blank=True, null=True) + state = models.CharField(max_length=31, choices=STATES, default=STATES[0][0]) + categories = models.ManyToManyField(Category) + owner = models.ForeignKey(User, null=True, blank=True, related_name='owned_items') + + taken_by = models.ForeignKey(User, null=True, blank=True, related_name='taken_items') + taken_on = models.DateTimeField(blank=True, null=True) + taken_until = models.DateTimeField(blank=True, null=True) + + props = hstore.DictionaryField() + + objects = hstore.HStoreManager() + + def __str__(self): + return self.name + + +class ItemImage(models.Model): + item = models.ForeignKey(Item, related_name='images') + image = models.ImageField() diff --git a/storage/tests.py b/storage/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/storage/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/storage/views.py b/storage/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/storage/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here.