Skip to content

Commit

Permalink
Fix various minor issues (#545)
Browse files Browse the repository at this point in the history
* Add absolute URL to power tests

* Update to target Python 3.10

* Return user to current page when clicking 'mark reviewed'

* Add units to power test record detail and form

I'm a bad scientist (coz I'm an engineer)

* Allow a higher value in PSSC fields

* Default venue to event venue in EC/PT

* Fix population of initial venue values for EC/PT

* Add link to create power test from EC detail

* Do not set power plan field to required on RA

"This might be a problem if the risk assessment is being done by one person and the power plan by another."

* Default power MIC to MIC

* Implement some suggestions from the Doctor

* Prevent checking in to cancelled events and dry hires

Will close #539

* Exclude dry hires from H&S overview list

* Add "ex VAT" tooltips to asset purchase price and replacement cost

* Automagically clear and focus ID field when audit modal closes

Closes #533

* Delete unused things

* Allow two decimal places in cable length, show training item IDs in selectpicker

Will close #540

* Fix #524 500 Error when viewing qualification list for items nobody is qualified in

* Update README.md

* Add a guard against nulls in recent changes

Maybe fixes #537 I'm unable to replicate locally

* Turn down verbosity of CI tests, fix tests, potential speedup

* Squash migration

* Add encoding to open

* Update to v3 upload-artifact

Resolves a deprecation warning
  • Loading branch information
FreneticScribbler authored May 29, 2023
1 parent 26942b8 commit 54b4440
Show file tree
Hide file tree
Showing 41 changed files with 294 additions and 129 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PYTHONDONTWRITEBYTECODE: 1
steps:
- uses: actions/checkout@v3
- name: Set up Python
Expand Down Expand Up @@ -41,8 +42,8 @@ jobs:
pipenv run python3 manage.py makemigrations --check --dry-run
pipenv run python3 manage.py collectstatic --noinput
- name: Run Tests
run: pipenv run pytest -n auto -vv --cov
- uses: actions/upload-artifact@v2
run: pipenv run pytest -n auto --cov
- uses: actions/upload-artifact@v3
if: failure()
with:
name: failure-screenshots ${{ matrix.test-group }}
Expand Down
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pytest = "*"
pytest-reverse = "*"

[requires]
python_version = "3.9"
python_version = "3.10"

[dev-packages.pytest-xdist]
extras = [ "psutil",]
Expand Down
104 changes: 83 additions & 21 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions PyRIGS/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,6 @@

FORMAT_MODULE_PATH = 'PyRIGS.formats'

USE_I18N = True

USE_L10N = True

USE_TZ = True
Expand Down Expand Up @@ -264,3 +262,10 @@
AUTHORISATION_NOTIFICATION_ADDRESS = '[email protected]'

DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'

SECURE_HSTS_SECONDS = 3600
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
SECURE_CONTENT_TYPE_NOSNIFF = True
SESSION_COOKIE_SECURE = env('SESSION_COOKIE_SECURE_ENABLED', True)
CSRF_COOKIE_SECURE = env('CSRF_COOKIE_SECURE_ENABLED', True)
SECURE_HSTS_PRELOAD = True
2 changes: 1 addition & 1 deletion PyRIGS/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def wrapper_func(self, *args, **kwargs):
if not pathlib.Path("screenshots").is_dir():
os.mkdir("screenshots")
self.driver.save_screenshot(screenshot_file)
print("Error in test {} is at path {}".format(screenshot_name, screenshot_file), file=sys.stderr)
print(f"Error in test {screenshot_name} is at path {screenshot_file}", file=sys.stderr)
raise e

return wrapper_func
Expand Down
8 changes: 4 additions & 4 deletions PyRIGS/tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def test_sample_data(self):
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
assert not Asset.objects.all().exists()
assert not Event.objects.all().exists()


@override_settings(DEBUG=True)
Expand All @@ -76,9 +76,9 @@ def test_unauthenticated(client): # Nothing should be available to the unauthen
assertTemplateUsed(response, 'login_redirect.html')
else:
if "embed" in str(url):
expected_url = "{0}?next={1}".format(reverse('login_embed'), request_url)
expected_url = f"{reverse('login_embed')}?next={request_url}"
else:
expected_url = "{0}?next={1}".format(reverse('login'), request_url)
expected_url = f"{reverse('login')}?next={request_url}"
assertRedirects(response, expected_url)
call_command('deleteSampleData')

Expand Down
7 changes: 4 additions & 3 deletions PyRIGS/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Index(generic.TemplateView): # Displays the current rig count along with
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['rig_count'] = models.Event.objects.rig_count()
context['now'] = models.Event.objects.events_in_bounds(timezone.now(), timezone.now())
context['now'] = models.Event.objects.events_in_bounds(timezone.now(), timezone.now()).exclude(dry_hire=True).exclude(status=models.Event.CANCELLED)
return context


Expand Down Expand Up @@ -135,10 +135,11 @@ def get(self, request, model, pk=None, param=None):
query = reduce(operator.and_, queries)
objects = self.models[model].objects.filter(query)
for o in objects:
name = o.display_name if hasattr(o, 'display_name') else o.name
data = {
'pk': o.pk,
'value': o.pk,
'text': o.name,
'text': name,
}
try: # See if there is a valid update URL
data['update'] = reverse(f"{model}_update", kwargs={'pk': o.pk})
Expand Down Expand Up @@ -183,7 +184,7 @@ def get_close_url(self, update, detail):
url = reverse_lazy('closemodal')
update_url = str(reverse_lazy(update, kwargs={'pk': self.object.pk}))
messages.info(self.request, "modalobject=" + serializers.serialize("json", [self.object]))
messages.info(self.request, "modalobject[0]['update_url']='" + update_url + "'")
messages.info(self.request, f"modalobject[0]['update_url']='{update_url}'")
else:
url = reverse_lazy(detail, kwargs={
'pk': self.object.pk,
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ For setup information and other such helpful stuff check the [Wiki](https://gith
- PyRIGS: Base app, stores 'global' information
- RIGS: Rigboard stuff - event calendar etc
- assets: Database of our kit, testing data etc
- training: Logs in-house training within various "departments" (sound, lighting etc).
- versioning: Our custom logic built on top of django-reversion. Semi-modular.
- users: Our custom logic for registration and profiles. Semi-modular.
- training: SoonTM


[![forthebadge](https://forthebadge.com/images/badges/built-with-resentment.svg)](https://forthebadge.com) [![forthebadge](https://forthebadge.com/images/badges/contains-technical-debt.svg)](https://forthebadge.com)
11 changes: 7 additions & 4 deletions RIGS/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class BaseClientEventAuthorisationForm(forms.ModelForm):
def clean(self):
if self.cleaned_data.get('amount') != self.instance.event.total:
self.add_error('amount', 'The amount authorised must equal the total for the event (inc VAT).')
return super(BaseClientEventAuthorisationForm, self).clean()
return super().clean()

class Meta:
abstract = True
Expand Down Expand Up @@ -179,7 +179,7 @@ def clean(self):
unexpected_values.append(f"<li>{self._meta.model._meta.get_field(field).help_text}</li>")
if len(unexpected_values) > 0 and not self.cleaned_data.get('supervisor_consulted'):
raise forms.ValidationError(f"Your answers to these questions: <ul>{''.join([str(elem) for elem in unexpected_values])}</ul> require consulting with a supervisor.", code='unusual_answers')
return super(EventRiskAssessmentForm, self).clean()
return super().clean()

class Meta:
model = models.RiskAssessment
Expand All @@ -195,8 +195,6 @@ def __init__(self, *args, **kwargs):
if field.__class__ == forms.NullBooleanField:
# Only display yes/no to user, the 'none' is only ever set in the background
field.widget = forms.CheckboxInput()
# Parsed from incoming form data by clean, then saved into models when the form is saved
items = {}

related_models = {
'venue': models.Venue,
Expand All @@ -216,6 +214,11 @@ def __init__(self, *args, **kwargs):
# Only display yes/no to user, the 'none' is only ever set in the background
field.widget = forms.CheckboxInput()

related_models = {
'venue': models.Venue,
'power_mic': models.Profile,
}

class Meta:
model = models.PowerTestRecord
fields = '__all__'
Expand Down
Loading

0 comments on commit 54b4440

Please sign in to comment.