mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-24 17:02:18 +00:00
Added options to ical interface - issue #80
This commit is contained in:
53
RIGS/ical.py
53
RIGS/ical.py
@@ -17,15 +17,58 @@ class CalendarICS(ICalFeed):
|
|||||||
timezone = settings.TIME_ZONE
|
timezone = settings.TIME_ZONE
|
||||||
file_name = "rigs.ics"
|
file_name = "rigs.ics"
|
||||||
|
|
||||||
def get(self, *args, **kwargs):
|
# Cancelled = 'cancelled' = False
|
||||||
timezone.activate(timezone.UTC)
|
# Dry Hire = 'dry-hire' = True
|
||||||
return super(CalendarICS, self).get(*args, **kwargs)
|
# Non Rig = 'non-rig' = True
|
||||||
|
# Rig = 'rig' = True
|
||||||
|
# Provisional = 'provisional' = True
|
||||||
|
# Confirmed/Booked = 'confirmed' = True
|
||||||
|
|
||||||
|
def get_object(self, request, *args, **kwargs):
|
||||||
|
params = {}
|
||||||
|
|
||||||
def items(self):
|
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
|
#include events from up to 1 year ago
|
||||||
start = datetime.datetime.now() - datetime.timedelta(days=365)
|
start = datetime.datetime.now() - datetime.timedelta(days=365)
|
||||||
filter = Q(start_date__gte=start) & ~Q(status=models.Event.CANCELLED)
|
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')
|
return models.Event.objects.filter(filter).order_by('-start_date').select_related('person', 'organisation', 'venue', 'mic')
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,29 @@
|
|||||||
|
|
||||||
{% block title %}RIGS Profile {{object.pk}}{% endblock %}
|
{% block title %}RIGS Profile {{object.pk}}{% endblock %}
|
||||||
|
|
||||||
|
{% block js %}
|
||||||
|
<script>
|
||||||
|
$(document).ready(function() {
|
||||||
|
$('#urlParamForm').change(function(){
|
||||||
|
url = "?";
|
||||||
|
$('#urlParamForm *').filter(':input').each(function(index, value){
|
||||||
|
param = $(value).val();
|
||||||
|
val = $(value).prop('checked');
|
||||||
|
url = url+param+"="+val+"&";
|
||||||
|
});
|
||||||
|
ics_url = $('#cal-url').data('url') + url.substring(0, url.length - 1);
|
||||||
|
$('#cal-url').text(ics_url);
|
||||||
|
|
||||||
|
gcal_url = $('#gcal-link').data('url') + encodeURIComponent(url.substring(0, url.length - 1));
|
||||||
|
$('#gcal-link').attr('href',gcal_url);
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#urlParamForm').change(); //Do the initial setting
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-10 col-md-offset-1">
|
<div class="col-md-10 col-md-offset-1">
|
||||||
@@ -68,16 +91,42 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</dd>
|
</dd>
|
||||||
|
|
||||||
|
<dt>Calendar Options</dt>
|
||||||
|
<dd>
|
||||||
|
<div class="well well-sm text-center">
|
||||||
|
<form class="form-inline" id="urlParamForm">
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="checkbox-inline">
|
||||||
|
<input type="checkbox" value="rig" checked> Rigs
|
||||||
|
</label>
|
||||||
|
<label class="checkbox-inline">
|
||||||
|
<input type="checkbox" value="non-rig" checked> Non-Rigs
|
||||||
|
</label>
|
||||||
|
<label class="checkbox-inline">
|
||||||
|
<input type="checkbox" value="dry-hire" checked> Dry-Hires
|
||||||
|
</label>
|
||||||
|
<label class="checkbox-inline">
|
||||||
|
<input type="checkbox" value="cancelled"> Cancelled
|
||||||
|
</label>
|
||||||
|
<label class="checkbox-inline">
|
||||||
|
<input type="checkbox" value="provisional" checked> Provisional
|
||||||
|
</label>
|
||||||
|
<label class="checkbox-inline">
|
||||||
|
<input type="checkbox" value="confirmed" checked> Confirmed/Booked
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</dd>
|
||||||
<dt>Calendar URL</dt>
|
<dt>Calendar URL</dt>
|
||||||
<dd>
|
<dd>
|
||||||
{% if user.api_key %}
|
{% if user.api_key %}
|
||||||
<pre>http{{ request.is_secure|yesno:"s,"}}://{{ request.get_host }}{% url 'ics_calendar' api_pk=user.pk api_key=user.api_key %}</pre>
|
<pre id="cal-url" data-url="http{{ request.is_secure|yesno:"s,"}}://{{ request.get_host }}{% url 'ics_calendar' api_pk=user.pk api_key=user.api_key %}"></pre>
|
||||||
<small><a href="http://www.google.com/calendar/render?cid=http{{ request.is_secure|yesno:"s,"}}://{{ request.get_host }}{% url 'ics_calendar' api_pk=user.pk api_key=user.api_key %}">Click here</a> to add to google calendar.<br/>
|
<small><a id="gcal-link" data-url="http://www.google.com/calendar/render?cid=http{{ request.is_secure|yesno:"s,"}}://{{ request.get_host }}{% url 'ics_calendar' api_pk=user.pk api_key=user.api_key %}" href="">Click here</a> to add to google calendar.<br/>
|
||||||
To sync from google calendar to mobile device, visit <a href="https://www.google.com/calendar/syncselect" target="_blank">this page</a> on your device and tick "RIGS Calendar".</small>
|
To sync from google calendar to mobile device, visit <a href="https://www.google.com/calendar/syncselect" target="_blank">this page</a> on your device and tick "RIGS Calendar".</small>
|
||||||
{% else %}
|
{% else %}
|
||||||
<pre>No API Key Generated</pre>
|
<pre>No API Key Generated</pre>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
</dd>
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
Reference in New Issue
Block a user