mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-17 13:32:15 +00:00
Streamlined web-calendar logic, also fixed issue #94
This commit is contained in:
@@ -383,6 +383,25 @@ class Event(models.Model, RevisionMixin):
|
||||
|
||||
return earliest
|
||||
|
||||
@property
|
||||
def latest_time(self):
|
||||
"""Returns the end of the event - this function could return either a tzaware datetime, or a naiive date object"""
|
||||
|
||||
endDate = self.end_date
|
||||
if endDate is None:
|
||||
endDate = self.start_date
|
||||
|
||||
if self.has_end_time:
|
||||
endDateTime = datetime.datetime.combine(endDate,self.end_time)
|
||||
tz = pytz.timezone(settings.TIME_ZONE)
|
||||
endDateTime = tz.localize(endDateTime)
|
||||
|
||||
return endDateTime
|
||||
|
||||
else:
|
||||
return endDate
|
||||
|
||||
|
||||
objects = EventManager()
|
||||
|
||||
def get_absolute_url(self):
|
||||
|
||||
@@ -45,44 +45,33 @@
|
||||
url: '/api/event',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
start: moment(start_moment).format("YYYY-MM-DD[T]HH:mm:ss[Z]"),
|
||||
end: moment(end_moment).format("YYYY-MM-DD[T]HH:mm:ss[Z]")
|
||||
start: moment(start_moment).format("YYYY-MM-DD[T]HH:mm:ss"),
|
||||
end: moment(end_moment).format("YYYY-MM-DD[T]HH:mm:ss")
|
||||
},
|
||||
success: function(doc) {
|
||||
var events = [];
|
||||
var colours =
|
||||
colours = {'Provisional': '#f0ad4e',
|
||||
'Confirmed': '#5cb85c' ,
|
||||
'Booked': '#5cb85c' ,
|
||||
'Cancelled': 'grey' ,
|
||||
'non-rig': '#5bc0de'
|
||||
};
|
||||
$(doc).each(function() {
|
||||
thisEvent = [];
|
||||
colours = {'Provisional': '#f0ad4e',
|
||||
'Confirmed': '#5cb85c' ,
|
||||
'Booked': '#5cb85c' ,
|
||||
'Cancelled': 'grey' ,
|
||||
'non-rig': '#5bc0de'
|
||||
};
|
||||
|
||||
thisEvent['start'] = $(this).attr('start_date');
|
||||
if ($(this).attr('start_time')) {
|
||||
thisEvent['start'] += 'T' + $(this).attr('start_time');
|
||||
|
||||
}
|
||||
|
||||
if ($(this).attr('end_date')) {
|
||||
thisEvent['end'] = $(this).attr('end_date');
|
||||
if ($(this).attr('end_time')) {
|
||||
thisEvent['end'] += 'T' + $(this).attr('end_time');
|
||||
}
|
||||
}
|
||||
thisEvent['className'] = 'modal-href';
|
||||
|
||||
thisEvent['title'] = $(this).attr('title');
|
||||
|
||||
|
||||
thisEvent = {
|
||||
'start': $(this).attr('earliest'),
|
||||
'end': $(this).attr('latest'),
|
||||
'className': 'modal-href',
|
||||
'title': $(this).attr('title'),
|
||||
'url': $(this).attr('url')
|
||||
}
|
||||
|
||||
if($(this).attr('is_rig')==true || $(this).attr('status') == "Cancelled"){
|
||||
thisEvent['color'] = colours[$(this).attr('status')];
|
||||
}else{
|
||||
thisEvent['color'] = colours['non-rig'];
|
||||
}
|
||||
|
||||
thisEvent['url'] = $(this).attr('url');
|
||||
|
||||
events.push(thisEvent);
|
||||
});
|
||||
|
||||
@@ -6,9 +6,10 @@ from django.views import generic
|
||||
from django.db.models import Q
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.core import serializers
|
||||
from django.conf import settings
|
||||
import simplejson
|
||||
from django.contrib import messages
|
||||
import datetime
|
||||
import datetime, pytz
|
||||
import operator
|
||||
from registration.views import RegistrationView
|
||||
|
||||
@@ -298,39 +299,25 @@ class SecureAPIRequest(generic.View):
|
||||
|
||||
if model == "event" and start and end:
|
||||
# Probably a calendar request
|
||||
start_datetime = datetime.datetime.strptime( start, "%Y-%m-%dT%H:%M:%SZ" )
|
||||
end_datetime = datetime.datetime.strptime( end, "%Y-%m-%dT%H:%M:%SZ" )
|
||||
start_datetime = datetime.datetime.strptime( start, "%Y-%m-%dT%H:%M:%S" )
|
||||
end_datetime = datetime.datetime.strptime( end, "%Y-%m-%dT%H:%M:%S" )
|
||||
|
||||
tz = pytz.timezone(settings.TIME_ZONE)
|
||||
start_datetime = tz.localize(start_datetime)
|
||||
|
||||
objects = self.models[model].objects.events_in_bounds(start_datetime,end_datetime)
|
||||
|
||||
results = []
|
||||
for item in objects:
|
||||
data = {
|
||||
'pk': item.pk,
|
||||
'title': item.name
|
||||
'title': item.name,
|
||||
'is_rig': item.is_rig,
|
||||
'status': str(item.get_status_display()),
|
||||
'earliest': item.earliest_time.isoformat(),
|
||||
'latest': item.latest_time.isoformat(),
|
||||
'url': str(item.get_absolute_url())
|
||||
}
|
||||
|
||||
data['is_rig'] = item.is_rig
|
||||
data['status'] = str(item.get_status_display())
|
||||
|
||||
if item.start_date:
|
||||
data['start_date'] = item.start_date.strftime('%Y-%m-%d')
|
||||
|
||||
if item.has_start_time:
|
||||
data['start_time'] = item.start_time.strftime('%H:%M:%SZ')
|
||||
|
||||
if item.end_date:
|
||||
data['end_date'] = item.end_date.strftime('%Y-%m-%d')
|
||||
|
||||
if item.has_end_time:
|
||||
data['end_time'] = item.end_time.strftime('%H:%M:%SZ')
|
||||
|
||||
if item.meet_at:
|
||||
data['meet_at'] = item.meet_at.strftime('%Y-%m-%dT%H:%M:%SZ')
|
||||
|
||||
if item.access_at:
|
||||
data['access_at'] = item.access_at.strftime('%Y-%m-%dT%H:%M:%SZ')
|
||||
|
||||
data['url'] = str(reverse_lazy('event_detail',kwargs={'pk':item.pk}))
|
||||
|
||||
results.append(data)
|
||||
json = simplejson.dumps(results)
|
||||
|
||||
Reference in New Issue
Block a user