mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-03-30 15:29:05 +00:00
Compare commits
69 Commits
optimisati
...
aa51ce7861
| Author | SHA1 | Date | |
|---|---|---|---|
| aa51ce7861 | |||
| cdc8635e2f | |||
| 5d07a1853d | |||
| 1eed448828 | |||
| e2e83e2cd8 | |||
| 534e1000d4 | |||
| 84119f6685 | |||
| e50cf8d06c | |||
| a3970cf553 | |||
| 4b8639faf4 | |||
| 6a4620a2e5 | |||
| cc233e0223 | |||
| 2351201e13 | |||
| 874b8ef37a | |||
| 6a0b00dc76 | |||
| 1c31608951 | |||
| 37c0890a4b | |||
| c772744a4b | |||
| 5319c2f6e3 | |||
| aa525372a2 | |||
| 2774690b59 | |||
| 81733d32ba | |||
| e6527db6f7 | |||
| d109ee231f | |||
| cde46cc8e4 | |||
| dddf0dc42a | |||
| 19c5f282d2 | |||
| d5d2e9167c | |||
| 3b3ba0b87e | |||
| 1fbe59dfb0 | |||
| 65c5307072 | |||
| 638816535e | |||
| 8346d705ba | |||
| 18eed1a654 | |||
| 5174a442bc | |||
| 5f1fd59dd2 | |||
| 3be2a9f4b5 | |||
| 883ef4ed8b | |||
| 2195a60438 | |||
| 12c4b63947 | |||
| 39ab9df836 | |||
| a99e4b1d1c | |||
| 18a091f8ea | |||
| d64d0f54d4 | |||
| 8f54897b69 | |||
| 97830596b5 | |||
| 68f401097d | |||
| 8c5b2f426d | |||
| e3fc05772e | |||
| e38205b9e7 | |||
| f2b9642772 | |||
| 08939a0e1f | |||
| 15b7f9c7c1 | |||
| c67f7e1e54 | |||
| 4f268b3168 | |||
| 0e7723828a | |||
| c46a2c53f3 | |||
| b3617a74bf | |||
| 5806cbc72d | |||
| ab2ff9f146 | |||
| fd5575a818 | |||
| 402a1dd7f0 | |||
| be7688aa75 | |||
| a472e414f7 | |||
| 618c02aa9c | |||
| 3056b6ef71 | |||
| 548c960996 | |||
| 2cc43dcdb7 | |||
| 6db25fb56b |
16
.codeclimate.yml
Normal file
16
.codeclimate.yml
Normal file
@@ -0,0 +1,16 @@
|
||||
version: 2
|
||||
plugins:
|
||||
csslint:
|
||||
enabled: true
|
||||
duplication:
|
||||
enabled: true
|
||||
config:
|
||||
languages:
|
||||
- javascript
|
||||
- python
|
||||
eslint:
|
||||
enabled: true
|
||||
fixme:
|
||||
enabled: true
|
||||
radon:
|
||||
enabled: true
|
||||
@@ -1,5 +1,3 @@
|
||||
[run]
|
||||
omit = */migrations/*
|
||||
*/tests/*
|
||||
*/site-packages/*
|
||||
*/distutils/*
|
||||
plugins = django_coverage_plugin
|
||||
omit = *migrations*, *tests*
|
||||
|
||||
50
.github/workflows/django.yml
vendored
50
.github/workflows/django.yml
vendored
@@ -10,45 +10,49 @@ jobs:
|
||||
build:
|
||||
if: "!contains(github.event.head_commit.message, '[ci skip]')"
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
browser: ['chrome', 'firefox']
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
BROWSER: ${{ matrix.browser }}
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: bahmutov/npm-install@v1
|
||||
- run: node node_modules/gulp/bin/gulp build
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: 3.9
|
||||
- uses: actions/cache@v2
|
||||
id: pcache
|
||||
- name: Cache python deps
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/.local/share/virtualenvs
|
||||
key: ${{ runner.os }}-pipenv-${{ hashFiles('Pipfile.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-pipenv-
|
||||
path: ${{ env.pythonLocation }}
|
||||
key: ${{ env.pythonLocation }}-${{ hashFiles('requirements.txt') }}
|
||||
- name: Install Dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install pipenv
|
||||
pipenv install -d
|
||||
# if: steps.pcache.outputs.cache-hit != 'true'
|
||||
- name: Cache Static Files
|
||||
id: static-cache
|
||||
pip install pycodestyle coverage coveralls django_coverage_plugin pytest-cov
|
||||
pip install --upgrade --upgrade-strategy eager -r requirements.txt
|
||||
python manage.py collectstatic --noinput
|
||||
- name: Cache gulp output
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: 'pipeline/built_assets'
|
||||
key: ${{ hashFiles('package-lock.json') }}-${{ hashFiles('pipeline/source_assets') }}
|
||||
- uses: bahmutov/npm-install@v1
|
||||
if: steps.static-cache.outputs.cache-hit != 'true'
|
||||
- run: node node_modules/gulp/bin/gulp build
|
||||
if: steps.static-cache.outputs.cache-hit != 'true'
|
||||
path: static/
|
||||
key: static-${{ hashFiles('package-lock.json') }}-${{ hashFiles('pipeline/source_assets') }}
|
||||
- name: Basic Checks
|
||||
run: |
|
||||
pipenv run pycodestyle . --exclude=migrations,node_modules
|
||||
pipenv run python manage.py check
|
||||
pipenv run python manage.py makemigrations --check --dry-run
|
||||
pipenv run python manage.py collectstatic --noinput
|
||||
pycodestyle . --exclude=migrations,node_modules
|
||||
python manage.py check
|
||||
python manage.py makemigrations --check --dry-run
|
||||
- name: Run Tests
|
||||
run: pipenv run pytest -n auto -vv --cov
|
||||
uses: paambaati/codeclimate-action@v2.7.5
|
||||
env:
|
||||
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
||||
with:
|
||||
coverageCommand: coverage run -m pytest -n 8
|
||||
coverageLocations: |
|
||||
${{github.workspace}}/.coverage:coverage.py
|
||||
- uses: actions/upload-artifact@v2
|
||||
if: failure()
|
||||
with:
|
||||
@@ -56,4 +60,4 @@ jobs:
|
||||
path: screenshots/
|
||||
retention-days: 5
|
||||
- name: Coveralls
|
||||
run: pipenv run coveralls --service=github
|
||||
run: coveralls --service=github
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
*.sqlite3
|
||||
*.md
|
||||
**/tests
|
||||
conftest.py
|
||||
pytest.ini
|
||||
Dockerfile
|
||||
|
||||
101
Pipfile
101
Pipfile
@@ -1,101 +0,0 @@
|
||||
[[source]]
|
||||
url = "https://pypi.python.org/simple"
|
||||
verify_ssl = true
|
||||
name = "pypi"
|
||||
|
||||
[packages]
|
||||
ansicolors = "~=1.1.8"
|
||||
asgiref = "~=3.3.1"
|
||||
"backports.tempfile" = "~=1.0"
|
||||
"backports.weakref" = "~=1.0.post1"
|
||||
beautifulsoup4 = "~=4.9.3"
|
||||
Brotli = "~=1.0.9"
|
||||
cachetools = "~=4.2.1"
|
||||
certifi = "~=2020.12.5"
|
||||
chardet = "~=4.0.0"
|
||||
configparser = "~=5.0.1"
|
||||
contextlib2 = "~=0.6.0.post1"
|
||||
cssselect = "~=1.1.0"
|
||||
cssutils = "~=1.0.2"
|
||||
dj-database-url = "~=0.5.0"
|
||||
dj-static = "~=0.0.6"
|
||||
Django = "~=3.1.5"
|
||||
django-debug-toolbar = "~=3.2"
|
||||
django-filter = "~=2.4.0"
|
||||
django-ical = "~=1.7.1"
|
||||
django-recaptcha = "~=2.0.6"
|
||||
django-recurrence = "~=1.10.3"
|
||||
django-registration-redux = "~=2.9"
|
||||
django-reversion = "~=3.0.9"
|
||||
django-toolbelt = "~=0.0.1"
|
||||
django-widget-tweaks = "~=1.4.8"
|
||||
django-htmlmin = "~=0.11.0"
|
||||
envparse = "~=0.2.0"
|
||||
gunicorn = "~=20.0.4"
|
||||
icalendar = "~=4.0.7"
|
||||
idna = "~=2.10"
|
||||
importlib-metadata = "~=3.4.0"
|
||||
lxml = "~=4.6.2"
|
||||
Markdown = "~=3.3.3"
|
||||
msgpack = "~=1.0.2"
|
||||
pep517 = "~=0.9.1"
|
||||
Pillow = "~=8.1.0"
|
||||
premailer = "~=3.7.0"
|
||||
progress = "~=1.5"
|
||||
psutil = "~=5.8.0"
|
||||
psycopg2 = "~=2.8.6"
|
||||
Pygments = "~=2.7.4"
|
||||
pyparsing = "~=2.4.7"
|
||||
PyPDF2 = "~=1.26.0"
|
||||
PyPOM = "~=2.2.0"
|
||||
python-dateutil = "~=2.8.1"
|
||||
pytoml = "~=0.1.21"
|
||||
pytz = "~=2020.5"
|
||||
reportlab = "~=3.5.59"
|
||||
requests = "~=2.25.1"
|
||||
retrying = "~=1.3.3"
|
||||
simplejson = "~=3.17.2"
|
||||
six = "~=1.15.0"
|
||||
soupsieve = "~=2.1"
|
||||
sqlparse = "~=0.4.1"
|
||||
static3 = "~=0.7.0"
|
||||
svg2rlg = "~=0.3"
|
||||
tini = "~=3.0.1"
|
||||
tornado = "~=6.1"
|
||||
urllib3 = "~=1.26.2"
|
||||
whitenoise = "~=5.2.0"
|
||||
yolk = "~=0.4.3"
|
||||
"z3c.rml" = "~=4.1.2"
|
||||
zipp = "~=3.4.0"
|
||||
"zope.component" = "~=4.6.2"
|
||||
"zope.deferredimport" = "~=4.3.1"
|
||||
"zope.deprecation" = "~=4.4.0"
|
||||
"zope.event" = "~=4.5.0"
|
||||
"zope.hookable" = "~=5.0.1"
|
||||
"zope.interface" = "~=5.2.0"
|
||||
"zope.proxy" = "~=4.3.5"
|
||||
"zope.schema" = "~=6.0.1"
|
||||
sentry-sdk = "*"
|
||||
diff-match-patch = "*"
|
||||
|
||||
[dev-packages]
|
||||
selenium = "~=3.141.0"
|
||||
pycodestyle = "*"
|
||||
coveralls = "*"
|
||||
django-coverage-plugin = "*"
|
||||
pytest-cov = "*"
|
||||
pytest-django = "*"
|
||||
pluggy = "*"
|
||||
pytest-splinter = "*"
|
||||
pytest = "*"
|
||||
|
||||
[requires]
|
||||
python_version = "3.9"
|
||||
|
||||
[dev-packages.pytest-xdist]
|
||||
extras = [ "psutil",]
|
||||
version = "*"
|
||||
|
||||
[dev-packages.PyPOM]
|
||||
extras = [ "splinter",]
|
||||
version = "*"
|
||||
1544
Pipfile.lock
generated
1544
Pipfile.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,3 @@
|
||||
from django.conf import settings
|
||||
from django.contrib.auth import REDIRECT_FIELD_NAME
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import render
|
||||
@@ -16,7 +15,11 @@ def get_oembed(login_url, request, oembed_view, kwargs):
|
||||
return resp
|
||||
|
||||
|
||||
def has_oembed(oembed_view, login_url=settings.LOGIN_URL):
|
||||
def has_oembed(oembed_view, login_url=None):
|
||||
if not login_url:
|
||||
from django.conf import settings
|
||||
login_url = settings.LOGIN_URL
|
||||
|
||||
def _dec(view_func):
|
||||
def _checklogin(request, *args, **kwargs):
|
||||
if request.user.is_authenticated:
|
||||
|
||||
@@ -9,21 +9,27 @@ https://docs.djangoproject.com/en/1.7/ref/settings/
|
||||
"""
|
||||
|
||||
import datetime
|
||||
from pathlib import Path
|
||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||
import os
|
||||
import secrets
|
||||
|
||||
import sentry_sdk
|
||||
from sentry_sdk.integrations.django import DjangoIntegration
|
||||
import raven
|
||||
from envparse import env
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve(strict=True).parent.parent
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = env('SECRET_KEY', default='gxhy(a#5mhp289_=6xx$7jh=eh$ymxg^ymc+di*0c*geiu3p_e')
|
||||
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = env('DEBUG', cast=bool, default=True)
|
||||
|
||||
STAGING = env('STAGING', cast=bool, default=False)
|
||||
|
||||
CI = env('CI', cast=bool, default=False)
|
||||
|
||||
ALLOWED_HOSTS = ['pyrigs.nottinghamtec.co.uk', 'rigs.nottinghamtec.co.uk', 'pyrigs.herokuapp.com']
|
||||
@@ -49,7 +55,6 @@ if DEBUG:
|
||||
|
||||
# Application definition
|
||||
INSTALLED_APPS = (
|
||||
'whitenoise.runserver_nostatic',
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
@@ -67,11 +72,12 @@ INSTALLED_APPS = (
|
||||
'reversion',
|
||||
'captcha',
|
||||
'widget_tweaks',
|
||||
'raven.contrib.django.raven_compat',
|
||||
)
|
||||
|
||||
MIDDLEWARE = (
|
||||
'raven.contrib.django.raven_compat.middleware.SentryResponseErrorIdMiddleware',
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'whitenoise.middleware.WhiteNoiseMiddleware',
|
||||
'debug_toolbar.middleware.DebugToolbarMiddleware',
|
||||
'reversion.middleware.RevisionMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
@@ -80,8 +86,6 @@ MIDDLEWARE = (
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
'htmlmin.middleware.HtmlMinifyMiddleware',
|
||||
'htmlmin.middleware.MarkRequestMiddleware',
|
||||
)
|
||||
|
||||
ROOT_URLCONF = 'PyRIGS.urls'
|
||||
@@ -89,10 +93,11 @@ ROOT_URLCONF = 'PyRIGS.urls'
|
||||
WSGI_APPLICATION = 'PyRIGS.wsgi.application'
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': str(BASE_DIR / 'db.sqlite3'),
|
||||
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,12 +175,9 @@ else:
|
||||
}
|
||||
}
|
||||
|
||||
# Error/performance monitoring
|
||||
sentry_sdk.init(
|
||||
dsn=env('SENTRY_DSN', default=""),
|
||||
integrations=[DjangoIntegration()],
|
||||
traces_sample_rate=1.0,
|
||||
)
|
||||
RAVEN_CONFIG = {
|
||||
'dsn': env('RAVEN_DSN', default=""),
|
||||
}
|
||||
|
||||
# User system
|
||||
AUTH_USER_MODEL = 'RIGS.Profile'
|
||||
@@ -228,18 +230,21 @@ USE_TZ = True
|
||||
DATETIME_INPUT_FORMATS = ('%Y-%m-%dT%H:%M', '%Y-%m-%dT%H:%M:%S')
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
|
||||
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'
|
||||
STATIC_URL = '/static/'
|
||||
STATIC_ROOT = str(BASE_DIR / 'static/')
|
||||
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
|
||||
STATIC_DIRS = (
|
||||
os.path.join(BASE_DIR, 'static/')
|
||||
)
|
||||
STATICFILES_DIRS = [
|
||||
str(BASE_DIR / 'pipeline/built_assets'),
|
||||
os.path.join(BASE_DIR, 'pipeline/built_assets/'),
|
||||
]
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [
|
||||
BASE_DIR / 'templates'
|
||||
os.path.join(BASE_DIR, 'templates')
|
||||
],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
|
||||
@@ -11,29 +11,33 @@ from selenium.webdriver.support.wait import WebDriverWait
|
||||
|
||||
from RIGS import models as rigsmodels
|
||||
from . import pages
|
||||
|
||||
from pytest_django.asserts import assertContains
|
||||
from envparse import env
|
||||
|
||||
|
||||
def create_datetime(year, month, day, hour, minute):
|
||||
def create_datetime(year, month, day, hour, min):
|
||||
tz = pytz.timezone(settings.TIME_ZONE)
|
||||
return tz.localize(datetime(year, month, day, hour, minute)).astimezone(tz)
|
||||
return tz.localize(datetime(year, month, day, hour, min)).astimezone(pytz.utc)
|
||||
|
||||
|
||||
def create_browser():
|
||||
options = webdriver.ChromeOptions()
|
||||
options.add_argument("--window-size=1920,1080")
|
||||
options.add_argument("--headless")
|
||||
if settings.CI:
|
||||
options.add_argument("--no-sandbox")
|
||||
driver = webdriver.Chrome(options=options)
|
||||
def create_browser(browser):
|
||||
if browser == "firefox":
|
||||
options = webdriver.FirefoxOptions()
|
||||
options.headless = True
|
||||
driver = webdriver.Firefox(options=options)
|
||||
else:
|
||||
options = webdriver.ChromeOptions()
|
||||
options.add_argument("--window-size=1920,1080")
|
||||
options.add_argument("--headless")
|
||||
if settings.CI:
|
||||
options.add_argument("--no-sandbox")
|
||||
driver = webdriver.Chrome(options=options)
|
||||
return driver
|
||||
|
||||
|
||||
class BaseTest(LiveServerTestCase):
|
||||
def setUp(self):
|
||||
super().setUpClass()
|
||||
self.driver = create_browser()
|
||||
self.driver = create_browser(env('BROWSER', default="chrome"))
|
||||
self.wait = WebDriverWait(self.driver, 15)
|
||||
|
||||
def tearDown(self):
|
||||
@@ -52,7 +56,6 @@ class AutoLoginTest(BaseTest):
|
||||
login_page.login("EventTest", "EventTestPassword")
|
||||
|
||||
|
||||
# FIXME Refactor as a pytest fixture
|
||||
def screenshot_failure(func):
|
||||
def wrapper_func(self, *args, **kwargs):
|
||||
try:
|
||||
@@ -76,30 +79,5 @@ def screenshot_failure_cls(cls):
|
||||
return cls
|
||||
|
||||
|
||||
def assert_times_almost_equal(first_time, second_time):
|
||||
assert first_time.replace(microsecond=0, second=0) == second_time.replace(microsecond=0, second=0)
|
||||
|
||||
|
||||
def assert_oembed(alt_event_embed_url, alt_oembed_url, client, event_embed_url, event_url, oembed_url):
|
||||
# Test the meta tag is in place
|
||||
response = client.get(event_url, follow=True, HTTP_HOST='example.com')
|
||||
assertContains(response, 'application/json+oembed')
|
||||
assertContains(response, oembed_url)
|
||||
# Test that the JSON exists
|
||||
response = client.get(oembed_url, follow=True, HTTP_HOST='example.com')
|
||||
assert response.status_code == 200
|
||||
assertContains(response, event_embed_url)
|
||||
# Should also work for non-existant events
|
||||
response = client.get(alt_oembed_url, follow=True, HTTP_HOST='example.com')
|
||||
assert response.status_code == 200
|
||||
assertContains(response, alt_event_embed_url)
|
||||
|
||||
|
||||
def login(client, django_user_model):
|
||||
pwd = 'testuser'
|
||||
usr = 'TestUser'
|
||||
user = django_user_model.objects.create_user(username=usr, email="TestUser@test.com", password=pwd,
|
||||
is_superuser=True,
|
||||
is_active=True, is_staff=True)
|
||||
assert client.login(username=usr, password=pwd)
|
||||
return user
|
||||
def assert_times_equal(first_time, second_time):
|
||||
assert first_time.replace(microsecond=0) == second_time.replace(microsecond=0)
|
||||
|
||||
@@ -71,12 +71,11 @@ class BootstrapSelectElement(Region):
|
||||
self.find_element(*self._deselect_all_locator).click()
|
||||
|
||||
def search(self, query):
|
||||
# self.wait.until(expected_conditions.visibility_of_element_located(self._status_locator))
|
||||
search_box = self.find_element(*self._search_locator)
|
||||
self.open()
|
||||
search_box.clear()
|
||||
search_box.send_keys(query)
|
||||
self.wait.until(expected_conditions.invisibility_of_element_located(self._status_locator))
|
||||
self.wait.until(expected_conditions.invisibility_of_element_located(*self._status_locator))
|
||||
|
||||
@property
|
||||
def options(self):
|
||||
|
||||
@@ -1,145 +0,0 @@
|
||||
import pytest
|
||||
from django.core.management import call_command
|
||||
from django.template.defaultfilters import striptags
|
||||
from django.urls import URLPattern, URLResolver
|
||||
from django.urls import reverse
|
||||
from django.urls.exceptions import NoReverseMatch
|
||||
from pytest_django.asserts import assertRedirects, assertContains, assertNotContains
|
||||
from pytest_django.asserts import assertTemplateUsed, assertInHTML
|
||||
|
||||
from PyRIGS import urls
|
||||
from RIGS.models import Event
|
||||
from assets.models import Asset
|
||||
from django.db import connection
|
||||
import pytest
|
||||
from django.core.management import call_command
|
||||
from django.template.defaultfilters import striptags
|
||||
from django.urls.exceptions import NoReverseMatch
|
||||
|
||||
from RIGS.models import Event
|
||||
from assets.models import Asset
|
||||
from django.db import connection
|
||||
from django.test import TestCase
|
||||
from django.test.utils import override_settings
|
||||
|
||||
|
||||
def find_urls_recursive(patterns):
|
||||
urls_to_check = []
|
||||
for url in patterns:
|
||||
if isinstance(url, URLResolver):
|
||||
urls_to_check += find_urls_recursive(url.url_patterns)
|
||||
elif isinstance(url, URLPattern):
|
||||
# Skip some things that actually don't need auth (mainly OEmbed JSONs that are essentially just a redirect)
|
||||
if url.name is not None and url.name != "closemodal" and "json" not in str(url):
|
||||
urls_to_check.append(url)
|
||||
return urls_to_check
|
||||
|
||||
|
||||
def get_request_url(url):
|
||||
pattern = str(url.pattern)
|
||||
try:
|
||||
kwargz = {}
|
||||
if ":pk>" in pattern:
|
||||
kwargz['pk'] = 1
|
||||
if ":model>" in pattern:
|
||||
kwargz['model'] = "event"
|
||||
return reverse(url.name, kwargs=kwargz)
|
||||
except NoReverseMatch:
|
||||
print("Couldn't test url " + pattern)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("command", ['generateSampleAssetsData', 'generateSampleRIGSData', 'generateSampleUserData',
|
||||
'deleteSampleData'])
|
||||
def test_production_exception(command):
|
||||
from django.core.management.base import CommandError
|
||||
with pytest.raises(CommandError, match=".*production"):
|
||||
call_command(command)
|
||||
|
||||
|
||||
class TestSampleDataGenerator(TestCase):
|
||||
@override_settings(DEBUG=True)
|
||||
def test_sample_data(self):
|
||||
call_command('generateSampleData')
|
||||
assert Asset.objects.all().count() > 50
|
||||
assert Event.objects.all().count() > 100
|
||||
call_command('deleteSampleData')
|
||||
assert Asset.objects.all().count() == 0
|
||||
assert Event.objects.all().count() == 0
|
||||
|
||||
|
||||
class TestSampleDataGenerator(TestCase):
|
||||
@override_settings(DEBUG=True)
|
||||
def setUp(self):
|
||||
call_command('generateSampleData')
|
||||
|
||||
def test_unauthenticated(self): # Nothing should be available to the unauthenticated
|
||||
for url in find_urls_recursive(urls.urlpatterns):
|
||||
request_url = get_request_url(url)
|
||||
if request_url and 'user' not in request_url: # User module is full of edge cases
|
||||
response = self.client.get(request_url, follow=True, HTTP_HOST='example.com')
|
||||
assertContains(response, 'Login')
|
||||
if 'application/json+oembed' in response.content.decode():
|
||||
assertTemplateUsed(response, 'login_redirect.html')
|
||||
else:
|
||||
if "embed" in str(url):
|
||||
expected_url = "{0}?next={1}".format(reverse('login_embed'), request_url)
|
||||
else:
|
||||
expected_url = "{0}?next={1}".format(reverse('login'), request_url)
|
||||
assertRedirects(response, expected_url)
|
||||
|
||||
def test_page_titles(self):
|
||||
assert self.client.login(username='superuser', password='superuser')
|
||||
for url in filter((lambda u: "embed" not in u.name), find_urls_recursive(urls.urlpatterns)):
|
||||
request_url = get_request_url(url)
|
||||
response = self.client.get(request_url)
|
||||
if hasattr(response, "context_data") and "page_title" in response.context_data:
|
||||
expected_title = striptags(response.context_data["page_title"])
|
||||
assertInHTML('<title>{} | Rig Information Gathering System'.format(expected_title),
|
||||
response.content.decode())
|
||||
print("{} | {}".format(request_url, expected_title)) # If test fails, tell me where!
|
||||
self.client.logout()
|
||||
|
||||
def test_basic_access(self):
|
||||
assert self.client.login(username="basic", password="basic")
|
||||
|
||||
url = reverse('asset_list')
|
||||
response = self.client.get(url)
|
||||
# Check edit and duplicate buttons NOT shown in list
|
||||
assertNotContains(response, 'Edit')
|
||||
assertNotContains(response,
|
||||
'Duplicate') # If this line is randomly failing, check the debug toolbar HTML hasn't crept in
|
||||
|
||||
url = reverse('asset_detail', kwargs={'pk': Asset.objects.first().asset_id})
|
||||
response = self.client.get(url)
|
||||
assertNotContains(response, 'Purchase Details')
|
||||
assertNotContains(response, 'View Revision History')
|
||||
|
||||
urlz = {'asset_history', 'asset_update', 'asset_duplicate'}
|
||||
for url_name in urlz:
|
||||
request_url = reverse(url_name, kwargs={'pk': Asset.objects.first().asset_id})
|
||||
response = self.client.get(request_url, follow=True)
|
||||
assert response.status_code == 403
|
||||
|
||||
request_url = reverse('supplier_create')
|
||||
response = self.client.get(request_url, follow=True)
|
||||
assert response.status_code == 403
|
||||
|
||||
request_url = reverse('supplier_update', kwargs={'pk': 1})
|
||||
response = self.client.get(request_url, follow=True)
|
||||
assert response.status_code == 403
|
||||
self.client.logout()
|
||||
|
||||
def test_keyholder_access(self):
|
||||
assert self.client.login(username="keyholder", password="keyholder")
|
||||
|
||||
url = reverse('asset_list')
|
||||
response = self.client.get(url)
|
||||
# Check edit and duplicate buttons shown in list
|
||||
assertContains(response, 'Edit')
|
||||
assertContains(response, 'Duplicate')
|
||||
|
||||
url = reverse('asset_detail', kwargs={'pk': Asset.objects.first().asset_id})
|
||||
response = self.client.get(url)
|
||||
assertContains(response, 'Purchase Details')
|
||||
assertContains(response, 'View Revision History')
|
||||
self.client.logout()
|
||||
@@ -3,7 +3,7 @@ from django.conf.urls import include
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
|
||||
from django.urls import path
|
||||
from django.urls import path, re_path
|
||||
from django.views.generic import TemplateView
|
||||
|
||||
from PyRIGS import views
|
||||
@@ -22,19 +22,18 @@ urlpatterns = [
|
||||
name="api_secure"),
|
||||
|
||||
path('closemodal/', views.CloseModal.as_view(), name='closemodal'),
|
||||
path('search_help/', login_required(views.SearchHelp.as_view()), name='search_help'),
|
||||
path('search_help/', views.SearchHelp.as_view(), name='search_help'),
|
||||
|
||||
path('', include('users.urls')),
|
||||
|
||||
path('admin/', admin.site.urls),
|
||||
path("robots.txt", TemplateView.as_view(template_name="robots.txt", content_type="text/plain")),
|
||||
]
|
||||
|
||||
if settings.DEBUG:
|
||||
urlpatterns += staticfiles_urlpatterns()
|
||||
|
||||
import debug_toolbar
|
||||
urlpatterns += [
|
||||
path('__debug__/', include(debug_toolbar.urls)),
|
||||
urlpatterns = [
|
||||
re_path(r'^__debug__/', include(debug_toolbar.urls)),
|
||||
path('bootstrap/', TemplateView.as_view(template_name="bootstrap.html")),
|
||||
]
|
||||
] + urlpatterns
|
||||
|
||||
@@ -3,7 +3,6 @@ import operator
|
||||
from functools import reduce
|
||||
|
||||
import simplejson
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib import messages
|
||||
from django.core import serializers
|
||||
from django.core.exceptions import PermissionDenied
|
||||
@@ -12,7 +11,6 @@ from django.http import HttpResponse
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.urls import reverse_lazy, reverse, NoReverseMatch
|
||||
from django.views import generic
|
||||
from django.views.decorators.clickjacking import xframe_options_exempt
|
||||
|
||||
from RIGS import models
|
||||
from assets import models as asset_models
|
||||
@@ -21,8 +19,10 @@ from assets import models as asset_models
|
||||
def is_ajax(request):
|
||||
return request.headers.get('x-requested-with') == 'XMLHttpRequest'
|
||||
|
||||
# Displays the current rig count along with a few other bits and pieces
|
||||
|
||||
class Index(generic.TemplateView): # Displays the current rig count along with a few other bits and pieces
|
||||
|
||||
class Index(generic.TemplateView):
|
||||
template_name = 'index.html'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
@@ -230,29 +230,15 @@ class SearchHelp(generic.TemplateView):
|
||||
template_name = 'search_help.html'
|
||||
|
||||
|
||||
"""
|
||||
Called from a modal window (e.g. when an item is submitted to an event/invoice).
|
||||
May optionally also include some javascript in a success message to cause a load of
|
||||
the new information onto the page.
|
||||
"""
|
||||
|
||||
|
||||
class CloseModal(generic.TemplateView):
|
||||
"""
|
||||
Called from a modal window (e.g. when an item is submitted to an event/invoice).
|
||||
May optionally also include some javascript in a success message to cause a load of
|
||||
the new information onto the page.
|
||||
"""
|
||||
template_name = 'closemodal.html'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
return {'messages': messages.get_messages(self.request)}
|
||||
|
||||
|
||||
class OEmbedView(generic.View):
|
||||
def get(self, request, pk=None):
|
||||
embed_url = reverse(self.url_name, args=[pk])
|
||||
full_url = "{0}://{1}{2}".format(request.scheme, request.META['HTTP_HOST'], embed_url)
|
||||
|
||||
data = {
|
||||
'html': '<iframe src="{0}" frameborder="0" width="100%" height="250"></iframe>'.format(full_url),
|
||||
'version': '1.0',
|
||||
'type': 'rich',
|
||||
'height': '250'
|
||||
}
|
||||
|
||||
json = simplejson.JSONEncoderForHTML().encode(data)
|
||||
return HttpResponse(json, content_type="application/json")
|
||||
|
||||
@@ -10,7 +10,7 @@ from django.http import Http404, HttpResponseRedirect
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.template.loader import get_template
|
||||
from django.urls import reverse
|
||||
from django.urls import reverse_lazy
|
||||
from django.views import generic
|
||||
from z3c.rml import rml2pdf
|
||||
|
||||
@@ -67,6 +67,12 @@ class InvoicePrint(generic.View):
|
||||
|
||||
context = {
|
||||
'object': object,
|
||||
'fonts': {
|
||||
'opensans': {
|
||||
'regular': 'RIGS/static/fonts/OPENSANS-REGULAR.TTF',
|
||||
'bold': 'RIGS/static/fonts/OPENSANS-BOLD.TTF',
|
||||
}
|
||||
},
|
||||
'invoice': invoice,
|
||||
'current_user': request.user,
|
||||
'filename': 'Invoice {} for {} {}.pdf'.format(invoice.display_id, object.display_id, re.sub(r'[^a-zA-Z0-9 \n\.]', '', object.name))
|
||||
@@ -92,8 +98,8 @@ class InvoiceVoid(generic.View):
|
||||
object.save()
|
||||
|
||||
if object.void:
|
||||
return HttpResponseRedirect(reverse('invoice_list'))
|
||||
return HttpResponseRedirect(reverse('invoice_detail', kwargs={'pk': object.pk}))
|
||||
return HttpResponseRedirect(reverse_lazy('invoice_list'))
|
||||
return HttpResponseRedirect(reverse_lazy('invoice_detail', kwargs={'pk': object.pk}))
|
||||
|
||||
|
||||
class InvoiceDelete(generic.DeleteView):
|
||||
@@ -104,14 +110,14 @@ class InvoiceDelete(generic.DeleteView):
|
||||
obj = self.get_object()
|
||||
if obj.payment_set.all().count() > 0:
|
||||
messages.info(self.request, 'To delete an invoice, delete the payments first.')
|
||||
return HttpResponseRedirect(reverse('invoice_detail', kwargs={'pk': obj.pk}))
|
||||
return HttpResponseRedirect(reverse_lazy('invoice_detail', kwargs={'pk': obj.pk}))
|
||||
return super(InvoiceDelete, self).get(pk)
|
||||
|
||||
def post(self, request, pk):
|
||||
obj = self.get_object()
|
||||
if obj.payment_set.all().count() > 0:
|
||||
messages.info(self.request, 'To delete an invoice, delete the payments first.')
|
||||
return HttpResponseRedirect(reverse('invoice_detail', kwargs={'pk': obj.pk}))
|
||||
return HttpResponseRedirect(reverse_lazy('invoice_detail', kwargs={'pk': obj.pk}))
|
||||
return super(InvoiceDelete, self).post(pk)
|
||||
|
||||
def get_success_url(self):
|
||||
@@ -166,17 +172,16 @@ class InvoiceWaiting(generic.ListView):
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(InvoiceWaiting, self).get_context_data(**kwargs)
|
||||
total = 0
|
||||
objects = self.get_queryset()
|
||||
for obj in objects:
|
||||
for obj in self.get_objects():
|
||||
total += obj.sum_total
|
||||
context['page_title'] = "Events for Invoice ({} Events, £{:.2f})".format(len(objects), total)
|
||||
context['page_title'] = "Events for Invoice ({} Events, £{:.2f})".format(len(self.get_objects()), total)
|
||||
return context
|
||||
|
||||
def get_queryset(self):
|
||||
return self.get_objects()
|
||||
|
||||
def get_objects(self):
|
||||
# TODO find a way to select items
|
||||
# @todo find a way to select items
|
||||
events = self.model.objects.filter(
|
||||
(
|
||||
Q(start_date__lte=datetime.date.today(), end_date__isnull=True) | # Starts before with no end
|
||||
@@ -211,7 +216,7 @@ class InvoiceEvent(generic.View):
|
||||
invoice.save()
|
||||
messages.warning(self.request, 'Invoice voided')
|
||||
|
||||
return HttpResponseRedirect(reverse('invoice_detail', kwargs={'pk': invoice.pk}))
|
||||
return HttpResponseRedirect(reverse_lazy('invoice_detail', kwargs={'pk': invoice.pk}))
|
||||
|
||||
|
||||
class PaymentCreate(generic.CreateView):
|
||||
@@ -237,7 +242,7 @@ class PaymentCreate(generic.CreateView):
|
||||
|
||||
def get_success_url(self):
|
||||
messages.info(self.request, "location.reload()")
|
||||
return reverse('closemodal')
|
||||
return reverse_lazy('closemodal')
|
||||
|
||||
|
||||
class PaymentDelete(generic.DeleteView):
|
||||
|
||||
@@ -76,9 +76,6 @@ class EventRiskAssessmentList(generic.ListView):
|
||||
model = models.RiskAssessment
|
||||
template_name = 'hs_object_list.html'
|
||||
|
||||
def get_queryset(self):
|
||||
return self.model.objects.order_by('reviewed_at').select_related('event')
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(EventRiskAssessmentList, self).get_context_data(**kwargs)
|
||||
context['title'] = 'Risk Assessment'
|
||||
@@ -86,6 +83,7 @@ class EventRiskAssessmentList(generic.ListView):
|
||||
context['edit'] = 'ra_edit'
|
||||
context['review'] = 'ra_review'
|
||||
context['perm'] = 'perms.RIGS.review_riskassessment'
|
||||
context['fields'] = [n.name for n in list(self.model._meta.get_fields()) if n.name != 'reviewed_at' and n.name != 'reviewed_by' and not n.is_relation and not n.auto_created]
|
||||
return context
|
||||
|
||||
|
||||
@@ -189,6 +187,7 @@ class EventChecklistList(generic.ListView):
|
||||
context['edit'] = 'ec_edit'
|
||||
context['review'] = 'ec_review'
|
||||
context['perm'] = 'perms.RIGS.review_eventchecklist'
|
||||
context['fields'] = [n.name for n in list(self.model._meta.get_fields()) if n.name != 'reviewed_at' and n.name != 'reviewed_by' and not n.is_relation and not n.auto_created]
|
||||
return context
|
||||
|
||||
|
||||
@@ -210,7 +209,7 @@ class HSList(generic.ListView):
|
||||
template_name = 'hs_list.html'
|
||||
|
||||
def get_queryset(self):
|
||||
return models.Event.objects.all().order_by('-start_date').select_related('riskassessment').prefetch_related('checklists')
|
||||
return models.Event.objects.all().order_by('-start_date')
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(HSList, self).get_context_data(**kwargs)
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
|
||||
from django.contrib.auth.models import Group
|
||||
from assets import models
|
||||
from RIGS import models as rigsmodels
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Deletes testing sample data'
|
||||
|
||||
def handle(self, *args, **kwargs):
|
||||
from django.conf import settings
|
||||
|
||||
if not settings.DEBUG:
|
||||
raise CommandError('You cannot run this command in production')
|
||||
|
||||
self.delete_objects(models.AssetCategory)
|
||||
self.delete_objects(models.AssetStatus)
|
||||
self.delete_objects(models.Supplier)
|
||||
self.delete_objects(models.Connector)
|
||||
self.delete_objects(models.Asset)
|
||||
self.delete_objects(rigsmodels.VatRate)
|
||||
self.delete_objects(rigsmodels.Profile)
|
||||
self.delete_objects(rigsmodels.Person)
|
||||
self.delete_objects(rigsmodels.Organisation)
|
||||
self.delete_objects(rigsmodels.Venue)
|
||||
self.delete_objects(Group)
|
||||
self.delete_objects(rigsmodels.Event)
|
||||
self.delete_objects(rigsmodels.EventItem)
|
||||
self.delete_objects(rigsmodels.Invoice)
|
||||
self.delete_objects(rigsmodels.Payment)
|
||||
self.delete_objects(rigsmodels.RiskAssessment)
|
||||
self.delete_objects(rigsmodels.EventChecklist)
|
||||
|
||||
def delete_objects(self, model):
|
||||
for obj in model.objects.all():
|
||||
obj.delete()
|
||||
@@ -1,14 +1,11 @@
|
||||
from django.core.management import call_command
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from RIGS import models
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Adds sample data to use for testing'
|
||||
can_import_settings = True
|
||||
|
||||
def handle(self, *args, **options):
|
||||
call_command('generateSampleUserData')
|
||||
call_command('generateSampleRIGSData')
|
||||
call_command('generateSampleAssetsData')
|
||||
|
||||
@@ -4,7 +4,6 @@ import random
|
||||
from django.contrib.auth.models import Group, Permission
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.db import transaction
|
||||
from django.utils import timezone
|
||||
from reversion import revisions as reversion
|
||||
|
||||
from RIGS import models
|
||||
@@ -17,8 +16,11 @@ class Command(BaseCommand):
|
||||
people = []
|
||||
organisations = []
|
||||
venues = []
|
||||
events = []
|
||||
profiles = models.Profile.objects.all()
|
||||
profiles = []
|
||||
|
||||
keyholder_group = None
|
||||
finance_group = None
|
||||
hs_group = None
|
||||
|
||||
def handle(self, *args, **options):
|
||||
from django.conf import settings
|
||||
@@ -31,12 +33,20 @@ class Command(BaseCommand):
|
||||
|
||||
with transaction.atomic():
|
||||
models.VatRate.objects.create(start_at='2014-03-05', rate=0.20, comment='test1')
|
||||
self.setup_people()
|
||||
self.setup_organisations()
|
||||
self.setup_venues()
|
||||
self.setup_events()
|
||||
|
||||
def setup_people(self):
|
||||
self.setupGenericProfiles()
|
||||
|
||||
self.setupPeople()
|
||||
self.setupOrganisations()
|
||||
self.setupVenues()
|
||||
|
||||
self.setupGroups()
|
||||
|
||||
self.setupEvents()
|
||||
|
||||
self.setupUsefulProfiles()
|
||||
|
||||
def setupPeople(self):
|
||||
names = ["Regulus Black", "Sirius Black", "Lavender Brown", "Cho Chang", "Vincent Crabbe", "Vincent Crabbe",
|
||||
"Bartemius Crouch", "Fleur Delacour", "Cedric Diggory", "Alberforth Dumbledore", "Albus Dumbledore",
|
||||
"Dudley Dursley", "Petunia Dursley", "Vernon Dursley", "Argus Filch", "Seamus Finnigan",
|
||||
@@ -51,25 +61,25 @@ class Command(BaseCommand):
|
||||
"Ron Weasley", "Dobby", "Fluffy", "Hedwig", "Moaning Myrtle", "Aragog", "Grawp"] # noqa
|
||||
for i, name in enumerate(names):
|
||||
with reversion.create_revision():
|
||||
reversion.set_user(random.choice(models.Profile.objects.all()))
|
||||
person = models.Person.objects.create(name=name)
|
||||
reversion.set_user(random.choice(self.profiles))
|
||||
|
||||
newPerson = models.Person.objects.create(name=name)
|
||||
if i % 3 == 0:
|
||||
person.email = "address@person.com"
|
||||
newPerson.email = "address@person.com"
|
||||
|
||||
if i % 5 == 0:
|
||||
person.notes = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua"
|
||||
newPerson.notes = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua"
|
||||
|
||||
if i % 7 == 0:
|
||||
person.address = "1 Person Test Street \n Demoton \n United States of TEC \n RMRF 567"
|
||||
newPerson.address = "1 Person Test Street \n Demoton \n United States of TEC \n RMRF 567"
|
||||
|
||||
if i % 9 == 0:
|
||||
person.phone = "01234 567894"
|
||||
newPerson.phone = "01234 567894"
|
||||
|
||||
person.save()
|
||||
self.people.append(person)
|
||||
newPerson.save()
|
||||
self.people.append(newPerson)
|
||||
|
||||
def setup_organisations(self):
|
||||
def setupOrganisations(self):
|
||||
names = ["Acme, inc.", "Widget Corp", "123 Warehousing", "Demo Company", "Smith and Co.", "Foo Bars",
|
||||
"ABC Telecom", "Fake Brothers", "QWERTY Logistics", "Demo, inc.", "Sample Company", "Sample, inc",
|
||||
"Acme Corp", "Allied Biscuit", "Ankh-Sto Associates", "Extensive Enterprise", "Galaxy Corp",
|
||||
@@ -98,28 +108,27 @@ class Command(BaseCommand):
|
||||
"Tip Top Cafe", "Moes Tavern", "Central Perk", "Chasers"] # noqa
|
||||
for i, name in enumerate(names):
|
||||
with reversion.create_revision():
|
||||
reversion.set_user(random.choice(models.Profile.objects.all()))
|
||||
new_organisation = models.Organisation.objects.create(name=name)
|
||||
|
||||
reversion.set_user(random.choice(self.profiles))
|
||||
newOrganisation = models.Organisation.objects.create(name=name)
|
||||
if i % 2 == 0:
|
||||
new_organisation.has_su_account = True
|
||||
newOrganisation.has_su_account = True
|
||||
|
||||
if i % 3 == 0:
|
||||
new_organisation.email = "address@organisation.com"
|
||||
newOrganisation.email = "address@organisation.com"
|
||||
|
||||
if i % 5 == 0:
|
||||
new_organisation.notes = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua"
|
||||
newOrganisation.notes = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua"
|
||||
|
||||
if i % 7 == 0:
|
||||
new_organisation.address = "1 Organisation Test Street \n Demoton \n United States of TEC \n RMRF 567"
|
||||
newOrganisation.address = "1 Organisation Test Street \n Demoton \n United States of TEC \n RMRF 567"
|
||||
|
||||
if i % 9 == 0:
|
||||
new_organisation.phone = "01234 567894"
|
||||
newOrganisation.phone = "01234 567894"
|
||||
|
||||
new_organisation.save()
|
||||
self.organisations.append(new_organisation)
|
||||
newOrganisation.save()
|
||||
self.organisations.append(newOrganisation)
|
||||
|
||||
def setup_venues(self):
|
||||
def setupVenues(self):
|
||||
names = ["Bear Island", "Crossroads Inn", "Deepwood Motte", "The Dreadfort", "The Eyrie", "Greywater Watch",
|
||||
"The Iron Islands", "Karhold", "Moat Cailin", "Oldstones", "Raventree Hall", "Riverlands",
|
||||
"The Ruby Ford", "Saltpans", "Seagard", "Torrhen's Square", "The Trident", "The Twins",
|
||||
@@ -135,27 +144,108 @@ class Command(BaseCommand):
|
||||
for i, name in enumerate(names):
|
||||
with reversion.create_revision():
|
||||
reversion.set_user(random.choice(self.profiles))
|
||||
new_venue = models.Venue.objects.create(name=name)
|
||||
|
||||
newVenue = models.Venue.objects.create(name=name)
|
||||
if i % 2 == 0:
|
||||
new_venue.three_phase_available = True
|
||||
newVenue.three_phase_available = True
|
||||
|
||||
if i % 3 == 0:
|
||||
new_venue.email = "address@venue.com"
|
||||
newVenue.email = "address@venue.com"
|
||||
|
||||
if i % 5 == 0:
|
||||
new_venue.notes = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua"
|
||||
newVenue.notes = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua"
|
||||
|
||||
if i % 7 == 0:
|
||||
new_venue.address = "1 Venue Test Street \n Demoton \n United States of TEC \n RMRF 567"
|
||||
newVenue.address = "1 Venue Test Street \n Demoton \n United States of TEC \n RMRF 567"
|
||||
|
||||
if i % 9 == 0:
|
||||
new_venue.phone = "01234 567894"
|
||||
newVenue.phone = "01234 567894"
|
||||
|
||||
new_venue.save()
|
||||
self.venues.append(new_venue)
|
||||
newVenue.save()
|
||||
self.venues.append(newVenue)
|
||||
|
||||
def setup_events(self):
|
||||
def setupGroups(self):
|
||||
self.keyholder_group = Group.objects.create(name='Keyholders')
|
||||
self.finance_group = Group.objects.create(name='Finance')
|
||||
self.hs_group = Group.objects.create(name='H&S')
|
||||
|
||||
keyholderPerms = ["add_event", "change_event", "view_event",
|
||||
"add_eventitem", "change_eventitem", "delete_eventitem",
|
||||
"add_organisation", "change_organisation", "view_organisation",
|
||||
"add_person", "change_person", "view_person", "view_profile",
|
||||
"add_venue", "change_venue", "view_venue",
|
||||
"add_asset", "change_asset", "delete_asset",
|
||||
"view_asset", "view_supplier", "change_supplier", "asset_finance",
|
||||
"add_supplier", "view_cabletype", "change_cabletype",
|
||||
"add_cabletype", "view_eventchecklist", "change_eventchecklist",
|
||||
"add_eventchecklist", "view_riskassessment", "change_riskassessment",
|
||||
"add_riskassessment", "add_eventchecklistcrew", "change_eventchecklistcrew",
|
||||
"delete_eventchecklistcrew", "view_eventchecklistcrew", "add_eventchecklistvehicle",
|
||||
"change_eventchecklistvehicle",
|
||||
"delete_eventchecklistvehicle", "view_eventchecklistvehicle", ]
|
||||
financePerms = keyholderPerms + ["add_invoice", "change_invoice", "view_invoice",
|
||||
"add_payment", "change_payment", "delete_payment"]
|
||||
hsPerms = keyholderPerms + ["review_riskassessment", "review_eventchecklist"]
|
||||
|
||||
for permId in keyholderPerms:
|
||||
self.keyholder_group.permissions.add(Permission.objects.get(codename=permId))
|
||||
|
||||
for permId in financePerms:
|
||||
self.finance_group.permissions.add(Permission.objects.get(codename=permId))
|
||||
|
||||
for permId in hsPerms:
|
||||
self.hs_group.permissions.add(Permission.objects.get(codename=permId))
|
||||
|
||||
def setupGenericProfiles(self):
|
||||
names = ["Clara Oswin Oswald", "Rory Williams", "Amy Pond", "River Song", "Martha Jones", "Donna Noble",
|
||||
"Jack Harkness", "Mickey Smith", "Rose Tyler"]
|
||||
for i, name in enumerate(names):
|
||||
newProfile = models.Profile.objects.create(username=name.replace(" ", ""), first_name=name.split(" ")[0],
|
||||
last_name=name.split(" ")[-1],
|
||||
email=name.replace(" ", "") + "@example.com",
|
||||
initials="".join([j[0].upper() for j in name.split()]))
|
||||
if i % 2 == 0:
|
||||
newProfile.phone = "01234 567894"
|
||||
|
||||
newProfile.save()
|
||||
self.profiles.append(newProfile)
|
||||
|
||||
def setupUsefulProfiles(self):
|
||||
superUser = models.Profile.objects.create(username="superuser", first_name="Super", last_name="User",
|
||||
initials="SU",
|
||||
email="superuser@example.com", is_superuser=True, is_active=True,
|
||||
is_staff=True)
|
||||
superUser.set_password('superuser')
|
||||
superUser.save()
|
||||
|
||||
financeUser = models.Profile.objects.create(username="finance", first_name="Finance", last_name="User",
|
||||
initials="FU",
|
||||
email="financeuser@example.com", is_active=True, is_approved=True)
|
||||
financeUser.groups.add(self.finance_group)
|
||||
financeUser.groups.add(self.keyholder_group)
|
||||
financeUser.set_password('finance')
|
||||
financeUser.save()
|
||||
|
||||
hsUser = models.Profile.objects.create(username="hs", first_name="HS", last_name="User",
|
||||
initials="HSU",
|
||||
email="hsuser@example.com", is_active=True, is_approved=True)
|
||||
hsUser.groups.add(self.hs_group)
|
||||
hsUser.groups.add(self.keyholder_group)
|
||||
hsUser.set_password('hs')
|
||||
hsUser.save()
|
||||
|
||||
keyholderUser = models.Profile.objects.create(username="keyholder", first_name="Keyholder", last_name="User",
|
||||
initials="KU",
|
||||
email="keyholderuser@example.com", is_active=True, is_approved=True)
|
||||
keyholderUser.groups.add(self.keyholder_group)
|
||||
keyholderUser.set_password('keyholder')
|
||||
keyholderUser.save()
|
||||
|
||||
basicUser = models.Profile.objects.create(username="basic", first_name="Basic", last_name="User", initials="BU",
|
||||
email="basicuser@example.com", is_active=True, is_approved=True)
|
||||
basicUser.set_password('basic')
|
||||
basicUser.save()
|
||||
|
||||
def setupEvents(self):
|
||||
names = ["Outdoor Concert", "Hall Open Mic Night", "Festival", "Weekend Event", "Magic Show", "Society Ball",
|
||||
"Evening Show", "Talent Show", "Acoustic Evening", "Hire of Things", "SU Event",
|
||||
"End of Term Show", "Theatre Show", "Outdoor Fun Day", "Summer Carnival", "Open Days", "Magic Show",
|
||||
@@ -166,7 +256,7 @@ class Command(BaseCommand):
|
||||
notes = ["The client came into the office at some point", "Who knows if this will happen",
|
||||
"Probably should check this event", "Maybe not happening", "Run away!"]
|
||||
|
||||
item_options = [
|
||||
itemOptions = [
|
||||
{'name': 'Speakers', 'description': 'Some really really big speakers \n these are very loud', 'quantity': 2,
|
||||
'cost': 200.00},
|
||||
{'name': 'Projector',
|
||||
@@ -183,7 +273,7 @@ class Command(BaseCommand):
|
||||
{'name': 'Crew', 'description': 'Costs nothing, because reasons', 'quantity': 1, 'cost': 0.00},
|
||||
{'name': 'Loyalty Discount', 'description': 'Have some negative moneys', 'quantity': 1, 'cost': -50.00}]
|
||||
|
||||
day_delta = -120 # start adding events from 4 months ago
|
||||
dayDelta = -120 # start adding events from 4 months ago
|
||||
|
||||
for i in range(150): # Let's add 100 events
|
||||
with reversion.create_revision():
|
||||
@@ -191,100 +281,65 @@ class Command(BaseCommand):
|
||||
|
||||
name = names[i % len(names)]
|
||||
|
||||
start_date = datetime.date.today() + datetime.timedelta(days=day_delta)
|
||||
day_delta = day_delta + random.randint(0, 3)
|
||||
startDate = datetime.date.today() + datetime.timedelta(days=dayDelta)
|
||||
dayDelta = dayDelta + random.randint(0, 3)
|
||||
|
||||
new_event = models.Event.objects.create(name=name, start_date=start_date)
|
||||
newEvent = models.Event.objects.create(name=name, start_date=startDate)
|
||||
|
||||
if random.randint(0, 2) > 1: # 1 in 3 have a start time
|
||||
new_event.start_time = datetime.time(random.randint(15, 20))
|
||||
newEvent.start_time = datetime.time(random.randint(15, 20))
|
||||
if random.randint(0, 2) > 1: # of those, 1 in 3 have an end time on the same day
|
||||
new_event.end_time = datetime.time(random.randint(21, 23))
|
||||
newEvent.end_time = datetime.time(random.randint(21, 23))
|
||||
elif random.randint(0, 1) > 0: # half of the others finish early the next day
|
||||
new_event.end_date = new_event.start_date + datetime.timedelta(days=1)
|
||||
new_event.end_time = datetime.time(random.randint(0, 5))
|
||||
newEvent.end_date = newEvent.start_date + datetime.timedelta(days=1)
|
||||
newEvent.end_time = datetime.time(random.randint(0, 5))
|
||||
elif random.randint(0, 2) > 1: # 1 in 3 of the others finish a few days ahead
|
||||
new_event.end_date = new_event.start_date + datetime.timedelta(days=random.randint(1, 4))
|
||||
newEvent.end_date = newEvent.start_date + datetime.timedelta(days=random.randint(1, 4))
|
||||
|
||||
if random.randint(0, 6) > 0: # 5 in 6 have MIC
|
||||
new_event.mic = random.choice(self.profiles)
|
||||
newEvent.mic = random.choice(self.profiles)
|
||||
|
||||
if random.randint(0, 6) > 0: # 5 in 6 have organisation
|
||||
new_event.organisation = random.choice(self.organisations)
|
||||
newEvent.organisation = random.choice(self.organisations)
|
||||
|
||||
if random.randint(0, 6) > 0: # 5 in 6 have person
|
||||
new_event.person = random.choice(self.people)
|
||||
newEvent.person = random.choice(self.people)
|
||||
|
||||
if random.randint(0, 6) > 0: # 5 in 6 have venue
|
||||
new_event.venue = random.choice(self.venues)
|
||||
newEvent.venue = random.choice(self.venues)
|
||||
|
||||
# Could have any status, equally weighted
|
||||
new_event.status = random.choice(
|
||||
newEvent.status = random.choice(
|
||||
[models.Event.BOOKED, models.Event.CONFIRMED, models.Event.PROVISIONAL, models.Event.CANCELLED])
|
||||
|
||||
new_event.dry_hire = (random.randint(0, 7) == 0) # 1 in 7 are dry hire
|
||||
newEvent.dry_hire = (random.randint(0, 7) == 0) # 1 in 7 are dry hire
|
||||
|
||||
if random.randint(0, 1) > 0: # 1 in 2 have description
|
||||
new_event.description = random.choice(descriptions)
|
||||
newEvent.description = random.choice(descriptions)
|
||||
|
||||
if random.randint(0, 1) > 0: # 1 in 2 have notes
|
||||
new_event.notes = random.choice(notes)
|
||||
newEvent.notes = random.choice(notes)
|
||||
|
||||
new_event.save()
|
||||
newEvent.save()
|
||||
|
||||
# Now add some items
|
||||
for j in range(random.randint(1, 5)):
|
||||
item_data = item_options[random.randint(0, len(item_options) - 1)]
|
||||
new_item = models.EventItem.objects.create(event=new_event, order=j, **item_data)
|
||||
new_item.save()
|
||||
itemData = itemOptions[random.randint(0, len(itemOptions) - 1)]
|
||||
newItem = models.EventItem.objects.create(event=newEvent, order=j, **itemData)
|
||||
newItem.save()
|
||||
|
||||
while new_event.sum_total < 0:
|
||||
item_data = item_options[random.randint(0, len(item_options) - 1)]
|
||||
new_item = models.EventItem.objects.create(event=new_event, order=j, **item_data)
|
||||
new_item.save()
|
||||
while newEvent.sum_total < 0:
|
||||
itemData = itemOptions[random.randint(0, len(itemOptions) - 1)]
|
||||
newItem = models.EventItem.objects.create(event=newEvent, order=j, **itemData)
|
||||
newItem.save()
|
||||
|
||||
with reversion.create_revision():
|
||||
reversion.set_user(random.choice(self.profiles))
|
||||
if new_event.start_date < datetime.date.today(): # think about adding an invoice
|
||||
if newEvent.start_date < datetime.date.today(): # think about adding an invoice
|
||||
if random.randint(0, 2) > 0: # 2 in 3 have had paperwork sent to treasury
|
||||
new_invoice = models.Invoice.objects.create(event=new_event)
|
||||
if new_event.status is models.Event.CANCELLED: # void cancelled events
|
||||
new_invoice.void = True
|
||||
newInvoice = models.Invoice.objects.create(event=newEvent)
|
||||
if newEvent.status is models.Event.CANCELLED: # void cancelled events
|
||||
newInvoice.void = True
|
||||
elif random.randint(0, 2) > 1: # 1 in 3 have been paid
|
||||
models.Payment.objects.create(invoice=new_invoice, amount=new_invoice.balance,
|
||||
models.Payment.objects.create(invoice=newInvoice, amount=newInvoice.balance,
|
||||
date=datetime.date.today())
|
||||
if i == 1 or random.randint(0, 5) > 0: # Event 1 and 1 in 5 have a RA
|
||||
models.RiskAssessment.objects.create(event=new_event, supervisor_consulted=bool(random.getrandbits(1)),
|
||||
nonstandard_equipment=bool(random.getrandbits(1)),
|
||||
nonstandard_use=bool(random.getrandbits(1)),
|
||||
contractors=bool(random.getrandbits(1)),
|
||||
other_companies=bool(random.getrandbits(1)),
|
||||
crew_fatigue=bool(random.getrandbits(1)),
|
||||
big_power=bool(random.getrandbits(1)),
|
||||
generators=bool(random.getrandbits(1)),
|
||||
other_companies_power=bool(random.getrandbits(1)),
|
||||
nonstandard_equipment_power=bool(random.getrandbits(1)),
|
||||
multiple_electrical_environments=bool(random.getrandbits(1)),
|
||||
noise_monitoring=bool(random.getrandbits(1)),
|
||||
known_venue=bool(random.getrandbits(1)),
|
||||
safe_loading=bool(random.getrandbits(1)),
|
||||
safe_storage=bool(random.getrandbits(1)),
|
||||
area_outside_of_control=bool(random.getrandbits(1)),
|
||||
barrier_required=bool(random.getrandbits(1)),
|
||||
nonstandard_emergency_procedure=bool(random.getrandbits(1)),
|
||||
special_structures=bool(random.getrandbits(1)),
|
||||
suspended_structures=bool(random.getrandbits(1)),
|
||||
outside=bool(random.getrandbits(1)))
|
||||
if i == 0 or random.randint(0, 1) > 0: # Event 1 and 1 in 10 have a Checklist
|
||||
models.EventChecklist.objects.create(event=new_event, power_mic=random.choice(self.profiles),
|
||||
safe_parking=bool(random.getrandbits(1)),
|
||||
safe_packing=bool(random.getrandbits(1)),
|
||||
exits=bool(random.getrandbits(1)),
|
||||
trip_hazard=bool(random.getrandbits(1)),
|
||||
warning_signs=bool(random.getrandbits(1)),
|
||||
ear_plugs=bool(random.getrandbits(1)),
|
||||
hs_location="Locked away safely",
|
||||
extinguishers_location="Somewhere, I forgot",
|
||||
earthing=bool(random.getrandbits(1)),
|
||||
pat=bool(random.getrandbits(1)),
|
||||
date=timezone.now(), venue=random.choice(self.venues))
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Generated by Django 2.0.13 on 2020-01-11 18:29
|
||||
# This migration ensures that legacy Profiles from before approvals were implemented are automatically approved
|
||||
# This migration ensures that legacy Profiles from before approvals were implemented are automatically approved
|
||||
from django.db import migrations
|
||||
|
||||
def approve_legacy(apps, schema_editor):
|
||||
@@ -15,5 +15,5 @@ class Migration(migrations.Migration):
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(approve_legacy, migrations.RunPython.noop)
|
||||
migrations.RunPython(approve_legacy)
|
||||
]
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
# Generated by Django 3.1.5 on 2021-02-06 10:43
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('RIGS', '0039_auto_20210123_1910'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='profile',
|
||||
name='dark_theme',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
]
|
||||
@@ -1,199 +0,0 @@
|
||||
# Generated by Django 3.1.5 on 2021-02-08 16:03
|
||||
|
||||
import RIGS.models
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('RIGS', '0040_profile_dark_theme'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='event',
|
||||
name='auth_request_to',
|
||||
field=models.EmailField(blank=True, default='', max_length=254),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='event',
|
||||
name='collector',
|
||||
field=models.CharField(blank=True, default='', max_length=255, verbose_name='collected by'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='event',
|
||||
name='description',
|
||||
field=models.TextField(blank=True, default=''),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='event',
|
||||
name='meet_info',
|
||||
field=models.CharField(blank=True, default='', max_length=255),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='event',
|
||||
name='notes',
|
||||
field=models.TextField(blank=True, default=''),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='event',
|
||||
name='payment_method',
|
||||
field=models.CharField(blank=True, default='', max_length=255),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='event',
|
||||
name='payment_received',
|
||||
field=models.CharField(blank=True, default='', max_length=255),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='event',
|
||||
name='purchase_order',
|
||||
field=models.CharField(blank=True, default='', max_length=255, verbose_name='PO'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='eventauthorisation',
|
||||
name='account_code',
|
||||
field=models.CharField(blank=True, default='', max_length=50),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='eventauthorisation',
|
||||
name='uni_id',
|
||||
field=models.CharField(blank=True, default='', max_length=10, verbose_name='University ID'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='eventchecklist',
|
||||
name='extinguishers_location',
|
||||
field=models.CharField(blank=True, default='', help_text='Location of fire extinguishers', max_length=255),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='eventchecklist',
|
||||
name='hs_location',
|
||||
field=models.CharField(blank=True, default='', help_text='Location of Safety Bag/Box', max_length=255),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='eventchecklist',
|
||||
name='w1_description',
|
||||
field=models.CharField(blank=True, default='', help_text='Description', max_length=255),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='eventchecklist',
|
||||
name='w2_description',
|
||||
field=models.CharField(blank=True, default='', help_text='Description', max_length=255),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='eventchecklist',
|
||||
name='w3_description',
|
||||
field=models.CharField(blank=True, default='', help_text='Description', max_length=255),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='eventitem',
|
||||
name='description',
|
||||
field=models.TextField(blank=True, default=''),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='organisation',
|
||||
name='address',
|
||||
field=models.TextField(blank=True, default=''),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='organisation',
|
||||
name='email',
|
||||
field=models.EmailField(blank=True, default='', max_length=254),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='organisation',
|
||||
name='notes',
|
||||
field=models.TextField(blank=True, default=''),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='organisation',
|
||||
name='phone',
|
||||
field=models.CharField(blank=True, default='', max_length=15),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='payment',
|
||||
name='method',
|
||||
field=models.CharField(blank=True, choices=[('C', 'Cash'), ('I', 'Internal'), ('E', 'External'), ('SU', 'SU Core'), ('T', 'TEC Adjustment')], default='', max_length=2),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='person',
|
||||
name='address',
|
||||
field=models.TextField(blank=True, default=''),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='person',
|
||||
name='email',
|
||||
field=models.EmailField(blank=True, default='', max_length=254),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='person',
|
||||
name='notes',
|
||||
field=models.TextField(blank=True, default=''),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='person',
|
||||
name='phone',
|
||||
field=models.CharField(blank=True, default='', max_length=15),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='profile',
|
||||
name='api_key',
|
||||
field=models.CharField(blank=True, default='', editable=False, max_length=40),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='profile',
|
||||
name='phone',
|
||||
field=models.CharField(default='', max_length=13, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='riskassessment',
|
||||
name='general_notes',
|
||||
field=models.TextField(blank=True, default='', help_text='Did you have to consult a supervisor about any of the above? If so who did you consult and what was the outcome?'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='riskassessment',
|
||||
name='persons_responsible_structures',
|
||||
field=models.TextField(blank=True, default='', help_text='Who are the persons on site responsible for their use?'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='riskassessment',
|
||||
name='power_notes',
|
||||
field=models.TextField(blank=True, default='', help_text='Did you have to consult a supervisor about any of the above? If so who did you consult and what was the outcome?'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='riskassessment',
|
||||
name='power_plan',
|
||||
field=models.URLField(blank=True, default='', help_text="Upload your power plan to the <a href='https://nottinghamtec.sharepoint.com/'>Sharepoint</a> and submit a link", validators=[RIGS.models.validate_url]),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='riskassessment',
|
||||
name='rigging_plan',
|
||||
field=models.URLField(blank=True, default='', help_text="Upload your rigging plan to the <a href='https://nottinghamtec.sharepoint.com/'>Sharepoint</a> and submit a link", validators=[RIGS.models.validate_url]),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='riskassessment',
|
||||
name='sound_notes',
|
||||
field=models.TextField(blank=True, default='', help_text='Did you have to consult a supervisor about any of the above? If so who did you consult and what was the outcome?'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='venue',
|
||||
name='address',
|
||||
field=models.TextField(blank=True, default=''),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='venue',
|
||||
name='email',
|
||||
field=models.EmailField(blank=True, default='', max_length=254),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='venue',
|
||||
name='notes',
|
||||
field=models.TextField(blank=True, default=''),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='venue',
|
||||
name='phone',
|
||||
field=models.CharField(blank=True, default='', max_length=15),
|
||||
),
|
||||
]
|
||||
@@ -1,18 +0,0 @@
|
||||
# Generated by Django 3.1.7 on 2021-03-02 11:21
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('RIGS', '0041_auto_20210208_1603'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='profile',
|
||||
name='phone',
|
||||
field=models.CharField(blank=True, default='', max_length=13),
|
||||
),
|
||||
]
|
||||
132
RIGS/models.py
132
RIGS/models.py
@@ -12,7 +12,7 @@ from django.conf import settings
|
||||
from django.contrib.auth.models import AbstractUser
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db import models
|
||||
from django.urls import reverse
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils import timezone
|
||||
from django.utils.functional import cached_property
|
||||
from reversion import revisions as reversion
|
||||
@@ -21,12 +21,11 @@ from reversion.models import Version
|
||||
|
||||
class Profile(AbstractUser):
|
||||
initials = models.CharField(max_length=5, unique=True, null=True, blank=False)
|
||||
phone = models.CharField(max_length=13, blank=True, default='')
|
||||
api_key = models.CharField(max_length=40, blank=True, editable=False, default='')
|
||||
phone = models.CharField(max_length=13, null=True, blank=True)
|
||||
api_key = models.CharField(max_length=40, blank=True, editable=False, null=True)
|
||||
is_approved = models.BooleanField(default=False)
|
||||
# Currently only populated by the admin approval email. TODO: Populate it each time we send any email, might need that...
|
||||
last_emailed = models.DateTimeField(blank=True, null=True)
|
||||
dark_theme = models.BooleanField(default=False)
|
||||
last_emailed = models.DateTimeField(blank=True,
|
||||
null=True) # Currently only populated by the admin approval email. TODO: Populate it each time we send any email, might need that...
|
||||
|
||||
@classmethod
|
||||
def make_api_key(cls):
|
||||
@@ -52,7 +51,7 @@ class Profile(AbstractUser):
|
||||
|
||||
@property
|
||||
def latest_events(self):
|
||||
return self.event_mic.order_by('-start_date').select_related('person', 'organisation', 'venue', 'mic', 'riskassessment', 'invoice').prefetch_related('checklists')
|
||||
return self.event_mic.order_by('-start_date').select_related('person', 'organisation', 'venue', 'mic')
|
||||
|
||||
@classmethod
|
||||
def admins(cls):
|
||||
@@ -103,12 +102,12 @@ class RevisionMixin(object):
|
||||
|
||||
class Person(models.Model, RevisionMixin):
|
||||
name = models.CharField(max_length=50)
|
||||
phone = models.CharField(max_length=15, blank=True, default='')
|
||||
email = models.EmailField(blank=True, default='')
|
||||
phone = models.CharField(max_length=15, blank=True, null=True)
|
||||
email = models.EmailField(blank=True, null=True)
|
||||
|
||||
address = models.TextField(blank=True, default='')
|
||||
address = models.TextField(blank=True, null=True)
|
||||
|
||||
notes = models.TextField(blank=True, default='')
|
||||
notes = models.TextField(blank=True, null=True)
|
||||
|
||||
def __str__(self):
|
||||
string = self.name
|
||||
@@ -134,17 +133,17 @@ class Person(models.Model, RevisionMixin):
|
||||
return self.event_set.order_by('-start_date').select_related('person', 'organisation', 'venue', 'mic')
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('person_detail', kwargs={'pk': self.pk})
|
||||
return reverse_lazy('person_detail', kwargs={'pk': self.pk})
|
||||
|
||||
|
||||
class Organisation(models.Model, RevisionMixin):
|
||||
name = models.CharField(max_length=50)
|
||||
phone = models.CharField(max_length=15, blank=True, default='')
|
||||
email = models.EmailField(blank=True, default='')
|
||||
phone = models.CharField(max_length=15, blank=True, null=True)
|
||||
email = models.EmailField(blank=True, null=True)
|
||||
|
||||
address = models.TextField(blank=True, default='')
|
||||
address = models.TextField(blank=True, null=True)
|
||||
|
||||
notes = models.TextField(blank=True, default='')
|
||||
notes = models.TextField(blank=True, null=True)
|
||||
union_account = models.BooleanField(default=False)
|
||||
|
||||
def __str__(self):
|
||||
@@ -171,7 +170,7 @@ class Organisation(models.Model, RevisionMixin):
|
||||
return self.event_set.order_by('-start_date').select_related('person', 'organisation', 'venue', 'mic')
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('organisation_detail', kwargs={'pk': self.pk})
|
||||
return reverse_lazy('organisation_detail', kwargs={'pk': self.pk})
|
||||
|
||||
|
||||
class VatManager(models.Manager):
|
||||
@@ -179,6 +178,7 @@ class VatManager(models.Manager):
|
||||
return self.find_rate(timezone.now())
|
||||
|
||||
def find_rate(self, date):
|
||||
# return self.filter(startAt__lte=date).latest()
|
||||
try:
|
||||
return self.filter(start_at__lte=date).latest()
|
||||
except VatRate.DoesNotExist:
|
||||
@@ -211,12 +211,12 @@ class VatRate(models.Model, RevisionMixin):
|
||||
|
||||
class Venue(models.Model, RevisionMixin):
|
||||
name = models.CharField(max_length=255)
|
||||
phone = models.CharField(max_length=15, blank=True, default='')
|
||||
email = models.EmailField(blank=True, default='')
|
||||
phone = models.CharField(max_length=15, blank=True, null=True)
|
||||
email = models.EmailField(blank=True, null=True)
|
||||
three_phase_available = models.BooleanField(default=False)
|
||||
notes = models.TextField(blank=True, default='')
|
||||
notes = models.TextField(blank=True, null=True)
|
||||
|
||||
address = models.TextField(blank=True, default='')
|
||||
address = models.TextField(blank=True, null=True)
|
||||
|
||||
def __str__(self):
|
||||
string = self.name
|
||||
@@ -229,23 +229,24 @@ class Venue(models.Model, RevisionMixin):
|
||||
return self.event_set.order_by('-start_date').select_related('person', 'organisation', 'venue', 'mic')
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('venue_detail', kwargs={'pk': self.pk})
|
||||
return reverse_lazy('venue_detail', kwargs={'pk': self.pk})
|
||||
|
||||
|
||||
class EventManager(models.Manager):
|
||||
def current_events(self):
|
||||
events = self.filter(
|
||||
(models.Q(start_date__gte=timezone.now(), end_date__isnull=True, dry_hire=False) & ~models.Q(
|
||||
(models.Q(start_date__gte=timezone.now().date(), end_date__isnull=True, dry_hire=False) & ~models.Q(
|
||||
status=Event.CANCELLED)) | # Starts after with no end
|
||||
(models.Q(end_date__gte=timezone.now().date(), dry_hire=False) & ~models.Q(
|
||||
status=Event.CANCELLED)) | # Ends after
|
||||
(models.Q(dry_hire=True, start_date__gte=timezone.now()) & ~models.Q(
|
||||
(models.Q(dry_hire=True, start_date__gte=timezone.now().date()) & ~models.Q(
|
||||
status=Event.CANCELLED)) | # Active dry hire
|
||||
(models.Q(dry_hire=True, checked_in_by__isnull=True) & (
|
||||
models.Q(status=Event.BOOKED) | models.Q(status=Event.CONFIRMED))) | # Active dry hire GT
|
||||
models.Q(status=Event.CANCELLED, start_date__gte=timezone.now()) # Canceled but not started
|
||||
).order_by('start_date', 'end_date', 'start_time', 'end_time', 'meet_at').select_related('person', 'organisation', 'venue', 'mic')
|
||||
|
||||
models.Q(status=Event.CANCELLED, start_date__gte=timezone.now().date()) # Canceled but not started
|
||||
).order_by('start_date', 'end_date', 'start_time', 'end_time', 'meet_at').select_related('person',
|
||||
'organisation',
|
||||
'venue', 'mic')
|
||||
return events
|
||||
|
||||
def events_in_bounds(self, start, end):
|
||||
@@ -268,12 +269,12 @@ class EventManager(models.Manager):
|
||||
|
||||
def rig_count(self):
|
||||
event_count = self.filter(
|
||||
(models.Q(start_date__gte=timezone.now(), end_date__isnull=True, dry_hire=False,
|
||||
(models.Q(start_date__gte=timezone.now().date(), end_date__isnull=True, dry_hire=False,
|
||||
is_rig=True) & ~models.Q(
|
||||
status=Event.CANCELLED)) | # Starts after with no end
|
||||
(models.Q(end_date__gte=timezone.now(), dry_hire=False, is_rig=True) & ~models.Q(
|
||||
(models.Q(end_date__gte=timezone.now().date(), dry_hire=False, is_rig=True) & ~models.Q(
|
||||
status=Event.CANCELLED)) | # Ends after
|
||||
(models.Q(dry_hire=True, start_date__gte=timezone.now(), is_rig=True) & ~models.Q(
|
||||
(models.Q(dry_hire=True, start_date__gte=timezone.now().date(), is_rig=True) & ~models.Q(
|
||||
status=Event.CANCELLED)) # Active dry hire
|
||||
).count()
|
||||
return event_count
|
||||
@@ -297,8 +298,8 @@ class Event(models.Model, RevisionMixin):
|
||||
person = models.ForeignKey('Person', null=True, blank=True, on_delete=models.CASCADE)
|
||||
organisation = models.ForeignKey('Organisation', blank=True, null=True, on_delete=models.CASCADE)
|
||||
venue = models.ForeignKey('Venue', blank=True, null=True, on_delete=models.CASCADE)
|
||||
description = models.TextField(blank=True, default='')
|
||||
notes = models.TextField(blank=True, default='')
|
||||
description = models.TextField(blank=True, null=True)
|
||||
notes = models.TextField(blank=True, null=True)
|
||||
status = models.IntegerField(choices=EVENT_STATUS_CHOICES, default=PROVISIONAL)
|
||||
dry_hire = models.BooleanField(default=False)
|
||||
is_rig = models.BooleanField(default=True)
|
||||
@@ -312,7 +313,7 @@ class Event(models.Model, RevisionMixin):
|
||||
end_time = models.TimeField(blank=True, null=True)
|
||||
access_at = models.DateTimeField(blank=True, null=True)
|
||||
meet_at = models.DateTimeField(blank=True, null=True)
|
||||
meet_info = models.CharField(max_length=255, blank=True, default='')
|
||||
meet_info = models.CharField(max_length=255, blank=True, null=True)
|
||||
|
||||
# Crew management
|
||||
checked_in_by = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='event_checked_in', blank=True, null=True,
|
||||
@@ -321,15 +322,15 @@ class Event(models.Model, RevisionMixin):
|
||||
verbose_name="MIC", on_delete=models.CASCADE)
|
||||
|
||||
# Monies
|
||||
payment_method = models.CharField(max_length=255, blank=True, default='')
|
||||
payment_received = models.CharField(max_length=255, blank=True, default='')
|
||||
purchase_order = models.CharField(max_length=255, blank=True, default='', verbose_name='PO')
|
||||
collector = models.CharField(max_length=255, blank=True, default='', verbose_name='collected by')
|
||||
payment_method = models.CharField(max_length=255, blank=True, null=True)
|
||||
payment_received = models.CharField(max_length=255, blank=True, null=True)
|
||||
purchase_order = models.CharField(max_length=255, blank=True, null=True, verbose_name='PO')
|
||||
collector = models.CharField(max_length=255, blank=True, null=True, verbose_name='collected by')
|
||||
|
||||
# Authorisation request details
|
||||
auth_request_by = models.ForeignKey('Profile', null=True, blank=True, on_delete=models.CASCADE)
|
||||
auth_request_at = models.DateTimeField(null=True, blank=True)
|
||||
auth_request_to = models.EmailField(blank=True, default='')
|
||||
auth_request_to = models.EmailField(null=True, blank=True)
|
||||
|
||||
@property
|
||||
def display_id(self):
|
||||
@@ -345,7 +346,7 @@ class Event(models.Model, RevisionMixin):
|
||||
|
||||
@property
|
||||
def sum_total(self):
|
||||
total = self.items.aggregate(
|
||||
total = EventItem.objects.filter(event=self).aggregate(
|
||||
sum_total=models.Sum(models.F('cost') * models.F('quantity'),
|
||||
output_field=models.DecimalField(max_digits=10, decimal_places=2))
|
||||
)['sum_total']
|
||||
@@ -455,7 +456,7 @@ class Event(models.Model, RevisionMixin):
|
||||
objects = EventManager()
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('event_detail', kwargs={'pk': self.pk})
|
||||
return reverse_lazy('event_detail', kwargs={'pk': self.pk})
|
||||
|
||||
def __str__(self):
|
||||
return "{}: {}".format(self.display_id, self.name)
|
||||
@@ -489,7 +490,7 @@ class Event(models.Model, RevisionMixin):
|
||||
class EventItem(models.Model, RevisionMixin):
|
||||
event = models.ForeignKey('Event', related_name='items', blank=True, on_delete=models.CASCADE)
|
||||
name = models.CharField(max_length=255)
|
||||
description = models.TextField(blank=True, default='')
|
||||
description = models.TextField(blank=True, null=True)
|
||||
quantity = models.IntegerField()
|
||||
cost = models.DecimalField(max_digits=10, decimal_places=2)
|
||||
order = models.IntegerField()
|
||||
@@ -504,7 +505,7 @@ class EventItem(models.Model, RevisionMixin):
|
||||
ordering = ['order']
|
||||
|
||||
def __str__(self):
|
||||
return "{}.{}: {} | {}".format(self.event_id, self.order, self.event.name, self.name)
|
||||
return str(self.event.pk) + "." + str(self.order) + ": " + self.event.name + " | " + self.name
|
||||
|
||||
@property
|
||||
def activity_feed_string(self):
|
||||
@@ -516,13 +517,13 @@ class EventAuthorisation(models.Model, RevisionMixin):
|
||||
event = models.OneToOneField('Event', related_name='authorisation', on_delete=models.CASCADE)
|
||||
email = models.EmailField()
|
||||
name = models.CharField(max_length=255)
|
||||
uni_id = models.CharField(max_length=10, blank=True, default='', verbose_name="University ID")
|
||||
account_code = models.CharField(max_length=50, default='', blank=True)
|
||||
uni_id = models.CharField(max_length=10, blank=True, null=True, verbose_name="University ID")
|
||||
account_code = models.CharField(max_length=50, blank=True, null=True)
|
||||
amount = models.DecimalField(max_digits=10, decimal_places=2, verbose_name="authorisation amount")
|
||||
sent_by = models.ForeignKey('Profile', on_delete=models.CASCADE)
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('event_detail', kwargs={'pk': self.event_id})
|
||||
return reverse_lazy('event_detail', kwargs={'pk': self.event.pk})
|
||||
|
||||
@property
|
||||
def activity_feed_string(self):
|
||||
@@ -561,11 +562,11 @@ class Invoice(models.Model, RevisionMixin):
|
||||
return self.balance == 0 or self.void
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('invoice_detail', kwargs={'pk': self.pk})
|
||||
return reverse_lazy('invoice_detail', kwargs={'pk': self.pk})
|
||||
|
||||
@property
|
||||
def activity_feed_string(self):
|
||||
return "#{} for Event {}".format(self.display_id, self.event.display_id)
|
||||
return "#{} for Event {}".format(self.display_id, "N%05d" % self.event.pk)
|
||||
|
||||
def __str__(self):
|
||||
return "%i: %s (%.2f)" % (self.pk, self.event, self.balance)
|
||||
@@ -596,7 +597,7 @@ class Payment(models.Model, RevisionMixin):
|
||||
invoice = models.ForeignKey('Invoice', on_delete=models.CASCADE)
|
||||
date = models.DateField()
|
||||
amount = models.DecimalField(max_digits=10, decimal_places=2, help_text='Please use ex. VAT')
|
||||
method = models.CharField(max_length=2, choices=METHODS, default='', blank=True)
|
||||
method = models.CharField(max_length=2, choices=METHODS, null=True, blank=True)
|
||||
|
||||
reversion_hide = True
|
||||
|
||||
@@ -631,9 +632,10 @@ class RiskAssessment(models.Model, RevisionMixin):
|
||||
contractors = models.BooleanField(help_text="Are you using any external contractors?<br><small>i.e. Freelancers/Crewing Companies</small>")
|
||||
other_companies = models.BooleanField(help_text="Are TEC working with any other companies on site?<br><small>e.g. TEC is providing the lighting while another company does sound</small>")
|
||||
crew_fatigue = models.BooleanField(help_text="Is crew fatigue likely to be a risk at any point during this event?")
|
||||
general_notes = models.TextField(blank=True, default='', help_text="Did you have to consult a supervisor about any of the above? If so who did you consult and what was the outcome?")
|
||||
general_notes = models.TextField(blank=True, null=True, help_text="Did you have to consult a supervisor about any of the above? If so who did you consult and what was the outcome?")
|
||||
|
||||
# Power
|
||||
# event_size = models.IntegerField(blank=True, null=True, choices=SIZES)
|
||||
big_power = models.BooleanField(help_text="Does the event require larger power supplies than 13A or 16A single phase wall sockets, or draw more than 20A total current?")
|
||||
# If yes to the above two, you must answer...
|
||||
power_mic = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='power_mic', blank=True, null=True,
|
||||
@@ -643,12 +645,12 @@ class RiskAssessment(models.Model, RevisionMixin):
|
||||
other_companies_power = models.BooleanField(help_text="Will TEC be supplying power to any other companies?")
|
||||
nonstandard_equipment_power = models.BooleanField(help_text="Does the power plan require the use of any power equipment (distros, dimmers, motor controllers, etc.) that does not belong to TEC?")
|
||||
multiple_electrical_environments = models.BooleanField(help_text="Will the electrical installation occupy more than one electrical environment?")
|
||||
power_notes = models.TextField(blank=True, default='', help_text="Did you have to consult a supervisor about any of the above? If so who did you consult and what was the outcome?")
|
||||
power_plan = models.URLField(blank=True, default='', help_text="Upload your power plan to the <a href='https://nottinghamtec.sharepoint.com/'>Sharepoint</a> and submit a link", validators=[validate_url])
|
||||
power_notes = models.TextField(blank=True, null=True, help_text="Did you have to consult a supervisor about any of the above? If so who did you consult and what was the outcome?")
|
||||
power_plan = models.URLField(blank=True, null=True, help_text="Upload your power plan to the <a href='https://nottinghamtec.sharepoint.com/'>Sharepoint</a> and submit a link", validators=[validate_url])
|
||||
|
||||
# Sound
|
||||
noise_monitoring = models.BooleanField(help_text="Does the event require noise monitoring or any non-standard procedures in order to comply with health and safety legislation or site rules?")
|
||||
sound_notes = models.TextField(blank=True, default='', help_text="Did you have to consult a supervisor about any of the above? If so who did you consult and what was the outcome?")
|
||||
sound_notes = models.TextField(blank=True, null=True, help_text="Did you have to consult a supervisor about any of the above? If so who did you consult and what was the outcome?")
|
||||
|
||||
# Site
|
||||
known_venue = models.BooleanField(help_text="Is this venue new to you (the MIC) or new to TEC?")
|
||||
@@ -661,8 +663,8 @@ class RiskAssessment(models.Model, RevisionMixin):
|
||||
# Structures
|
||||
special_structures = models.BooleanField(help_text="Does the event require use of winch stands, motors, MPT Towers, or staging?")
|
||||
suspended_structures = models.BooleanField(help_text="Are any structures (excluding projector screens and IWBs) being suspended from TEC's structures?")
|
||||
persons_responsible_structures = models.TextField(blank=True, default='', help_text="Who are the persons on site responsible for their use?")
|
||||
rigging_plan = models.URLField(blank=True, default='', help_text="Upload your rigging plan to the <a href='https://nottinghamtec.sharepoint.com/'>Sharepoint</a> and submit a link", validators=[validate_url])
|
||||
persons_responsible_structures = models.TextField(blank=True, null=True, help_text="Who are the persons on site responsible for their use?")
|
||||
rigging_plan = models.URLField(blank=True, null=True, help_text="Upload your rigging plan to the <a href='https://nottinghamtec.sharepoint.com/'>Sharepoint</a> and submit a link", validators=[validate_url])
|
||||
|
||||
# Blimey that was a lot of options
|
||||
|
||||
@@ -706,10 +708,6 @@ class RiskAssessment(models.Model, RevisionMixin):
|
||||
('review_riskassessment', 'Can review Risk Assessments')
|
||||
]
|
||||
|
||||
@cached_property
|
||||
def fieldz(self):
|
||||
return [n.name for n in list(self._meta.get_fields()) if n.name != 'reviewed_at' and n.name != 'reviewed_by' and not n.is_relation and not n.auto_created]
|
||||
|
||||
@property
|
||||
def event_size(self):
|
||||
# Confirm event size. Check all except generators, since generators entails outside
|
||||
@@ -725,7 +723,7 @@ class RiskAssessment(models.Model, RevisionMixin):
|
||||
return str(self.event)
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('ra_detail', kwargs={'pk': self.pk})
|
||||
return reverse_lazy('ra_detail', kwargs={'pk': self.pk})
|
||||
|
||||
def __str__(self):
|
||||
return "%i - %s" % (self.pk, self.event)
|
||||
@@ -748,8 +746,8 @@ class EventChecklist(models.Model, RevisionMixin):
|
||||
trip_hazard = models.BooleanField(blank=True, null=True, help_text="Appropriate barriers around kit and cabling secured?")
|
||||
warning_signs = models.BooleanField(blank=True, help_text="Warning signs in place?<br><small>(strobe, smoke, power etc.)</small>")
|
||||
ear_plugs = models.BooleanField(blank=True, null=True, help_text="Ear plugs issued to crew where needed?")
|
||||
hs_location = models.CharField(blank=True, default='', max_length=255, help_text="Location of Safety Bag/Box")
|
||||
extinguishers_location = models.CharField(blank=True, default='', max_length=255, help_text="Location of fire extinguishers")
|
||||
hs_location = models.CharField(blank=True, null=True, max_length=255, help_text="Location of Safety Bag/Box")
|
||||
extinguishers_location = models.CharField(blank=True, null=True, max_length=255, help_text="Location of fire extinguishers")
|
||||
|
||||
# Small Electrical Checks
|
||||
rcds = models.BooleanField(blank=True, null=True, help_text="RCDs installed where needed and tested?")
|
||||
@@ -770,15 +768,15 @@ class EventChecklist(models.Model, RevisionMixin):
|
||||
fd_earth_fault = models.IntegerField(blank=True, null=True, verbose_name="Earth Fault Loop Impedance", help_text="Earth Fault Loop Impedance (Z<small>S</small>)")
|
||||
fd_pssc = models.IntegerField(blank=True, null=True, verbose_name="PSCC", help_text="Prospective Short Circuit Current")
|
||||
# Worst case points
|
||||
w1_description = models.CharField(blank=True, default='', max_length=255, help_text="Description")
|
||||
w1_description = models.CharField(blank=True, null=True, max_length=255, help_text="Description")
|
||||
w1_polarity = models.BooleanField(blank=True, null=True, help_text="Polarity Checked?")
|
||||
w1_voltage = models.IntegerField(blank=True, null=True, help_text="Voltage")
|
||||
w1_earth_fault = models.IntegerField(blank=True, null=True, help_text="Earth Fault Loop Impedance (Z<small>S</small>)")
|
||||
w2_description = models.CharField(blank=True, default='', max_length=255, help_text="Description")
|
||||
w2_description = models.CharField(blank=True, null=True, max_length=255, help_text="Description")
|
||||
w2_polarity = models.BooleanField(blank=True, null=True, help_text="Polarity Checked?")
|
||||
w2_voltage = models.IntegerField(blank=True, null=True, help_text="Voltage")
|
||||
w2_earth_fault = models.IntegerField(blank=True, null=True, help_text="Earth Fault Loop Impedance (Z<small>S</small>)")
|
||||
w3_description = models.CharField(blank=True, default='', max_length=255, help_text="Description")
|
||||
w3_description = models.CharField(blank=True, null=True, max_length=255, help_text="Description")
|
||||
w3_polarity = models.BooleanField(blank=True, null=True, help_text="Polarity Checked?")
|
||||
w3_voltage = models.IntegerField(blank=True, null=True, help_text="Voltage")
|
||||
w3_earth_fault = models.IntegerField(blank=True, null=True, help_text="Earth Fault Loop Impedance (Z<small>S</small>)")
|
||||
@@ -798,16 +796,12 @@ class EventChecklist(models.Model, RevisionMixin):
|
||||
('review_eventchecklist', 'Can review Event Checklists')
|
||||
]
|
||||
|
||||
@cached_property
|
||||
def fieldz(self):
|
||||
return [n.name for n in list(self._meta.get_fields()) if n.name != 'reviewed_at' and n.name != 'reviewed_by' and not n.is_relation and not n.auto_created]
|
||||
|
||||
@property
|
||||
def activity_feed_string(self):
|
||||
return str(self.event)
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('ec_detail', kwargs={'pk': self.pk})
|
||||
return reverse_lazy('ec_detail', kwargs={'pk': self.pk})
|
||||
|
||||
def __str__(self):
|
||||
return "%i - %s" % (self.pk, self.event)
|
||||
|
||||
@@ -11,7 +11,7 @@ import simplejson
|
||||
from PyPDF2 import PdfFileMerger, PdfFileReader
|
||||
from django.conf import settings
|
||||
from django.contrib import messages
|
||||
from django.contrib.staticfiles import finders
|
||||
from django.contrib.staticfiles.storage import staticfiles_storage
|
||||
from django.core import signing
|
||||
from django.core.exceptions import SuspiciousOperation
|
||||
from django.core.mail import EmailMultiAlternatives
|
||||
@@ -27,7 +27,6 @@ from django.views import generic
|
||||
from z3c.rml import rml2pdf
|
||||
|
||||
from PyRIGS import decorators
|
||||
from PyRIGS.views import OEmbedView, is_ajax
|
||||
from RIGS import models, forms
|
||||
|
||||
__author__ = 'ghost'
|
||||
@@ -41,7 +40,7 @@ class RigboardIndex(generic.TemplateView):
|
||||
context = super(RigboardIndex, self).get_context_data(**kwargs)
|
||||
|
||||
# call out method to get current events
|
||||
context['events'] = models.Event.objects.current_events().select_related('riskassessment', 'invoice').prefetch_related('checklists')
|
||||
context['events'] = models.Event.objects.current_events()
|
||||
context['page_title'] = "Rigboard"
|
||||
return context
|
||||
|
||||
@@ -60,24 +59,29 @@ class EventDetail(generic.DetailView):
|
||||
template_name = 'event_detail.html'
|
||||
model = models.Event
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(EventDetail, self).get_context_data(**kwargs)
|
||||
title = "{} | {}".format(self.object.display_id, self.object.name)
|
||||
if self.object.dry_hire:
|
||||
title += " <span class='badge badge-secondary'>Dry Hire</span>"
|
||||
context['page_title'] = title
|
||||
return context
|
||||
|
||||
class EventOembed(generic.View):
|
||||
model = models.Event
|
||||
|
||||
def get(self, request, pk=None):
|
||||
embed_url = reverse('event_embed', args=[pk])
|
||||
full_url = "{0}://{1}{2}".format(request.scheme, request.META['HTTP_HOST'], embed_url)
|
||||
|
||||
data = {
|
||||
'html': '<iframe src="{0}" frameborder="0" width="100%" height="250"></iframe>'.format(full_url),
|
||||
'version': '1.0',
|
||||
'type': 'rich',
|
||||
'height': '250'
|
||||
}
|
||||
|
||||
json = simplejson.JSONEncoderForHTML().encode(data)
|
||||
return HttpResponse(json, content_type="application/json")
|
||||
|
||||
|
||||
class EventEmbed(EventDetail):
|
||||
template_name = 'event_embed.html'
|
||||
|
||||
|
||||
class EventOEmbed(OEmbedView):
|
||||
model = models.Event
|
||||
url_name = 'event_embed'
|
||||
|
||||
|
||||
class EventCreate(generic.CreateView):
|
||||
model = models.Event
|
||||
form_class = forms.EventForm
|
||||
@@ -153,7 +157,7 @@ class EventDuplicate(EventUpdate):
|
||||
new.checked_in_by = None
|
||||
|
||||
# Remove all the authorisation information from the new event
|
||||
new.auth_request_to = ''
|
||||
new.auth_request_to = None
|
||||
new.auth_request_by = None
|
||||
new.auth_request_at = None
|
||||
|
||||
@@ -181,9 +185,15 @@ class EventPrint(generic.View):
|
||||
|
||||
context = {
|
||||
'object': object,
|
||||
'fonts': {
|
||||
'opensans': {
|
||||
'regular': 'static/fonts/OPENSANS-REGULAR.TTF',
|
||||
'bold': 'static/fonts/OPENSANS-BOLD.TTF',
|
||||
}
|
||||
},
|
||||
'quote': True,
|
||||
'current_user': request.user,
|
||||
'filename': 'Event_{}_{}_{}.pdf'.format(object.display_id, re.sub(r'[^a-zA-Z0-9 \n\.]', '', object.name), object.start_date)
|
||||
'filename': 'Event {} {} {}.pdf'.format(object.display_id, re.sub(r'[^a-zA-Z0-9 \n\.]', '', object.name), object.start_date)
|
||||
}
|
||||
|
||||
rml = template.render(context)
|
||||
@@ -274,7 +284,6 @@ class EventArchive(generic.ListView):
|
||||
class EventAuthorise(generic.UpdateView):
|
||||
template_name = 'eventauthorisation_form.html'
|
||||
success_template = 'eventauthorisation_success.html'
|
||||
preview = False
|
||||
|
||||
def form_valid(self, form):
|
||||
self.object = form.save()
|
||||
@@ -302,7 +311,6 @@ class EventAuthorise(generic.UpdateView):
|
||||
context['page_title'] = "{}: {}".format(self.event.display_id, self.event.name)
|
||||
if self.event.dry_hire:
|
||||
context['page_title'] += ' <span class="badge badge-secondary align-top">Dry Hire</span>'
|
||||
context['preview'] = self.preview
|
||||
return context
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
@@ -351,7 +359,7 @@ class EventAuthorisationRequest(generic.FormView, generic.detail.SingleObjectMix
|
||||
return self.get_object()
|
||||
|
||||
def get_success_url(self):
|
||||
if is_ajax(self.request):
|
||||
if self.request.is_ajax():
|
||||
url = reverse_lazy('closemodal')
|
||||
messages.info(self.request, "location.reload()")
|
||||
else:
|
||||
@@ -389,7 +397,7 @@ class EventAuthorisationRequest(generic.FormView, generic.detail.SingleObjectMix
|
||||
to=[email],
|
||||
reply_to=[self.request.user.email],
|
||||
)
|
||||
css = finders.find('css/email.css')
|
||||
css = staticfiles_storage.path('css/email.css')
|
||||
html = premailer.Premailer(get_template("eventauthorisation_client_request.html").render(context),
|
||||
external_styles=css).transform()
|
||||
msg.attach_alternative(html, 'text/html')
|
||||
@@ -404,7 +412,8 @@ class EventAuthoriseRequestEmailPreview(generic.DetailView):
|
||||
model = models.Event
|
||||
|
||||
def render_to_response(self, context, **response_kwargs):
|
||||
css = finders.find('css/email.css')
|
||||
from django.contrib.staticfiles.storage import staticfiles_storage
|
||||
css = staticfiles_storage.path('css/email.css')
|
||||
response = super(EventAuthoriseRequestEmailPreview, self).render_to_response(context, **response_kwargs)
|
||||
assert isinstance(response, HttpResponse)
|
||||
response.content = premailer.Premailer(response.rendered_content, external_styles=css).transform()
|
||||
@@ -418,5 +427,4 @@ class EventAuthoriseRequestEmailPreview(generic.DetailView):
|
||||
'sent_by': self.request.user.pk,
|
||||
})
|
||||
context['to_name'] = self.request.GET.get('to_name', None)
|
||||
context['target'] = 'event_authorise_form_preview'
|
||||
return context
|
||||
|
||||
@@ -6,7 +6,7 @@ from io import BytesIO
|
||||
|
||||
from PyPDF2 import PdfFileReader, PdfFileMerger
|
||||
from django.conf import settings
|
||||
from django.contrib.staticfiles import finders
|
||||
from django.contrib.staticfiles.storage import staticfiles_storage
|
||||
from django.core.cache import cache
|
||||
from django.core.mail import EmailMessage, EmailMultiAlternatives
|
||||
from django.db.models.signals import post_save
|
||||
@@ -25,6 +25,12 @@ def send_eventauthorisation_success_email(instance):
|
||||
# Generate PDF first to prevent context conflicts
|
||||
context = {
|
||||
'object': instance.event,
|
||||
'fonts': {
|
||||
'opensans': {
|
||||
'regular': 'RIGS/static/fonts/OPENSANS-REGULAR.TTF',
|
||||
'bold': 'RIGS/static/fonts/OPENSANS-BOLD.TTF',
|
||||
}
|
||||
},
|
||||
'receipt': True,
|
||||
'current_user': False,
|
||||
}
|
||||
@@ -63,7 +69,7 @@ def send_eventauthorisation_success_email(instance):
|
||||
reply_to=[settings.AUTHORISATION_NOTIFICATION_ADDRESS],
|
||||
)
|
||||
|
||||
css = finders.find('css/email.css')
|
||||
css = staticfiles_storage.path('css/email.css')
|
||||
html = Premailer(get_template("eventauthorisation_client_success.html").render(context),
|
||||
external_styles=css).transform()
|
||||
client_email.attach_alternative(html, 'text/html')
|
||||
@@ -121,7 +127,7 @@ def send_admin_awaiting_approval_email(user, request, **kwargs):
|
||||
to=[admin.email],
|
||||
reply_to=[user.email],
|
||||
)
|
||||
css = finders.find('css/email.css')
|
||||
css = staticfiles_storage.path('css/email.css')
|
||||
html = Premailer(get_template("admin_awaiting_approval.html").render(context),
|
||||
external_styles=css).transform()
|
||||
email.attach_alternative(html, 'text/html')
|
||||
|
||||
BIN
RIGS/static/fonts/OPENSANS-BOLDITALIC.TTF
Normal file
BIN
RIGS/static/fonts/OPENSANS-BOLDITALIC.TTF
Normal file
Binary file not shown.
BIN
RIGS/static/fonts/OPENSANS-ITALIC.TTF
Normal file
BIN
RIGS/static/fonts/OPENSANS-ITALIC.TTF
Normal file
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 28 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 4.2 KiB |
@@ -74,7 +74,6 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block js %}
|
||||
{{ block.super }}
|
||||
<script src="{% static 'js/tooltip.js' %}"></script>
|
||||
<script src="{% static 'js/popover.js' %}"></script>
|
||||
<script>
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
{% block title %}Calendar{% endblock %}
|
||||
|
||||
{% block css %}
|
||||
<link href="{% static 'css/main.css' %}" rel='stylesheet' />
|
||||
<link href="{% static 'css/main.min.css' %}" rel='stylesheet' />
|
||||
{% endblock %}
|
||||
|
||||
{% block js %}
|
||||
<script src="{% static 'js/moment.js' %}"></script>
|
||||
<script src="{% static 'js/main.js' %}"></script>
|
||||
<script src="{% static 'js/main.min.js' %}"></script>
|
||||
<script>
|
||||
viewToUrl = {
|
||||
'timeGridWeek':'week',
|
||||
|
||||
@@ -5,13 +5,11 @@
|
||||
{% load static %}
|
||||
|
||||
{% block css %}
|
||||
{{ block.super }}
|
||||
<link rel="stylesheet" href="{% static 'css/selects.css' %}"/>
|
||||
<link rel="stylesheet" href="{% static 'css/bootstrap-select.css' %}"/>
|
||||
{% endblock %}
|
||||
|
||||
{% block preload_js %}
|
||||
{{ block.super }}
|
||||
<script src="{% static 'js/selects.js' %}" async></script>
|
||||
<script src="{% static 'js/bootstrap-select.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
@@ -235,6 +235,7 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12 text-right">
|
||||
{% button 'edit' url='ec_edit' pk=object.pk %}
|
||||
{% button 'view' url='event_detail' pk=object.pk text="Event" %}
|
||||
|
||||
@@ -7,28 +7,34 @@
|
||||
|
||||
{% block css %}
|
||||
{{ block.super }}
|
||||
<link rel="stylesheet" href="{% static 'css/selects.css' %}"/>
|
||||
<link rel="stylesheet" href="{% static 'css/bootstrap-select.css' %}"/>
|
||||
<link rel="stylesheet" href="{% static 'css/ajax-bootstrap-select.css' %}"/>
|
||||
{% endblock %}
|
||||
|
||||
{% block preload_js %}
|
||||
{{ block.super }}
|
||||
<script src="{% static 'js/selects.js' %}"></script>
|
||||
<script src="{% static 'js/bootstrap-select.js' %}"></script>
|
||||
<script src="{% static 'js/ajax-bootstrap-select.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block js %}
|
||||
{{ block.super }}
|
||||
<script src="{% static 'js/autocompleter.js' %}"></script>
|
||||
<script src="{% static 'js/jquery-ui.js' %}"></script><!--TODO optimise-->
|
||||
<script src="{% static 'js/interaction.js' %}"></script>
|
||||
<script src="{% static 'js/modal.js' %}"></script>
|
||||
<script src="{% static 'js/tooltip.js' %}"></script>
|
||||
|
||||
<script src="{% static 'js/autocompleter.js' %}"></script>
|
||||
|
||||
{% include 'partials/datetime-fix.html' %}
|
||||
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
$('button[data-action=add]').on('click', function (event) {
|
||||
event.preventDefault();
|
||||
let target = $($(this).attr('data-target'));
|
||||
let newID = Number(target.attr('data-pk'));
|
||||
let newRow = $($(this).attr('data-clone'))
|
||||
var target = $($(this).attr('data-target'));
|
||||
var newID = Number(target.attr('data-pk'));
|
||||
var newRow = $($(this).attr('data-clone'))
|
||||
.clone().attr('style', "")
|
||||
.attr('id', function(i, val){
|
||||
return val.split("_")[0] + '_' + newID;
|
||||
@@ -128,20 +134,20 @@
|
||||
<tbody id="vehiclest" data-pk="-1">
|
||||
<tr id="vehicles_new" style="display: none;">
|
||||
<td><input type="text" class="form-control" name="vehicle_new" disabled="true"/></td>
|
||||
<td><select data-container="body" class="form-control" data-live-search="true" data-sourceurl="{% url 'api_secure' model='profile' %}?fields=first_name,last_name,initials" name="driver_new" disabled="true"></select></td>
|
||||
<td><button type="button" class="btn btn-danger btn-sm mt-1" data-action='delete' data-target='#vehicle'><span class="fas fa-times"></span></button></td>
|
||||
<td><select class="form-control" data-live-search="true" data-sourceurl="{% url 'api_secure' model='profile' %}?fields=first_name,last_name,initials" name="driver_new" disabled="true"></select></td>
|
||||
<td><button type="button" class="btn btn-danger btn-sm mt-1" data-action='delete' data-target='#vehicle'><span class="fas fa-times"></span></button</td>
|
||||
</tr>
|
||||
{% for i in object.vehicles.all %}
|
||||
<tr id="vehicles_{{i.pk}}">
|
||||
<td><input name="vehicle_{{i.pk}}" type="text" class="form-control" value="{{ i.vehicle }}"/></td>
|
||||
<td>
|
||||
<select data-container="body" name="driver_{{i.pk}}" class="form-control selectpicker" data-live-search="true" data-sourceurl="{% url 'api_secure' model='profile' %}?fields=first_name,last_name,initials">
|
||||
<select name="driver_{{i.pk}}" class="form-control selectpicker" data-live-search="true" data-sourceurl="{% url 'api_secure' model='profile' %}?fields=first_name,last_name,initials">
|
||||
{% if i.driver != '' %}
|
||||
<option value="{{i.driver.pk}}" selected="selected">{{ i.driver.name }}</option>
|
||||
{% endif %}
|
||||
</select>
|
||||
</td>
|
||||
<td><button type="button" class="btn btn-danger btn-sm mt-1" data-id='{{i.pk}}' data-action='delete' data-target='#vehicle'><span class="fas fa-times"></span></button></td>
|
||||
<td><button type="button" class="btn btn-danger btn-sm mt-1" data-id='{{i.pk}}' data-action='delete' data-target='#vehicle'><span class="fas fa-times"></span></button</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
@@ -196,17 +202,17 @@
|
||||
<tbody id="crewmemberst" data-pk="-1">
|
||||
<tr id="crew_new" style="display: none;">
|
||||
<td>
|
||||
<select name="crewmember_new" class="form-control" data-container="body" data-live-search="true" data-sourceurl="{% url 'api_secure' model='profile' %}?fields=first_name,last_name,initials" disabled="true"></select>
|
||||
<select name="crewmember_new" class="form-control" data-live-search="true" data-sourceurl="{% url 'api_secure' model='profile' %}?fields=first_name,last_name,initials" disabled="true"></select>
|
||||
</td>
|
||||
<td style="min-width: 15ch"><input name="start_new" type="datetime-local" class="form-control" value="{{ i.start }}" disabled=""/></td>
|
||||
<td style="min-width: 15ch"><input name="start_new" type="datetime-local" class="form-control" value="{{ i.start }}" disabled="true"/></td>
|
||||
<td style="min-width: 15ch"><input name="role_new" type="text" class="form-control" value="{{ i.role }}" disabled="true"/></td>
|
||||
<td style="min-width: 15ch"><input name="end_new" type="datetime-local" class="form-control" value="{{ i.end }}" disabled="true" /></td>
|
||||
<td><button type="button" class="btn btn-danger btn-sm mt-1" data-id='{{crew.pk}}' data-action='delete' data-target='#crewmember'><span class="fas fa-times"></span></button></td>
|
||||
<td><button type="button" class="btn btn-danger btn-sm mt-1" data-id='{{crew.pk}}' data-action='delete' data-target='#crewmember'><span class="fas fa-times"></span></button</td>
|
||||
</tr>
|
||||
{% for crew in object.crew.all %}
|
||||
<tr id="crew_{{crew.pk}}">
|
||||
<td>
|
||||
<select data-container="body" name="crewmember_{{crew.pk}}" class="form-control selectpicker" data-live-search="true" data-sourceurl="{% url 'api_secure' model='profile' %}?fields=first_name,last_name,initials">
|
||||
<select name="crewmember_{{crew.pk}}" class="form-control selectpicker" data-live-search="true" data-sourceurl="{% url 'api_secure' model='profile' %}?fields=first_name,last_name,initials">
|
||||
{% if crew.crewmember != '' %}
|
||||
<option value="{{crew.crewmember.pk}}" selected="selected">{{ crew.crewmember.name }}</option>
|
||||
{% endif %}
|
||||
@@ -215,7 +221,7 @@
|
||||
<td><input name="start_{{crew.pk}}" type="datetime-local" class="form-control" value="{{ crew.start|date:'Y-m-d' }}T{{ crew.start|date:'H:i:s' }}"/></td>
|
||||
<td><input name="role_{{crew.pk}}" type="text" class="form-control" value="{{ crew.role }}"/></td>
|
||||
<td><input name="end_{{crew.pk}}" type="datetime-local" class="form-control" value="{{ crew.end|date:'Y-m-d' }}T{{ crew.end|date:'H:i:s' }}"/></td>
|
||||
<td><button type="button" class="btn btn-danger btn-sm mt-1" data-id='{{crew.pk}}' data-action='delete' data-target='#crewmember'><span class="fas fa-times"></span></button></td>
|
||||
<td><button type="button" class="btn btn-danger btn-sm mt-1" data-id='{{crew.pk}}' data-action='delete' data-target='#crewmember'><span class="fas fa-times"></span></button</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
@@ -234,7 +240,7 @@
|
||||
<div class="row my-3" id="size-0">
|
||||
<div class="col-12">
|
||||
<div class="card border-success">
|
||||
<div class="card-header">Electrical Checks <small>for ‘Small’ TEC Events <6kVA (approx. 26A)</small></div>
|
||||
<div class="card-header">Electrical Checks <small>for ‘Small’ TEC Events <6kVA (aprox. 26A)</small></div>
|
||||
<div class="card-body">
|
||||
{% include 'partials/checklist_checkbox.html' with formitem=form.rcds %}
|
||||
{% include 'partials/checklist_checkbox.html' with formitem=form.supply_test %}
|
||||
@@ -331,7 +337,7 @@
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<hr/>
|
||||
<hr>
|
||||
{% include 'partials/checklist_checkbox.html' with formitem=form.all_rcds_tested %}
|
||||
{% include 'partials/checklist_checkbox.html' with formitem=form.public_sockets_tested %}
|
||||
{% include 'partials/ec_power_info.html' %}
|
||||
|
||||
@@ -2,12 +2,20 @@
|
||||
{% load linkornone from filters %}
|
||||
{% load namewithnotes from filters %}
|
||||
|
||||
{% block title %}{% if object.is_rig %}N{{ object.pk|stringformat:"05d" }}{% else %}{{ object.pk }}{% endif %} | {{object.name}}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row my-3 py-3">
|
||||
{% if not request.is_ajax %}
|
||||
<div class="col-sm-12">
|
||||
<h1>
|
||||
{% if object.is_rig %}N{{ object.pk|stringformat:"05d" }}{% else %}{{ object.pk }}{% endif %}
|
||||
| {{ object.name }} {% if event.dry_hire %}<span class="badge badge-secondary">Dry Hire</span>{% endif %}
|
||||
</h1>
|
||||
</div>
|
||||
{% if perms.RIGS.view_event %}
|
||||
<div class="col-sm-12 text-right">
|
||||
{% include 'partials/event_detail_buttons.html' %}
|
||||
{% include 'event_detail_buttons.html' %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
@@ -30,7 +38,7 @@
|
||||
<dt class="col-sm-6">Email</dt>
|
||||
<dd class="col-sm-6">{{ object.person.email|linkornone:'mailto' }}</dd>
|
||||
<dt class="col-sm-6">Phone Number</dt>
|
||||
<dd class="col-sm-6">{{ object.person.phone|linkornone:'tel' }}</dd>
|
||||
<dd class="col-sm-6">{{ object.person.phone|linkornone:'tel' }}</a></dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
@@ -51,7 +59,7 @@
|
||||
<dt class="col-sm-6">Email</dt>
|
||||
<dd class="col-sm-6">{{ object.organisation.email|linkornone:'mailto' }}</dd>
|
||||
<dt class="col-sm-6">Phone Number</dt>
|
||||
<dd class="col-sm-6">{{ object.organisation.phone|linkornone:'tel' }}</dd>
|
||||
<dd class="col-sm-6">{{ object.organisation.phone|linkornone:'tel' }}</a></dd>
|
||||
<dt class="col-sm-6">Has SU Account</dt>
|
||||
<dd class="col-sm-6">{{ event.organisation.union_account|yesno|capfirst }}</dd>
|
||||
</dl>
|
||||
@@ -77,7 +85,7 @@
|
||||
{% endif %}
|
||||
{% if not request.is_ajax and perms.RIGS.view_event %}
|
||||
<div class="col-sm-12 text-right">
|
||||
{% include 'partials/event_detail_buttons.html' %}
|
||||
{% include 'event_detail_buttons.html' %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if event.is_rig %}
|
||||
@@ -97,7 +105,7 @@
|
||||
</div>
|
||||
{% if not request.is_ajax and perms.RIGS.view_event %}
|
||||
<div class="col-sm-12 text-right">
|
||||
{% include 'partials/event_detail_buttons.html' %}
|
||||
{% include 'event_detail_buttons.html' %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
{% if event.internal %}
|
||||
<a class="btn item-add modal-href event-authorise-request
|
||||
{% if event.authorised %}
|
||||
btn-success active
|
||||
btn-success
|
||||
{% elif event.authorisation and event.authorisation.amount != event.total and event.authorisation.last_edited_at > event.auth_request_at %}
|
||||
btn-warning
|
||||
{% elif event.auth_request_to %}
|
||||
@@ -19,7 +19,7 @@
|
||||
{% endif %}
|
||||
"
|
||||
href="{% url 'event_authorise_request' object.pk %}">
|
||||
<span class="fas fa-paper-plane"></span>
|
||||
<i class="fas fa-paper-plane"></i>
|
||||
<span class="d-none d-sm-inline">
|
||||
{% if event.authorised %}
|
||||
Authorised
|
||||
@@ -1,78 +1,87 @@
|
||||
{% extends 'base_embed.html' %}
|
||||
{% load static %}
|
||||
|
||||
{% block extra-head %}
|
||||
<link href="{% static 'fontawesome_free/css/fontawesome.css' %}" rel="stylesheet" type="text/css">
|
||||
<link href="{% static 'fontawesome_free/css/solid.css' %}" rel="stylesheet" type="text/css">
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<span class="float-right">
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<a href="/">
|
||||
<span class="source"> R<small>ig</small> I<small>nformation</small> G<small>athering</small> S<small>ystem</small></span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="col-sm-12">
|
||||
<span class="pull-right">
|
||||
{% if object.mic %}
|
||||
<div class="text-center">
|
||||
<img src="{{ object.mic.profile_picture }}" class="event-mic-photo rounded"/>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
<img src="{{ object.mic.profile_picture }}" class="event-mic-photo rounded"/>
|
||||
</div>
|
||||
{% elif object.is_rig %}
|
||||
<span class="fas fa-exclamation-sign"></span>
|
||||
<span class="fas fa-exclamation-sign"></span>
|
||||
{% endif %}
|
||||
</span>
|
||||
|
||||
<h3>
|
||||
<a href="{% url 'event_detail' object.pk %}">{{ object.display_id }} | {{ object.name }}</a>
|
||||
{% if object.venue %}
|
||||
<small>at {{ object.venue }}</small>
|
||||
{% endif %}
|
||||
<br/><small>
|
||||
{{ object.start_date|date:"D d/m/Y" }}
|
||||
{% if object.has_start_time %}
|
||||
<a href="{% url 'event_detail' object.pk %}">
|
||||
{% if object.is_rig %}N{{ object.pk|stringformat:"05d" }}{% else %}{{ object.pk }}{% endif %}
|
||||
| {{ object.name }} </a>
|
||||
{% if object.venue %}
|
||||
<small>at {{ object.venue }}</small>
|
||||
{% endif %}
|
||||
<br/><small>
|
||||
{{ object.start_date|date:"D d/m/Y" }}
|
||||
{% if object.has_start_time %}
|
||||
{{ object.start_time|date:"H:i" }}
|
||||
{% endif %}
|
||||
{% if object.end_date or object.has_end_time %}
|
||||
{% endif %}
|
||||
{% if object.end_date or object.has_end_time %}
|
||||
–
|
||||
{% endif %}
|
||||
{% if object.end_date and object.end_date != object.start_date %}
|
||||
{{ object.end_date|date:"D d/m/Y" }}
|
||||
{% endif %}
|
||||
{% if object.has_end_time %}
|
||||
{% endif %}
|
||||
{% if object.end_date and object.end_date != object.start_date %}
|
||||
{{ object.end_date|date:"D d/m/Y" }}
|
||||
{% endif %}
|
||||
{% if object.has_end_time %}
|
||||
{{ object.end_time|date:"H:i" }}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</small>
|
||||
</h3>
|
||||
{% include 'partials/event_status.html' %}
|
||||
<div class="row ml-2">
|
||||
<div class="col-xs-6 pr-2">
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-6">
|
||||
<p>
|
||||
<strong>Status:</strong>
|
||||
{{ object.get_status_display }}
|
||||
</p>
|
||||
<p>
|
||||
{% if object.is_rig %}
|
||||
<strong>Client:</strong> {{ object.person.name }}
|
||||
{% if object.organisation %}
|
||||
for {{ object.organisation.name }}
|
||||
{% endif %}
|
||||
{% if object.dry_hire %}(Dry Hire){% endif %}
|
||||
<strong>Client:</strong> {{ object.person.name }}
|
||||
{% if object.organisation %}
|
||||
for {{ object.organisation.name }}
|
||||
{% endif %}
|
||||
{% if object.dry_hire %}(Dry Hire){% endif %}
|
||||
{% else %}
|
||||
<strong>Non-Rig</strong>
|
||||
<strong>Non-Rig</strong>
|
||||
{% endif %}
|
||||
</p>
|
||||
<p>
|
||||
<strong>MIC:</strong>
|
||||
{% if object.mic %}
|
||||
{{object.mic.name}}
|
||||
{{object.mic.name}}
|
||||
{% else %}
|
||||
None
|
||||
None
|
||||
{% endif %}
|
||||
</p>
|
||||
</div>
|
||||
<div class="col-xs-6 px-2">
|
||||
<div class="col-xs-6">
|
||||
{% if object.meet_at %}
|
||||
<p>
|
||||
<strong>Crew meet:</strong>
|
||||
{{ object.meet_at|date:"H:i" }} {{ object.meet_at|date:"(Y-m-d)" }}
|
||||
</p>
|
||||
<p>
|
||||
<strong>Crew meet:</strong>
|
||||
{{ object.meet_at|date:"H:i" }} {{ object.meet_at|date:"(Y-m-d)" }}
|
||||
</p>
|
||||
{% endif %}
|
||||
{% if object.access_at %}
|
||||
<p>
|
||||
<strong>Access at:</strong>
|
||||
{{ object.access_at|date:"H:i" }} {{ object.access_at|date:"(Y-m-d)" }}
|
||||
</p>
|
||||
<p>
|
||||
<strong>Access at:</strong>
|
||||
{{ object.access_at|date:"H:i" }} {{ object.access_at|date:"(Y-m-d)" }}
|
||||
</p>
|
||||
{% endif %}
|
||||
<p>
|
||||
<strong>Last updated:</strong>
|
||||
@@ -81,9 +90,12 @@
|
||||
</div>
|
||||
</div>
|
||||
{% if object.description %}
|
||||
<p>
|
||||
<p>
|
||||
<strong>Description: </strong>
|
||||
{{ object.description|linebreaksbr }}
|
||||
</p>
|
||||
</p>
|
||||
{% endif %}
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
@@ -7,20 +7,26 @@
|
||||
|
||||
{% block css %}
|
||||
{{ block.super }}
|
||||
<link rel="stylesheet" type="text/css" href="{% static 'css/selects.css' %}"/>
|
||||
<link rel="stylesheet" href="{% static 'css/bootstrap-select.css' %}"/>
|
||||
<link rel="stylesheet" href="{% static 'css/ajax-bootstrap-select.css' %}"/>
|
||||
<link rel="stylesheet" href="{% static 'css/flatpickr.css' %}"/>
|
||||
{% endblock %}
|
||||
|
||||
{% block preload_js %}
|
||||
{{ block.super }}
|
||||
<script src="{% static 'js/selects.js' %}"></script>
|
||||
<script src="{% static 'js/bootstrap-select.js' %}"></script>
|
||||
<script src="{% static 'js/ajax-bootstrap-select.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block js %}
|
||||
{{ block.super }}
|
||||
<script src="{% static 'js/autocompleter.js' %}"></script>
|
||||
<script src="{% static 'js/jquery-ui.js' %}"></script><!--TODO optimise--->
|
||||
<script src="{% static 'js/interaction.js' %}"></script>
|
||||
<script src="{% static 'js/modal.js' %}"></script>
|
||||
<script src="{% static 'js/tooltip.js' %}"></script>
|
||||
|
||||
<script src="{% static 'js/autocompleter.js' %}"></script>
|
||||
|
||||
{% include 'partials/datetime-fix.html' %}
|
||||
|
||||
<script>
|
||||
@@ -73,7 +79,7 @@
|
||||
|
||||
{% block content %}
|
||||
{% include 'item_modal.html' %}
|
||||
<form class="itemised_form" role="form" method="POST">
|
||||
<form class=" itemised_form" role="form" method="POST">
|
||||
{% csrf_token %}
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
{% load multiply from filters %}
|
||||
{% load static %}
|
||||
<!DOCTYPE document SYSTEM "rml.dtd">
|
||||
|
||||
<document filename="{{filename}}">
|
||||
<docinit>
|
||||
<registerTTFont faceName="OpenSans" fileName="static/fonts/OpenSans-Regular.tff"/>
|
||||
<registerTTFont faceName="OpenSans-Bold" fileName="static/fonts/OpenSans-Bold.tff"/>
|
||||
<registerTTFont faceName="OpenSans" fileName="{{ fonts.opensans.regular }}"/>
|
||||
<registerTTFont faceName="OpenSans-Bold" fileName="{{ fonts.opensans.bold }}"/>
|
||||
<registerFontFamily name="OpenSans" bold="OpenSans-Bold" boldItalic="OpenSans-Bold"/>
|
||||
</docinit>
|
||||
|
||||
@@ -79,11 +82,11 @@
|
||||
<template > {# Note: page is 595x842 points (1 point=1/72in) #}
|
||||
<pageTemplate id="Headed" >
|
||||
<pageGraphics>
|
||||
<image file="static/imgs/paperwork/corner-tr-su.jpg" x="395" y="642" height="200" width="200"/>
|
||||
<image file="static/imgs/paperwork/corner-bl.jpg" x="0" y="0" height="200" width="200"/>
|
||||
<image file="RIGS/static/imgs/paperwork/corner-tr-su.jpg" x="395" y="642" height="200" width="200"/>
|
||||
<image file="RIGS/static/imgs/paperwork/corner-bl.jpg" x="0" y="0" height="200" width="200"/>
|
||||
|
||||
{# logo positioned 42 from left, 33 from top #}
|
||||
<image file="static/imgs/paperwork/tec-logo.jpg" x="42" y="719" height="90" width="84"/>
|
||||
<image file="RIGS/static/imgs/paperwork/tec-logo.jpg" x="42" y="719" height="90" width="84"/>
|
||||
|
||||
<setFont name="OpenSans-Bold" size="22.5" leading="10"/>
|
||||
<drawString x="137" y="780">TEC PA & Lighting</drawString>
|
||||
@@ -107,8 +110,8 @@
|
||||
|
||||
<pageTemplate id="Main">
|
||||
<pageGraphics>
|
||||
<image file="static/imgs/paperwork/corner-tr.jpg" x="395" y="642" height="200" width="200"/>
|
||||
<image file="static/imgs/paperwork/corner-bl.jpg" x="0" y="0" height="200" width="200"/>
|
||||
<image file="RIGS/static/imgs/paperwork/corner-tr.jpg" x="395" y="642" height="200" width="200"/>
|
||||
<image file="RIGS/static/imgs/paperwork/corner-bl.jpg" x="0" y="0" height="200" width="200"/>
|
||||
|
||||
<setFont name="OpenSans" size="10"/>
|
||||
<drawCenteredString x="302.5" y="38">[Page <pageNumber/> of <getName id="lastPage" default="0" />]</drawCenteredString>
|
||||
|
||||
10
RIGS/templates/event_print_signature.xml
Normal file
10
RIGS/templates/event_print_signature.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<blockTable style="signatureTable" colWidths="50,120,60,120,35,110">
|
||||
<tr>
|
||||
<td>Signature</td>
|
||||
<td></td>
|
||||
<td>Print Name</td>
|
||||
<td></td>
|
||||
<td>Date</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</blockTable>
|
||||
@@ -1,10 +1,10 @@
|
||||
{% extends 'base_client_email.html' %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
|
||||
<p>Hi {{ to_name|default:"there" }},</p>
|
||||
|
||||
<p><b>{{ request.user.get_full_name }}</b> has requested that you authorise <b>{{ object.display_id }}
|
||||
<p><b>{{ request.user.get_full_name }}</b> has requested that you authorise <b>N{{ object.pk|stringformat:"05d" }}
|
||||
| {{ object.name }}</b>{% if not to_name %} on behalf of <b>{{ object.person.name }}</b>{% endif %}.</p>
|
||||
|
||||
<p>
|
||||
@@ -23,7 +23,7 @@
|
||||
<table border="0" cellspacing="0" cellpadding="0">
|
||||
<tr>
|
||||
<td class="button" align="center">
|
||||
<a href="{{ request.scheme }}://{{ request.get_host }}{% url target|default:'event_authorise' object.pk hmac %}">
|
||||
<a href="{{ request.scheme }}://{{ request.get_host }}{% url 'event_authorise' object.pk hmac %}">
|
||||
Complete Authorisation Form
|
||||
</a>
|
||||
</td>
|
||||
@@ -36,7 +36,6 @@
|
||||
|
||||
<p>Your event will not be booked until you complete this form.</p>
|
||||
|
||||
<p>TEC PA & Lighting</p>
|
||||
<br/>
|
||||
<p>TEC PA & Lighting<br/>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
{% extends 'eventauthorisation.html' %}
|
||||
{% load widget_tweaks %}
|
||||
|
||||
{% block js %}
|
||||
{% endblock %}
|
||||
|
||||
{% block authorisation %}
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
@@ -83,7 +86,7 @@
|
||||
|
||||
<div class="text-right">
|
||||
<div class="btn-group">
|
||||
<button class="btn btn-primary btn-lg" type="submit" {% if preview %}disabled="" data-toggle="tooltip" title="This is only a preview!"{%endif%}>Authorise</button>
|
||||
<button class="btn btn-primary btn-lg" type="submit">Authorise</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -30,6 +30,14 @@
|
||||
{% render_field form.email type="email" class+="form-control" %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-right col-sm-3 offset-sm-9">
|
||||
<div class="form-group">
|
||||
<button type="submit" class="form-control btn btn-primary">
|
||||
<i class="fas fa-paper-plane"></i>
|
||||
Send
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@@ -40,14 +48,3 @@
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
{% block footer %}
|
||||
<div class="form-row">
|
||||
<div class="btn-group" role="group">
|
||||
<a type="button" target="_blank" href="{% url 'event_authorise_preview' object.pk %}" class="btn btn-info text-nowrap"><span class="fas fa-drafting-compass"></span> Preview</a>
|
||||
<button type="submit" class="form-control btn btn-primary" form="auth-request-form">
|
||||
<span class="fas fa-paper-plane"></span> Send
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
<th scope="col">Event</th>
|
||||
{# mmm hax #}
|
||||
{% if object_list.0 != None %}
|
||||
{% for field in object_list.0.fieldz %}
|
||||
{% for field in fields %}
|
||||
<th scope="col">{{ object_list.0|verbose_name:field|title }}</th>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
@@ -33,7 +33,7 @@
|
||||
<tr class="{% if object.reviewed_by %}table-success{%endif%}">
|
||||
{# General #}
|
||||
<th scope="row"><a href="{% url 'event_detail' object.event.pk %}">{{ object.event }}</a></th>
|
||||
{% for field in object_list.0.fieldz %}
|
||||
{% for field in fields %}
|
||||
<td>{{ object|get_field:field }}</td>
|
||||
{% endfor %}
|
||||
{# Buttons #}
|
||||
|
||||
@@ -60,10 +60,10 @@
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Date</th>
|
||||
<th scope="col">Amount</th>
|
||||
<th scope="col">Method</th>
|
||||
<th scope="col"></th>
|
||||
<th scope="col">Date</td>
|
||||
<th scope="col">Amount</td>
|
||||
<th scope="col">Method</td>
|
||||
<th scope="col"></td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -73,7 +73,7 @@
|
||||
<td>{{ payment.amount|floatformat:2 }}</td>
|
||||
<td>{{ payment.get_method_display }}</td>
|
||||
<td>
|
||||
<a href="{% url 'payment_delete' payment.pk %}" class="btn btn-small btn-danger"><span class="fas fa-times"></span></a>
|
||||
<a href="{% url 'payment_delete' payment.pk %}" class="btn btn-small btn-danger"><span class="fas fa-times"</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
<span class="text-muted">{% if invoice.void %}(VOID){% elif invoice.is_closed %}(PAID){% else %}(O/S){% endif %}</span></th>
|
||||
<td><a href="{% url 'event_detail' invoice.event.pk %}">N{{ invoice.event.pk|stringformat:"05d" }}</a>: {{ invoice.event.name }} <br>
|
||||
<span class="text-muted">{{ invoice.event.get_status_display }}{% if not invoice.event.mic %}, No MIC{% endif %}
|
||||
</span>
|
||||
</span></td>
|
||||
</td>
|
||||
<td>{% if invoice.event.organisation %}
|
||||
{{ invoice.event.organisation.name }}
|
||||
@@ -42,7 +42,7 @@
|
||||
<td>{{ invoice.event.start_date }}</td>
|
||||
<td>{{ invoice.invoice_date }}</td>
|
||||
<td>
|
||||
£{{ invoice.balance|floatformat:2 }}
|
||||
{{ invoice.balance|floatformat:2 }}
|
||||
{% if not invoice.event.internal %}
|
||||
<br />
|
||||
<span class="text-muted">{{ invoice.event.purchase_order }}</span>
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
£{{ event.sum_total|floatformat:2 }}
|
||||
{{ event.sum_total|floatformat:2 }}
|
||||
<br />
|
||||
<span class="text-muted">{% if not event.internal %}{{ event.purchase_order }}{% endif %}</span>
|
||||
</td>
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
<div class="card card-default
|
||||
{% if event.authorised %}
|
||||
border-success
|
||||
{% if object.authorised %}
|
||||
card-success
|
||||
{% elif event.authorisation and event.authorisation.amount != event.total and event.authorisation.last_edited_at > event.auth_request_at %}
|
||||
border-warning
|
||||
card-warning
|
||||
{% elif event.auth_request_to %}
|
||||
border-info
|
||||
card-info
|
||||
{% endif %}
|
||||
">
|
||||
<div class="card-header">Client Authorisation</div>
|
||||
<div class="card-body row">
|
||||
<dl class="col-sm-6">
|
||||
<dl class="col-md-6">
|
||||
<dt>Authorisation Request</dt>
|
||||
<dd>{{ object.auth_request_to|yesno:"Yes,No" }}</dd>
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
<dt>To</dt>
|
||||
<dd>{{ object.auth_request_to }}</dd>
|
||||
</dl>
|
||||
<dl class="col-sm-6">
|
||||
<hr class="d-block d-sm-none">
|
||||
<dd class="d-block d-sm-none"> </dd>
|
||||
<dl class="col-md-6">
|
||||
<dt>Authorised</dt>
|
||||
<dd>{{ object.authorised|yesno:"Yes,No" }}</dd>
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
<tr>
|
||||
<td>300</td>
|
||||
<td>167</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>500</td>
|
||||
<td>100</td>
|
||||
|
||||
@@ -20,7 +20,15 @@
|
||||
|
||||
{% if event.is_rig %}
|
||||
<dt class="col-sm-6">Event MIC</dt>
|
||||
<dd class="col-sm-6">{% include 'partials/linked_name.html' with profile=event.mic %}</dd>
|
||||
<dd class="col-sm-6">
|
||||
{% if event.mic and perms.RIGS.view_profile %}
|
||||
<a href="{% url 'profile_detail' event.mic.pk %}" class="modal-href">
|
||||
{{ event.mic.name }}
|
||||
</a>
|
||||
{% else %}
|
||||
{{ event.mic.name }}
|
||||
{% endif %}
|
||||
</dd>
|
||||
{% endif %}
|
||||
|
||||
<dt class="col-sm-6">Status</dt>
|
||||
@@ -63,7 +71,7 @@
|
||||
|
||||
{% if event.dry_hire %}
|
||||
<dt class="col-sm-6">Checked In By</dt>
|
||||
<dd class="col-sm-6">{% include 'partials/linked_name.html' with profile=event.checked_in_by %}</dd>
|
||||
<dd class="col-sm-6">{{ object.checked_in_by.name }}</dd>
|
||||
{% endif %}
|
||||
|
||||
{% if event.is_rig %}
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
<div>
|
||||
<h5>
|
||||
<span class="badge badge-{% if event.confirmed %}success{% elif event.cancelled %}dark{% else %}warning{% endif %}">Status: {{ event.get_status_display }}</span>
|
||||
{% if event.is_rig %}
|
||||
{% if event.sum_total > 0 %}
|
||||
{% if event.purchase_order %}
|
||||
<span class="badge badge-success">PO: {{ event.purchase_order }}</span>
|
||||
{% elif event.authorised %}
|
||||
<span class="badge badge-success">Authorisation: Complete <span class="fas fa-check"></span></span>
|
||||
{% else %}
|
||||
<span class="badge badge-danger">Authorisation: <span class="fas fa-times"></span></span>
|
||||
{% endif %}
|
||||
{% if event.purchase_order %}
|
||||
<span class="badge badge-success">PO: {{ event.purchase_order }}</span>
|
||||
{% elif event.authorised %}
|
||||
<span class="badge badge-success">Authorisation: Complete <span class="fas fa-check"></span></span>
|
||||
{% else %}
|
||||
<span class="badge badge-danger">Authorisation: <span class="fas fa-times"></span></span>
|
||||
{% endif %}
|
||||
{% if not event.dry_hire %}
|
||||
{% if event.riskassessment %}
|
||||
@@ -16,6 +14,8 @@
|
||||
{% else %}
|
||||
<span class="badge badge-danger">RA: <span class="fas fa-times"></span></span>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<span class="badge badge-secondary">RA: N/A</span>
|
||||
{% endif %}
|
||||
{% if not event.dry_hire %}
|
||||
{% if event.hs_done %}
|
||||
@@ -24,6 +24,8 @@
|
||||
{% else %}
|
||||
<span class="badge badge-danger">Checklist: <span class="fas fa-times"></span></span>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<span class="badge badge-secondary">Checklist: N/A</span>
|
||||
{% endif %}
|
||||
{% if perms.RIGS.view_invoice %}
|
||||
{% if event.invoice %}
|
||||
@@ -39,4 +41,4 @@
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
</h5>
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
{% endif %}
|
||||
{% else %}
|
||||
table-warning
|
||||
{% endif %}" {% if event.cancelled %}style="opacity: 50% !important;"{% endif %} id="event_row">
|
||||
{% endif %}" id="event_row">
|
||||
<!---Number-->
|
||||
<th scope="row" id="event_number">{{ event.display_id }}</th>
|
||||
<!--Dates & Times-->
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
{% if profile and perms.RIGS.view_profile %}
|
||||
<a href="{% url 'profile_detail' profile.pk %}" class="modal-href">
|
||||
{{ profile.name }}
|
||||
</a>
|
||||
{% else %}
|
||||
{{ profile.name }}
|
||||
{% endif %}
|
||||
@@ -2,9 +2,9 @@
|
||||
{% load button from filters %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row align-items-center justify-content-between py-2 align-middle">
|
||||
<div class="col-sm-12 col-md align-middle">
|
||||
Key: <span class="table-success mr-1 px-2 rounded">Ready</span><span class="table-warning mr-1 px-2 rounded">Action Required</span><span class="table-danger mr-1 px-2 rounded">Needs MIC</span><span class="table-secondary mr-1 px-2 rounded">Cancelled</span><span class="table-info px-2 rounded">Non-Rig</span>
|
||||
<div class="row align-items-center justify-content-between py-2">
|
||||
<div class="col-sm-12 col-md">
|
||||
Key: <span class="table-success mr-1 px-2">Ready</span><span class="table-warning mr-1 px-2">Action Required</span><span class="table-danger mr-1 px-2">Needs MIC</span><span class="table-secondary mr-1 px-2">Cancelled</span><span class="table-info px-2">Non-Rig</span>
|
||||
</div>
|
||||
{% if perms.RIGS.add_event %}
|
||||
<div class="col text-right">
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
{% load linkornone from filters %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row py-3">
|
||||
<div class="col-12">
|
||||
<div class="row py-3">
|
||||
<div class="col-12">
|
||||
<h3>Risk Assessment for Event N{{ object.event.pk|stringformat:"05d" }} {{ object.event.name }}</h3>
|
||||
<div class="card card-default mb-3">
|
||||
<div class="card-header">General</div>
|
||||
@@ -47,7 +47,7 @@
|
||||
<dd class="col-sm-6">
|
||||
{{ object.big_power|yesnoi:'invert' }}
|
||||
</dd>
|
||||
<dt class="col-sm-6">{{ object|help_text:'power_mic'|safe }}</dt>
|
||||
<dt class="col-sm-6">{{ object|help_text:'power_mic' }}</dt>
|
||||
<dd class="col-sm-6">
|
||||
{{ object.power_mic.name|default:'None' }}
|
||||
</dd>
|
||||
@@ -152,12 +152,13 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12 text-right">
|
||||
<a href="{% url 'ra_edit' object.pk %}" class="btn btn-warning my-3"><span class="fas fa-edit"></span> <span
|
||||
class="d-none d-sm-inline">Edit</span></a>
|
||||
<a href="{% url 'event_detail' object.event.pk %}" class="btn btn-primary"><span class="fas fa-eye"></span> View Event</a>
|
||||
{{ object.review_string|safe }}
|
||||
{% include 'partials/last_edited.html' with target="riskassessment_history" %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12 text-right">
|
||||
<a href="{% url 'ra_edit' object.pk %}" class="btn btn-warning my-3"><span class="fas fa-edit"></span> <span
|
||||
class="d-none d-sm-inline">Edit</span></a>
|
||||
<a href="{% url 'event_detail' object.event.pk %}" class="btn btn-primary"><span class="fas fa-eye"></span> View Event</a>
|
||||
{{ object.review_string|safe }}
|
||||
{% include 'partials/last_edited.html' with target="riskassessment_history" %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
@@ -6,19 +6,25 @@
|
||||
|
||||
{% block css %}
|
||||
{{ block.super }}
|
||||
<link rel="stylesheet" href="{% static 'css/selects.css' %}"/>
|
||||
<link rel="stylesheet" href="{% static 'css/bootstrap-select.css' %}"/>
|
||||
<link rel="stylesheet" href="{% static 'css/ajax-bootstrap-select.css' %}"/>
|
||||
{% endblock %}
|
||||
|
||||
{% block preload_js %}
|
||||
{{ block.super }}
|
||||
<script src="{% static 'js/selects.js' %}" async></script>
|
||||
<script src="{% static 'js/bootstrap-select.js' %}"></script>
|
||||
<script src="{% static 'js/ajax-bootstrap-select.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block js %}
|
||||
{{ block.super }}
|
||||
<script src="{% static 'js/autocompleter.js' %}"></script>
|
||||
<script src="{% static 'js/jquery-ui.js' %}"></script><!--TODO optimise--->
|
||||
<script src="{% static 'js/interaction.js' %}"></script>
|
||||
<script src="{% static 'js/modal.js' %}"></script>
|
||||
<script src="{% static 'js/tooltip.js' %}"></script>
|
||||
|
||||
<script src="{% static 'js/autocompleter.js' %}"></script>
|
||||
|
||||
<script>
|
||||
function parseBool(str) {
|
||||
return str.toLowerCase() == 'true';
|
||||
|
||||
@@ -4,7 +4,7 @@ from django.forms.forms import NON_FIELD_ERRORS
|
||||
from django.forms.utils import ErrorDict
|
||||
from django.template.defaultfilters import stringfilter
|
||||
from django.template.defaultfilters import yesno, title, truncatewords
|
||||
from django.urls import reverse
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils.html import escape
|
||||
from django.utils.safestring import SafeData, mark_safe
|
||||
from django.utils.text import normalize_newlines
|
||||
@@ -173,7 +173,7 @@ def title_spaced(string):
|
||||
@register.filter(needs_autoescape=True)
|
||||
def namewithnotes(obj, url, autoescape=True):
|
||||
if hasattr(obj, 'notes') and obj.notes is not None and len(obj.notes) > 0:
|
||||
return mark_safe(obj.name + " <a href='{}'><span class='fas fa-sticky-note'></span></a>".format(reverse(url, kwargs={'pk': obj.pk})))
|
||||
return mark_safe(obj.name + " <a href='{}'><span class='far fa-sticky-note'></span></a>".format(reverse_lazy(url, kwargs={'pk': obj.pk})))
|
||||
else:
|
||||
return obj.name
|
||||
|
||||
|
||||
@@ -1,108 +0,0 @@
|
||||
from RIGS import models
|
||||
import pytest
|
||||
from django.utils import timezone
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def basic_event(db):
|
||||
event = models.Event.objects.create(name="TE E1", start_date=timezone.now())
|
||||
yield event
|
||||
event.delete()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def ra(basic_event, admin_user):
|
||||
ra = models.RiskAssessment.objects.create(event=basic_event, nonstandard_equipment=False, nonstandard_use=False,
|
||||
contractors=False, other_companies=False, crew_fatigue=False,
|
||||
big_power=False, power_mic=admin_user, generators=False,
|
||||
other_companies_power=False, nonstandard_equipment_power=False,
|
||||
multiple_electrical_environments=False, noise_monitoring=False,
|
||||
known_venue=True, safe_loading=True, safe_storage=True,
|
||||
area_outside_of_control=True, barrier_required=True,
|
||||
nonstandard_emergency_procedure=True, special_structures=False,
|
||||
suspended_structures=False, outside=False)
|
||||
yield ra
|
||||
ra.delete()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def medium_ra(ra):
|
||||
ra.big_power = True
|
||||
ra.save()
|
||||
yield ra
|
||||
ra.big_power = False
|
||||
ra.save()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def venue(db):
|
||||
venue = models.Venue.objects.create(name="Venue 1")
|
||||
yield venue
|
||||
venue.delete()
|
||||
|
||||
|
||||
@pytest.fixture # TODO parameterise with Event sizes
|
||||
def checklist(basic_event, venue, admin_user, ra):
|
||||
checklist = models.EventChecklist.objects.create(event=basic_event, power_mic=admin_user, safe_parking=False,
|
||||
safe_packing=False, exits=False, trip_hazard=False, warning_signs=False,
|
||||
ear_plugs=False, hs_location="Locked away safely",
|
||||
extinguishers_location="Somewhere, I forgot", earthing=False, pat=False,
|
||||
date=timezone.now(), venue=venue)
|
||||
yield checklist
|
||||
checklist.delete()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def many_events(db, admin_user, scope="class"):
|
||||
many_events = {
|
||||
# produce 7 normal events - 5 current
|
||||
1: models.Event.objects.create(name="TE E1", start_date=date.today() + timedelta(days=6),
|
||||
description="start future no end"),
|
||||
2: models.Event.objects.create(name="TE E2", start_date=date.today(), description="start today no end"),
|
||||
3: models.Event.objects.create(name="TE E3", start_date=date.today(), end_date=date.today(),
|
||||
description="start today with end today"),
|
||||
4: models.Event.objects.create(name="TE E4", start_date='2014-03-20', description="start past no end"),
|
||||
5: models.Event.objects.create(name="TE E5", start_date='2014-03-20', end_date='2014-03-21',
|
||||
description="start past with end past"),
|
||||
6: models.Event.objects.create(name="TE E6", start_date=date.today() - timedelta(days=2),
|
||||
end_date=date.today() + timedelta(days=2),
|
||||
description="start past, end future"),
|
||||
7: models.Event.objects.create(name="TE E7", start_date=date.today() + timedelta(days=2),
|
||||
end_date=date.today() + timedelta(days=2),
|
||||
description="start + end in future"),
|
||||
|
||||
# 2 cancelled - 1 current
|
||||
8: models.Event.objects.create(name="TE E8", start_date=date.today() + timedelta(days=2),
|
||||
end_date=date.today() + timedelta(days=2), status=models.Event.CANCELLED,
|
||||
description="cancelled in future"),
|
||||
9: models.Event.objects.create(name="TE E9", start_date=date.today() - timedelta(days=1),
|
||||
end_date=date.today() + timedelta(days=2), status=models.Event.CANCELLED,
|
||||
description="cancelled and started"),
|
||||
|
||||
# 5 dry hire - 3 current
|
||||
10: models.Event.objects.create(name="TE E10", start_date=date.today(), dry_hire=True,
|
||||
description="dryhire today"),
|
||||
11: models.Event.objects.create(name="TE E11", start_date=date.today(), dry_hire=True,
|
||||
checked_in_by=admin_user,
|
||||
description="dryhire today, checked in"),
|
||||
12: models.Event.objects.create(name="TE E12", start_date=date.today() - timedelta(days=1), dry_hire=True,
|
||||
status=models.Event.BOOKED, description="dryhire past"),
|
||||
13: models.Event.objects.create(name="TE E13", start_date=date.today() - timedelta(days=2), dry_hire=True,
|
||||
checked_in_by=admin_user, description="dryhire past checked in"),
|
||||
14: models.Event.objects.create(name="TE E14", start_date=date.today(), dry_hire=True,
|
||||
status=models.Event.CANCELLED, description="dryhire today cancelled"),
|
||||
|
||||
# 4 non rig - 3 current
|
||||
15: models.Event.objects.create(name="TE E15", start_date=date.today(), is_rig=False,
|
||||
description="non rig today"),
|
||||
16: models.Event.objects.create(name="TE E16", start_date=date.today() + timedelta(days=1), is_rig=False,
|
||||
description="non rig tomorrow"),
|
||||
17: models.Event.objects.create(name="TE E17", start_date=date.today() - timedelta(days=1), is_rig=False,
|
||||
description="non rig yesterday"),
|
||||
18: models.Event.objects.create(name="TE E18", start_date=date.today(), is_rig=False,
|
||||
status=models.Event.CANCELLED,
|
||||
description="non rig today cancelled"),
|
||||
}
|
||||
yield many_events
|
||||
for event in many_events:
|
||||
event.delete()
|
||||
@@ -52,7 +52,7 @@ class EventDetail(BasePage):
|
||||
URL_TEMPLATE = 'event/{event_id}'
|
||||
|
||||
# TODO Refactor into regions to match template fragmentation
|
||||
_event_name_selector = (By.XPATH, '//h2')
|
||||
_event_name_selector = (By.XPATH, '//h1')
|
||||
_person_panel_selector = (By.XPATH, '//div[contains(text(), "Contact Details")]/..')
|
||||
_name_selector = (By.XPATH, '//dt[text()="Person"]/following-sibling::dd[1]')
|
||||
_email_selector = (By.XPATH, '//dt[text()="Email"]/following-sibling::dd[1]')
|
||||
@@ -230,11 +230,9 @@ class CreateEventChecklist(FormPage):
|
||||
URL_TEMPLATE = 'event/{event_id}/checklist'
|
||||
|
||||
_submit_locator = (By.XPATH, "//button[@type='submit' and contains(., 'Save')]")
|
||||
_power_mic_selector = (By.XPATH, "//div[select[@id='id_power_mic']]")
|
||||
_power_mic_selector = (By.XPATH, "//div[@id='id_power_mic-group']//div[contains(@class, 'bootstrap-select')]")
|
||||
_add_vehicle_locator = (By.XPATH, "//button[contains(., 'Vehicle')]")
|
||||
_add_crew_locator = (By.XPATH, "//button[contains(., 'Crew')]")
|
||||
_vehicle_row_locator = ('xpath', "//tr[@id[starts-with(., 'vehicle') and not(contains(.,'new'))]]")
|
||||
_crew_row_locator = ('xpath', "//tr[@id[starts-with(., 'crew') and not(contains(.,'new'))]]")
|
||||
|
||||
form_items = {
|
||||
'safe_parking': (regions.CheckBox, (By.ID, 'id_safe_parking')),
|
||||
@@ -273,61 +271,11 @@ class CreateEventChecklist(FormPage):
|
||||
def power_mic(self):
|
||||
return regions.BootstrapSelectElement(self, self.find_element(*self._power_mic_selector))
|
||||
|
||||
@property
|
||||
def vehicles(self):
|
||||
return [self.VehicleRow(self, el) for el in self.find_elements(*self._vehicle_row_locator)]
|
||||
|
||||
class VehicleRow(Region):
|
||||
_name_locator = ('xpath', ".//input")
|
||||
_select_locator = ('xpath', ".//div[contains(@class,'bootstrap-select')]/..")
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return regions.TextBox(self, self.root.find_element(*self._name_locator))
|
||||
|
||||
@property
|
||||
def vehicle(self):
|
||||
return regions.BootstrapSelectElement(self, self.root.find_element(*self._select_locator))
|
||||
|
||||
@property
|
||||
def crew(self):
|
||||
return [self.CrewRow(self, el) for el in self.find_elements(*self._crew_row_locator)]
|
||||
|
||||
class CrewRow(Region):
|
||||
_select_locator = ('xpath', ".//div[contains(@class,'bootstrap-select')]/..")
|
||||
_start_time_locator = ('xpath', ".//input[@name[starts-with(., 'start') and not(contains(.,'new'))]]")
|
||||
_end_time_locator = ('xpath', ".//input[@name[starts-with(., 'end') and not(contains(.,'new'))]]")
|
||||
_role_locator = ('xpath', ".//input[@name[starts-with(., 'role') and not(contains(.,'new'))]]")
|
||||
|
||||
@property
|
||||
def crewmember(self):
|
||||
return regions.BootstrapSelectElement(self, self.root.find_element(*self._select_locator))
|
||||
|
||||
@property
|
||||
def start_time(self):
|
||||
return regions.DateTimePicker(self, self.root.find_element(*self._start_time_locator))
|
||||
|
||||
@property
|
||||
def end_time(self):
|
||||
return regions.DateTimePicker(self, self.root.find_element(*self._end_time_locator))
|
||||
|
||||
@property
|
||||
def role(self):
|
||||
return regions.TextBox(self, self.root.find_element(*self._role_locator))
|
||||
|
||||
@property
|
||||
def success(self):
|
||||
return '{event_id}' not in self.driver.current_url
|
||||
|
||||
|
||||
class EditEventChecklist(CreateEventChecklist):
|
||||
URL_TEMPLATE = '/event/checklist/{pk}/edit'
|
||||
|
||||
@property
|
||||
def success(self):
|
||||
return 'edit' not in self.driver.current_url
|
||||
|
||||
|
||||
class GenericList(BasePage):
|
||||
_search_selector = (By.CSS_SELECTOR, 'div.input-group:nth-child(2) > input:nth-child(1)')
|
||||
_search_go_selector = (By.ID, 'id_search')
|
||||
|
||||
@@ -8,12 +8,54 @@ from django.http import HttpResponseBadRequest
|
||||
from django.test import TestCase
|
||||
from django.urls import reverse
|
||||
|
||||
import PyRIGS.tests.base
|
||||
from RIGS import models
|
||||
from pytest_django.asserts import assertContains, assertNotContains, assertFormError
|
||||
from pytest_django.asserts import assertContains, assertNotContains
|
||||
|
||||
|
||||
class BaseCase(TestCase):
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
cls.vatrate = models.VatRate.objects.create(start_at='2014-03-05', rate=0.20, comment='test1')
|
||||
cls.profile = models.Profile.objects.get_or_create(
|
||||
first_name='Test',
|
||||
last_name='TEC User',
|
||||
username='eventauthtest',
|
||||
email='teccie@functional.test',
|
||||
is_superuser=True # lazily grant all permissions
|
||||
)[0]
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.profile.set_password('testuser')
|
||||
self.profile.save()
|
||||
self.assertTrue(self.client.login(username=self.profile.username, password='testuser'))
|
||||
venue = models.Venue.objects.create(name='Authorisation Test Venue')
|
||||
client = models.Person.objects.create(name='Authorisation Test Person', email='authorisation@functional.test')
|
||||
organisation = models.Organisation.objects.create(name='Authorisation Test Organisation', union_account=True)
|
||||
self.event = models.Event.objects.create(
|
||||
name='Authorisation Test',
|
||||
start_date=date.today(),
|
||||
venue=venue,
|
||||
person=client,
|
||||
organisation=organisation,
|
||||
)
|
||||
|
||||
|
||||
class TestEventValidation(BaseCase):
|
||||
def test_create(self):
|
||||
url = reverse('event_create')
|
||||
# end time before start access after start
|
||||
response = self.client.post(url, {'start_date': datetime.date(2020, 1, 1), 'start_time': datetime.time(10, 00),
|
||||
'end_time': datetime.time(9, 00),
|
||||
'access_at': datetime.datetime(2020, 1, 5, 10)})
|
||||
self.assertFormError(response, 'form', 'end_time',
|
||||
"Unless you've invented time travel, the event can't finish before it has started.")
|
||||
self.assertFormError(response, 'form', 'access_at',
|
||||
"Regardless of what some clients might think, access time cannot be after the event has started.")
|
||||
|
||||
|
||||
def setup_event():
|
||||
models.VatRate.objects.create(start_at='2014-03-05', rate=0.20, comment='test1')
|
||||
venue = models.Venue.objects.create(name='Authorisation Test Venue')
|
||||
client = models.Person.objects.create(name='Authorisation Test Person', email='authorisation@functional.test')
|
||||
organisation = models.Organisation.objects.create(name='Authorisation Test Organisation', union_account=True)
|
||||
@@ -42,18 +84,6 @@ def setup_mail(event, profile):
|
||||
return auth_data, hmac, url
|
||||
|
||||
|
||||
def test_create(admin_client):
|
||||
url = reverse('event_create')
|
||||
# end time before start access after start
|
||||
response = admin_client.post(url, {'start_date': datetime.date(2020, 1, 1), 'start_time': datetime.time(10, 00),
|
||||
'end_time': datetime.time(9, 00),
|
||||
'access_at': datetime.datetime(2020, 1, 5, 10)})
|
||||
assertFormError(response, 'form', 'end_time',
|
||||
"Unless you've invented time travel, the event can't finish before it has started.")
|
||||
assertFormError(response, 'form', 'access_at',
|
||||
"Regardless of what some clients might think, access time cannot be after the event has started.")
|
||||
|
||||
|
||||
def test_requires_valid_hmac(client, admin_user):
|
||||
event = setup_event()
|
||||
auth_data, hmac, url = setup_mail(event, admin_user)
|
||||
@@ -108,7 +138,7 @@ def test_duplicate_warning(client, admin_user):
|
||||
assertContains(response, 'amount has changed')
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
@pytest.mark.django_db(transaction=True)
|
||||
def test_email_sent(admin_client, admin_user, mailoutbox):
|
||||
event = setup_event()
|
||||
auth_data, hmac, url = setup_mail(event, admin_user)
|
||||
@@ -122,36 +152,36 @@ def test_email_sent(admin_client, admin_user, mailoutbox):
|
||||
assert mailoutbox[1].to == [settings.AUTHORISATION_NOTIFICATION_ADDRESS]
|
||||
|
||||
|
||||
def test_email_check(admin_client, admin_user):
|
||||
event = setup_event()
|
||||
url = reverse('event_authorise_request', kwargs={'pk': event.pk})
|
||||
admin_user.email = 'teccie@someotherdomain.com'
|
||||
admin_user.save()
|
||||
class TECEventAuthorisationTest(BaseCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.url = reverse('event_authorise_request', kwargs={'pk': self.event.pk})
|
||||
|
||||
response = admin_client.post(url)
|
||||
def test_email_check(self):
|
||||
self.profile.email = 'teccie@someotherdomain.com'
|
||||
self.profile.save()
|
||||
|
||||
assertContains(response, 'must have an @nottinghamtec.co.uk email address')
|
||||
response = self.client.post(self.url)
|
||||
|
||||
self.assertContains(response, 'must have an @nottinghamtec.co.uk email address')
|
||||
|
||||
def test_request_send(admin_client, admin_user):
|
||||
event = setup_event()
|
||||
url = reverse('event_authorise_request', kwargs={'pk': event.pk})
|
||||
admin_user.email = 'teccie@nottinghamtec.co.uk'
|
||||
admin_user.save()
|
||||
response = admin_client.post(url)
|
||||
assertContains(response, 'This field is required.')
|
||||
def test_request_send(self):
|
||||
self.profile.email = 'teccie@nottinghamtec.co.uk'
|
||||
self.profile.save()
|
||||
response = self.client.post(self.url)
|
||||
self.assertContains(response, 'This field is required.')
|
||||
|
||||
mail.outbox = []
|
||||
mail.outbox = []
|
||||
|
||||
response = admin_client.post(url, {'email': 'client@functional.test'})
|
||||
assert response.status_code == 302
|
||||
assert len(mail.outbox) == 1
|
||||
email = mail.outbox[0]
|
||||
assert 'client@functional.test' in email.to
|
||||
assert '/event/%d/' % event.pk in email.body
|
||||
response = self.client.post(self.url, {'email': 'client@functional.test'})
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertEqual(len(mail.outbox), 1)
|
||||
email = mail.outbox[0]
|
||||
self.assertIn('client@functional.test', email.to)
|
||||
self.assertIn('/event/%d/' % (self.event.pk), email.body)
|
||||
|
||||
# Check sent by details are populated
|
||||
event.refresh_from_db()
|
||||
assert event.auth_request_by == admin_user
|
||||
assert event.auth_request_to == 'client@functional.test'
|
||||
assert event.auth_request_at is not None
|
||||
# Check sent by details are populated
|
||||
self.event.refresh_from_db()
|
||||
self.assertEqual(self.event.auth_request_by, self.profile)
|
||||
self.assertEqual(self.event.auth_request_to, 'client@functional.test')
|
||||
self.assertIsNotNone(self.event.auth_request_at)
|
||||
|
||||
@@ -15,11 +15,6 @@ from PyRIGS.tests.pages import animation_is_finished
|
||||
from RIGS import models
|
||||
from RIGS.tests import regions
|
||||
from . import pages
|
||||
import pytest
|
||||
import time as t
|
||||
|
||||
|
||||
pytestmark = pytest.mark.django_db(transaction=True)
|
||||
|
||||
|
||||
@screenshot_failure_cls
|
||||
@@ -312,13 +307,13 @@ class TestEventDuplicate(BaseRigboardTest):
|
||||
# TODO Rewrite when EventDetail page is implemented
|
||||
newEvent = models.Event.objects.latest('pk')
|
||||
|
||||
assert newEvent.auth_request_to == ''
|
||||
self.assertEqual(newEvent.auth_request_to, None)
|
||||
self.assertEqual(newEvent.auth_request_by, None)
|
||||
self.assertEqual(newEvent.auth_request_at, None)
|
||||
|
||||
self.assertFalse(newEvent.authorised)
|
||||
|
||||
self.assertNotIn("N%05d" % self.testEvent.pk, self.driver.find_element_by_xpath('//h2').text)
|
||||
self.assertNotIn("N%05d" % self.testEvent.pk, self.driver.find_element_by_xpath('//h1').text)
|
||||
self.assertNotIn("Event data duplicated but not yet saved", self.page.warning) # Check info message not visible
|
||||
|
||||
# Check the new items are visible
|
||||
@@ -450,7 +445,7 @@ class TestEventDetail(BaseRigboardTest):
|
||||
self.assertIn("N%05d | %s" % (self.testEvent.pk, self.testEvent.name), self.page.event_name)
|
||||
self.assertEqual(self.client.name, self.page.name)
|
||||
self.assertEqual(self.client.email, self.page.email)
|
||||
assert self.client.phone == ''
|
||||
self.assertEqual(self.client.phone, None)
|
||||
|
||||
|
||||
@screenshot_failure_cls
|
||||
@@ -638,190 +633,270 @@ class TestCalendar(BaseRigboardTest):
|
||||
else:
|
||||
self.assertNotContains(response, "TE E" + str(test) + " ")
|
||||
|
||||
def test_calendar_buttons(self): # If FullCalendar fails to load for whatever reason, the buttons don't work
|
||||
self.page = pages.CalendarPage(self.driver, self.live_server_url).open()
|
||||
self.assertIn(timezone.now().strftime("%Y-%m"), self.driver.current_url)
|
||||
|
||||
def test_calendar_buttons(logged_in_browser, live_server): # If FullCalendar fails to load for whatever reason, the buttons don't work
|
||||
page = pages.CalendarPage(logged_in_browser.driver, live_server.url).open()
|
||||
assert timezone.now().strftime("%Y-%m") in logged_in_browser.url
|
||||
target_date = datetime.date(2020, 1, 1)
|
||||
self.page.target_date.set_value(target_date)
|
||||
self.page.go()
|
||||
self.assertIn(self.page.target_date.value.strftime("%Y-%m"), self.driver.current_url)
|
||||
|
||||
target_date = datetime.date(2020, 1, 1)
|
||||
page.target_date.set_value(target_date)
|
||||
page.go()
|
||||
assert page.target_date.value.strftime("%Y-%m") in logged_in_browser.url
|
||||
|
||||
page.next()
|
||||
target_date += datetime.timedelta(days=32)
|
||||
assert target_date.strftime("%m") in logged_in_browser.url
|
||||
self.page.next()
|
||||
target_date += datetime.timedelta(days=32)
|
||||
self.assertIn(target_date.strftime("%m"), self.driver.current_url)
|
||||
|
||||
|
||||
def test_ra_edit(logged_in_browser, live_server, ra):
|
||||
page = pages.EditRiskAssessment(logged_in_browser.driver, live_server.url, pk=ra.pk).open()
|
||||
page.nonstandard_equipment = nse = True
|
||||
page.general_notes = gn = "There are some notes, but I've not written them here as that would be helpful"
|
||||
page.submit()
|
||||
assert not page.success
|
||||
page.supervisor_consulted = True
|
||||
page.submit()
|
||||
assert page.success
|
||||
# Check that data is right
|
||||
ra = models.RiskAssessment.objects.get(pk=ra.pk)
|
||||
assert ra.general_notes == gn
|
||||
assert ra.nonstandard_equipment == nse
|
||||
@screenshot_failure_cls
|
||||
class TestHealthAndSafety(BaseRigboardTest):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.profile = models.Profile.objects.get_or_create(
|
||||
first_name='Test',
|
||||
last_name='TEC User',
|
||||
username='eventtest',
|
||||
email='teccie@functional.test',
|
||||
is_superuser=True # lazily grant all permissions
|
||||
)[0]
|
||||
self.venue = models.Venue.objects.create(name="Venue 1")
|
||||
|
||||
self.testEvent = models.Event.objects.create(name="TE E1", status=models.Event.PROVISIONAL,
|
||||
start_date=date.today() + timedelta(days=6),
|
||||
description="start future no end",
|
||||
purchase_order='TESTPO',
|
||||
person=self.client,
|
||||
venue=self.venue)
|
||||
self.testEvent2 = models.Event.objects.create(name="TE E2", status=models.Event.PROVISIONAL,
|
||||
start_date=date.today() + timedelta(days=6),
|
||||
description="start future no end",
|
||||
purchase_order='TESTPO',
|
||||
person=self.client,
|
||||
venue=self.venue)
|
||||
self.testEvent3 = models.Event.objects.create(name="TE E3", status=models.Event.PROVISIONAL,
|
||||
start_date=date.today() + timedelta(days=6),
|
||||
description="start future no end",
|
||||
purchase_order='TESTPO',
|
||||
person=self.client,
|
||||
venue=self.venue)
|
||||
self.testRA = models.RiskAssessment.objects.create(event=self.testEvent2, supervisor_consulted=False, nonstandard_equipment=False,
|
||||
nonstandard_use=False,
|
||||
contractors=False,
|
||||
other_companies=False,
|
||||
crew_fatigue=False,
|
||||
big_power=False,
|
||||
generators=False,
|
||||
other_companies_power=False,
|
||||
nonstandard_equipment_power=False,
|
||||
multiple_electrical_environments=False,
|
||||
noise_monitoring=False,
|
||||
known_venue=True,
|
||||
safe_loading=True,
|
||||
safe_storage=True,
|
||||
area_outside_of_control=False,
|
||||
barrier_required=False,
|
||||
nonstandard_emergency_procedure=False,
|
||||
special_structures=False,
|
||||
suspended_structures=False,
|
||||
outside=False)
|
||||
self.testRA2 = models.RiskAssessment.objects.create(event=self.testEvent3, supervisor_consulted=False, nonstandard_equipment=False,
|
||||
nonstandard_use=False,
|
||||
contractors=False,
|
||||
other_companies=False,
|
||||
crew_fatigue=False,
|
||||
big_power=True,
|
||||
generators=False,
|
||||
other_companies_power=False,
|
||||
nonstandard_equipment_power=False,
|
||||
multiple_electrical_environments=False,
|
||||
noise_monitoring=False,
|
||||
known_venue=True,
|
||||
safe_loading=True,
|
||||
safe_storage=True,
|
||||
area_outside_of_control=False,
|
||||
barrier_required=False,
|
||||
nonstandard_emergency_procedure=False,
|
||||
special_structures=False,
|
||||
suspended_structures=False,
|
||||
outside=False)
|
||||
self.page = pages.EventDetail(self.driver, self.live_server_url, event_id=self.testEvent.pk).open()
|
||||
|
||||
def small_ec(page, admin_user):
|
||||
page.safe_parking = True
|
||||
page.safe_packing = True
|
||||
page.exits = True
|
||||
page.trip_hazard = True
|
||||
page.warning_signs = True
|
||||
page.ear_plugs = True
|
||||
page.hs_location = "The Moon"
|
||||
page.extinguishers_location = "With the rest of the fire"
|
||||
# If we do this first the search fails, for ... reasons
|
||||
page.power_mic.search(admin_user.name)
|
||||
page.power_mic.toggle()
|
||||
assert not page.power_mic.is_open
|
||||
page.earthing = True
|
||||
page.rcds = True
|
||||
page.supply_test = True
|
||||
page.pat = True
|
||||
# TODO Can I loop through all the boolean fields and test them at once?
|
||||
def test_ra_creation(self):
|
||||
self.page = pages.CreateRiskAssessment(self.driver, self.live_server_url, event_id=self.testEvent.pk).open()
|
||||
|
||||
# Check there are no defaults
|
||||
self.assertIsNone(self.page.nonstandard_equipment)
|
||||
|
||||
def test_ec_create_small(logged_in_browser, live_server, admin_user, ra):
|
||||
page = pages.CreateEventChecklist(logged_in_browser.driver, live_server.url, event_id=ra.event.pk).open()
|
||||
small_ec(page, admin_user)
|
||||
page.submit()
|
||||
assert page.success
|
||||
# No database side validation, only HTML5.
|
||||
|
||||
self.page.nonstandard_equipment = False
|
||||
self.page.nonstandard_use = False
|
||||
self.page.contractors = False
|
||||
self.page.other_companies = False
|
||||
self.page.crew_fatigue = False
|
||||
self.page.general_notes = "There are no notes."
|
||||
self.page.big_power = False
|
||||
self.page.outside = False
|
||||
self.page.power_mic.search(self.profile.name)
|
||||
self.page.power_mic.set_option(self.profile.name, True)
|
||||
# TODO This should not be necessary, normally closes automatically
|
||||
self.page.power_mic.toggle()
|
||||
self.assertFalse(self.page.power_mic.is_open)
|
||||
self.page.generators = False
|
||||
self.page.other_companies_power = False
|
||||
self.page.nonstandard_equipment_power = False
|
||||
self.page.multiple_electrical_environments = False
|
||||
self.page.power_notes = "Remember to bring some power"
|
||||
self.page.noise_monitoring = False
|
||||
self.page.sound_notes = "Loud, but not too loud"
|
||||
self.page.known_venue = False
|
||||
self.page.safe_loading = False
|
||||
self.page.safe_storage = False
|
||||
self.page.area_outside_of_control = False
|
||||
self.page.barrier_required = False
|
||||
self.page.nonstandard_emergency_procedure = False
|
||||
self.page.special_structures = False
|
||||
# self.page.persons_responsible_structures = "Nobody and her cat, She"
|
||||
|
||||
def test_ec_create_medium(logged_in_browser, live_server, admin_user, medium_ra):
|
||||
page = pages.CreateEventChecklist(logged_in_browser.driver, live_server.url, event_id=medium_ra.event.pk).open()
|
||||
self.page.suspended_structures = True
|
||||
# TODO Test for this proper
|
||||
self.page.rigging_plan = "https://nottinghamtec.sharepoint.com/test/"
|
||||
self.page.submit()
|
||||
self.assertFalse(self.page.success)
|
||||
|
||||
page.safe_parking = True
|
||||
page.safe_packing = True
|
||||
page.exits = True
|
||||
page.trip_hazard = True
|
||||
page.warning_signs = True
|
||||
page.ear_plugs = True
|
||||
page.hs_location = "Death Valley"
|
||||
page.extinguishers_location = "With the rest of the fire"
|
||||
# If we do this first the search fails, for ... reasons
|
||||
page.power_mic.search(admin_user.name)
|
||||
page.power_mic.toggle()
|
||||
assert not page.power_mic.is_open
|
||||
self.page.suspended_structures = False
|
||||
self.page.submit()
|
||||
self.assertTrue(self.page.success)
|
||||
|
||||
# Gotta scroll to make the button clickable
|
||||
logged_in_browser.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
|
||||
# Test that we can't make another one
|
||||
self.page = pages.CreateRiskAssessment(self.driver, self.live_server_url, event_id=self.testEvent.pk).open()
|
||||
self.assertIn('edit', self.driver.current_url)
|
||||
|
||||
page.earthing = True
|
||||
page.pat = True
|
||||
page.source_rcd = True
|
||||
page.labelling = True
|
||||
page.fd_voltage_l1 = 240
|
||||
page.fd_voltage_l2 = 235
|
||||
page.fd_voltage_l3 = 0
|
||||
page.fd_phase_rotation = True
|
||||
page.fd_earth_fault = 666
|
||||
page.fd_pssc = 1984
|
||||
page.w1_description = "In the carpark, by the bins"
|
||||
page.w1_polarity = True
|
||||
page.w1_voltage = 240
|
||||
page.w1_earth_fault = 333
|
||||
def test_ra_edit(self):
|
||||
self.page = pages.EditRiskAssessment(self.driver, self.live_server_url, pk=self.testRA.pk).open()
|
||||
self.page.nonstandard_equipment = nse = True
|
||||
self.page.general_notes = gn = "There are some notes, but I've not written them here as that would be helpful"
|
||||
self.page.submit()
|
||||
self.assertFalse(self.page.success)
|
||||
self.page.supervisor_consulted = True
|
||||
self.page.submit()
|
||||
self.assertTrue(self.page.success)
|
||||
# Check that data is right
|
||||
ra = models.RiskAssessment.objects.get(pk=self.testRA.pk)
|
||||
self.assertEqual(ra.general_notes, gn)
|
||||
self.assertEqual(ra.nonstandard_equipment, nse)
|
||||
|
||||
page.submit()
|
||||
assert page.success
|
||||
def test_ec_create_small(self):
|
||||
self.page = pages.CreateEventChecklist(self.driver, self.live_server_url, event_id=self.testEvent2.pk).open()
|
||||
|
||||
self.page.safe_parking = True
|
||||
self.page.safe_packing = True
|
||||
self.page.exits = True
|
||||
self.page.trip_hazard = True
|
||||
self.page.warning_signs = True
|
||||
self.page.ear_plugs = True
|
||||
self.page.hs_location = "The Moon"
|
||||
self.page.extinguishers_location = "With the rest of the fire"
|
||||
# If we do this first the search fails, for ... reasons
|
||||
self.page.power_mic.search(self.profile.name)
|
||||
self.page.power_mic.toggle()
|
||||
self.assertFalse(self.page.power_mic.is_open)
|
||||
|
||||
def test_ec_create_vehicle(logged_in_browser, live_server, admin_user, checklist):
|
||||
page = pages.EditEventChecklist(logged_in_browser.driver, live_server.url, pk=checklist.pk).open()
|
||||
small_ec(page, admin_user)
|
||||
page.add_vehicle()
|
||||
assert len(page.vehicles) == 1
|
||||
vehicle_name = 'Brian'
|
||||
page.vehicles[0].name.set_value(vehicle_name)
|
||||
# Appears we're moving too fast for javascript...
|
||||
t.sleep(1)
|
||||
page.vehicles[0].vehicle.search(admin_user.first_name)
|
||||
t.sleep(1)
|
||||
page.submit()
|
||||
assert page.success
|
||||
# Check data is correct
|
||||
checklist.refresh_from_db()
|
||||
vehicle = models.EventChecklistVehicle.objects.get(checklist=checklist.pk)
|
||||
assert vehicle_name == vehicle.vehicle
|
||||
# Gotta scroll to make the button clickable
|
||||
self.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
|
||||
|
||||
self.page.earthing = True
|
||||
self.page.rcds = True
|
||||
self.page.supply_test = True
|
||||
self.page.pat = True
|
||||
|
||||
# TODO Test validation of end before start
|
||||
def test_ec_create_crew(logged_in_browser, live_server, admin_user, checklist):
|
||||
page = pages.EditEventChecklist(logged_in_browser.driver, live_server.url, pk=checklist.pk).open()
|
||||
small_ec(page, admin_user)
|
||||
page.add_crew()
|
||||
assert len(page.crew) == 1
|
||||
role = "MIC"
|
||||
start_time = timezone.make_aware(datetime.datetime(2015, 1, 1, 9, 0))
|
||||
end_time = timezone.make_aware(datetime.datetime(2015, 1, 1, 10, 30))
|
||||
crew = page.crew[0]
|
||||
t.sleep(2)
|
||||
crew.crewmember.search(admin_user.first_name)
|
||||
t.sleep(2)
|
||||
crew.role.set_value(role)
|
||||
crew.start_time.set_value(start_time)
|
||||
crew.end_time.set_value(end_time)
|
||||
page.submit()
|
||||
assert page.success
|
||||
# Check data is correct
|
||||
crew_obj = models.EventChecklistCrew.objects.get(checklist=checklist.pk)
|
||||
assert admin_user.pk == crew_obj.crewmember.pk
|
||||
assert role == crew_obj.role
|
||||
assert start_time == crew_obj.start
|
||||
assert end_time == crew_obj.end
|
||||
self.page.submit()
|
||||
self.assertTrue(self.page.success)
|
||||
|
||||
def test_ec_create_medium(self):
|
||||
self.page = pages.CreateEventChecklist(self.driver, self.live_server_url, event_id=self.testEvent3.pk).open()
|
||||
|
||||
# TODO Can I loop through all the boolean fields and test them at once?
|
||||
def test_ra_creation(logged_in_browser, live_server, admin_user, basic_event):
|
||||
page = pages.CreateRiskAssessment(logged_in_browser.driver, live_server.url, event_id=basic_event.pk).open()
|
||||
self.page.safe_parking = True
|
||||
self.page.safe_packing = True
|
||||
self.page.exits = True
|
||||
self.page.trip_hazard = True
|
||||
self.page.warning_signs = True
|
||||
self.page.ear_plugs = True
|
||||
self.page.hs_location = "Death Valley"
|
||||
self.page.extinguishers_location = "With the rest of the fire"
|
||||
# If we do this first the search fails, for ... reasons
|
||||
self.page.power_mic.search(self.profile.name)
|
||||
self.page.power_mic.toggle()
|
||||
self.assertFalse(self.page.power_mic.is_open)
|
||||
|
||||
# Check there are no defaults
|
||||
assert page.nonstandard_equipment is None
|
||||
# Gotta scroll to make the button clickable
|
||||
self.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
|
||||
|
||||
# No database side validation, only HTML5.
|
||||
page.nonstandard_equipment = False
|
||||
page.nonstandard_use = False
|
||||
page.contractors = False
|
||||
page.other_companies = False
|
||||
page.crew_fatigue = False
|
||||
page.general_notes = "There are no notes."
|
||||
page.big_power = False
|
||||
page.outside = False
|
||||
page.power_mic.search(admin_user.first_name)
|
||||
page.generators = False
|
||||
page.other_companies_power = False
|
||||
page.nonstandard_equipment_power = False
|
||||
page.multiple_electrical_environments = False
|
||||
page.power_notes = "Remember to bring some power"
|
||||
page.noise_monitoring = False
|
||||
page.sound_notes = "Loud, but not too loud"
|
||||
page.known_venue = False
|
||||
page.safe_loading = False
|
||||
page.safe_storage = False
|
||||
page.area_outside_of_control = False
|
||||
page.barrier_required = False
|
||||
page.nonstandard_emergency_procedure = False
|
||||
page.special_structures = False
|
||||
# self.page.persons_responsible_structures = "Nobody and her cat, She"
|
||||
self.page.earthing = True
|
||||
self.page.pat = True
|
||||
self.page.source_rcd = True
|
||||
self.page.labelling = True
|
||||
self.page.fd_voltage_l1 = 240
|
||||
self.page.fd_voltage_l2 = 235
|
||||
self.page.fd_voltage_l3 = 0
|
||||
self.page.fd_phase_rotation = True
|
||||
self.page.fd_earth_fault = 666
|
||||
self.page.fd_pssc = 1984
|
||||
self.page.w1_description = "In the carpark, by the bins"
|
||||
self.page.w1_polarity = True
|
||||
self.page.w1_voltage = 240
|
||||
self.page.w1_earth_fault = 333
|
||||
|
||||
page.suspended_structures = True
|
||||
# TODO Test for this proper
|
||||
page.rigging_plan = "https://nottinghamtec.sharepoint.com/test/"
|
||||
page.submit()
|
||||
assert not page.success
|
||||
self.page.submit()
|
||||
self.assertTrue(self.page.success)
|
||||
|
||||
page.suspended_structures = False
|
||||
page.submit()
|
||||
assert page.success
|
||||
def test_ec_create_extras(self):
|
||||
eid = self.testEvent2.pk
|
||||
self.page = pages.CreateEventChecklist(self.driver, self.live_server_url, event_id=eid).open()
|
||||
self.page.add_vehicle()
|
||||
self.page.add_crew()
|
||||
|
||||
self.page.safe_parking = True
|
||||
self.page.safe_packing = True
|
||||
self.page.exits = True
|
||||
self.page.trip_hazard = True
|
||||
self.page.warning_signs = True
|
||||
self.page.ear_plugs = True
|
||||
self.page.hs_location = "The Moon"
|
||||
self.page.extinguishers_location = "With the rest of the fire"
|
||||
# If we do this first the search fails, for ... reasons
|
||||
self.page.power_mic.search(self.profile.name)
|
||||
self.page.power_mic.toggle()
|
||||
self.assertFalse(self.page.power_mic.is_open)
|
||||
|
||||
def test_ra_no_duplicates(logged_in_browser, live_server, ra):
|
||||
# Test that we can't make another one
|
||||
page = pages.CreateRiskAssessment(logged_in_browser.driver, live_server.url, event_id=ra.event.pk).open()
|
||||
assert 'edit' in logged_in_browser.url
|
||||
vehicle_name = 'Brian'
|
||||
self.driver.find_element(By.XPATH, '//*[@name="vehicle_-1"]').send_keys(vehicle_name)
|
||||
driver = base_regions.BootstrapSelectElement(self.page, self.driver.find_element(By.XPATH, '//tr[@id="vehicles_-1"]//div[contains(@class, "bootstrap-select")]'))
|
||||
driver.search(self.profile.name)
|
||||
|
||||
crew = self.profile
|
||||
role = "MIC"
|
||||
crew_select = base_regions.BootstrapSelectElement(self.page, self.driver.find_element(By.XPATH, '//tr[@id="crew_-1"]//div[contains(@class, "bootstrap-select")]'))
|
||||
start_time = base_regions.DateTimePicker(self.page, self.driver.find_element(By.XPATH, '//*[@name="start_-1"]'))
|
||||
end_time = base_regions.DateTimePicker(self.page, self.driver.find_element(By.XPATH, '//*[@name="end_-1"]'))
|
||||
|
||||
start_time.set_value(timezone.make_aware(datetime.datetime(2015, 1, 1, 9, 0)))
|
||||
# TODO Test validation of end before start
|
||||
end_time.set_value(timezone.make_aware(datetime.datetime(2015, 1, 1, 10, 30)))
|
||||
crew_select.search(crew.name)
|
||||
self.driver.find_element(By.XPATH, '//*[@name="role_-1"]').send_keys(role)
|
||||
|
||||
self.page.earthing = True
|
||||
self.page.rcds = True
|
||||
self.page.supply_test = True
|
||||
self.page.pat = True
|
||||
|
||||
self.page.submit()
|
||||
self.assertTrue(self.page.success)
|
||||
|
||||
checklist = models.EventChecklist.objects.get(event=eid)
|
||||
vehicle = models.EventChecklistVehicle.objects.get(checklist=checklist.pk)
|
||||
self.assertEqual(vehicle_name, vehicle.vehicle)
|
||||
crew_obj = models.EventChecklistCrew.objects.get(checklist=checklist.pk)
|
||||
self.assertEqual(crew.pk, crew_obj.crewmember.pk)
|
||||
self.assertEqual(role, crew_obj.role)
|
||||
|
||||
@@ -2,7 +2,6 @@ from datetime import date, timedelta, datetime, time
|
||||
from decimal import *
|
||||
|
||||
import pytz
|
||||
import pytest
|
||||
from django.conf import settings
|
||||
from django.test import TestCase
|
||||
from reversion import revisions as reversion
|
||||
@@ -10,56 +9,110 @@ from reversion import revisions as reversion
|
||||
from RIGS import models
|
||||
|
||||
|
||||
def assert_decimal_equality(d1, d2):
|
||||
assert float(d1) == pytest.approx(float(d2))
|
||||
class ProfileTestCase(TestCase):
|
||||
def test_str(self):
|
||||
profile = models.Profile(first_name='Test', last_name='Case')
|
||||
self.assertEqual(str(profile), 'Test Case')
|
||||
profile.initials = 'TC'
|
||||
self.assertEqual(str(profile), 'Test Case "TC"')
|
||||
|
||||
|
||||
def test_str():
|
||||
profile = models.Profile(first_name='Test', last_name='Case')
|
||||
assert str(profile) == 'Test Case'
|
||||
profile.initials = 'TC'
|
||||
assert str(profile) == 'Test Case "TC"'
|
||||
class VatRateTestCase(TestCase):
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
cls.rates = {
|
||||
0: models.VatRate.objects.create(start_at='2014-03-01', rate=0.20, comment='test1'),
|
||||
1: models.VatRate.objects.create(start_at='2016-03-01', rate=0.15, comment='test2'),
|
||||
}
|
||||
|
||||
def test_find_correct(self):
|
||||
r = models.VatRate.objects.find_rate('2015-03-01')
|
||||
self.assertEqual(r, self.rates[0])
|
||||
r = models.VatRate.objects.find_rate('2016-03-01')
|
||||
self.assertEqual(r, self.rates[1])
|
||||
|
||||
def test_percent_correct(self):
|
||||
self.assertEqual(self.rates[0].as_percent, 20)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_find_correct(vat_rate):
|
||||
new_rate = models.VatRate.objects.create(start_at='2016-03-01', rate=0.15, comment='test2')
|
||||
r = models.VatRate.objects.find_rate('2015-03-01')
|
||||
assert_decimal_equality(r.rate, vat_rate.rate)
|
||||
r = models.VatRate.objects.find_rate('2016-03-01')
|
||||
assert_decimal_equality(r.rate, new_rate.rate)
|
||||
class EventTestCase(TestCase):
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
cls.all_events = set(range(1, 18))
|
||||
cls.current_events = (1, 2, 3, 6, 7, 8, 10, 11, 12, 14, 15, 16, 18)
|
||||
cls.not_current_events = set(cls.all_events) - set(cls.current_events)
|
||||
|
||||
cls.vatrate = models.VatRate.objects.create(start_at='2014-03-05', rate=0.20, comment='test1')
|
||||
cls.profile = models.Profile.objects.create(username="testuser1", email="1@test.com")
|
||||
|
||||
def test_percent_correct(vat_rate):
|
||||
assert vat_rate.as_percent == 20
|
||||
cls.events = {
|
||||
# produce 7 normal events - 5 current
|
||||
1: models.Event.objects.create(name="TE E1", start_date=date.today() + timedelta(days=6),
|
||||
description="start future no end"),
|
||||
2: models.Event.objects.create(name="TE E2", start_date=date.today(), description="start today no end"),
|
||||
3: models.Event.objects.create(name="TE E3", start_date=date.today(), end_date=date.today(),
|
||||
description="start today with end today"),
|
||||
4: models.Event.objects.create(name="TE E4", start_date='2014-03-20', description="start past no end"),
|
||||
5: models.Event.objects.create(name="TE E5", start_date='2014-03-20', end_date='2014-03-21',
|
||||
description="start past with end past"),
|
||||
6: models.Event.objects.create(name="TE E6", start_date=date.today() - timedelta(days=2),
|
||||
end_date=date.today() + timedelta(days=2),
|
||||
description="start past, end future"),
|
||||
7: models.Event.objects.create(name="TE E7", start_date=date.today() + timedelta(days=2),
|
||||
end_date=date.today() + timedelta(days=2),
|
||||
description="start + end in future"),
|
||||
|
||||
# 2 cancelled - 1 current
|
||||
8: models.Event.objects.create(name="TE E8", start_date=date.today() + timedelta(days=2),
|
||||
end_date=date.today() + timedelta(days=2), status=models.Event.CANCELLED,
|
||||
description="cancelled in future"),
|
||||
9: models.Event.objects.create(name="TE E9", start_date=date.today() - timedelta(days=1),
|
||||
end_date=date.today() + timedelta(days=2), status=models.Event.CANCELLED,
|
||||
description="cancelled and started"),
|
||||
|
||||
def test_related_vatrate(basic_event, vat_rate):
|
||||
assert_decimal_equality(vat_rate.rate, basic_event.vat_rate.rate)
|
||||
# 5 dry hire - 3 current
|
||||
10: models.Event.objects.create(name="TE E10", start_date=date.today(), dry_hire=True,
|
||||
description="dryhire today"),
|
||||
11: models.Event.objects.create(name="TE E11", start_date=date.today(), dry_hire=True,
|
||||
checked_in_by=cls.profile,
|
||||
description="dryhire today, checked in"),
|
||||
12: models.Event.objects.create(name="TE E12", start_date=date.today() - timedelta(days=1), dry_hire=True,
|
||||
status=models.Event.BOOKED, description="dryhire past"),
|
||||
13: models.Event.objects.create(name="TE E13", start_date=date.today() - timedelta(days=2), dry_hire=True,
|
||||
checked_in_by=cls.profile, description="dryhire past checked in"),
|
||||
14: models.Event.objects.create(name="TE E14", start_date=date.today(), dry_hire=True,
|
||||
status=models.Event.CANCELLED, description="dryhire today cancelled"),
|
||||
|
||||
# 4 non rig - 3 current
|
||||
15: models.Event.objects.create(name="TE E15", start_date=date.today(), is_rig=False,
|
||||
description="non rig today"),
|
||||
16: models.Event.objects.create(name="TE E16", start_date=date.today() + timedelta(days=1), is_rig=False,
|
||||
description="non rig tomorrow"),
|
||||
17: models.Event.objects.create(name="TE E17", start_date=date.today() - timedelta(days=1), is_rig=False,
|
||||
description="non rig yesterday"),
|
||||
18: models.Event.objects.create(name="TE E18", start_date=date.today(), is_rig=False,
|
||||
status=models.Event.CANCELLED,
|
||||
description="non rig today cancelled"),
|
||||
}
|
||||
|
||||
class EventTest():
|
||||
def test_count(many_events):
|
||||
# Sanity check we have the expected events created
|
||||
assert models.Event.objects.count() == 18
|
||||
def test_count(self):
|
||||
# Santiy check we have the expected events created
|
||||
self.assertEqual(models.Event.objects.count(), 18, "Incorrect number of events, check setup")
|
||||
|
||||
def test_rig_count(many_events):
|
||||
def test_rig_count(self):
|
||||
# Changed to not include unreturned dry hires in rig count
|
||||
assert models.Event.objects.rig_count() == 7
|
||||
self.assertEqual(models.Event.objects.rig_count(), 7)
|
||||
|
||||
def test_current_events(many_events):
|
||||
all_events = set(range(1, 18))
|
||||
current_events = (1, 2, 3, 6, 7, 8, 10, 11, 12, 14, 15, 16, 18)
|
||||
not_current_events = set(cls.all_events) - set(cls.current_events)
|
||||
def test_current_events(self):
|
||||
current_events = models.Event.objects.current_events()
|
||||
assert len(current_events) == len(self.current_events)
|
||||
for eid in current_events:
|
||||
assert models.Event.objects.get(name="TE E%d" % eid) in current_events
|
||||
self.assertEqual(len(current_events), len(self.current_events))
|
||||
for eid in self.current_events:
|
||||
self.assertIn(models.Event.objects.get(name="TE E%d" % eid), current_events)
|
||||
|
||||
for eid in not_current_events:
|
||||
assert models.Event.objects.get(name="TE E%d" % eid) not in current_events
|
||||
for eid in self.not_current_events:
|
||||
self.assertNotIn(models.Event.objects.get(name="TE E%d" % eid), current_events)
|
||||
|
||||
def test_related(many_events):
|
||||
def test_related_venue(self):
|
||||
v1 = models.Venue.objects.create(name="TE V1")
|
||||
v2 = models.Venue.objects.create(name="TE V2")
|
||||
|
||||
@@ -74,13 +127,16 @@ class EventTest():
|
||||
e2.append(event)
|
||||
event.save()
|
||||
|
||||
assert set(e1) == set(v1.latest_events)
|
||||
assert set(e2) == set(v2.latest_events)
|
||||
# Cleanup
|
||||
v1.delete()
|
||||
v2.delete()
|
||||
self.assertCountEqual(e1, v1.latest_events)
|
||||
self.assertCountEqual(e2, v2.latest_events)
|
||||
|
||||
def test_related_person(many_events):
|
||||
for (key, event) in self.events.items():
|
||||
event.venue = None
|
||||
|
||||
def test_related_vatrate(self):
|
||||
self.assertEqual(self.vatrate, models.Event.objects.all()[0].vat_rate)
|
||||
|
||||
def test_related_person(self):
|
||||
p1 = models.Person.objects.create(name="TE P1")
|
||||
p2 = models.Person.objects.create(name="TE P2")
|
||||
|
||||
@@ -95,13 +151,13 @@ class EventTest():
|
||||
e2.append(event)
|
||||
event.save()
|
||||
|
||||
assert set(e1) == set(p1.latest_events)
|
||||
assert set(e2) == set(p2.latest_events)
|
||||
self.assertCountEqual(e1, p1.latest_events)
|
||||
self.assertCountEqual(e2, p2.latest_events)
|
||||
|
||||
p1.delete()
|
||||
p2.delete()
|
||||
for (key, event) in self.events.items():
|
||||
event.person = None
|
||||
|
||||
def test_related_organisation(many_events):
|
||||
def test_related_organisation(self):
|
||||
o1 = models.Organisation.objects.create(name="TE O1")
|
||||
o2 = models.Organisation.objects.create(name="TE O2")
|
||||
|
||||
@@ -116,13 +172,13 @@ class EventTest():
|
||||
e2.append(event)
|
||||
event.save()
|
||||
|
||||
assert set(e1) == set(o1.latest_events)
|
||||
assert set(e1) == set(o2.latest_events)
|
||||
self.assertCountEqual(e1, o1.latest_events)
|
||||
self.assertCountEqual(e2, o2.latest_events)
|
||||
|
||||
for (key, event) in self.events.items():
|
||||
event.organisation = None
|
||||
|
||||
def test_organisation_person_join(many_events):
|
||||
def test_organisation_person_join(self):
|
||||
p1 = models.Person.objects.create(name="TE P1")
|
||||
p2 = models.Person.objects.create(name="TE P2")
|
||||
o1 = models.Organisation.objects.create(name="TE O1")
|
||||
@@ -146,109 +202,105 @@ class EventTest():
|
||||
events = models.Event.objects.all()
|
||||
|
||||
# Check person's organisations
|
||||
assert (o1, 2) in p1.organisations
|
||||
assert (o2, 1) in p1.organisations
|
||||
assert (o1, 2) in p2.organisations
|
||||
assert len(p2.organisations) == 1
|
||||
self.assertIn((o1, 2), p1.organisations)
|
||||
self.assertIn((o2, 1), p1.organisations)
|
||||
self.assertIn((o1, 2), p2.organisations)
|
||||
self.assertEqual(len(p2.organisations), 1)
|
||||
|
||||
# Check organisation's persons
|
||||
assert (p1, 2) in o1.persons
|
||||
assert (p2, 2) in o1.persons
|
||||
assert (p1, 1) in o2.persons
|
||||
assert len(o2.persons) == 1
|
||||
self.assertIn((p1, 2), o1.persons)
|
||||
self.assertIn((p2, 2), o1.persons)
|
||||
self.assertIn((p1, 1), o2.persons)
|
||||
self.assertEqual(len(o2.persons), 1)
|
||||
|
||||
def test_cancelled_property(many_events):
|
||||
edit = many_events[1]
|
||||
def test_cancelled_property(self):
|
||||
edit = self.events[1]
|
||||
edit.status = models.Event.CANCELLED
|
||||
edit.save()
|
||||
event = models.Event.objects.get(pk=edit.pk)
|
||||
assert event.status == models.Event.CANCELLED
|
||||
assert event.cancelled
|
||||
self.assertEqual(event.status, models.Event.CANCELLED)
|
||||
self.assertTrue(event.cancelled)
|
||||
event.status = models.Event.PROVISIONAL
|
||||
event.save()
|
||||
|
||||
def test_confirmed_property(many_events):
|
||||
edit = many_events[1]
|
||||
def test_confirmed_property(self):
|
||||
edit = self.events[1]
|
||||
edit.status = models.Event.CONFIRMED
|
||||
edit.save()
|
||||
event = models.Event.objects.get(pk=edit.pk)
|
||||
assert event.status == models.Event.CONFIRMED
|
||||
assert event.confirmed
|
||||
self.assertEqual(event.status, models.Event.CONFIRMED)
|
||||
self.assertTrue(event.confirmed)
|
||||
event.status = models.Event.PROVISIONAL
|
||||
event.save()
|
||||
|
||||
def test_earliest_time(self):
|
||||
event = models.Event(name="TE ET", start_date=date(2016, 0o1, 0o1))
|
||||
|
||||
def test_earliest_time():
|
||||
event = models.Event(name="TE ET", start_date=date(2016, 0o1, 0o1))
|
||||
# Just a start date
|
||||
self.assertEqual(event.earliest_time, date(2016, 0o1, 0o1))
|
||||
|
||||
# Just a start date
|
||||
assert event.earliest_time == date(2016, 0o1, 0o1)
|
||||
# With start time
|
||||
event.start_time = time(9, 00)
|
||||
self.assertEqual(event.earliest_time, self.create_datetime(2016, 1, 1, 9, 00))
|
||||
|
||||
# With start time
|
||||
event.start_time = time(9, 00)
|
||||
assert event.earliest_time == create_datetime(2016, 1, 1, 9, 00)
|
||||
# With access time
|
||||
event.access_at = self.create_datetime(2015, 12, 0o3, 9, 57)
|
||||
self.assertEqual(event.earliest_time, event.access_at)
|
||||
|
||||
# With access time
|
||||
event.access_at = create_datetime(2015, 12, 0o3, 9, 57)
|
||||
assert event.earliest_time == event.access_at
|
||||
# With meet time
|
||||
event.meet_at = self.create_datetime(2015, 12, 0o3, 9, 55)
|
||||
self.assertEqual(event.earliest_time, event.meet_at)
|
||||
|
||||
# With meet time
|
||||
event.meet_at = create_datetime(2015, 12, 0o3, 9, 55)
|
||||
assert event.earliest_time == event.meet_at
|
||||
# Check order isn't important
|
||||
event.start_date = date(2015, 12, 0o3)
|
||||
self.assertEqual(event.earliest_time, self.create_datetime(2015, 12, 0o3, 9, 00))
|
||||
|
||||
# Check order isn't important
|
||||
event.start_date = date(2015, 12, 0o3)
|
||||
assert event.earliest_time == create_datetime(2015, 12, 0o3, 9, 00)
|
||||
def test_latest_time(self):
|
||||
event = models.Event(name="TE LT", start_date=date(2016, 0o1, 0o1))
|
||||
|
||||
# Just start date
|
||||
self.assertEqual(event.latest_time, event.start_date)
|
||||
|
||||
def test_latest_time():
|
||||
event = models.Event(name="TE LT", start_date=date(2016, 0o1, 0o1))
|
||||
# Just end date
|
||||
event.end_date = date(2016, 1, 2)
|
||||
self.assertEqual(event.latest_time, event.end_date)
|
||||
|
||||
# Just start date
|
||||
assert event.latest_time == event.start_date
|
||||
# With end time
|
||||
event.end_time = time(23, 00)
|
||||
self.assertEqual(event.latest_time, self.create_datetime(2016, 1, 2, 23, 00))
|
||||
|
||||
# Just end date
|
||||
event.end_date = date(2016, 1, 2)
|
||||
assert event.latest_time == event.end_date
|
||||
def test_in_bounds(self):
|
||||
manager = models.Event.objects
|
||||
events = [
|
||||
manager.create(name="TE IB0", start_date='2016-01-02'), # yes no
|
||||
manager.create(name="TE IB1", start_date='2015-12-31', end_date='2016-01-04'),
|
||||
|
||||
# With end time
|
||||
event.end_time = time(23, 00)
|
||||
assert event.latest_time == create_datetime(2016, 1, 2, 23, 00)
|
||||
# basic checks
|
||||
manager.create(name='TE IB2', start_date='2016-01-02', end_date='2016-01-04'),
|
||||
manager.create(name='TE IB3', start_date='2015-12-31', end_date='2016-01-03'),
|
||||
manager.create(name='TE IB4', start_date='2016-01-04',
|
||||
access_at=self.create_datetime(2016, 0o1, 0o3, 00, 00)),
|
||||
manager.create(name='TE IB5', start_date='2016-01-04',
|
||||
meet_at=self.create_datetime(2016, 0o1, 0o2, 00, 00)),
|
||||
|
||||
# negative check
|
||||
manager.create(name='TE IB6', start_date='2015-12-31', end_date='2016-01-01'),
|
||||
]
|
||||
|
||||
def test_in_bounds():
|
||||
manager = models.Event.objects
|
||||
events = [
|
||||
manager.create(name="TE IB0", start_date='2016-01-02'), # yes no
|
||||
manager.create(name="TE IB1", start_date='2015-12-31', end_date='2016-01-04'),
|
||||
in_bounds = manager.events_in_bounds(self.create_datetime(2016, 1, 2, 0, 0),
|
||||
self.create_datetime(2016, 1, 3, 0, 0))
|
||||
self.assertIn(events[0], in_bounds)
|
||||
self.assertIn(events[1], in_bounds)
|
||||
self.assertIn(events[2], in_bounds)
|
||||
self.assertIn(events[3], in_bounds)
|
||||
self.assertIn(events[4], in_bounds)
|
||||
self.assertIn(events[5], in_bounds)
|
||||
|
||||
# basic checks
|
||||
manager.create(name='TE IB2', start_date='2016-01-02', end_date='2016-01-04'),
|
||||
manager.create(name='TE IB3', start_date='2015-12-31', end_date='2016-01-03'),
|
||||
manager.create(name='TE IB4', start_date='2016-01-04',
|
||||
access_at=create_datetime(2016, 0o1, 0o3, 00, 00)),
|
||||
manager.create(name='TE IB5', start_date='2016-01-04',
|
||||
meet_at=create_datetime(2016, 0o1, 0o2, 00, 00)),
|
||||
self.assertNotIn(events[6], in_bounds)
|
||||
|
||||
# negative check
|
||||
manager.create(name='TE IB6', start_date='2015-12-31', end_date='2016-01-01'),
|
||||
]
|
||||
|
||||
in_bounds = manager.events_in_bounds(create_datetime(2016, 1, 2, 0, 0),
|
||||
create_datetime(2016, 1, 3, 0, 0))
|
||||
assert events[0] in in_bounds
|
||||
assert events[1], in_bounds
|
||||
assert events[2], in_bounds
|
||||
assert events[3], in_bounds
|
||||
assert events[4], in_bounds
|
||||
assert events[5], in_bounds
|
||||
|
||||
assert events[6] not in in_bounds
|
||||
|
||||
|
||||
def create_datetime(year, month, day, hour, minute):
|
||||
tz = pytz.timezone(settings.TIME_ZONE)
|
||||
return tz.localize(datetime(year, month, day, hour, minute))
|
||||
def create_datetime(self, year, month, day, hour, min):
|
||||
tz = pytz.timezone(settings.TIME_ZONE)
|
||||
return tz.localize(datetime(year, month, day, hour, min))
|
||||
|
||||
|
||||
class EventItemTestCase(TestCase):
|
||||
@@ -279,6 +331,7 @@ class EventItemTestCase(TestCase):
|
||||
|
||||
class EventPricingTestCase(TestCase):
|
||||
def setUp(self):
|
||||
models.VatRate.objects.create(rate=0.20, comment="TP V1", start_at='2013-01-01')
|
||||
models.VatRate.objects.create(rate=0.10, comment="TP V2", start_at=date.today() - timedelta(days=1))
|
||||
self.e1 = models.Event.objects.create(name="TP E1", start_date=date.today() - timedelta(days=2))
|
||||
self.e2 = models.Event.objects.create(name="TP E2", start_date=date.today())
|
||||
@@ -311,6 +364,7 @@ class EventPricingTestCase(TestCase):
|
||||
|
||||
class EventAuthorisationTestCase(TestCase):
|
||||
def setUp(self):
|
||||
models.VatRate.objects.create(rate=0.20, comment="TP V1", start_at='2013-01-01')
|
||||
self.profile = models.Profile.objects.get_or_create(
|
||||
first_name='Test',
|
||||
last_name='TEC User',
|
||||
|
||||
@@ -1,25 +1,23 @@
|
||||
from datetime import date
|
||||
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.core.management import call_command
|
||||
from django.test import TestCase
|
||||
from django.test.utils import override_settings
|
||||
from django.urls import reverse, reverse_lazy
|
||||
from django.utils import timezone
|
||||
from pytest_django.asserts import assertRedirects, assertNotContains, assertContains
|
||||
|
||||
from PyRIGS.tests.base import assert_times_almost_equal, assert_oembed, login
|
||||
from PyRIGS.tests.base import assert_times_equal
|
||||
from RIGS import models
|
||||
|
||||
import pytest
|
||||
|
||||
pytestmark = pytest.mark.django_db
|
||||
|
||||
|
||||
class TestAdminMergeObjects(TestCase):
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
cls.profile = models.Profile.objects.create(username="testuser1", email="1@test.com", is_superuser=True,
|
||||
is_active=True, is_staff=True)
|
||||
|
||||
cls.persons = {
|
||||
1: models.Person.objects.create(name="Person 1"),
|
||||
2: models.Person.objects.create(name="Person 2"),
|
||||
@@ -170,6 +168,9 @@ class TestInvoiceDelete(TestCase):
|
||||
def setUpTestData(cls):
|
||||
cls.profile = models.Profile.objects.create(username="testuser1", email="1@test.com", is_superuser=True,
|
||||
is_active=True, is_staff=True)
|
||||
|
||||
cls.vatrate = models.VatRate.objects.create(start_at='2014-03-05', rate=0.20, comment='test1')
|
||||
|
||||
cls.events = {
|
||||
1: models.Event.objects.create(name="TE E1", start_date=date.today()),
|
||||
2: models.Event.objects.create(name="TE E2", start_date=date.today())
|
||||
@@ -200,7 +201,7 @@ class TestInvoiceDelete(TestCase):
|
||||
self.assertTrue(models.Invoice.objects.get(pk=self.invoices[2].pk))
|
||||
|
||||
# Actually delete it
|
||||
self.client.post(request_url, follow=True)
|
||||
response = self.client.post(request_url, follow=True)
|
||||
|
||||
# Check the invoice is deleted
|
||||
self.assertRaises(ObjectDoesNotExist, models.Invoice.objects.get, pk=self.invoices[2].pk)
|
||||
@@ -215,7 +216,7 @@ class TestInvoiceDelete(TestCase):
|
||||
self.assertTrue(models.Invoice.objects.get(pk=self.invoices[1].pk))
|
||||
|
||||
# Try to actually delete it
|
||||
self.client.post(request_url, follow=True)
|
||||
response = self.client.post(request_url, follow=True)
|
||||
|
||||
# Check this didn't work
|
||||
self.assertTrue(models.Invoice.objects.get(pk=self.invoices[1].pk))
|
||||
@@ -226,6 +227,9 @@ class TestPrintPaperwork(TestCase):
|
||||
def setUpTestData(cls):
|
||||
cls.profile = models.Profile.objects.create(username="testuser1", email="1@test.com", is_superuser=True,
|
||||
is_active=True, is_staff=True)
|
||||
|
||||
cls.vatrate = models.VatRate.objects.create(start_at='2014-03-05', rate=0.20, comment='test1')
|
||||
|
||||
cls.events = {
|
||||
1: models.Event.objects.create(name="TE E1", start_date=date.today(),
|
||||
description="This is an event description\nthat for a very specific reason spans two lines."),
|
||||
@@ -253,50 +257,102 @@ class TestPrintPaperwork(TestCase):
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
|
||||
def test_login_redirect(client, django_user_model):
|
||||
request_url = reverse('event_embed', kwargs={'pk': 1})
|
||||
expected_url = "{0}?next={1}".format(reverse('login_embed'), request_url)
|
||||
class TestEmbeddedViews(TestCase):
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
cls.profile = models.Profile.objects.create(username="testuser1", email="1@test.com", is_superuser=True,
|
||||
is_active=True, is_staff=True)
|
||||
|
||||
# Request the page and check it redirects
|
||||
response = client.get(request_url, follow=True)
|
||||
assertRedirects(response, expected_url, status_code=302, target_status_code=200)
|
||||
cls.events = {
|
||||
1: models.Event.objects.create(name="TE E1", start_date=date.today()),
|
||||
2: models.Event.objects.create(name="TE E2", start_date=date.today())
|
||||
}
|
||||
|
||||
# Now login
|
||||
login(client, django_user_model)
|
||||
cls.invoices = {
|
||||
1: models.Invoice.objects.create(event=cls.events[1]),
|
||||
2: models.Invoice.objects.create(event=cls.events[2])
|
||||
}
|
||||
|
||||
# And check that it no longer redirects
|
||||
response = client.get(request_url, follow=True)
|
||||
assert len(response.redirect_chain) == 0
|
||||
cls.payments = {
|
||||
1: models.Payment.objects.create(invoice=cls.invoices[1], date=date.today(), amount=12.34,
|
||||
method=models.Payment.CASH)
|
||||
}
|
||||
|
||||
def setUp(self):
|
||||
self.profile.set_password('testuser')
|
||||
self.profile.save()
|
||||
|
||||
def testLoginRedirect(self):
|
||||
request_url = reverse('event_embed', kwargs={'pk': 1})
|
||||
expected_url = "{0}?next={1}".format(reverse('login_embed'), request_url)
|
||||
|
||||
# Request the page and check it redirects
|
||||
response = self.client.get(request_url, follow=True)
|
||||
self.assertRedirects(response, expected_url, status_code=302, target_status_code=200)
|
||||
|
||||
# Now login
|
||||
self.assertTrue(self.client.login(username=self.profile.username, password='testuser'))
|
||||
|
||||
# And check that it no longer redirects
|
||||
response = self.client.get(request_url, follow=True)
|
||||
self.assertEqual(len(response.redirect_chain), 0)
|
||||
|
||||
def testLoginCookieWarning(self):
|
||||
login_url = reverse('login_embed')
|
||||
response = self.client.post(login_url, follow=True)
|
||||
self.assertContains(response, "Cookies do not seem to be enabled")
|
||||
|
||||
def testXFrameHeaders(self):
|
||||
event_url = reverse('event_embed', kwargs={'pk': 1})
|
||||
login_url = reverse('login_embed')
|
||||
|
||||
self.assertTrue(self.client.login(username=self.profile.username, password='testuser'))
|
||||
|
||||
response = self.client.get(event_url, follow=True)
|
||||
with self.assertRaises(KeyError):
|
||||
response._headers["X-Frame-Options"]
|
||||
|
||||
response = self.client.get(login_url, follow=True)
|
||||
with self.assertRaises(KeyError):
|
||||
response._headers["X-Frame-Options"]
|
||||
|
||||
def testOEmbed(self):
|
||||
event_url = reverse('event_detail', kwargs={'pk': 1})
|
||||
event_embed_url = reverse('event_embed', kwargs={'pk': 1})
|
||||
oembed_url = reverse('event_oembed', kwargs={'pk': 1})
|
||||
|
||||
alt_oembed_url = reverse('event_oembed', kwargs={'pk': 999})
|
||||
alt_event_embed_url = reverse('event_embed', kwargs={'pk': 999})
|
||||
|
||||
# Test the meta tag is in place
|
||||
response = self.client.get(event_url, follow=True, HTTP_HOST='example.com')
|
||||
self.assertContains(response, '<link rel="alternate" type="application/json+oembed"')
|
||||
self.assertContains(response, oembed_url)
|
||||
|
||||
# Test that the JSON exists
|
||||
response = self.client.get(oembed_url, follow=True, HTTP_HOST='example.com')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertContains(response, event_embed_url)
|
||||
|
||||
# Should also work for non-existant events
|
||||
response = self.client.get(alt_oembed_url, follow=True, HTTP_HOST='example.com')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertContains(response, alt_event_embed_url)
|
||||
|
||||
|
||||
def test_login_cookie_warning(client):
|
||||
login_url = reverse('login_embed')
|
||||
response = client.post(login_url, follow=True)
|
||||
assertContains(response, "Cookies do not seem to be enabled")
|
||||
class TestSampleDataGenerator(TestCase):
|
||||
@override_settings(DEBUG=True)
|
||||
def test_generate_sample_data(self):
|
||||
# Run the management command and check there are no exceptions
|
||||
call_command('generateSampleRIGSData')
|
||||
|
||||
# Check there are lots of events
|
||||
self.assertTrue(models.Event.objects.all().count() > 100)
|
||||
|
||||
def test_xframe_headers(admin_client, basic_event):
|
||||
event_url = reverse('event_embed', kwargs={'pk': basic_event.pk})
|
||||
login_url = reverse('login_embed')
|
||||
def test_production_exception(self):
|
||||
from django.core.management.base import CommandError
|
||||
|
||||
response = admin_client.get(event_url, follow=True)
|
||||
with pytest.raises(KeyError):
|
||||
response._headers["X-Frame-Options"]
|
||||
|
||||
response = admin_client.get(login_url, follow=True)
|
||||
with pytest.raises(KeyError):
|
||||
response._headers["X-Frame-Options"]
|
||||
|
||||
|
||||
def test_oembed(client, basic_event):
|
||||
event_url = reverse('event_detail', kwargs={'pk': basic_event.pk})
|
||||
event_embed_url = reverse('event_embed', kwargs={'pk': basic_event.pk})
|
||||
oembed_url = reverse('event_oembed', kwargs={'pk': basic_event.pk})
|
||||
|
||||
alt_oembed_url = reverse('event_oembed', kwargs={'pk': 999})
|
||||
alt_event_embed_url = reverse('event_embed', kwargs={'pk': 999})
|
||||
|
||||
assert_oembed(alt_event_embed_url, alt_oembed_url, client, event_embed_url, event_url, oembed_url)
|
||||
self.assertRaisesRegex(CommandError, ".*production", call_command, 'generateSampleRIGSData')
|
||||
|
||||
|
||||
def search(client, url, found, notfound, arguments):
|
||||
@@ -335,11 +391,45 @@ def test_search(admin_client):
|
||||
['name', 'id', 'address'])
|
||||
|
||||
|
||||
def test_hs_list(admin_client, basic_event):
|
||||
def setup_for_hs():
|
||||
models.VatRate.objects.create(start_at='2014-03-05', rate=0.20, comment='test1')
|
||||
venue = models.Venue.objects.create(name="Venue 1")
|
||||
return venue, {
|
||||
1: models.Event.objects.create(name="TE E1", start_date=date.today(),
|
||||
description="This is an event description\nthat for a very specific reason spans two lines.",
|
||||
venue=venue),
|
||||
2: models.Event.objects.create(name="TE E2", start_date=date.today()),
|
||||
}
|
||||
|
||||
|
||||
def create_ra(usr):
|
||||
venue, events = setup_for_hs()
|
||||
return models.RiskAssessment.objects.create(event=events[1], nonstandard_equipment=False, nonstandard_use=False,
|
||||
contractors=False, other_companies=False, crew_fatigue=False,
|
||||
big_power=False, power_mic=usr, generators=False,
|
||||
other_companies_power=False, nonstandard_equipment_power=False,
|
||||
multiple_electrical_environments=False, noise_monitoring=False,
|
||||
known_venue=True, safe_loading=True, safe_storage=True,
|
||||
area_outside_of_control=True, barrier_required=True,
|
||||
nonstandard_emergency_procedure=True, special_structures=False,
|
||||
suspended_structures=False, outside=False)
|
||||
|
||||
|
||||
def create_checklist(usr):
|
||||
venue, events = setup_for_hs()
|
||||
return models.EventChecklist.objects.create(event=events[1], power_mic=usr, safe_parking=False,
|
||||
safe_packing=False, exits=False, trip_hazard=False, warning_signs=False,
|
||||
ear_plugs=False, hs_location="Locked away safely",
|
||||
extinguishers_location="Somewhere, I forgot", earthing=False, pat=False,
|
||||
date=timezone.now(), venue=venue)
|
||||
|
||||
|
||||
def test_list(admin_client):
|
||||
venue, events = setup_for_hs()
|
||||
request_url = reverse('hs_list')
|
||||
response = admin_client.get(request_url, follow=True)
|
||||
assertContains(response, basic_event.name)
|
||||
# assertContains(response, events[2].name)
|
||||
assertContains(response, events[1].name)
|
||||
assertContains(response, events[2].name)
|
||||
assertContains(response, 'Create')
|
||||
|
||||
|
||||
@@ -349,18 +439,19 @@ def review(client, profile, obj, request_url):
|
||||
obj.refresh_from_db()
|
||||
assertContains(response, 'Reviewed by')
|
||||
assertContains(response, profile.name)
|
||||
assert_times_almost_equal(time, obj.reviewed_at)
|
||||
assert_times_equal(time, obj.reviewed_at)
|
||||
|
||||
|
||||
def test_ra_review(admin_client, admin_user, ra):
|
||||
review(admin_client, admin_user, ra, 'ra_review')
|
||||
def test_ra_review(admin_client, admin_user):
|
||||
review(admin_client, admin_user, create_ra(admin_user), 'ra_review')
|
||||
|
||||
|
||||
def test_checklist_review(admin_client, admin_user, checklist):
|
||||
review(admin_client, admin_user, checklist, 'ec_review')
|
||||
def test_checklist_review(admin_client, admin_user):
|
||||
review(admin_client, admin_user, create_checklist(admin_user), 'ec_review')
|
||||
|
||||
|
||||
def test_ra_redirect(admin_client, admin_user, ra):
|
||||
def test_ra_redirect(admin_client, admin_user):
|
||||
ra = create_ra(admin_user)
|
||||
request_url = reverse('event_ra', kwargs={'pk': ra.event.pk})
|
||||
expected_url = reverse('ra_edit', kwargs={'pk': ra.pk})
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.urls import path, re_path
|
||||
from django.views.decorators.clickjacking import xframe_options_exempt
|
||||
from django.views.generic import RedirectView
|
||||
@@ -61,7 +62,7 @@ urlpatterns = [
|
||||
path('event/<int:pk>/embed/',
|
||||
xframe_options_exempt(login_required(login_url='/user/login/embed/')(rigboard.EventEmbed.as_view())),
|
||||
name='event_embed'),
|
||||
path('event/<int:pk>/oembed_json/', rigboard.EventOEmbed.as_view(),
|
||||
path('event/<int:pk>/oembed_json/', rigboard.EventOembed.as_view(),
|
||||
name='event_oembed'),
|
||||
path('event/<int:pk>/print/', permission_required_with_403('RIGS.view_event')(rigboard.EventPrint.as_view()),
|
||||
name='event_print'),
|
||||
@@ -132,8 +133,6 @@ urlpatterns = [
|
||||
name='event_authorise_preview'),
|
||||
re_path(r'^event/(?P<pk>\d+)/(?P<hmac>[-:\w]+)/$', rigboard.EventAuthorise.as_view(),
|
||||
name='event_authorise'),
|
||||
re_path(r'^event/(?P<pk>\d+)/(?P<hmac>[-:\w]+)/preview/$', rigboard.EventAuthorise.as_view(preview=True),
|
||||
name='event_authorise_form_preview'),
|
||||
|
||||
# ICS Calendar - API key authentication
|
||||
re_path(r'^ical/(?P<api_pk>\d+)/(?P<api_key>\w+)/rigs.ics$', api_key_required(ical.CalendarICS()),
|
||||
|
||||
5
app.json
5
app.json
@@ -2,7 +2,8 @@
|
||||
"name": "PyRIGS",
|
||||
"description": "",
|
||||
"scripts": {
|
||||
"postdeploy": "python manage.py migrate && python manage.py generateSampleData"
|
||||
"postdeploy": "python manage.py migrate && python manage.py generateSampleData",
|
||||
"heroku-cleanup": "rm -rf node_modules pipeline"
|
||||
},
|
||||
"stack": "heroku-20",
|
||||
"env": {
|
||||
@@ -51,7 +52,7 @@
|
||||
"url": "heroku/nodejs"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/nottinghamtec/heroku-buildpack-python"
|
||||
"url": "heroku/python"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
default_app_config = 'assets.apps.AssetsAppConfig'
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class AssetsAppConfig(AppConfig):
|
||||
name = 'assets'
|
||||
|
||||
def ready(self):
|
||||
import assets.signals
|
||||
23
assets/management/commands/deleteSampleData.py
Normal file
23
assets/management/commands/deleteSampleData.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
|
||||
from assets import models
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Deletes testing sample data'
|
||||
|
||||
def handle(self, *args, **kwargs):
|
||||
from django.conf import settings
|
||||
|
||||
if not (settings.DEBUG):
|
||||
raise CommandError('You cannot run this command in production')
|
||||
|
||||
self.delete_objects(models.AssetCategory)
|
||||
self.delete_objects(models.AssetStatus)
|
||||
self.delete_objects(models.Supplier)
|
||||
self.delete_objects(models.Connector)
|
||||
self.delete_objects(models.Asset)
|
||||
|
||||
def delete_objects(self, model):
|
||||
for object in model.objects.all():
|
||||
object.delete()
|
||||
@@ -1,24 +1,16 @@
|
||||
import random
|
||||
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.db import transaction
|
||||
from django.utils import timezone
|
||||
from reversion import revisions as reversion
|
||||
|
||||
from RIGS import models as rigsmodels
|
||||
from assets import models
|
||||
from assets.models import get_available_asset_id
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Creates some sample data for testing'
|
||||
|
||||
categories = []
|
||||
statuses = []
|
||||
suppliers = []
|
||||
connectors = []
|
||||
assets = []
|
||||
|
||||
def handle(self, *args, **kwargs):
|
||||
from django.conf import settings
|
||||
|
||||
@@ -27,42 +19,57 @@ class Command(BaseCommand):
|
||||
|
||||
random.seed('Some object to see the random number generator')
|
||||
|
||||
with transaction.atomic():
|
||||
self.create_categories()
|
||||
self.create_statuses()
|
||||
self.create_suppliers()
|
||||
self.create_assets()
|
||||
self.create_connectors()
|
||||
self.create_cables()
|
||||
self.create_profile()
|
||||
self.create_categories()
|
||||
self.create_statuses()
|
||||
self.create_suppliers()
|
||||
self.create_assets()
|
||||
self.create_connectors()
|
||||
self.create_cables()
|
||||
|
||||
# Make sure that there's at least one profile if this command is run standalone
|
||||
def create_profile(self):
|
||||
name = "Fred Johnson"
|
||||
models.Profile.objects.create(username=name.replace(" ", ""), first_name=name.split(" ")[0], last_name=name.split(" ")[-1],
|
||||
email=name.replace(" ", "") + "@example.com",
|
||||
initials="".join([j[0].upper() for j in name.split()]))
|
||||
|
||||
def create_categories(self):
|
||||
choices = ['Case', 'Video', 'General', 'Sound', 'Lighting', 'Rigging']
|
||||
for cat in choices:
|
||||
self.categories.append(models.AssetCategory.objects.create(name=cat))
|
||||
categories = ['Case', 'Video', 'General', 'Sound', 'Lighting', 'Rigging']
|
||||
|
||||
for cat in categories:
|
||||
models.AssetCategory.objects.create(name=cat)
|
||||
|
||||
def create_statuses(self):
|
||||
choices = [('In Service', True, 'success'), ('Lost', False, 'warning'), ('Binned', False, 'danger'), ('Sold', False, 'danger'), ('Broken', False, 'warning')]
|
||||
for stat in choices:
|
||||
self.statuses.append(models.AssetStatus.objects.create(name=stat[0], should_show=stat[1], display_class=stat[2]))
|
||||
statuses = [('In Service', True, 'success'), ('Lost', False, 'warning'), ('Binned', False, 'danger'), ('Sold', False, 'danger'), ('Broken', False, 'warning')]
|
||||
|
||||
for stat in statuses:
|
||||
models.AssetStatus.objects.create(name=stat[0], should_show=stat[1], display_class=stat[2])
|
||||
|
||||
def create_suppliers(self):
|
||||
choices = ["Acme, inc.", "Widget Corp", "123 Warehousing", "Demo Company", "Smith and Co.", "Foo Bars", "ABC Telecom", "Fake Brothers", "QWERTY Logistics", "Demo, inc.", "Sample Company", "Sample, inc", "Acme Corp", "Allied Biscuit", "Ankh-Sto Associates", "Extensive Enterprise", "Galaxy Corp", "Globo-Chem", "Mr. Sparkle", "Globex Corporation", "LexCorp", "LuthorCorp", "North Central Positronics", "Omni Consimer Products", "Praxis Corporation", "Sombra Corporation", "Sto Plains Holdings", "Tessier-Ashpool", "Wayne Enterprises", "Wentworth Industries", "ZiffCorp", "Bluth Company", "Strickland Propane", "Thatherton Fuels", "Three Waters", "Water and Power", "Western Gas & Electric", "Mammoth Pictures", "Mooby Corp", "Gringotts", "Thrift Bank", "Flowers By Irene", "The Legitimate Businessmens Club", "Osato Chemicals", "Transworld Consortium", "Universal Export", "United Fried Chicken", "Virtucon", "Kumatsu Motors", "Keedsler Motors", "Powell Motors", "Industrial Automation", "Sirius Cybernetics Corporation", "U.S. Robotics and Mechanical Men", "Colonial Movers", "Corellian Engineering Corporation", "Incom Corporation", "General Products", "Leeding Engines Ltd.", "Blammo", # noqa
|
||||
suppliers = ["Acme, inc.", "Widget Corp", "123 Warehousing", "Demo Company", "Smith and Co.", "Foo Bars", "ABC Telecom", "Fake Brothers", "QWERTY Logistics", "Demo, inc.", "Sample Company", "Sample, inc", "Acme Corp", "Allied Biscuit", "Ankh-Sto Associates", "Extensive Enterprise", "Galaxy Corp", "Globo-Chem", "Mr. Sparkle", "Globex Corporation", "LexCorp", "LuthorCorp", "North Central Positronics", "Omni Consimer Products", "Praxis Corporation", "Sombra Corporation", "Sto Plains Holdings", "Tessier-Ashpool", "Wayne Enterprises", "Wentworth Industries", "ZiffCorp", "Bluth Company", "Strickland Propane", "Thatherton Fuels", "Three Waters", "Water and Power", "Western Gas & Electric", "Mammoth Pictures", "Mooby Corp", "Gringotts", "Thrift Bank", "Flowers By Irene", "The Legitimate Businessmens Club", "Osato Chemicals", "Transworld Consortium", "Universal Export", "United Fried Chicken", "Virtucon", "Kumatsu Motors", "Keedsler Motors", "Powell Motors", "Industrial Automation", "Sirius Cybernetics Corporation", "U.S. Robotics and Mechanical Men", "Colonial Movers", "Corellian Engineering Corporation", "Incom Corporation", "General Products", "Leeding Engines Ltd.", "Blammo", # noqa
|
||||
"Input, Inc.", "Mainway Toys", "Videlectrix", "Zevo Toys", "Ajax", "Axis Chemical Co.", "Barrytron", "Carrys Candles", "Cogswell Cogs", "Spacely Sprockets", "General Forge and Foundry", "Duff Brewing Company", "Dunder Mifflin", "General Services Corporation", "Monarch Playing Card Co.", "Krustyco", "Initech", "Roboto Industries", "Primatech", "Sonky Rubber Goods", "St. Anky Beer", "Stay Puft Corporation", "Vandelay Industries", "Wernham Hogg", "Gadgetron", "Burleigh and Stronginthearm", "BLAND Corporation", "Nordyne Defense Dynamics", "Petrox Oil Company", "Roxxon", "McMahon and Tate", "Sixty Second Avenue", "Charles Townsend Agency", "Spade and Archer", "Megadodo Publications", "Rouster and Sideways", "C.H. Lavatory and Sons", "Globo Gym American Corp", "The New Firm", "SpringShield", "Compuglobalhypermeganet", "Data Systems", "Gizmonic Institute", "Initrode", "Taggart Transcontinental", "Atlantic Northern", "Niagular", "Plow King", "Big Kahuna Burger", "Big T Burgers and Fries", "Chez Quis", "Chotchkies", "The Frying Dutchman", "Klimpys", "The Krusty Krab", "Monks Diner", "Milliways", "Minuteman Cafe", "Taco Grande", "Tip Top Cafe", "Moes Tavern", "Central Perk", "Chasers"] # noqa
|
||||
for supplier in choices:
|
||||
self.suppliers.append(models.Supplier.objects.create(name=supplier))
|
||||
|
||||
with reversion.create_revision():
|
||||
for supplier in suppliers:
|
||||
reversion.set_user(random.choice(rigsmodels.Profile.objects.all()))
|
||||
models.Supplier.objects.create(name=supplier)
|
||||
|
||||
def create_assets(self):
|
||||
asset_description = ['Large cable', 'Shiny thing', 'New lights', 'Really expensive microphone', 'Box of fuse flaps', 'Expensive tool we didn\'t agree to buy', 'Cable drums', 'Boring amount of tape', 'Video stuff no one knows how to use', 'More amplifiers', 'Heatshrink']
|
||||
|
||||
for i in range(100):
|
||||
with reversion.create_revision():
|
||||
categories = models.AssetCategory.objects.all()
|
||||
statuses = models.AssetStatus.objects.all()
|
||||
suppliers = models.Supplier.objects.all()
|
||||
|
||||
with reversion.create_revision():
|
||||
for i in range(100):
|
||||
reversion.set_user(random.choice(rigsmodels.Profile.objects.all()))
|
||||
asset_id = str(get_available_asset_id())
|
||||
asset = models.Asset(
|
||||
asset_id=asset_id,
|
||||
asset_id='{}'.format(models.Asset.get_available_asset_id()),
|
||||
description=random.choice(asset_description),
|
||||
category=random.choice(self.categories),
|
||||
status=random.choice(self.statuses),
|
||||
category=random.choice(categories),
|
||||
status=random.choice(statuses),
|
||||
date_acquired=timezone.now().date()
|
||||
)
|
||||
|
||||
@@ -70,11 +77,53 @@ class Command(BaseCommand):
|
||||
asset.parent = models.Asset.objects.order_by('?').first()
|
||||
|
||||
if i % 3 == 0:
|
||||
asset.purchased_from = random.choice(self.suppliers)
|
||||
|
||||
asset.purchased_from = random.choice(suppliers)
|
||||
asset.clean()
|
||||
asset.save()
|
||||
|
||||
def create_cables(self):
|
||||
asset_description = ['The worm', 'Harting without a cap', 'Heavy cable', 'Extension lead', 'IEC cable that we should remember to prep']
|
||||
asset_prefixes = ["C", "C4P", "CBNC", "CDMX", "CDV", "CRCD", "CSOCA", "CXLR"]
|
||||
|
||||
csas = [0.75, 1.00, 1.25, 2.5, 4]
|
||||
lengths = [1, 2, 5, 10, 15, 20, 25, 30, 50, 100]
|
||||
cores = [3, 5]
|
||||
circuits = [1, 2, 3, 6]
|
||||
categories = models.AssetCategory.objects.all()
|
||||
statuses = models.AssetStatus.objects.all()
|
||||
suppliers = models.Supplier.objects.all()
|
||||
connectors = models.Connector.objects.all()
|
||||
|
||||
for i in range(len(connectors)):
|
||||
models.CableType.objects.create(plug=random.choice(connectors), socket=random.choice(connectors), circuits=random.choice(circuits), cores=random.choice(cores))
|
||||
|
||||
for i in range(100):
|
||||
asset = models.Asset(
|
||||
asset_id='{}'.format(models.Asset.get_available_asset_id()),
|
||||
description=random.choice(asset_description),
|
||||
category=random.choice(categories),
|
||||
status=random.choice(statuses),
|
||||
date_acquired=timezone.now().date(),
|
||||
|
||||
is_cable=True,
|
||||
cable_type=random.choice(models.CableType.objects.all()),
|
||||
csa=random.choice(csas),
|
||||
length=random.choice(lengths),
|
||||
)
|
||||
|
||||
if i % 5 == 0:
|
||||
prefix = random.choice(asset_prefixes)
|
||||
asset.asset_id = prefix + str(models.Asset.get_available_asset_id(wanted_prefix=prefix))
|
||||
|
||||
if i % 4 == 0:
|
||||
asset.parent = models.Asset.objects.order_by('?').first()
|
||||
|
||||
if i % 3 == 0:
|
||||
asset.purchased_from = random.choice(suppliers)
|
||||
|
||||
asset.clean()
|
||||
asset.save()
|
||||
|
||||
def create_connectors(self):
|
||||
connectors = [
|
||||
{"description": "13A UK", "current_rating": 13, "voltage_rating": 230, "num_pins": 3},
|
||||
@@ -85,43 +134,3 @@ class Command(BaseCommand):
|
||||
for connector in connectors:
|
||||
conn = models.Connector.objects.create(** connector)
|
||||
conn.save()
|
||||
self.connectors.append(conn)
|
||||
|
||||
def create_cables(self):
|
||||
asset_description = ['The worm', 'Harting without a cap', 'Heavy cable', 'Extension lead', 'IEC cable that we should remember to prep']
|
||||
asset_prefixes = ["C", "C4P", "CBNC", "CDMX", "CDV", "CRCD", "CSOCA", "CXLR"]
|
||||
|
||||
csas = [0.75, 1.00, 1.25, 2.5, 4]
|
||||
lengths = [1, 2, 5, 10, 15, 20, 25, 30, 50, 100]
|
||||
cores = [3, 5]
|
||||
circuits = [1, 2, 3, 6]
|
||||
types = []
|
||||
|
||||
for i in range(len(self.connectors)):
|
||||
types.append(models.CableType.objects.create(plug=random.choice(self.connectors), socket=random.choice(self.connectors), circuits=random.choice(circuits), cores=random.choice(cores)))
|
||||
|
||||
for i in range(100):
|
||||
prefix = random.choice(asset_prefixes)
|
||||
asset_id = str(get_available_asset_id(wanted_prefix=prefix))
|
||||
asset_id = prefix + asset_id
|
||||
asset = models.Asset(
|
||||
asset_id=asset_id,
|
||||
description=random.choice(asset_description),
|
||||
category=random.choice(self.categories),
|
||||
status=random.choice(self.statuses),
|
||||
date_acquired=timezone.now().date(),
|
||||
|
||||
is_cable=True,
|
||||
cable_type=random.choice(types),
|
||||
csa=random.choice(csas),
|
||||
length=random.choice(lengths),
|
||||
)
|
||||
|
||||
if i % 4 == 0:
|
||||
asset.parent = models.Asset.objects.order_by('?').first()
|
||||
|
||||
if i % 3 == 0:
|
||||
asset.purchased_from = random.choice(self.suppliers)
|
||||
|
||||
asset.clean()
|
||||
asset.save()
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
# Generated by Django 3.1.5 on 2021-02-08 16:02
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def add_default(apps, schema_editor):
|
||||
CableType = apps.get_model('assets', 'CableType')
|
||||
Connector = apps.get_model('assets', 'Connector')
|
||||
for cable_type in CableType.objects.all():
|
||||
if cable_type.plug is None:
|
||||
cable_type.plug = Connector.first()
|
||||
if cable_type.socket is None:
|
||||
cable_type.socket = Connector.first()
|
||||
cable_type.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('assets', '0018_auto_20200415_1940'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(add_default, migrations.RunPython.noop)
|
||||
]
|
||||
@@ -1,50 +0,0 @@
|
||||
# Generated by Django 3.1.5 on 2021-02-08 16:03
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('assets', '0019_fix_cabletype'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='assetstatus',
|
||||
name='display_class',
|
||||
field=models.CharField(blank=True, default='', help_text='HTML class to be appended to alter display of assets with this status, such as in the list.', max_length=80),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='cabletype',
|
||||
name='plug',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='plug', to='assets.connector'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='cabletype',
|
||||
name='socket',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='socket', to='assets.connector'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='supplier',
|
||||
name='address',
|
||||
field=models.TextField(blank=True, default=''),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='supplier',
|
||||
name='email',
|
||||
field=models.EmailField(blank=True, default='', max_length=254),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='supplier',
|
||||
name='notes',
|
||||
field=models.TextField(blank=True, default=''),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='supplier',
|
||||
name='phone',
|
||||
field=models.CharField(blank=True, default='', max_length=15),
|
||||
),
|
||||
]
|
||||
107
assets/models.py
107
assets/models.py
@@ -2,6 +2,8 @@ import re
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db import models, connection
|
||||
from django.db.models.signals import pre_save
|
||||
from django.dispatch.dispatcher import receiver
|
||||
from django.urls import reverse
|
||||
from reversion import revisions as reversion
|
||||
from reversion.models import Version
|
||||
@@ -10,44 +12,44 @@ from RIGS.models import RevisionMixin, Profile
|
||||
|
||||
|
||||
class AssetCategory(models.Model):
|
||||
name = models.CharField(max_length=80)
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'Asset Category'
|
||||
verbose_name_plural = 'Asset Categories'
|
||||
ordering = ['name']
|
||||
|
||||
name = models.CharField(max_length=80)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class AssetStatus(models.Model):
|
||||
name = models.CharField(max_length=80)
|
||||
should_show = models.BooleanField(
|
||||
default=True, help_text="Should this be shown by default in the asset list.")
|
||||
display_class = models.CharField(max_length=80, blank=True, help_text="HTML class to be appended to alter display of assets with this status, such as in the list.")
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'Asset Status'
|
||||
verbose_name_plural = 'Asset Statuses'
|
||||
ordering = ['name']
|
||||
|
||||
name = models.CharField(max_length=80)
|
||||
should_show = models.BooleanField(
|
||||
default=True, help_text="Should this be shown by default in the asset list.")
|
||||
display_class = models.CharField(max_length=80, blank=True, null=True, help_text="HTML class to be appended to alter display of assets with this status, such as in the list.")
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
@reversion.register
|
||||
class Supplier(models.Model, RevisionMixin):
|
||||
name = models.CharField(max_length=80)
|
||||
phone = models.CharField(max_length=15, blank=True, default="")
|
||||
email = models.EmailField(blank=True, default="")
|
||||
address = models.TextField(blank=True, default="")
|
||||
|
||||
notes = models.TextField(blank=True, default="")
|
||||
|
||||
class Meta:
|
||||
ordering = ['name']
|
||||
|
||||
name = models.CharField(max_length=80)
|
||||
phone = models.CharField(max_length=15, blank=True, null=True)
|
||||
email = models.EmailField(blank=True, null=True)
|
||||
address = models.TextField(blank=True, null=True)
|
||||
|
||||
notes = models.TextField(blank=True, null=True)
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('supplier_list')
|
||||
|
||||
@@ -65,16 +67,17 @@ class Connector(models.Model):
|
||||
return self.description
|
||||
|
||||
|
||||
# Things are nullable that shouldn't be because I didn't properly fix the data structure when moving this to its own model...
|
||||
class CableType(models.Model):
|
||||
class Meta:
|
||||
ordering = ['plug', 'socket', '-circuits']
|
||||
|
||||
circuits = models.IntegerField(default=1)
|
||||
cores = models.IntegerField(default=3)
|
||||
plug = models.ForeignKey(Connector, on_delete=models.CASCADE,
|
||||
related_name='plug')
|
||||
related_name='plug', null=True)
|
||||
socket = models.ForeignKey(Connector, on_delete=models.CASCADE,
|
||||
related_name='socket')
|
||||
|
||||
class Meta:
|
||||
ordering = ['plug', 'socket', '-circuits']
|
||||
related_name='socket', null=True)
|
||||
|
||||
def __str__(self):
|
||||
if self.plug and self.socket:
|
||||
@@ -83,27 +86,14 @@ class CableType(models.Model):
|
||||
return "Unknown"
|
||||
|
||||
|
||||
def get_available_asset_id(wanted_prefix=""):
|
||||
sql = """
|
||||
SELECT a.asset_id_number+1
|
||||
FROM assets_asset a
|
||||
LEFT OUTER JOIN assets_asset b ON
|
||||
(a.asset_id_number + 1 = b.asset_id_number AND
|
||||
a.asset_id_prefix = b.asset_id_prefix)
|
||||
WHERE b.asset_id IS NULL AND a.asset_id_number >= %s AND a.asset_id_prefix = %s;
|
||||
"""
|
||||
with connection.cursor() as cursor:
|
||||
cursor.execute(sql, [9000, wanted_prefix])
|
||||
row = cursor.fetchone()
|
||||
if row is None or row[0] is None:
|
||||
return 9000
|
||||
else:
|
||||
return row[0]
|
||||
cursor.close()
|
||||
|
||||
|
||||
@reversion.register
|
||||
class Asset(models.Model, RevisionMixin):
|
||||
class Meta:
|
||||
ordering = ['asset_id_prefix', 'asset_id_number']
|
||||
permissions = [
|
||||
('asset_finance', 'Can see financial data for assets')
|
||||
]
|
||||
|
||||
parent = models.ForeignKey(to='self', related_name='asset_parent',
|
||||
blank=True, null=True, on_delete=models.SET_NULL)
|
||||
asset_id = models.CharField(max_length=15, unique=True)
|
||||
@@ -137,18 +127,32 @@ class Asset(models.Model, RevisionMixin):
|
||||
|
||||
reversion_perm = 'assets.asset_finance'
|
||||
|
||||
class Meta:
|
||||
ordering = ['asset_id_prefix', 'asset_id_number']
|
||||
permissions = [
|
||||
('asset_finance', 'Can see financial data for assets')
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
return "{} | {}".format(self.asset_id, self.description)
|
||||
def get_available_asset_id(wanted_prefix=""):
|
||||
sql = """
|
||||
SELECT a.asset_id_number+1
|
||||
FROM assets_asset a
|
||||
LEFT OUTER JOIN assets_asset b ON
|
||||
(a.asset_id_number + 1 = b.asset_id_number AND
|
||||
a.asset_id_prefix = b.asset_id_prefix)
|
||||
WHERE b.asset_id IS NULL AND a.asset_id_number >= %s AND a.asset_id_prefix = %s;
|
||||
"""
|
||||
with connection.cursor() as cursor:
|
||||
cursor.execute(sql, [9000, wanted_prefix])
|
||||
row = cursor.fetchone()
|
||||
if row is None or row[0] is None:
|
||||
return 9000
|
||||
else:
|
||||
return row[0]
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('asset_detail', kwargs={'pk': self.asset_id})
|
||||
|
||||
def __str__(self):
|
||||
out = str(self.asset_id) + ' - ' + self.description
|
||||
if self.is_cable and self.cable_type is not None:
|
||||
out += '{} - {}m - {}'.format(self.cable_type.plug, self.length, self.cable_type.socket)
|
||||
return out
|
||||
|
||||
def clean(self):
|
||||
errdict = {}
|
||||
if self.date_sold and self.date_acquired > self.date_sold:
|
||||
@@ -184,3 +188,14 @@ class Asset(models.Model, RevisionMixin):
|
||||
@property
|
||||
def display_id(self):
|
||||
return str(self.asset_id)
|
||||
|
||||
|
||||
@receiver(pre_save, sender=Asset)
|
||||
def pre_save_asset(sender, instance, **kwargs):
|
||||
"""Automatically fills in hidden members on database access"""
|
||||
asset_search = re.search("^([a-zA-Z0-9]*?[a-zA-Z]?)([0-9]+)$", instance.asset_id)
|
||||
if asset_search is None:
|
||||
instance.asset_id += "1"
|
||||
asset_search = re.search("^([a-zA-Z0-9]*?[a-zA-Z]?)([0-9]+)$", instance.asset_id)
|
||||
instance.asset_id_prefix = asset_search.group(1)
|
||||
instance.asset_id_number = int(asset_search.group(2))
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
import re
|
||||
from django.db.models.signals import pre_save
|
||||
from django.dispatch.dispatcher import receiver
|
||||
from .models import Asset
|
||||
|
||||
|
||||
@receiver(pre_save, sender=Asset)
|
||||
def pre_save_asset(sender, instance, **kwargs):
|
||||
"""Automatically fills in hidden members on database access"""
|
||||
asset_search = re.search("^([a-zA-Z0-9]*?[a-zA-Z]?)([0-9]+)$", instance.asset_id)
|
||||
if asset_search is None:
|
||||
instance.asset_id += "1"
|
||||
asset_search = re.search("^([a-zA-Z0-9]*?[a-zA-Z]?)([0-9]+)$", instance.asset_id)
|
||||
instance.asset_id_prefix = asset_search.group(1)
|
||||
instance.asset_id_number = int(asset_search.group(2))
|
||||
@@ -40,8 +40,8 @@
|
||||
<div class="form-group form-row">
|
||||
{% include 'partials/form_field.html' with field=form.date_acquired col="col-6" %}
|
||||
<div class="col-sm-4">
|
||||
<button class="btn btn-info" onclick="setAcquired(true);" tabindex="-1">Today</button>
|
||||
<button class="btn btn-warning" onclick="setAcquired(false);" tabindex="-1">Unknown</button>
|
||||
<btn class="btn btn-info" onclick="setAcquired(true);" tabindex="-1">Today</btn>
|
||||
<btn class="btn btn-warning" onclick="setAcquired(false);" tabindex="-1">Unknown</btn>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group form-row">
|
||||
@@ -64,16 +64,16 @@
|
||||
<div class="form-group form-row">
|
||||
{% include 'partials/form_field.html' with field=form.length append=form.length.help_text col="col-6" %}
|
||||
<div class="col-4">
|
||||
<button class="btn btn-danger" onclick="setFieldValue('{{ form.length.id_for_label }}','5');" tabindex="-1">5{{ form.length.help_text }}</button>
|
||||
<button class="btn btn-success" onclick="setFieldValue('{{ form.length.id_for_label }}','10');" tabindex="-1">10{{ form.length.help_text }}</button>
|
||||
<button class="btn btn-info" onclick="setFieldValue('{{ form.length.id_for_label }}','20');" tabindex="-1">20{{ form.length.help_text }}</button>
|
||||
<btn class="btn btn-danger" onclick="setFieldValue('{{ form.length.id_for_label }}','5');" tabindex="-1">5{{ form.length.help_text }}</btn>
|
||||
<btn class="btn btn-success" onclick="setFieldValue('{{ form.length.id_for_label }}','10');" tabindex="-1">10{{ form.length.help_text }}</btn>
|
||||
<btn class="btn btn-info" onclick="setFieldValue('{{ form.length.id_for_label }}','20');" tabindex="-1">20{{ form.length.help_text }}</btn>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group form-row">
|
||||
{% include 'partials/form_field.html' with field=form.csa append=form.csa.help_text title='CSA' col="col-6" %}
|
||||
<div class="col-4">
|
||||
<button class="btn btn-secondary" onclick="setFieldValue('{{ form.csa.id_for_label }}', '1.5');" tabindex="-1">1.5{{ form.csa.help_text }}</button>
|
||||
<button class="btn btn-secondary" onclick="setFieldValue('{{ form.csa.id_for_label }}', '2.5');" tabindex="-1">2.5{{ form.csa.help_text }}</button>
|
||||
<btn class="btn btn-secondary" onclick="setFieldValue('{{ form.csa.id_for_label }}', '1.5');" tabindex="-1">1.5{{ form.csa.help_text }}</btn>
|
||||
<btn class="btn btn-secondary" onclick="setFieldValue('{{ form.csa.id_for_label }}', '2.5');" tabindex="-1">2.5{{ form.csa.help_text }}</btn>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
{% load widget_tweaks %}
|
||||
|
||||
{% block js %}
|
||||
<script src="{% static 'js/jquery-ui.js' %}"></script>
|
||||
<script src="{% static "js/interaction.js" %}"></script>
|
||||
<script src="{% static "js/modal.js" %}"></script>
|
||||
<script>
|
||||
$('document').ready(function(){
|
||||
$('#asset-search-form').submit(function () {
|
||||
@@ -46,7 +49,7 @@
|
||||
<span>Asset with that ID does not exist!</span>
|
||||
</div>
|
||||
|
||||
<form id="asset-search-form" class="mb-3" method="GET">
|
||||
<form id="asset-search-form" class="mb-3" method="POST">
|
||||
<div class="form-group form-row">
|
||||
<h3>Audit Asset:</h3>
|
||||
<div class="input-group input-group-lg">
|
||||
|
||||
@@ -2,35 +2,37 @@
|
||||
{% load static %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<a href="/assets">
|
||||
<span class="source"> TEC Asset Database</span>
|
||||
</a>
|
||||
</div>
|
||||
<div class="col-sm-12">
|
||||
<h3><a href="{% url 'asset_detail' object.asset_id %}">Asset: {{ object.asset_id }} | {{ object.description }} </a></h3>
|
||||
<h4>
|
||||
<span class="label label-default">
|
||||
<strong>Category:</strong>
|
||||
{{ object.category }}
|
||||
</span>
|
||||
|
||||
<span class="label label-{{ object.status.display_class|default:'default' }}">
|
||||
<strong>Status:</strong>
|
||||
{{ object.status }}
|
||||
</span>
|
||||
</h4>
|
||||
<dl>
|
||||
{% if object.serial_number %}
|
||||
<dt>Serial Number: </dt>
|
||||
<dd>{{ object.serial_number }}</dd>
|
||||
{% endif %}
|
||||
{% if object.comments %}
|
||||
<dt>Comments: </dt>
|
||||
<dd class="dont-break-out">{{ object.comments|linebreaksbr }}<dd>
|
||||
{% endif %}
|
||||
</dl>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<a href="/assets">
|
||||
<span class="source"> TEC Asset Database</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="col-sm-12">
|
||||
<h3><a href="{% url 'asset_detail' object.asset_id %}">Asset: {{ object.asset_id }} | {{ object.description }} </a></h3>
|
||||
<h4>
|
||||
<span class="label label-default">
|
||||
<strong>Category:</strong>
|
||||
{{ object.category }}
|
||||
</span>
|
||||
|
||||
<span class="label label-{{ object.status.display_class|default:'default' }}">
|
||||
<strong>Status:</strong>
|
||||
{{ object.status }}
|
||||
</span>
|
||||
</h4>
|
||||
<dl>
|
||||
{% if object.serial_number %}
|
||||
<dt>Serial Number: </dt>
|
||||
<dd>{{ object.serial_number }}</dd>
|
||||
{% endif %}
|
||||
{% if object.comments %}
|
||||
<dt>Comments: </dt>
|
||||
<dd class="dont-break-out">{{ object.comments|linebreaksbr }}<dd>
|
||||
{% endif %}
|
||||
</dl>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
@@ -3,17 +3,13 @@
|
||||
{% load static %}
|
||||
|
||||
{% block css %}
|
||||
{{ block.super }}
|
||||
<link rel="stylesheet" href="{% static 'css/selects.css' %}"/>
|
||||
{% endblock %}
|
||||
|
||||
{% block preload_js %}
|
||||
{{ block.super }}
|
||||
<script src="{% static 'js/selects.js' %}"></script>
|
||||
<link rel="stylesheet" href="{% static 'css/bootstrap-select.css' %}"/>
|
||||
<link rel="stylesheet" href="{% static 'css/ajax-bootstrap-select.css' %}"/>
|
||||
{% endblock %}
|
||||
|
||||
{% block js %}
|
||||
{{ block.super }}
|
||||
<script src="{% static 'js/bootstrap-select.js' %}"></script>
|
||||
<script src="{% static 'js/ajax-bootstrap-select.js' %}"></script>
|
||||
<script src="{% static 'js/autocompleter.js' %}"></script>
|
||||
<script>
|
||||
const matches = window.matchMedia("(prefers-reduced-motion: reduce)").matches || window.matchMedia("(update: slow)").matches;
|
||||
@@ -37,7 +33,7 @@
|
||||
url: '{% url 'asset_search_json' %}',
|
||||
type: "GET",
|
||||
data: function () {
|
||||
let params = {
|
||||
var params = {
|
||||
{% verbatim %}query: '{{{q}}}'{% endverbatim %}
|
||||
};
|
||||
return params;
|
||||
|
||||
@@ -5,17 +5,16 @@
|
||||
{% load static %}
|
||||
|
||||
{% block css %}
|
||||
{{ block.super }}
|
||||
<link rel="stylesheet" href="{% static 'css/selects.css' %}"/>
|
||||
<link rel="stylesheet" href="{% static 'css/bootstrap-select.css' %}"/>
|
||||
<link rel="stylesheet" href="{% static 'css/ajax-bootstrap-select.css' %}"/>
|
||||
{% endblock %}
|
||||
|
||||
{% block preload_js %}
|
||||
{{ block.super }}
|
||||
<script src="{% static 'js/selects.js' %}" async></script>
|
||||
<script src="{% static 'js/bootstrap-select.js' %}"></script>
|
||||
<script src="{% static 'js/ajax-bootstrap-select.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block js %}
|
||||
{{ block.super }}
|
||||
<script>
|
||||
//Get querystring value
|
||||
function getParameterByName(name) {
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
{% extends 'base_assets.html' %}
|
||||
{% load button from filters %}
|
||||
{% load cache %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<div class="col">
|
||||
<div class="card">
|
||||
<dl class="card-body row">
|
||||
<dt class="col-6">Socket</dt>
|
||||
<dd>{{ object.socket|default_if_none:'-' }}</dd>
|
||||
|
||||
<dt class="col-6">Plug</dt>
|
||||
<dd>{{ object.plug|default_if_none:'-' }}</dd>
|
||||
|
||||
<dt class="col-6">Circuits</dt>
|
||||
<dd>{{ object.circuits|default_if_none:'-' }}</dd>
|
||||
|
||||
<dt class="col-6">Cores</dt>
|
||||
<dd>{{ object.cores|default_if_none:'-' }}</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col mt-2 text-right">
|
||||
{% button 'edit' url='cable_type_update' pk=object.id %}
|
||||
</div>
|
||||
{% cache None cable_type_assets object %}
|
||||
<div class="col mt-2">
|
||||
<div class="card">
|
||||
<div class="card-header">Associated Assets</div>
|
||||
{% with object.asset_set.all as object_list %}
|
||||
{% include 'partials/asset_list_table.html' %}
|
||||
{% endwith %}
|
||||
</div>
|
||||
</div>
|
||||
{% endcache %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -4,25 +4,58 @@
|
||||
{% load cache %}
|
||||
|
||||
{% block content %}
|
||||
{% if create %}
|
||||
<form method="POST" action="{% url 'cable_type_create'%}">
|
||||
{% elif edit %}
|
||||
<form method="POST" action="{% url 'cable_type_update' object.id %}">
|
||||
{% endif %}
|
||||
{% if create %}
|
||||
<form method="POST" action="{% url 'cable_type_create'%}">
|
||||
{% elif edit %}
|
||||
<form method="POST" action="{% url 'cable_type_update' object.id %}">
|
||||
{% endif %}
|
||||
{% include 'form_errors.html' %}
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="id" value="{{ object.id|default:0 }}" hidden="">
|
||||
<input type="hidden" name="id" value="{{ object.id|default:0 }}" hidden=true>
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
{% for field in form %}
|
||||
<div class="form-group">
|
||||
{% include 'partials/form_field.html' with field=field %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
<div class="text-right">
|
||||
{% button 'submit' %}
|
||||
<div class="col-sm-12">
|
||||
{% if create or edit %}
|
||||
{% for field in form %}
|
||||
<div class="form-group">
|
||||
{% include 'partials/form_field.html' with field=field %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
<div class="text-right">
|
||||
{% button 'submit' %}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="col">
|
||||
<div class="card">
|
||||
<dl class="card-body row">
|
||||
<dt class="col-6">Socket</dt>
|
||||
<dd>{{ object.socket|default_if_none:'-' }}</dd>
|
||||
|
||||
<dt class="col-6">Plug</dt>
|
||||
<dd>{{ object.plug|default_if_none:'-' }}</dd>
|
||||
|
||||
<dt class="col-6">Circuits</dt>
|
||||
<dd>{{ object.circuits|default_if_none:'-' }}</dd>
|
||||
|
||||
<dt class="col-6">Cores</dt>
|
||||
<dd>{{ object.cores|default_if_none:'-' }}</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col mt-2 text-right">
|
||||
{% button 'edit' url='cable_type_update' pk=object.id %}
|
||||
</div>
|
||||
{% cache None cable_type_assets object %}
|
||||
<div class="col mt-2">
|
||||
<div class="card">
|
||||
<div class="card-header">Associated Assets</div>
|
||||
{% with object.asset_set.all as object_list %}
|
||||
{% include 'partials/asset_list_table.html' %}
|
||||
{% endwith %}
|
||||
</div>
|
||||
</div>
|
||||
{% endcache %}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
{% button 'submit' %}
|
||||
{% elif duplicate %}
|
||||
<!--duplicate-->
|
||||
<button type="submit" class="btn btn-success"><span class="fas fa-check"></span> Create Duplicate</button>
|
||||
<button type="submit" class="btn btn-success"><i class="fas fa-tick"></i> Create Duplicate</button>
|
||||
{% else %}
|
||||
<!--detail view-->
|
||||
<div class="btn-group">
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
{% button 'view' url='asset_detail' pk=item.asset_id clazz="btn-sm" %}
|
||||
{% if perms.assets.change_asset %}
|
||||
{% button 'edit' url='asset_update' pk=item.asset_id clazz="btn-sm" %}
|
||||
{% endif %}
|
||||
{% if perms.assets.add_asset %}
|
||||
{% button 'duplicate' url='asset_duplicate' pk=item.asset_id clazz="btn-sm" %}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
import pytest
|
||||
from assets import models
|
||||
import datetime
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def category(db):
|
||||
category = models.AssetCategory.objects.create(name="Sound")
|
||||
yield category
|
||||
category.delete()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def status(db):
|
||||
status = models.AssetStatus.objects.create(name="Broken", should_show=True)
|
||||
yield status
|
||||
status.delete()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_cable(db, category, status):
|
||||
connector = models.Connector.objects.create(description="16A IEC", current_rating=16, voltage_rating=240, num_pins=3)
|
||||
cable_type = models.CableType.objects.create(circuits=11, cores=3, plug=connector, socket=connector)
|
||||
cable = models.Asset.objects.create(asset_id="9666", description="125A -> Jack", comments="The cable from Hell...", status=status, category=category, date_acquired=datetime.date(2006, 6, 6), is_cable=True, cable_type=cable_type, length=10, csa="1.5")
|
||||
yield cable
|
||||
connector.delete()
|
||||
cable_type.delete()
|
||||
cable.delete()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_asset(db, category, status):
|
||||
asset, created = models.Asset.objects.get_or_create(asset_id="91991", description="Spaceflower", status=status, category=category, date_acquired=datetime.date(1991, 12, 26))
|
||||
yield asset
|
||||
asset.delete()
|
||||
@@ -17,7 +17,6 @@ class AssetList(BasePage):
|
||||
_status_select_locator = (By.CSS_SELECTOR, 'div#status-group>div.bootstrap-select')
|
||||
_category_select_locator = (By.CSS_SELECTOR, 'div#category-group>div.bootstrap-select')
|
||||
_go_button_locator = (By.ID, 'id_search')
|
||||
_filter_button_locator = (By.ID, 'filter-submit')
|
||||
|
||||
class AssetListRow(Region):
|
||||
_asset_id_locator = (By.CLASS_NAME, "assetID")
|
||||
@@ -57,9 +56,6 @@ class AssetList(BasePage):
|
||||
def search(self):
|
||||
self.find_element(*self._go_button_locator).click()
|
||||
|
||||
def filter(self):
|
||||
self.find_element(*self._filter_button_locator).click()
|
||||
|
||||
@property
|
||||
def status_selector(self):
|
||||
return regions.BootstrapSelectElement(self, self.find_element(*self._status_select_locator))
|
||||
|
||||
@@ -5,7 +5,7 @@ from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.support import expected_conditions as ec
|
||||
from selenium.webdriver.support.ui import WebDriverWait
|
||||
|
||||
from PyRIGS.tests.base import AutoLoginTest, screenshot_failure_cls, assert_times_almost_equal
|
||||
from PyRIGS.tests.base import AutoLoginTest, screenshot_failure_cls, assert_times_equal
|
||||
from PyRIGS.tests.pages import animation_is_finished
|
||||
from assets import models
|
||||
from . import pages
|
||||
@@ -78,7 +78,7 @@ class TestAssetList(AutoLoginTest):
|
||||
self.page.status_selector.select_all()
|
||||
self.page.status_selector.toggle()
|
||||
self.assertFalse(self.page.status_selector.is_open)
|
||||
self.page.filter()
|
||||
self.page.search()
|
||||
self.assertTrue(len(self.page.assets) == 4)
|
||||
|
||||
self.page.category_selector.toggle()
|
||||
@@ -86,7 +86,7 @@ class TestAssetList(AutoLoginTest):
|
||||
self.page.category_selector.set_option("Sound", True)
|
||||
self.page.category_selector.close()
|
||||
self.assertFalse(self.page.category_selector.is_open)
|
||||
self.page.filter()
|
||||
self.page.search()
|
||||
self.assertTrue(len(self.page.assets) == 2)
|
||||
asset_ids = list(map(lambda x: x.id, self.page.assets))
|
||||
self.assertEqual("1", asset_ids[0])
|
||||
@@ -110,7 +110,7 @@ class TestAssetForm(AutoLoginTest):
|
||||
|
||||
def test_asset_create(self):
|
||||
# Test that ID is automatically assigned and properly incremented
|
||||
# self.assertIn(self.page.asset_id, "9001") FIXME
|
||||
self.assertIn(self.page.asset_id, "9001")
|
||||
|
||||
self.page.remove_all_required()
|
||||
self.page.asset_id = "XX$X"
|
||||
@@ -128,20 +128,20 @@ class TestAssetForm(AutoLoginTest):
|
||||
self.page.serial_number = sn = "0124567890-SAUSAGE"
|
||||
self.page.comments = comments = "This is actually a sledgehammer, not a cable..."
|
||||
|
||||
self.page.purchase_price = "12.99"
|
||||
self.page.salvage_value = "99.12"
|
||||
self.page.date_acquired = acquired = datetime.date(2020, 5, 2)
|
||||
self.page.purchased_from_selector.toggle()
|
||||
self.assertTrue(self.page.purchased_from_selector.is_open)
|
||||
self.page.purchased_from_selector.search(self.supplier.name[:-8])
|
||||
self.page.purchased_from_selector.set_option(self.supplier.name, True)
|
||||
self.page.purchase_price = "12.99"
|
||||
self.page.salvage_value = "99.12"
|
||||
self.page.date_acquired = acquired = datetime.date(2020, 5, 2)
|
||||
|
||||
self.page.parent_selector.toggle()
|
||||
self.assertTrue(self.page.parent_selector.is_open)
|
||||
option = str(self.parent)
|
||||
self.page.parent_selector.search(option)
|
||||
self.page.parent_selector.search(self.parent.asset_id)
|
||||
# Needed here but not earlier for whatever reason
|
||||
self.driver.implicitly_wait(1)
|
||||
self.page.parent_selector.set_option(option, True)
|
||||
self.page.parent_selector.set_option(self.parent.asset_id + " | " + self.parent.description, True)
|
||||
self.assertTrue(self.page.parent_selector.options[0].selected)
|
||||
self.page.parent_selector.toggle()
|
||||
|
||||
@@ -272,16 +272,6 @@ class TestSupplierCreateAndEdit(AutoLoginTest):
|
||||
self.assertTrue(self.page.success)
|
||||
|
||||
|
||||
def test_audit_search(logged_in_browser, live_server, test_asset):
|
||||
page = pages.AssetAuditList(logged_in_browser.driver, live_server.url).open()
|
||||
# Check that a failed search works
|
||||
page.set_query("NOTFOUND")
|
||||
page.search()
|
||||
assert not logged_in_browser.find_by_id('modal').visible
|
||||
logged_in_browser.driver.implicitly_wait(4)
|
||||
assert logged_in_browser.is_text_present("Asset with that ID does not exist!")
|
||||
|
||||
|
||||
@screenshot_failure_cls
|
||||
class TestAssetAudit(AutoLoginTest):
|
||||
def setUp(self):
|
||||
@@ -297,14 +287,14 @@ class TestAssetAudit(AutoLoginTest):
|
||||
category=self.category, date_acquired=datetime.date(2020, 2, 1))
|
||||
models.Asset.objects.create(asset_id="111", description="Erms", status=self.status, category=self.category,
|
||||
date_acquired=datetime.date(2020, 2, 1))
|
||||
self.asset = models.Asset.objects.create(asset_id="1111", description="A hammer", status=self.status,
|
||||
category=self.category,
|
||||
date_acquired=datetime.date(2020, 2, 1))
|
||||
models.Asset.objects.create(asset_id="1111", description="A hammer", status=self.status, category=self.category,
|
||||
date_acquired=datetime.date(2020, 2, 1))
|
||||
self.page = pages.AssetAuditList(self.driver, self.live_server_url).open()
|
||||
self.wait = WebDriverWait(self.driver, 20)
|
||||
|
||||
def test_audit_fail(self):
|
||||
self.page.set_query(self.asset.asset_id)
|
||||
def test_audit_process(self):
|
||||
asset_id = "1111"
|
||||
self.page.set_query(asset_id)
|
||||
self.page.search()
|
||||
self.wait.until(ec.visibility_of_element_located((By.ID, 'modal')))
|
||||
# Do it wrong on purpose to check error display
|
||||
@@ -312,27 +302,20 @@ class TestAssetAudit(AutoLoginTest):
|
||||
self.page.modal.description = ""
|
||||
self.page.modal.submit()
|
||||
self.wait.until(animation_is_finished())
|
||||
self.driver.implicitly_wait(4)
|
||||
self.assertIn("This field is required.", self.page.modal.errors["Description"])
|
||||
|
||||
def test_audit_success(self):
|
||||
self.page.set_query(self.asset.asset_id)
|
||||
self.page.search()
|
||||
self.wait.until(ec.visibility_of_element_located((By.ID, 'modal')))
|
||||
# Now do it properly
|
||||
self.page.modal.description = new_desc = "A BIG hammer"
|
||||
self.page.modal.submit()
|
||||
self.driver.implicitly_wait(4)
|
||||
self.wait.until(animation_is_finished())
|
||||
submit_time = timezone.now()
|
||||
# Check data is correct
|
||||
self.asset.refresh_from_db()
|
||||
self.assertEqual(self.asset.description, new_desc)
|
||||
audited = models.Asset.objects.get(asset_id=asset_id)
|
||||
self.assertEqual(audited.description, new_desc)
|
||||
# Make sure audit 'log' was filled out
|
||||
self.assertEqual(self.profile.initials, self.asset.last_audited_by.initials)
|
||||
assert_times_almost_equal(submit_time, self.asset.last_audited_at)
|
||||
self.assertEqual(self.profile.initials, audited.last_audited_by.initials)
|
||||
assert_times_equal(submit_time, audited.last_audited_at)
|
||||
# Check we've removed it from the 'needing audit' list
|
||||
self.assertNotIn(self.asset.asset_id, self.page.assets)
|
||||
self.assertNotIn(asset_id, self.page.assets)
|
||||
|
||||
def test_audit_list(self):
|
||||
self.assertEqual(len(models.Asset.objects.filter(last_audited_at=None)), len(self.page.assets))
|
||||
@@ -345,3 +328,10 @@ class TestAssetAudit(AutoLoginTest):
|
||||
# Make sure audit log was NOT filled out
|
||||
audited = models.Asset.objects.get(asset_id=asset_row.id)
|
||||
assert audited.last_audited_by is None
|
||||
|
||||
def test_audit_search(self):
|
||||
# Check that a failed search works
|
||||
self.page.set_query("NOTFOUND")
|
||||
self.page.search()
|
||||
self.assertFalse(self.driver.find_element_by_id('modal').is_displayed())
|
||||
self.assertIn("Asset with that ID does not exist!", self.page.error.text)
|
||||
|
||||
@@ -1,41 +1,64 @@
|
||||
import datetime
|
||||
|
||||
import pytest
|
||||
from django.core.management import call_command
|
||||
from django.test.utils import override_settings
|
||||
from django.urls import reverse
|
||||
from pytest_django.asserts import assertFormError, assertRedirects, assertContains, assertNotContains
|
||||
|
||||
from PyRIGS.tests.base import assert_oembed, login
|
||||
from assets import models, urls
|
||||
|
||||
from assets import models
|
||||
|
||||
from django.utils import timezone
|
||||
|
||||
pytestmark = pytest.mark.django_db
|
||||
pytestmark = pytest.mark.django_db # TODO
|
||||
|
||||
|
||||
def test_supplier_create(admin_client):
|
||||
def login(client, django_user_model):
|
||||
pwd = 'testuser'
|
||||
usr = "TestUser"
|
||||
django_user_model.objects.create_user(username=usr, email="TestUser@test.com", password=pwd, is_superuser=True, is_active=True, is_staff=True)
|
||||
assert client.login(username=usr, password=pwd)
|
||||
|
||||
|
||||
def create_test_asset():
|
||||
working = models.AssetStatus.objects.create(name="Working", should_show=True)
|
||||
lighting = models.AssetCategory.objects.create(name="Lighting")
|
||||
asset = models.Asset.objects.create(asset_id="1991", description="Spaceflower", status=working, category=lighting, date_acquired=datetime.date(1991, 12, 26))
|
||||
return asset
|
||||
|
||||
|
||||
def create_test_cable():
|
||||
category = models.AssetCategory.objects.create(name="Sound")
|
||||
status = models.AssetStatus.objects.create(name="Broken", should_show=True)
|
||||
connector = models.Connector.objects.create(description="16A IEC", current_rating=16, voltage_rating=240, num_pins=3)
|
||||
cable_type = models.CableType.objects.create(circuits=11, cores=3, plug=connector, socket=connector)
|
||||
return models.Asset.objects.create(asset_id="666", description="125A -> Jack", comments="The cable from Hell...", status=status, category=category, date_acquired=datetime.date(2006, 6, 6), is_cable=True, cable_type=cable_type, length=10, csa="1.5")
|
||||
|
||||
|
||||
def test_supplier_create(client, django_user_model):
|
||||
login(client, django_user_model)
|
||||
url = reverse('supplier_create')
|
||||
response = admin_client.post(url)
|
||||
response = client.post(url)
|
||||
assertFormError(response, 'form', 'name', 'This field is required.')
|
||||
|
||||
|
||||
def test_supplier_edit(admin_client):
|
||||
def test_supplier_edit(client, django_user_model):
|
||||
login(client, django_user_model)
|
||||
supplier = models.Supplier.objects.create(name="Gadgetron Corporation")
|
||||
url = reverse('supplier_update', kwargs={'pk': supplier.pk})
|
||||
response = admin_client.post(url, {'name': ""})
|
||||
response = client.post(url, {'name': ""})
|
||||
assertFormError(response, 'form', 'name', 'This field is required.')
|
||||
|
||||
|
||||
def test_404(admin_client):
|
||||
def test_404(client, django_user_model):
|
||||
login(client, django_user_model)
|
||||
urls = {'asset_detail', 'asset_update', 'asset_duplicate', 'supplier_detail', 'supplier_update'}
|
||||
for url_name in urls:
|
||||
request_url = reverse(url_name, kwargs={'pk': "0000"})
|
||||
response = admin_client.get(request_url, follow=True)
|
||||
response = client.get(request_url, follow=True)
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
def test_embed_login_redirect(client, django_user_model, test_asset):
|
||||
request_url = reverse('asset_embed', kwargs={'pk': test_asset.asset_id})
|
||||
def test_embed_login_redirect(client, django_user_model):
|
||||
request_url = reverse('asset_embed', kwargs={'pk': create_test_asset().asset_id})
|
||||
expected_url = "{0}?next={1}".format(reverse('login_embed'), request_url)
|
||||
|
||||
# Request the page and check it redirects
|
||||
@@ -56,8 +79,8 @@ def test_login_cookie_warning(client, django_user_model):
|
||||
assert "Cookies do not seem to be enabled" in str(response.content)
|
||||
|
||||
|
||||
def test_x_frame_headers(client, django_user_model, test_asset):
|
||||
asset_url = reverse('asset_embed', kwargs={'pk': test_asset.asset_id})
|
||||
def test_x_frame_headers(client, django_user_model):
|
||||
asset_url = reverse('asset_embed', kwargs={'pk': create_test_asset().asset_id})
|
||||
login_url = reverse('login_embed')
|
||||
|
||||
login(client, django_user_model)
|
||||
@@ -71,42 +94,100 @@ def test_x_frame_headers(client, django_user_model, test_asset):
|
||||
response._headers["X-Frame-Options"]
|
||||
|
||||
|
||||
def test_oembed(client, test_asset):
|
||||
client.logout()
|
||||
asset_url = reverse('asset_detail', kwargs={'pk': test_asset.asset_id})
|
||||
asset_embed_url = reverse('asset_embed', kwargs={'pk': test_asset.asset_id})
|
||||
oembed_url = reverse('asset_oembed', kwargs={'pk': test_asset.asset_id})
|
||||
def test_oembed(client):
|
||||
asset = create_test_asset()
|
||||
asset_url = reverse('asset_detail', kwargs={'pk': asset.asset_id})
|
||||
asset_embed_url = reverse('asset_embed', kwargs={'pk': asset.asset_id})
|
||||
oembed_url = reverse('asset_oembed', kwargs={'pk': asset.asset_id})
|
||||
|
||||
alt_oembed_url = reverse('asset_oembed', kwargs={'pk': 999})
|
||||
alt_asset_embed_url = reverse('asset_embed', kwargs={'pk': 999})
|
||||
|
||||
assert_oembed(alt_asset_embed_url, alt_oembed_url, client, asset_embed_url, asset_url, oembed_url)
|
||||
# Test the meta tag is in place
|
||||
response = client.get(asset_url, follow=True, HTTP_HOST='example.com')
|
||||
assert '<link rel="alternate" type="application/json+oembed"' in str(response.content)
|
||||
assertContains(response, oembed_url)
|
||||
|
||||
# Test that the JSON exists
|
||||
response = client.get(oembed_url, follow=True, HTTP_HOST='example.com')
|
||||
assert response.status_code == 200
|
||||
assertContains(response, asset_embed_url)
|
||||
|
||||
# Should also work for non-existant
|
||||
response = client.get(alt_oembed_url, follow=True, HTTP_HOST='example.com')
|
||||
assert response.status_code == 200
|
||||
assertContains(response, alt_asset_embed_url)
|
||||
|
||||
|
||||
def test_asset_create(admin_client):
|
||||
response = admin_client.post(reverse('asset_create'), {'date_sold': '2000-01-01', 'date_acquired': '2020-01-01', 'purchase_price': '-30', 'salvage_value': '-30'})
|
||||
@override_settings(DEBUG=True)
|
||||
def test_generate_sample_data(client):
|
||||
# Run the management command and check there are no exceptions
|
||||
call_command('generateSampleAssetsData')
|
||||
|
||||
# Check there are lots
|
||||
assert models.Asset.objects.all().count() > 50
|
||||
assert models.Supplier.objects.all().count() > 50
|
||||
|
||||
|
||||
@override_settings(DEBUG=True)
|
||||
def test_delete_sample_data(client):
|
||||
call_command('deleteSampleData')
|
||||
|
||||
assert models.Asset.objects.all().count() == 0
|
||||
assert models.Supplier.objects.all().count() == 0
|
||||
|
||||
|
||||
def test_production_exception(client):
|
||||
from django.core.management.base import CommandError
|
||||
|
||||
with pytest.raises(CommandError, match=".*production"):
|
||||
call_command('generateSampleAssetsData')
|
||||
call_command('deleteSampleData')
|
||||
|
||||
|
||||
def test_asset_create(client, django_user_model):
|
||||
login(client, django_user_model)
|
||||
response = client.post(reverse('asset_create'), {'date_sold': '2000-01-01', 'date_acquired': '2020-01-01', 'purchase_price': '-30', 'salvage_value': '-30'})
|
||||
assertFormError(response, 'form', 'asset_id', 'This field is required.')
|
||||
assert_asset_form_errors(response)
|
||||
assertFormError(response, 'form', 'description', 'This field is required.')
|
||||
assertFormError(response, 'form', 'status', 'This field is required.')
|
||||
assertFormError(response, 'form', 'category', 'This field is required.')
|
||||
|
||||
assertFormError(response, 'form', 'date_sold', 'Cannot sell an item before it is acquired')
|
||||
assertFormError(response, 'form', 'purchase_price', 'A price cannot be negative')
|
||||
assertFormError(response, 'form', 'salvage_value', 'A price cannot be negative')
|
||||
|
||||
|
||||
def test_cable_create(admin_client):
|
||||
response = admin_client.post(reverse('asset_create'), {'asset_id': 'X$%A', 'is_cable': True})
|
||||
def test_cable_create(client, django_user_model):
|
||||
login(client, django_user_model)
|
||||
response = client.post(reverse('asset_create'), {'asset_id': 'X$%A', 'is_cable': True})
|
||||
assertFormError(response, 'form', 'asset_id', 'An Asset ID can only consist of letters and numbers, with a final number')
|
||||
|
||||
assertFormError(response, 'form', 'cable_type', 'A cable must have a type')
|
||||
assertFormError(response, 'form', 'length', 'The length of a cable must be more than 0')
|
||||
assertFormError(response, 'form', 'csa', 'The CSA of a cable must be more than 0')
|
||||
|
||||
|
||||
def test_asset_edit(admin_client, test_asset):
|
||||
url = reverse('asset_update', kwargs={'pk': test_asset.asset_id})
|
||||
response = admin_client.post(url, {'date_sold': '2000-12-01', 'date_acquired': '2020-12-01', 'purchase_price': '-50', 'salvage_value': '-50', 'description': "", 'status': "", 'category': ""})
|
||||
assert_asset_form_errors(response)
|
||||
# Given that validation is done at model level it *shouldn't* need retesting...gonna do it anyway!
|
||||
|
||||
|
||||
def test_cable_edit(admin_client, test_cable):
|
||||
url = reverse('asset_update', kwargs={'pk': test_cable.asset_id})
|
||||
def test_asset_edit(client, django_user_model):
|
||||
login(client, django_user_model)
|
||||
url = reverse('asset_update', kwargs={'pk': create_test_asset().asset_id})
|
||||
response = client.post(url, {'date_sold': '2000-12-01', 'date_acquired': '2020-12-01', 'purchase_price': '-50', 'salvage_value': '-50', 'description': "", 'status': "", 'category': ""})
|
||||
# assertFormError(response, 'form', 'asset_id', 'This field is required.')
|
||||
assertFormError(response, 'form', 'description', 'This field is required.')
|
||||
assertFormError(response, 'form', 'status', 'This field is required.')
|
||||
assertFormError(response, 'form', 'category', 'This field is required.')
|
||||
assertFormError(response, 'form', 'date_sold', 'Cannot sell an item before it is acquired')
|
||||
assertFormError(response, 'form', 'purchase_price', 'A price cannot be negative')
|
||||
assertFormError(response, 'form', 'salvage_value', 'A price cannot be negative')
|
||||
|
||||
|
||||
def test_cable_edit(client, django_user_model):
|
||||
login(client, django_user_model)
|
||||
url = reverse('asset_update', kwargs={'pk': create_test_cable().asset_id})
|
||||
# TODO Why do I have to send is_cable=True here?
|
||||
response = admin_client.post(url, {'is_cable': True, 'length': -3, 'csa': -3})
|
||||
response = client.post(url, {'is_cable': True, 'length': -3, 'csa': -3})
|
||||
|
||||
# TODO Can't figure out how to select the 'none' option...
|
||||
# assertFormError(response, 'form', 'cable_type', 'A cable must have a type')
|
||||
@@ -114,18 +195,95 @@ def test_cable_edit(admin_client, test_cable):
|
||||
assertFormError(response, 'form', 'csa', 'The CSA of a cable must be more than 0')
|
||||
|
||||
|
||||
def test_asset_duplicate(admin_client, test_cable):
|
||||
url = reverse('asset_duplicate', kwargs={'pk': test_cable.asset_id})
|
||||
response = admin_client.post(url, {'is_cable': True, 'length': 0, 'csa': 0})
|
||||
def test_asset_duplicate(client, django_user_model):
|
||||
login(client, django_user_model)
|
||||
url = reverse('asset_duplicate', kwargs={'pk': create_test_cable().asset_id})
|
||||
response = client.post(url, {'is_cable': True, 'length': 0, 'csa': 0})
|
||||
|
||||
assertFormError(response, 'form', 'length', 'The length of a cable must be more than 0')
|
||||
assertFormError(response, 'form', 'csa', 'The CSA of a cable must be more than 0')
|
||||
|
||||
|
||||
def assert_asset_form_errors(response):
|
||||
assertFormError(response, 'form', 'description', 'This field is required.')
|
||||
assertFormError(response, 'form', 'status', 'This field is required.')
|
||||
assertFormError(response, 'form', 'category', 'This field is required.')
|
||||
assertFormError(response, 'form', 'date_sold', 'Cannot sell an item before it is acquired')
|
||||
assertFormError(response, 'form', 'purchase_price', 'A price cannot be negative')
|
||||
assertFormError(response, 'form', 'salvage_value', 'A price cannot be negative')
|
||||
@override_settings(DEBUG=True)
|
||||
def create_asset_one():
|
||||
# Shortcut to create the levels - bonus side effect of testing the command (hopefully) matches production
|
||||
call_command('generateSampleData')
|
||||
# Create an asset with ID 1 to make things easier in loops (we can always use pk=1)
|
||||
category = models.AssetCategory.objects.create(name="Number One")
|
||||
status = models.AssetStatus.objects.create(name="Probably Fine", should_show=True)
|
||||
return models.Asset.objects.create(asset_id="1", description="Half Price Fish", status=status, category=category, date_acquired=datetime.date(2020, 2, 1))
|
||||
|
||||
# Nothing should be available to the unauthenticated
|
||||
|
||||
|
||||
def test_unauthenticated(client):
|
||||
for url in filter(lambda url: url.name is not None and "json" not in str(url), urls.urlpatterns):
|
||||
pattern = str(url.pattern)
|
||||
request_url = ""
|
||||
if ":pk>" in pattern:
|
||||
request_url = reverse(url.name, kwargs={'pk': 1})
|
||||
else:
|
||||
request_url = reverse(url.name)
|
||||
if request_url:
|
||||
response = client.get(request_url, follow=True, HTTP_HOST='example.com')
|
||||
# TODO Check the URL here
|
||||
assertContains(response, 'Login')
|
||||
|
||||
|
||||
def test_basic_access(client):
|
||||
create_asset_one()
|
||||
client.login(username="basic", password="basic")
|
||||
|
||||
url = reverse('asset_list')
|
||||
response = client.get(url)
|
||||
# Check edit and duplicate buttons NOT shown in list
|
||||
assertNotContains(response, 'Edit')
|
||||
assertNotContains(response, 'Duplicate')
|
||||
|
||||
url = reverse('asset_detail', kwargs={'pk': "9000"})
|
||||
response = client.get(url)
|
||||
assertNotContains(response, 'Purchase Details')
|
||||
assertNotContains(response, 'View Revision History')
|
||||
|
||||
urls = {'asset_history', 'asset_update', 'asset_duplicate'}
|
||||
for url_name in urls:
|
||||
request_url = reverse(url_name, kwargs={'pk': "9000"})
|
||||
response = client.get(request_url, follow=True)
|
||||
assert response.status_code == 403
|
||||
|
||||
request_url = reverse('supplier_create')
|
||||
response = client.get(request_url, follow=True)
|
||||
assert response.status_code == 403
|
||||
|
||||
request_url = reverse('supplier_update', kwargs={'pk': "1"})
|
||||
response = client.get(request_url, follow=True)
|
||||
assert response.status_code == 403
|
||||
|
||||
|
||||
def test_keyholder_access(client):
|
||||
create_asset_one()
|
||||
client.login(username="keyholder", password="keyholder")
|
||||
|
||||
url = reverse('asset_list')
|
||||
response = client.get(url)
|
||||
# Check edit and duplicate buttons shown in list
|
||||
assertContains(response, 'Edit')
|
||||
assertContains(response, 'Duplicate')
|
||||
|
||||
url = reverse('asset_detail', kwargs={'pk': "9000"})
|
||||
response = client.get(url)
|
||||
assertContains(response, 'Purchase Details')
|
||||
assertContains(response, 'View Revision History')
|
||||
|
||||
|
||||
def test_page_titles(admin_client):
|
||||
for url in filter(lambda url: url.name is not None and not any(s in url.name for s in ["json", "embed"]), urls.urlpatterns):
|
||||
request_url = ""
|
||||
if ":pk>" in str(url.pattern):
|
||||
request_url = reverse(url.name, kwargs={'pk': "1"})
|
||||
else:
|
||||
request_url = reverse(url.name)
|
||||
response = admin_client.get(request_url)
|
||||
if hasattr(response, "context_data") and "page_title" in response.context_data:
|
||||
expected_title = response.context_data["page_title"]
|
||||
assertContains(response, '<title>{} | Rig Information Gathering System</title>'.format(expected_title))
|
||||
|
||||
@@ -3,7 +3,6 @@ from django.urls import path
|
||||
from django.views.decorators.clickjacking import xframe_options_exempt
|
||||
|
||||
from PyRIGS.decorators import has_oembed, permission_required_with_403
|
||||
from PyRIGS.views import OEmbedView
|
||||
from assets import views
|
||||
|
||||
urlpatterns = [
|
||||
@@ -17,27 +16,29 @@ urlpatterns = [
|
||||
path('asset/id/<str:pk>/duplicate/', permission_required_with_403('assets.add_asset')
|
||||
(views.AssetDuplicate.as_view()), name='asset_duplicate'),
|
||||
|
||||
path('cabletype/list/', login_required(views.CableTypeList.as_view()), name='cable_type_list'),
|
||||
path('cabletype/list/', views.CableTypeList.as_view(), name='cable_type_list'),
|
||||
path('cabletype/create/', permission_required_with_403('assets.add_cable_type')(views.CableTypeCreate.as_view()), name='cable_type_create'),
|
||||
path('cabletype/<int:pk>/update/', permission_required_with_403('assets.change_cable_type')(views.CableTypeUpdate.as_view()), name='cable_type_update'),
|
||||
path('cabletype/<int:pk>/detail/', login_required(views.CableTypeDetail.as_view()), name='cable_type_detail'),
|
||||
path('cabletype/<int:pk>/detail/', views.CableTypeDetail.as_view(), name='cable_type_detail'),
|
||||
|
||||
path('asset/search/', login_required(views.AssetSearch.as_view()), name='asset_search_json'),
|
||||
path('asset/search/', views.AssetSearch.as_view(), name='asset_search_json'),
|
||||
path('asset/id/<str:pk>/embed/',
|
||||
xframe_options_exempt(
|
||||
login_required(login_url='/user/login/embed/')(views.AssetEmbed.as_view())),
|
||||
name='asset_embed'),
|
||||
path('asset/id/<str:pk>/oembed_json/', views.AssetOEmbed.as_view(), name='asset_oembed'),
|
||||
path('asset/id/<str:pk>/oembed_json/',
|
||||
views.AssetOembed.as_view(),
|
||||
name='asset_oembed'),
|
||||
|
||||
path('asset/audit/', permission_required_with_403('assets.change_asset')(views.AssetAuditList.as_view()), name='asset_audit_list'),
|
||||
path('asset/id/<str:pk>/audit/', permission_required_with_403('assets.change_asset')(views.AssetAudit.as_view()), name='asset_audit'),
|
||||
|
||||
path('supplier/list/', login_required(views.SupplierList.as_view()), name='supplier_list'),
|
||||
path('supplier/<int:pk>/', login_required(views.SupplierDetail.as_view()), name='supplier_detail'),
|
||||
path('supplier/list/', views.SupplierList.as_view(), name='supplier_list'),
|
||||
path('supplier/<int:pk>/', views.SupplierDetail.as_view(), name='supplier_detail'),
|
||||
path('supplier/create/', permission_required_with_403('assets.add_supplier')
|
||||
(views.SupplierCreate.as_view()), name='supplier_create'),
|
||||
path('supplier/<int:pk>/edit/', permission_required_with_403('assets.change_supplier')
|
||||
(views.SupplierUpdate.as_view()), name='supplier_update'),
|
||||
|
||||
path('supplier/search/', login_required(views.SupplierSearch.as_view()), name='supplier_search_json'),
|
||||
path('supplier/search/', views.SupplierSearch.as_view(), name='supplier_search_json'),
|
||||
]
|
||||
|
||||
@@ -11,11 +11,11 @@ from django.views import generic
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
||||
from PyRIGS.views import GenericListView, GenericDetailView, GenericUpdateView, GenericCreateView, ModalURLMixin, \
|
||||
is_ajax, OEmbedView
|
||||
is_ajax
|
||||
from assets import forms, models
|
||||
from assets.models import get_available_asset_id
|
||||
|
||||
|
||||
@method_decorator(csrf_exempt, name='dispatch')
|
||||
class AssetList(LoginRequiredMixin, generic.ListView):
|
||||
model = models.Asset
|
||||
template_name = 'asset_list.html'
|
||||
@@ -28,7 +28,9 @@ class AssetList(LoginRequiredMixin, generic.ListView):
|
||||
return initial
|
||||
|
||||
def get_queryset(self):
|
||||
if self.request.method == 'GET' and len(self.request.GET) > 0:
|
||||
if self.request.method == 'POST':
|
||||
self.form = forms.AssetSearchForm(data=self.request.POST)
|
||||
elif self.request.method == 'GET' and len(self.request.GET) > 0:
|
||||
self.form = forms.AssetSearchForm(data=self.request.GET)
|
||||
else:
|
||||
self.form = forms.AssetSearchForm(data=self.get_initial())
|
||||
@@ -55,7 +57,7 @@ class AssetList(LoginRequiredMixin, generic.ListView):
|
||||
queryset = queryset.filter(
|
||||
status__in=models.AssetStatus.objects.filter(should_show=True))
|
||||
|
||||
return queryset.select_related('category', 'status')
|
||||
return queryset
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(AssetList, self).get_context_data(**kwargs)
|
||||
@@ -140,7 +142,7 @@ class AssetCreate(LoginRequiredMixin, generic.CreateView):
|
||||
|
||||
def get_initial(self, *args, **kwargs):
|
||||
initial = super().get_initial(*args, **kwargs)
|
||||
initial["asset_id"] = get_available_asset_id()
|
||||
initial["asset_id"] = models.Asset.get_available_asset_id()
|
||||
return initial
|
||||
|
||||
def get_success_url(self):
|
||||
@@ -164,23 +166,37 @@ class AssetDuplicate(DuplicateMixin, AssetIDUrlMixin, AssetCreate):
|
||||
return context
|
||||
|
||||
|
||||
class AssetOembed(generic.View):
|
||||
model = models.Asset
|
||||
|
||||
def get(self, request, pk=None):
|
||||
embed_url = reverse('asset_embed', args=[pk])
|
||||
full_url = "{0}://{1}{2}".format(request.scheme, request.META['HTTP_HOST'], embed_url)
|
||||
|
||||
data = {
|
||||
'html': '<iframe src="{0}" frameborder="0" width="100%" height="250"></iframe>'.format(full_url),
|
||||
'version': '1.0',
|
||||
'type': 'rich',
|
||||
'height': '250'
|
||||
}
|
||||
|
||||
json = simplejson.JSONEncoderForHTML().encode(data)
|
||||
return HttpResponse(json, content_type="application/json")
|
||||
|
||||
|
||||
class AssetEmbed(AssetDetail):
|
||||
template_name = 'asset_embed.html'
|
||||
|
||||
|
||||
class AssetOEmbed(OEmbedView):
|
||||
model = models.Asset
|
||||
url_name = 'asset_embed'
|
||||
|
||||
|
||||
@method_decorator(csrf_exempt, name='dispatch')
|
||||
class AssetAuditList(AssetList):
|
||||
template_name = 'asset_audit_list.html'
|
||||
hide_hidden_status = False
|
||||
|
||||
# TODO Refresh this when the modal is submitted
|
||||
def get_queryset(self):
|
||||
self.form = forms.AssetSearchForm(data=self.request.GET)
|
||||
return self.model.objects.filter(Q(last_audited_at__isnull=True)).select_related('category', 'status')
|
||||
self.form = forms.AssetSearchForm(data={})
|
||||
return self.model.objects.filter(Q(last_audited_at__isnull=True))
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(AssetAuditList, self).get_context_data(**kwargs)
|
||||
@@ -288,9 +304,7 @@ class CableTypeList(generic.ListView):
|
||||
model = models.CableType
|
||||
template_name = 'cable_type_list.html'
|
||||
paginate_by = 40
|
||||
|
||||
def get_queryset(self):
|
||||
return self.model.objects.select_related('plug', 'socket')
|
||||
# ordering = ['__str__']
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
@@ -300,7 +314,7 @@ class CableTypeList(generic.ListView):
|
||||
|
||||
class CableTypeDetail(generic.DetailView):
|
||||
model = models.CableType
|
||||
template_name = 'cable_type_detail.html'
|
||||
template_name = 'cable_type_form.html'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(CableTypeDetail, self).get_context_data(**kwargs)
|
||||
|
||||
69
conftest.py
69
conftest.py
@@ -1,78 +1,9 @@
|
||||
from django.conf import settings
|
||||
import django
|
||||
import pytest
|
||||
from django.core.management import call_command
|
||||
from RIGS.models import VatRate, Profile
|
||||
import random
|
||||
from django.db import connection
|
||||
from PyRIGS.tests import pages
|
||||
import os
|
||||
from selenium import webdriver
|
||||
|
||||
|
||||
def pytest_configure():
|
||||
settings.PASSWORD_HASHERS = (
|
||||
'django.contrib.auth.hashers.MD5PasswordHasher',
|
||||
)
|
||||
settings.WHITENOISE_USE_FINDERS = True
|
||||
settings.WHITENOISE_AUTOREFRESH = True
|
||||
# TODO Why do we need this, with the above options enabled?
|
||||
settings.STATICFILES_DIRS += [
|
||||
os.path.join(settings.BASE_DIR, 'static/'),
|
||||
]
|
||||
django.setup()
|
||||
|
||||
|
||||
@pytest.fixture # Overrides the one from pytest-django
|
||||
def admin_user(admin_user):
|
||||
admin_user.username = "EventTest"
|
||||
admin_user.first_name = "Event"
|
||||
admin_user.last_name = "Test"
|
||||
admin_user.initials = "ETU"
|
||||
admin_user.save()
|
||||
return admin_user
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def logged_in_browser(live_server, admin_user, browser, db):
|
||||
login_page = pages.LoginPage(browser.driver, live_server.url).open()
|
||||
login_page.login(admin_user.username, "password")
|
||||
yield browser
|
||||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
def splinter_driver_kwargs():
|
||||
options = webdriver.ChromeOptions()
|
||||
options.add_argument("--window-size=1920,1080")
|
||||
options.add_argument("--headless")
|
||||
if settings.CI:
|
||||
options.add_argument("--no-sandbox")
|
||||
return {"options": options}
|
||||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
def splinter_webdriver():
|
||||
return 'chrome'
|
||||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
def splinter_screenshot_dir():
|
||||
return 'screenshots/'
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True) # Also enables DB access for all tests as a useful side effect
|
||||
def vat_rate(db):
|
||||
vat_rate = VatRate.objects.create(start_at='2014-03-05', rate=0.20, comment='test1')
|
||||
yield vat_rate
|
||||
vat_rate.delete()
|
||||
|
||||
|
||||
def _has_transactional_marker(item):
|
||||
db_marker = item.get_closest_marker("django_db")
|
||||
if db_marker and db_marker.kwargs.get("transaction"):
|
||||
return 1
|
||||
return 0
|
||||
|
||||
|
||||
def pytest_collection_modifyitems(items):
|
||||
items.sort(key=_has_transactional_marker)
|
||||
|
||||
70
gulpfile.js
70
gulpfile.js
@@ -2,52 +2,40 @@
|
||||
|
||||
var gulp = require('gulp');
|
||||
|
||||
const terser = require('gulp-uglify');
|
||||
const sass = require('gulp-sass');
|
||||
const flatten = require('gulp-flatten');
|
||||
const autoprefixer = require('autoprefixer')
|
||||
const postcss = require('gulp-postcss')
|
||||
const sourcemaps = require('gulp-sourcemaps');
|
||||
const browsersync = require('browser-sync').create();
|
||||
const { exec } = require("child_process");
|
||||
const spawn = require('child_process').spawn;
|
||||
const cssnano = require('cssnano');
|
||||
const con = require('gulp-concat');
|
||||
const gulpif = require('gulp-if');
|
||||
var terser = require('gulp-terser');
|
||||
var sass = require('gulp-sass');
|
||||
var flatten = require('gulp-flatten');
|
||||
var autoprefixer = require('autoprefixer')
|
||||
var postcss = require('gulp-postcss')
|
||||
var sourcemaps = require('gulp-sourcemaps');
|
||||
var browsersync = require('browser-sync').create();
|
||||
var { exec } = require("child_process");
|
||||
var spawn = require('child_process').spawn;
|
||||
|
||||
sass.compiler = require('node-sass');
|
||||
|
||||
function fonts(done) {
|
||||
return gulp.src('node_modules/@fortawesome/fontawesome-free/webfonts/fa-solid-900.*')
|
||||
.pipe(gulp.dest('pipeline/built_assets/fonts'))
|
||||
.pipe(browsersync.stream());
|
||||
}
|
||||
|
||||
function styles(done) {
|
||||
const bs_select = ["bootstrap-select.css", "ajax-bootstrap-select.css"]
|
||||
return gulp.src(['pipeline/source_assets/scss/**/*.scss',
|
||||
'node_modules/fullcalendar/main.css',
|
||||
'node_modules/fullcalendar/main.min.css',
|
||||
'node_modules/bootstrap-select/dist/css/bootstrap-select.css',
|
||||
'node_modules/ajax-bootstrap-select/dist/css/ajax-bootstrap-select.css',
|
||||
'node_modules/flatpickr/dist/flatpickr.css',])
|
||||
'node_modules/flatpickr/dist/flatpickr.css'])
|
||||
.pipe(sourcemaps.init())
|
||||
.pipe(sass().on('error', sass.logError))
|
||||
.pipe(gulpif(function(file) { return bs_select.includes(file.relative);}, con('selects.css')))
|
||||
.pipe(postcss([ autoprefixer(), cssnano() ]))
|
||||
.pipe(postcss([ autoprefixer() ]))
|
||||
.pipe(sourcemaps.write())
|
||||
.pipe(gulp.dest('pipeline/built_assets/css'))
|
||||
.pipe(browsersync.stream());
|
||||
}
|
||||
|
||||
function scripts() {
|
||||
const dest = 'pipeline/built_assets/js';
|
||||
const base_scripts = ["src.js", "util.js", "alert.js", "collapse.js", "dropdown.js", "modal.js", "konami.js"];
|
||||
const bs_select = ["bootstrap-select.js", "ajax-bootstrap-select.js"]
|
||||
const interaction = ["html5sortable.min.js", "interaction.js"]
|
||||
const jpop = ["jquery.min.js", "popper.min.js"]
|
||||
return gulp.src(['node_modules/jquery/dist/jquery.min.js',
|
||||
return gulp.src(['pipeline/source_assets/js/**/*.js',
|
||||
'node_modules/jquery/dist/jquery.js',
|
||||
/* JQuery Plugins */
|
||||
'node_modules/popper.js/dist/umd/popper.min.js',
|
||||
'node_modules/jquery-ui-dist/jquery-ui.js',
|
||||
|
||||
'node_modules/popper.js/dist/umd/popper.js',
|
||||
'node_modules/raven-js/dist/raven.js', //TODO Upgrade to Sentry
|
||||
/* Bootstrap Plugins */
|
||||
'node_modules/bootstrap/js/dist/util.js',
|
||||
'node_modules/bootstrap/js/dist/tooltip.js',
|
||||
@@ -57,22 +45,18 @@ function scripts() {
|
||||
'node_modules/bootstrap/js/dist/modal.js',
|
||||
'node_modules/bootstrap/js/dist/alert.js',
|
||||
|
||||
'node_modules/html5sortable/dist/html5sortable.min.js',
|
||||
'node_modules/clipboard/dist/clipboard.min.js',
|
||||
'node_modules/flatpickr/dist/flatpickr.min.js',
|
||||
'node_modules/@fortawesome/fontawesome-free/js/all.js',
|
||||
'node_modules/moment/moment.js',
|
||||
'node_modules/fullcalendar/main.js',
|
||||
'node_modules/fullcalendar/main.min.js',
|
||||
'node_modules/bootstrap-select/dist/js/bootstrap-select.js',
|
||||
'node_modules/ajax-bootstrap-select/dist/js/ajax-bootstrap-select.js',
|
||||
'node_modules/konami/konami.js',
|
||||
'pipeline/source_assets/js/**/*.js',])
|
||||
.pipe(gulpif(function(file) { return base_scripts.includes(file.relative);}, con('base.js')))
|
||||
.pipe(gulpif(function(file) { return bs_select.includes(file.relative);}, con('selects.js')))
|
||||
.pipe(gulpif(function(file) { return interaction.includes(file.relative);}, con('interaction.js')))
|
||||
.pipe(gulpif(function(file) { return jpop.includes(file.relative);}, con('jpop.js')))
|
||||
'node_modules/dark-mode-switch/dark-mode-switch.min.js'])
|
||||
.pipe(flatten())
|
||||
.pipe(terser())
|
||||
.pipe(gulp.dest(dest))
|
||||
.pipe(gulp.dest('pipeline/built_assets/js'))
|
||||
.pipe(browsersync.stream());
|
||||
}
|
||||
|
||||
@@ -80,8 +64,7 @@ function browserSync(done) {
|
||||
spawn('python', ['manage.py', 'runserver'], {stdio: 'inherit'});
|
||||
// TODO Wait for Django server to come up before browsersync, it seems inconsistent
|
||||
browsersync.init({
|
||||
notify: false,
|
||||
open: false,
|
||||
notify: true,
|
||||
port: 8001,
|
||||
proxy: 'localhost:8000'
|
||||
});
|
||||
@@ -94,10 +77,11 @@ function browserSyncReload(done) {
|
||||
}
|
||||
|
||||
function watchFiles() {
|
||||
gulp.watch("pipeline/source_assets/scss/**/*.scss", styles);
|
||||
gulp.watch("pipeline/source_assets/js/**/*.js", scripts);
|
||||
gulp.watch("RIGS/static/scss/**/*.scss", styles);
|
||||
// TODO This prevents reload looping, but means we don't reload if new third party scripts are added
|
||||
gulp.watch("RIGS/static/js/src/**/*.js", scripts);
|
||||
gulp.watch("**/templates/*.html", browserSyncReload);
|
||||
}
|
||||
|
||||
exports.build = gulp.parallel(styles, scripts, fonts);
|
||||
exports.build = gulp.parallel(styles, scripts);
|
||||
exports.watch = gulp.parallel(watchFiles, browserSync);
|
||||
|
||||
2862
package-lock.json
generated
2862
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
15
package.json
15
package.json
@@ -6,38 +6,35 @@
|
||||
"license": "Custom",
|
||||
"dependencies": {
|
||||
"@forevolve/bootstrap-dark": "^1.0.0-alpha.1075",
|
||||
"@fortawesome/fontawesome-free": "^5.15.2",
|
||||
"@fortawesome/fontawesome-free": "^5.13.1",
|
||||
"ajax-bootstrap-select": "^1.4.5",
|
||||
"autocompleter": "^6.0.3",
|
||||
"autoprefixer": "^9.8.0",
|
||||
"bootstrap": "^4.5.2",
|
||||
"bootstrap-select": "^1.13.17",
|
||||
"clipboard": "^2.0.6",
|
||||
"cssnano": "^4.1.10",
|
||||
"dark-mode-switch": "^1.0.0",
|
||||
"flatpickr": "^4.6.6",
|
||||
"fullcalendar": "^5.3.2",
|
||||
"gulp": "^4.0.2",
|
||||
"gulp-concat": "^2.6.1",
|
||||
"gulp-flatten": "^0.4.0",
|
||||
"gulp-if": "^3.0.0",
|
||||
"gulp-postcss": "^8.0.0",
|
||||
"gulp-sass": "^4.1.0",
|
||||
"gulp-sourcemaps": "^2.6.5",
|
||||
"gulp-uglify": "^3.0.2",
|
||||
"html5sortable": "^0.10.0",
|
||||
"gulp-terser": "^1.4.1",
|
||||
"jquery": "^3.5.1",
|
||||
"jquery-ui-dist": "^1.12.1",
|
||||
"konami": "^1.6.2",
|
||||
"moment": "^2.27.0",
|
||||
"node-sass": "^5.0.0",
|
||||
"popper.js": "^1.16.1",
|
||||
"uglify-js": "^3.12.6"
|
||||
"raven-js": "^3.27.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"browser-sync": "^2.26.12"
|
||||
},
|
||||
"scripts": {
|
||||
"gulp": "gulp",
|
||||
"build": "node node_modules/gulp/bin/gulp build",
|
||||
"heroku-cleanup": "rm -rf node_modules/ pipeline/source_assets gulpfile.js"
|
||||
"build": "node node_modules/gulp/bin/gulp build"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,9 +117,23 @@ $('body').on('submit', '.itemised_form', function (e) {
|
||||
$('#id_items_json').val(JSON.stringify(objectitems));
|
||||
});
|
||||
|
||||
sortable("#item-table tbody")[0].addEventListener('sortupdate', function (e) {
|
||||
var items = e.detail.destination.items;
|
||||
for(var i in items) {
|
||||
objectitems[items[i].dataset.pk].fields.order = i;
|
||||
// Return a helper with preserved width of cells
|
||||
var fixHelper = function (e, ui) {
|
||||
ui.children().each(function () {
|
||||
$(this).width($(this).width());
|
||||
});
|
||||
return ui;
|
||||
};
|
||||
|
||||
$("#item-table tbody").sortable({
|
||||
helper: fixHelper,
|
||||
update: function (e, ui) {
|
||||
info = $(this).sortable("toArray");
|
||||
itemorder = new Array();
|
||||
$.each(info, function (key, value) {
|
||||
pk = $('#' + value).data('pk');
|
||||
objectitems[pk].fields.order = key;
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
Date.prototype.getISOString = function () {
|
||||
var yyyy = this.getFullYear().toString();
|
||||
var mm = (this.getMonth() + 1).toString(); // getMonth() is zero-based
|
||||
var dd = this.getDate().toString();
|
||||
return yyyy + '-' + (mm[1] ? mm : "0" + mm[0]) + '-' + (dd[1] ? dd : "0" + dd[0]); // padding
|
||||
};
|
||||
jQuery(document).ready(function () {
|
||||
jQuery(document).on('click', '.modal-href', function (e) {
|
||||
$link = jQuery(this);
|
||||
// Anti modal inception
|
||||
if ($link.parents('#modal').length == 0) {
|
||||
e.preventDefault();
|
||||
modaltarget = $link.data('target');
|
||||
modalobject = "";
|
||||
jQuery('#modal').load($link.attr('href'), function (e) {
|
||||
jQuery('#modal').modal();
|
||||
});
|
||||
}
|
||||
});
|
||||
var easter_egg = new Konami();
|
||||
easter_egg.code = function () {
|
||||
var s = document.createElement('script');
|
||||
s.type = 'text/javascript';
|
||||
document.body.appendChild(s);
|
||||
s.src = '{% static "js/asteroids.min.js"%}';
|
||||
ga('send', 'event', 'easter_egg', 'activated');
|
||||
}
|
||||
easter_egg.load();
|
||||
});
|
||||
//CTRL-Enter form submission
|
||||
document.body.addEventListener('keydown', function(e) {
|
||||
if(e.keyCode == 13 && (e.metaKey || e.ctrlKey)) {
|
||||
var target = e.target;
|
||||
if(target.form) {
|
||||
target.form.submit();
|
||||
}
|
||||
}
|
||||
});
|
||||
$('.navbar-collapse').addClass('collapse');
|
||||
@@ -111,12 +111,4 @@
|
||||
.custom-control-input:focus ~ .custom-control-label::before {
|
||||
box-shadow: 0 0 0 $input-focus-width rgba($primary, 0.7) !important;
|
||||
}
|
||||
.source {
|
||||
color: white !important;
|
||||
}
|
||||
.embed_container {
|
||||
border-color: #3853a4 !important;
|
||||
background: #222;
|
||||
color: $gray-100;
|
||||
}
|
||||
}
|
||||
|
||||
1
pipeline/source_assets/scss/print.scss
Normal file
1
pipeline/source_assets/scss/print.scss
Normal file
@@ -0,0 +1 @@
|
||||
@import "node_modules/bootstrap/scss/bootstrap";
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user