mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-16 21:12:13 +00:00
* Upgrade to heroku-20 stack * Move some gulp deps to dev rather than prod * npm upgrade * Fix audit time check in asset audit test * Attempt at parallelising tests where possible * Add basic calendar button test Mainly to pickup on FullCalendar loading errors * Upgrade python deps * Tends to help if I push valid yaml * You valid now? * Fix whoops in requirements.txt * Change python ver * Define service in coveralls task * Run parallelised RIGS tests as one matrix job * Update python version in tests * Cache python dependencies Should majorly speedup parallelillelelised testing * Purge old vagrant config * No Ruby compass bodge, no need for rubocop! * Purge old .idea config * Switch to gh-a artifact uploading instead of imgur 'hack' For test failure screenshots. Happy now @mattysmith22? ;p * Oops, remove unused import * Exclude tests from the coverage stats Seems to be artifically deflating our stats * Refactor asset audit tests with better selectors Also fixed a silly title error with the modal * Add title checking to the slightly insane assets test * Fix unauth test to not just immediately pass out * Upload failure screenshots as individual artifacts not a zip Turns out I can't unzip things from my phone, which is a pain * Should fix asset test on CI * What about this? * What about this? Swear I spend my life jiggerypokerying the damn test suite... * Does this help the coverage be less weird? * Revert "Does this help the coverage be less weird?" This reverts commit39ab9df836. * Use pytest as our test runner for better parallelism Also rewrote some asset tests to be in the pytest style. May do some more. Some warnings cleaned up in the process. * Bah, codestyle * Oops, remove obsolete if check * Fix screenshot uploading on CI (again) * Try this way of parallel coverage * Add codeclimate maintainability badge * Remove some unused gulp dependencies * Run asset building serverside * Still helps if I commit valid YAML * See below * Different approach to CI dependencies * Exclude node_modules from codestyle * Does this work? * Parallel parallel builds were giving me a headache, try this * Update codeclimate settings, purge some config files * Well the YAML was *syntactically* valid.... * Switch back to old coveralls method * Fix codeclimate config, mark 2 * Attempt to bodge asset test * Oops, again Probably bedtime.. * Might fix heroku building * Attempt #2 at fixing heroku * Belt and braces approach to coverage * Github, you need a Actions YAML validator! * Might fix actions? * Try ignoring some third party deprecation warnings * Another go at making coverage show up * Some template cleanup * Minor python cleanup * Import optimisation * Revert "Minor python cleanup" This reverts commit6a4620a2e5. * Add format arg to coverage command * Ignore test directories from Heroku slug * Maybe this works to purge deps postbuild * Bunch of test refactoring * Restore signals import, screw you import optimisation * Further template refactoring * Add support for running tests with geckodriver, do this on CI * Screw you codestyle * Disable firefox tests for now That was way more errors than I expected * Run cleanup script from the right location * Plausibly fix tests * Helps if I don't delete the pipeline folder prior to collectstatic * Enable whitenoise * Can I delete pipeline here? * Allow seconds difference in assert_times_equal * Disable codeclimate * Remove not working rm command * Maybe this fixes coverage? * Try different coverage reporter * Fix search_help to need login * Made versioning magic a bit less expansive We have more apps than I thought... * Fix IDI0T error in Assets URLS * Refactor 'no access to unauthed' test to cover all of PyRIGS * Add RAs/Checklists to sample data generator * Fix some HTML errors in templates Which apparently only Django's HTML parser cares about, browsers DGAF... * Port title test to project level * Fix more HTML * Fix cable type detail
165 lines
6.1 KiB
Python
165 lines
6.1 KiB
Python
import datetime
|
|
|
|
import pytz
|
|
from django.conf import settings
|
|
from django.db.models import Q
|
|
from django_ical.views import ICalFeed
|
|
|
|
from RIGS import models
|
|
|
|
|
|
class CalendarICS(ICalFeed):
|
|
"""
|
|
A simple event calender
|
|
"""
|
|
# Metadata which is passed on to clients
|
|
product_id = 'RIGS'
|
|
title = 'RIGS Calendar'
|
|
timezone = settings.TIME_ZONE
|
|
file_name = "rigs.ics"
|
|
|
|
# Cancelled = 'cancelled' = False
|
|
# Dry Hire = 'dry-hire' = True
|
|
# Non Rig = 'non-rig' = True
|
|
# Rig = 'rig' = True
|
|
# Provisional = 'provisional' = True
|
|
# Confirmed/Booked = 'confirmed' = True
|
|
|
|
def get_object(self, request, *args, **kwargs):
|
|
params = {}
|
|
|
|
params['dry-hire'] = request.GET.get('dry-hire', 'true') == 'true'
|
|
params['non-rig'] = request.GET.get('non-rig', 'true') == 'true'
|
|
params['rig'] = request.GET.get('rig', 'true') == 'true'
|
|
|
|
params['cancelled'] = request.GET.get('cancelled', 'false') == 'true'
|
|
params['provisional'] = request.GET.get('provisional', 'true') == 'true'
|
|
params['confirmed'] = request.GET.get('confirmed', 'true') == 'true'
|
|
|
|
return params
|
|
|
|
def description(self, params):
|
|
desc = "Calendar generated by RIGS system. This includes event types: " + ('Rig, ' if params['rig'] else '') + (
|
|
'Non-rig, ' if params['non-rig'] else '') + ('Dry Hire ' if params['dry-hire'] else '') + '\n'
|
|
desc = desc + "Includes events with status: " + ('Cancelled, ' if params['cancelled'] else '') + (
|
|
'Provisional, ' if params['provisional'] else '') + ('Confirmed/Booked, ' if params['confirmed'] else '')
|
|
|
|
return desc
|
|
|
|
def items(self, params):
|
|
# include events from up to 1 year ago
|
|
start = datetime.datetime.now() - datetime.timedelta(days=365)
|
|
filter = Q(start_date__gte=start)
|
|
|
|
typeFilters = Q(pk=None) # Need something that is false for every entry
|
|
|
|
if params['dry-hire']:
|
|
typeFilters = typeFilters | Q(dry_hire=True, is_rig=True)
|
|
|
|
if params['non-rig']:
|
|
typeFilters = typeFilters | Q(is_rig=False)
|
|
|
|
if params['rig']:
|
|
typeFilters = typeFilters | Q(is_rig=True, dry_hire=False)
|
|
|
|
statusFilters = Q(pk=None) # Need something that is false for every entry
|
|
|
|
if params['cancelled']:
|
|
statusFilters = statusFilters | Q(status=models.Event.CANCELLED)
|
|
if params['provisional']:
|
|
statusFilters = statusFilters | Q(status=models.Event.PROVISIONAL)
|
|
if params['confirmed']:
|
|
statusFilters = statusFilters | Q(status=models.Event.CONFIRMED) | Q(status=models.Event.BOOKED)
|
|
|
|
filter = filter & typeFilters & statusFilters
|
|
|
|
return models.Event.objects.filter(filter).order_by('-start_date').select_related('person', 'organisation',
|
|
'venue', 'mic')
|
|
|
|
def item_title(self, item):
|
|
title = ''
|
|
|
|
# Prefix title with status (if it's a critical status)
|
|
if item.cancelled:
|
|
title += 'CANCELLED: '
|
|
|
|
if not item.is_rig:
|
|
title += 'NON-RIG: '
|
|
|
|
if item.dry_hire:
|
|
title += 'DRY HIRE: '
|
|
|
|
# Add the rig name
|
|
title += item.name
|
|
|
|
# Add the status
|
|
title += ' (' + str(item.get_status_display()) + ')'
|
|
|
|
return title
|
|
|
|
def item_start_datetime(self, item):
|
|
return item.earliest_time
|
|
|
|
def item_end_datetime(self, item):
|
|
if isinstance(item.latest_time, datetime.date): # Ical end_datetime is non-inclusive, so add a day
|
|
return item.latest_time + datetime.timedelta(days=1)
|
|
|
|
return item.latest_time
|
|
|
|
def item_location(self, item):
|
|
return item.venue
|
|
|
|
def item_description(self, item):
|
|
# Create a nice information-rich description
|
|
# note: only making use of information available to "non-keyholders"
|
|
|
|
tz = pytz.timezone(self.timezone)
|
|
|
|
desc = 'Rig ID = ' + str(item.pk) + '\n'
|
|
desc += 'Event = ' + item.name + '\n'
|
|
desc += 'Venue = ' + (item.venue.name if item.venue else '---') + '\n'
|
|
if item.is_rig and item.person:
|
|
desc += 'Client = ' + item.person.name + (
|
|
(' for ' + item.organisation.name) if item.organisation else '') + '\n'
|
|
desc += 'Status = ' + str(item.get_status_display()) + '\n'
|
|
desc += 'MIC = ' + (item.mic.name if item.mic else '---') + '\n'
|
|
|
|
desc += '\n'
|
|
if item.meet_at:
|
|
desc += 'Crew Meet = ' + (
|
|
item.meet_at.astimezone(tz).strftime('%Y-%m-%d %H:%M') if item.meet_at else '---') + '\n'
|
|
if item.access_at:
|
|
desc += 'Access At = ' + (
|
|
item.access_at.astimezone(tz).strftime('%Y-%m-%d %H:%M') if item.access_at else '---') + '\n'
|
|
if item.start_date:
|
|
desc += 'Event Start = ' + item.start_date.strftime('%Y-%m-%d') + (
|
|
(' ' + item.start_time.strftime('%H:%M')) if item.has_start_time else '') + '\n'
|
|
if item.end_date:
|
|
desc += 'Event End = ' + item.end_date.strftime('%Y-%m-%d') + (
|
|
(' ' + item.end_time.strftime('%H:%M')) if item.has_end_time else '') + '\n'
|
|
|
|
desc += '\n'
|
|
if item.description:
|
|
desc += 'Event Description:\n' + item.description + '\n\n'
|
|
# if item.notes: // Need to add proper keyholder checks before this gets put back
|
|
# desc += 'Notes:\n'+item.notes+'\n\n'
|
|
|
|
base_url = "https://rigs.nottinghamtec.co.uk"
|
|
desc += 'URL = ' + base_url + str(item.get_absolute_url())
|
|
|
|
return desc
|
|
|
|
def item_link(self, item):
|
|
# Make a link to the event in the web interface
|
|
# base_url = "https://pyrigs.nottinghamtec.co.uk"
|
|
return item.get_absolute_url()
|
|
|
|
# def item_created(self, item): #TODO - Implement created date-time (using django-reversion?) - not really necessary though
|
|
# return ''
|
|
|
|
def item_updated(self, item): # some ical clients will display this
|
|
return item.last_edited_at
|
|
|
|
def item_guid(self, item): # use the rig-id as the ical unique event identifier
|
|
return item.pk
|