Skip to content

Commit

Permalink
Merge branch 'master' into auth_fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
FreneticScribbler committed Dec 31, 2019
2 parents 8e27dae + 01a87e0 commit 081a9ea
Show file tree
Hide file tree
Showing 102 changed files with 2,883 additions and 354 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ htmlcov/
.tox/
.coverage
.cache
.pytest_cache
nosetests.xml
coverage.xml

Expand Down Expand Up @@ -107,3 +108,4 @@ atlassian-ide-plugin.xml
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
.vscode/
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
release: python manage.py migrate
web: gunicorn PyRIGS.wsgi --log-file -
1 change: 1 addition & 0 deletions PyRIGS/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
'django.contrib.messages',
'django.contrib.staticfiles',
'RIGS',
'assets',

'debug_toolbar',
'registration',
Expand Down
1 change: 1 addition & 0 deletions PyRIGS/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# url(r'^blog/', include('blog.urls')),

url(r'^', include('RIGS.urls')),
url('^assets/', include('assets.urls')),
url('^user/register/$', RegistrationView.as_view(form_class=RIGS.forms.ProfileRegistrationFormUniqueEmail),
name="registration_register"),
url('^user/', include('django.contrib.auth.urls')),
Expand Down
247 changes: 3 additions & 244 deletions RIGS/management/commands/generateSampleData.py

Large diffs are not rendered by default.

260 changes: 260 additions & 0 deletions RIGS/management/commands/generateSampleRIGSData.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion RIGS/templates/RIGS/activity_feed_data.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends request.is_ajax|yesno:"base_ajax_nomodal.html,base.html" %}
{% extends request.is_ajax|yesno:"base_ajax_nomodal.html,base_rigs.html" %}

{% load static %}
{% load paginator from filters %}
Expand Down
2 changes: 1 addition & 1 deletion RIGS/templates/RIGS/activity_table.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends request.is_ajax|yesno:"base_ajax.html,base.html" %}
{% extends request.is_ajax|yesno:"base_ajax.html,base_rigs.html" %}
{% load static %}
{% load paginator from filters %}
{% load to_class_name from filters %}
Expand Down
2 changes: 1 addition & 1 deletion RIGS/templates/RIGS/calendar.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends 'base.html' %}
{% extends 'base_rigs.html' %}
{% load static %}


Expand Down
2 changes: 1 addition & 1 deletion RIGS/templates/RIGS/event_archive.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends 'base.html' %}
{% extends 'base_rigs.html' %}
{% load paginator from filters %}

{% block title %}Event Archive{% endblock %}
Expand Down
4 changes: 2 additions & 2 deletions RIGS/templates/RIGS/event_detail.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends request.is_ajax|yesno:"base_ajax.html,base.html" %}
{% extends request.is_ajax|yesno:"base_ajax.html,base_rigs.html" %}
{% block title %}{% if object.is_rig %}N{{ object.pk|stringformat:"05d" }}{% else %}{{ object.pk }}{% endif %} | {{object.name}}{% endblock %}

{% block content %}
Expand Down Expand Up @@ -245,7 +245,7 @@ <h4>Notes</h4>
<div class="row">
<div class="col-sm-10 align-left">
<a href="{% url 'event_history' object.pk %}" title="View Revision History">
Last edited at {{ object.last_edited_at }} by {{ object.last_edited_by.name }}
Last edited at {{ object.last_edited_at|default:'never' }} by {{ object.last_edited_by.name|default:'nobody' }}
</a>
</div>
<div class="col-sm-2">
Expand Down
2 changes: 1 addition & 1 deletion RIGS/templates/RIGS/event_form.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends 'base.html' %}
{% extends 'base_rigs.html' %}
{% load widget_tweaks %}
{% load static %}
{% load multiply from filters %}
Expand Down
2 changes: 1 addition & 1 deletion RIGS/templates/RIGS/event_invoice.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends 'base.html' %}
{% extends 'base_rigs.html' %}
{% load paginator from filters %}
{% load static %}

Expand Down
2 changes: 1 addition & 1 deletion RIGS/templates/RIGS/eventauthorisation_request.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends request.is_ajax|yesno:'base_ajax.html,base.html' %}
{% extends request.is_ajax|yesno:'base_ajax.html,base_rigs.html' %}
{% load widget_tweaks %}

{% block title %}Request Authorisation{% endblock %}
Expand Down
2 changes: 1 addition & 1 deletion RIGS/templates/RIGS/eventauthorisation_request_error.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends request.is_ajax|yesno:'base_ajax.html,base.html' %}
{% extends request.is_ajax|yesno:'base_ajax.html,base_rigs.html' %}
{% load widget_tweaks %}

{% block title %}NottinghamTEC Email Address Required{% endblock %}
Expand Down
6 changes: 3 additions & 3 deletions RIGS/templates/RIGS/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends 'base.html' %}
{% extends 'base_rigs.html' %}
{% block title %}RIGS{% endblock %}

{% block content %}
Expand All @@ -20,6 +20,7 @@ <h4 class="list-group-item-heading">Quick Links</h4>
<a class="list-group-item" href="{% url 'rigboard' %}"><span class="glyphicon glyphicon-list"></span> Rigboard</a>
<a class="list-group-item" href="{% url 'web_calendar' %}"><span class="glyphicon glyphicon-calendar"></span> Calendar</a>
{% if perms.RIGS.add_event %}<a class="list-group-item" href="{% url 'event_create' %}"><span class="glyphicon glyphicon-plus"></span> New Event</a>{% endif %}
<a class="list-group-item" href="{% url 'asset_index' %}"><span class="glyphicon glyphicon-tag"></span> Asset Database </a>

<div class="list-group-item default"></div>

Expand Down Expand Up @@ -71,9 +72,8 @@ <h4 class="panel-title">Search Rigboard</h4>
</div>
</div>
{% if perms.RIGS.view_event %}
<div class="col-sm-6" >
<div class="col-sm-6">
{% include 'RIGS/activity_feed.html' %}

</div>
{% endif %}
</div>
Expand Down
2 changes: 1 addition & 1 deletion RIGS/templates/RIGS/invoice_confirm_delete.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends 'base.html' %}
{% extends 'base_rigs.html' %}

{% block title %}Delete payment on invoice {{ object.invoice.pk }}{% endblock %}

Expand Down
2 changes: 1 addition & 1 deletion RIGS/templates/RIGS/invoice_detail.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends 'base.html' %}
{% extends 'base_rigs.html' %}

{% block title %}Invoice {{ object.pk }}{% endblock %}

Expand Down
2 changes: 1 addition & 1 deletion RIGS/templates/RIGS/invoice_list.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends 'base.html' %}
{% extends 'base_rigs.html' %}
{% load paginator from filters %}

{% block title %}Invoices{% endblock %}
Expand Down
2 changes: 1 addition & 1 deletion RIGS/templates/RIGS/organisation_detail.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends request.is_ajax|yesno:"base_ajax.html,base.html" %}
{% extends request.is_ajax|yesno:"base_ajax.html,base_rigs.html" %}
{% load widget_tweaks %}

{% block title %}Organisation | {{ object.name }}{% endblock %}
Expand Down
2 changes: 1 addition & 1 deletion RIGS/templates/RIGS/organisation_form.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends request.is_ajax|yesno:'base_ajax.html,base.html' %}
{% extends request.is_ajax|yesno:'base_ajax.html,base_rigs.html' %}
{% load widget_tweaks %}

{% block title %}{% if object.pk %}Edit {{ object.name }}{% else %}Add Organisation{% endif %}{% endblock %}
Expand Down
2 changes: 1 addition & 1 deletion RIGS/templates/RIGS/organisation_list.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends request.is_ajax|yesno:"base_ajax.html,base.html" %}
{% extends request.is_ajax|yesno:"base_ajax.html,base_rigs.html" %}
{% load widget_tweaks %}
{% load paginator from filters %}
{% load url_replace from filters %}
Expand Down
2 changes: 1 addition & 1 deletion RIGS/templates/RIGS/payment_confirm_delete.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends 'base.html' %}
{% extends 'base_rigs.html' %}

{% block title %}Delete payment on invoice {{ object.invoice.pk }}{% endblock %}

Expand Down
2 changes: 1 addition & 1 deletion RIGS/templates/RIGS/person_detail.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends request.is_ajax|yesno:"base_ajax.html,base.html" %}
{% extends request.is_ajax|yesno:"base_ajax.html,base_rigs.html" %}
{% load widget_tweaks %}

{% block title %}Person | {{ object.name }}{% endblock %}
Expand Down
2 changes: 1 addition & 1 deletion RIGS/templates/RIGS/person_form.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends request.is_ajax|yesno:'base_ajax.html,base.html' %}
{% extends request.is_ajax|yesno:'base_ajax.html,base_rigs.html' %}
{% load widget_tweaks %}

{% block title %}{% if object.pk %}Edit {{ object.name }}{% else %}Add Person{% endif %}{% endblock %}
Expand Down
2 changes: 1 addition & 1 deletion RIGS/templates/RIGS/person_list.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends request.is_ajax|yesno:"base_ajax.html,base.html" %}
{% extends request.is_ajax|yesno:"base_ajax.html,base_rigs.html" %}
{% load widget_tweaks %}
{% load paginator from filters %}
{% load url_replace from filters %}
Expand Down
2 changes: 1 addition & 1 deletion RIGS/templates/RIGS/profile_detail.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends request.is_ajax|yesno:"base_ajax.html,base.html" %}
{% extends request.is_ajax|yesno:"base_ajax.html,base_rigs.html" %}

{% block title %}RIGS Profile {{object.pk}}{% endblock %}

Expand Down
2 changes: 1 addition & 1 deletion RIGS/templates/RIGS/profile_form.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends 'base.html' %}
{% extends 'base_rigs.html' %}
{% load widget_tweaks %}

{% block title %}Update Profile {{object.name}}{% endblock %}
Expand Down
2 changes: 1 addition & 1 deletion RIGS/templates/RIGS/rigboard.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends 'base.html' %}
{% extends 'base_rigs.html' %}

{% block title %}Rigboard{% endblock %}

Expand Down
2 changes: 1 addition & 1 deletion RIGS/templates/RIGS/venue_detail.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends request.is_ajax|yesno:"base_ajax.html,base.html" %}
{% extends request.is_ajax|yesno:"base_ajax.html,base_rigs.html" %}
{% load widget_tweaks %}

{% block title %}Venue | {{ object.name }}{% endblock %}
Expand Down
2 changes: 1 addition & 1 deletion RIGS/templates/RIGS/venue_form.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends request.is_ajax|yesno:'base_ajax.html,base.html' %}
{% extends request.is_ajax|yesno:'base_ajax.html,base_rigs.html' %}
{% load widget_tweaks %}

{% block title %}{{ object.pk|yesno:"Edit,Add" }} Venue{% endblock %}
Expand Down
2 changes: 1 addition & 1 deletion RIGS/templates/RIGS/venue_list.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends request.is_ajax|yesno:"base_ajax.html,base.html" %}
{% extends request.is_ajax|yesno:"base_ajax.html,base_rigs.html" %}
{% load widget_tweaks %}
{% load paginator from filters %}
{% load url_replace from filters %}
Expand Down
2 changes: 1 addition & 1 deletion RIGS/templates/RIGS/version_history.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends request.is_ajax|yesno:"base_ajax.html,base.html" %}
{% extends request.is_ajax|yesno:"base_ajax.html,base_rigs.html" %}
{% load to_class_name from filters %}
{% load paginator from filters %}
{% load static %}
Expand Down
7 changes: 4 additions & 3 deletions RIGS/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_registration(self):
initials.send_keys('JS')
phone.send_keys('0123456789')
self.browser.execute_script(
"return jQuery('#g-recaptcha-response').val('PASSED')")
"return function() {jQuery('#g-recaptcha-response').val('PASSED'); return 0}()")

# Submit incorrect form
submit = self.browser.find_element_by_xpath("//input[@type='submit']")
Expand All @@ -110,8 +110,9 @@ def test_registration(self):
# Correct error
password1.send_keys('correcthorsebatterystaple')
password2.send_keys('correcthorsebatterystaple')
self.browser.execute_script("console.log('Hello, world!')")
self.browser.execute_script(
"return jQuery('#g-recaptcha-response').val('PASSED')")
"return function() {jQuery('#g-recaptcha-response').val('PASSED'); return 0}()")

# Submit again
password2.send_keys(Keys.ENTER)
Expand Down Expand Up @@ -150,7 +151,7 @@ def test_registration(self):
username.send_keys('TestUsername')
password.send_keys('correcthorsebatterystaple')
self.browser.execute_script(
"return jQuery('#g-recaptcha-response').val('PASSED')")
"return function() {jQuery('#g-recaptcha-response').val('PASSED'); return 0}()")
password.send_keys(Keys.ENTER)

# Check we are logged in
Expand Down
4 changes: 2 additions & 2 deletions RIGS/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,12 @@ 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('generateSampleData')
call_command('generateSampleRIGSData')

# Check there are lots of events
self.assertTrue(models.Event.objects.all().count() > 100)

def test_production_exception(self):
from django.core.management.base import CommandError

self.assertRaisesRegex(CommandError, ".*production", call_command, 'generateSampleData')
self.assertRaisesRegex(CommandError, ".*production", call_command, 'generateSampleRIGSData')
11 changes: 4 additions & 7 deletions RIGS/versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,14 @@ class VersionHistory(generic.ListView):
paginate_by = 25

def get_queryset(self, **kwargs):
thisModel = self.kwargs['model']
return RIGSVersion.objects.get_for_object(self.get_object()).select_related("revision", "revision__user").all()

versions = RIGSVersion.objects.get_for_object_reference(thisModel, self.kwargs['pk']).select_related("revision", "revision__user").all()

return versions
def get_object(self, **kwargs):
return get_object_or_404(self.kwargs['model'], pk=self.kwargs['pk'])

def get_context_data(self, **kwargs):
thisModel = self.kwargs['model']
context = super(VersionHistory, self).get_context_data(**kwargs)
thisObject = get_object_or_404(thisModel, pk=self.kwargs['pk'])
context['object'] = thisObject
context['object'] = self.get_object()

return context

Expand Down
Empty file added assets/__init__.py
Empty file.
32 changes: 32 additions & 0 deletions assets/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from django.contrib import admin
from assets import models as assets


@admin.register(assets.AssetCategory)
class AssetCategoryAdmin(admin.ModelAdmin):
list_display = ['id', 'name']
ordering = ['id']


@admin.register(assets.AssetStatus)
class AssetStatusAdmin(admin.ModelAdmin):
list_display = ['id', 'name']
ordering = ['id']


@admin.register(assets.Supplier)
class SupplierAdmin(admin.ModelAdmin):
list_display = ['id', 'name']
ordering = ['id']


@admin.register(assets.Asset)
class AssetAdmin(admin.ModelAdmin):
list_display = ['id', 'asset_id', 'description', 'category', 'status']
list_filter = ['is_cable', 'category']
search_fields = ['id', 'asset_id', 'description']


@admin.register(assets.Connector)
class ConnectorAdmin(admin.ModelAdmin):
list_display = ['id', '__str__', 'current_rating', 'voltage_rating', 'num_pins']
5 changes: 5 additions & 0 deletions assets/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class AssetsConfig(AppConfig):
name = 'assets'
9 changes: 9 additions & 0 deletions assets/filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import django_filters

from assets import models


class AssetFilter(django_filters.FilterSet):
class Meta:
model = models.Asset
fields = ['asset_id', 'description', 'category', 'status']
31 changes: 31 additions & 0 deletions assets/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from django import forms

from assets import models


class AssetForm(forms.ModelForm):
class Meta:
model = models.Asset
fields = '__all__'
exclude = ['asset_id_prefix', 'asset_id_number']

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['date_sold'].widget.format = '%Y-%m-%d'
self.fields['date_acquired'].widget.format = '%Y-%m-%d'


class AssetSearchForm(forms.Form):
query = forms.CharField(required=False)
category = forms.ModelMultipleChoiceField(models.AssetCategory.objects.all(), required=False)
status = forms.ModelMultipleChoiceField(models.AssetStatus.objects.all(), required=False)


class SupplierForm(forms.ModelForm):
class Meta:
model = models.Supplier
fields = '__all__'


class SupplierSearchForm(forms.Form):
query = forms.CharField(required=False)
Empty file added assets/management/__init__.py
Empty file.
Empty file.
23 changes: 23 additions & 0 deletions assets/management/commands/deleteSampleData.py
Original file line number Diff line number Diff line change
@@ -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()
Loading

0 comments on commit 081a9ea

Please sign in to comment.