diff --git a/example/example/__init__.py b/example/example/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/example/example/forms.py b/example/example/forms.py new file mode 100644 index 0000000000000000000000000000000000000000..db42c2ad9d523317e337803ed50aaa59c8c0a01a --- /dev/null +++ b/example/example/forms.py @@ -0,0 +1,8 @@ +from django import forms +from django_starfield import Stars + +class RatingForm(forms.Form): + rating_1 = forms.IntegerField(label='Default rating', widget=Stars) + rating_2 = forms.IntegerField(label='Big rating', widget=Stars(stars=17)) + rating_3 = forms.IntegerField(label='Pink rating', widget=Stars(colour='#ff1493')) + rating_4 = forms.IntegerField(label='Dolphin rating', widget=Stars(codepoint='1f42c')) diff --git a/example/example/settings.py b/example/example/settings.py new file mode 100644 index 0000000000000000000000000000000000000000..0cc5dd11cf9c4930268b2376dc038aaddf549c67 --- /dev/null +++ b/example/example/settings.py @@ -0,0 +1,80 @@ +""" +Django settings for example project. + +Generated by 'django-admin startproject' using Django 2.0.7. + +For more information on this file, see +https://docs.djangoproject.com/en/2.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.0/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/2.0/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'kn+=4+#i($pch$5tgq2-teo&w14zrwlgb0#t=kcb@w*v7^h0ll' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.contenttypes', + 'django.contrib.staticfiles', + 'django_starfield', + 'example' +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'example.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', + ], + }, + }, +] + +WSGI_APPLICATION = 'example.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/2.0/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/example/example/templates/form.html b/example/example/templates/form.html new file mode 100644 index 0000000000000000000000000000000000000000..1ce77ad0296556bda5e3abc5d33af535e19940a3 --- /dev/null +++ b/example/example/templates/form.html @@ -0,0 +1,17 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>django_starfield example</title> + </head> + <body> + <form method="post"> + {% csrf_token %} + <table> + {{ rating_form.as_table }} + </table> + <input type="submit" value="Submit" /> + </form> + </body> +</html> diff --git a/example/example/urls.py b/example/example/urls.py new file mode 100644 index 0000000000000000000000000000000000000000..63a55bc63f5685bec774f817a05c610fc332e452 --- /dev/null +++ b/example/example/urls.py @@ -0,0 +1,6 @@ +from django.conf.urls import url +from . import views + +urlpatterns = [ + url(r'^$', views.form) +] diff --git a/example/example/views.py b/example/example/views.py new file mode 100644 index 0000000000000000000000000000000000000000..a6b5a86e4e48b4d792af142391610bae904a0525 --- /dev/null +++ b/example/example/views.py @@ -0,0 +1,11 @@ +from django.shortcuts import render + +from .forms import RatingForm + +def form(request): + if request.method == 'POST': + rating_form = RatingForm(request.POST) + else: + rating_form = RatingForm() + + return render(request, 'form.html', {'rating_form': rating_form}) diff --git a/example/example/wsgi.py b/example/example/wsgi.py new file mode 100644 index 0000000000000000000000000000000000000000..80b085ce4c3b1e4c6df63cc5a72b85c78e2368ac --- /dev/null +++ b/example/example/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for example 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/2.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings") + +application = get_wsgi_application() diff --git a/example/manage.py b/example/manage.py new file mode 100755 index 0000000000000000000000000000000000000000..6bfa2c471a29fbf79aef15fef145b1f1a82cce46 --- /dev/null +++ b/example/manage.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings") + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + 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?" + ) from exc + execute_from_command_line(sys.argv)