Skip to content

Commit

Permalink
Merge pull request #33 from moshthepitt/issue-15
Browse files Browse the repository at this point in the history
Add support for configurable templates
  • Loading branch information
moshthepitt authored Jan 7, 2019
2 parents 07a5e87 + 2ea7370 commit 654144f
Show file tree
Hide file tree
Showing 50 changed files with 11,376 additions and 44 deletions.
Empty file added example/artists/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions example/artists/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class ArtistsConfig(AppConfig):
name = 'artists'
55 changes: 55 additions & 0 deletions example/artists/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Generated by Django 2.1.4 on 2018-12-30 09:49

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = []

operations = [
migrations.CreateModel(
name='Artist',
fields=[
('id',
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name='ID')),
('name', models.CharField(max_length=100,
verbose_name='Name')),
],
options={
'verbose_name': 'Artist',
'verbose_name_plural': 'Artists',
'ordering': ['name'],
},
),
migrations.CreateModel(
name='Song',
fields=[
('id',
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name='ID')),
('name', models.CharField(max_length=100,
verbose_name='Name')),
('artist',
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
to='artists.Artist',
verbose_name='Artist')),
],
options={
'verbose_name': 'Song',
'verbose_name_plural': 'Songs',
'ordering': ['name'],
},
),
]
Empty file.
38 changes: 38 additions & 0 deletions example/artists/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""
Module for vega-admin test models
"""
from django.db import models
from django.utils.translation import ugettext as _


class Artist(models.Model):
"""
Artist Model class
"""
name = models.CharField(_("Name"), max_length=100)

class Meta:
ordering = ['name']
verbose_name = 'Artist'
verbose_name_plural = 'Artists'

def __str__(self):
"""Unicode representation of Song."""
return self.name


class Song(models.Model):
"""Model definition for Song."""
artist = models.ForeignKey(
Artist, verbose_name=_("Artist"), on_delete=models.PROTECT)
name = models.CharField(_("Name"), max_length=100)

class Meta:
"""Meta definition for Song."""
verbose_name = 'Song'
verbose_name_plural = 'Songs'
ordering = ['name']

def __str__(self):
"""Unicode representation of Song."""
return self.name
37 changes: 37 additions & 0 deletions example/artists/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""Artist app views module"""
from vega_admin.views import VegaCRUDView, VegaListView

from .models import Artist, Song


class ArtistCRUD(VegaCRUDView):
"""
CRUD view for artists
"""

model = Artist
protected_actions = None
permissions_actions = None


class SongCRUD(VegaCRUDView):
"""
CRUD view for songs
"""

class CustomListView(VegaListView):
"""Custom list view"""
model = Artist

model = Song
protected_actions = None
permissions_actions = None
list_fields = ["name", "artist", ]
read_fields = ["name", "artist", ]
table_attrs = {"class": "table song-table"}
table_actions = ["create", "artists", "update", "delete", ]
create_fields = ["name", "artist", ]
update_fields = ["name", ]
view_classes = {
"artists": CustomListView,
}
Empty file added example/example/__init__.py
Empty file.
126 changes: 126 additions & 0 deletions example/example/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
"""
Django settings for example project.
Generated by 'django-admin startproject' using Django 2.1.3.
For more information on this file, see
https://docs.djangoproject.com/en/2.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.1/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.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '4^lzr3=(u=(!-25j@dwzzem4*&e5!7*$9f!gpj_+_ely6x&2aq'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []

# Application definition

INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'crispy_forms',
'django_tables2',
'django_filters',
'vega_admin',
'artists',
]

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 = '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',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'example.wsgi.application'

# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}

# Password validation
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME':
'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', # noqa
},
{
'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/2.1/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/2.1/howto/static-files/

STATIC_URL = '/static/'

# vega settings
CRISPY_TEMPLATE_PACK = 'bootstrap3'
VEGA_TEMPLATE = 'badmin'
5 changes: 5 additions & 0 deletions example/example/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""example URL Configuration"""
from artists import views

urlpatterns = views.ArtistCRUD().url_patterns() +\
views.SongCRUD().url_patterns()
16 changes: 16 additions & 0 deletions example/example/wsgi.py
Original file line number Diff line number Diff line change
@@ -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.1/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()
15 changes: 15 additions & 0 deletions example/manage.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jdcal==1.4 # via openpyxl
odfpy==1.3.6 # via tablib
openpyxl==2.5.10 # via tablib
pytz==2018.7 # via django
pyyaml==3.13 # via tablib
pyyaml==4.2b4
tablib==0.12.1
unicodecsv==0.14.1 # via tablib
xlrd==1.1.0 # via tablib
Expand Down
2 changes: 1 addition & 1 deletion requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pylint-django==2.0.2
pylint-plugin-utils==0.4 # via pylint-django
pylint==2.1.1
pytz==2018.7 # via django
pyyaml==3.13 # via tablib
pyyaml==4.2b4 # via tablib
six==1.11.0 # via astroid, model-mommy, prompt-toolkit, tox, traitlets
tablib==0.12.1
toml==0.10.0 # via black, tox
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
'django-filter',
'django-tables2',
'tablib',
'pyyaml>=4.2b1', # fixes security vulnerability
],
classifiers=[
'Programming Language :: Python',
Expand Down
2 changes: 1 addition & 1 deletion tests/artist_app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
urlpatterns = [
path('list/artists/', views.ArtistListView.as_view()),
path('edit/artists/create/', views.ArtistCreate.as_view()),
path('view/artists/read/<int:pk>', views.ArtistRead.as_view()),
path('view/artists/view/<int:pk>', views.ArtistRead.as_view()),
path('edit/artists/edit/<int:pk>', views.ArtistUpdate.as_view()),
path('edit/artists/delete/<int:pk>', views.ArtistDelete.as_view()),
] + artist_crud_patterns + song_crud_patterns + custom_artist_crud_patterns +\
Expand Down
8 changes: 4 additions & 4 deletions tests/artist_app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class FooView(SimpleURLPatternMixin, TemplateView):
"""random template view"""
template_name = "artist_app/empty.html"

protected_actions = ["create", "update", "delete", "template", "read", ]
protected_actions = ["create", "update", "delete", "template", "view", ]
permissions_actions = None
crud_path = "private-songs"
view_classes = {
Expand All @@ -122,8 +122,8 @@ class PermsSongCRUD(CustomSongCRUD):
"""

protected_actions = [
"create", "update", "delete", "artists", "list", "read", ]
permissions_actions = ["create", "update", "delete", "artists", "read", ]
"create", "update", "delete", "artists", "list", "view", ]
permissions_actions = ["create", "update", "delete", "artists", "view", ]
crud_path = "hidden-songs"
form_class = SongForm

Expand Down Expand Up @@ -164,7 +164,7 @@ class CustomReadView(ArtistRead):

view_classes = {
"list": CustomListView,
"read": CustomReadView,
"view": CustomReadView,
"update": CustomUpdateView,
"create": CustomCreateView,
"delete": CustomDeleteView,
Expand Down
Loading

0 comments on commit 654144f

Please sign in to comment.