Skip to content
Snippets Groups Projects
Commit edbdc736 authored by Carlos Vega's avatar Carlos Vega
Browse files

Issue #282 create two different urls for event retreival. One with all kind of...

Issue #282 create two different urls for event retreival. One with all kind of events (scheduled, cancelled, finished, etc.) and the previous version with only scheduled events
parent 96e47449
No related branches found
No related tags found
1 merge request!206Improvement/interface changes
......@@ -63,7 +63,8 @@ urlpatterns = [
name='web.api.workers.daily_planning.availabilities$'),
# daily planning events
url(r'^events/(?P<date>\d{4}-\d{2}-\d{2})/$', daily_planning.events, name='web.api.events'),
url(r'^events/(?P<date>\d{4}-\d{2}-\d{2})/include_all$', daily_planning.events, {'include_all': True}, name='web.api.events_all'),
url(r'^events/(?P<date>\d{4}-\d{2}-\d{2})/$', daily_planning.events, {'include_all': False}, name='web.api.events'),
url(r'^availabilities/(?P<date>\d{4}-\d{2}-\d{2})/$', daily_planning.availabilities, name='web.api.availabilities'),
url(r'^events_persist$', daily_planning.events_persist, name='web.api.events_persist'),
......
......@@ -203,10 +203,16 @@ def get_conflicts(worker, date):
return result
def get_generic_appointment_events(request, date):
def get_generic_appointment_events(request, date, include_all=False):
result = {}
appointments = Appointment.objects.filter(
if include_all:
appointments = Appointment.objects.filter(
datetime_when__date=date,
location__in=get_filter_locations(request.user),
visit__isnull=True).all()
else:
appointments = Appointment.objects.filter(
datetime_when__date=date,
location__in=get_filter_locations(request.user),
status=Appointment.APPOINTMENT_STATUS_SCHEDULED,
......@@ -233,6 +239,7 @@ def get_generic_appointment_events(request, date):
event = {
'title': appointment.title(),
'short_title': appointment.title(),
'status': appointment.status,
'duration': build_duration(appointment.length),
'id': 'app-{}'.format(appointment.id),
'appointment_id': appointment.id,
......@@ -250,24 +257,40 @@ def get_generic_appointment_events(request, date):
return result.values()
def events(request, date):
appointments = Appointment.objects.filter(
def events(request, date, include_all=False):
#fetch appointments
if include_all:
appointments = Appointment.objects.filter(
datetime_when__date=date,
location__in=get_filter_locations(request.user),
visit__isnull=False).all()
else:
appointments = Appointment.objects.filter(
datetime_when__date=date,
location__in=get_filter_locations(request.user),
status=Appointment.APPOINTMENT_STATUS_SCHEDULED,
visit__isnull=False).all()
#store subjects
subjects = {}
#for each appointment
for i, appointment in enumerate(appointments):
#get its subject
appointment_subject = appointment.visit.subject
#if there is a subject we add it to the subjects dict
if appointment_subject.id not in subjects:
# create subject
flag_set = set([language.image.url for language in appointment_subject.subject.languages.all() if language.image is not None])
default_language = appointment_subject.subject.default_written_communication_language
if default_language is not None and default_language.image is not None:
flag_set.add(default_language.image.url)
subject = {
'name': unicode(appointment_subject),
'id': appointment_subject.id,
'appointment_id': appointment.id,
'color': RANDOM_COLORS[i],
'start': appointment.datetime_when.replace(tzinfo=None).strftime("%H:%M"),
'flags': [language.image.url for language in appointment_subject.subject.languages.all()],
'flags': list(flag_set),
# this indicates only location of the first appointment
# (there is small chance to have two appointments in two different places at the same day)
'location': str(appointment.location),
......@@ -275,8 +298,10 @@ def events(request, date):
}
subjects[appointment_subject.id] = subject
#get appointment type link of the appointment
links = AppointmentTypeLink.objects.filter(
appointment=appointment).all()
#for the AppointmentTypeLink, get all the info and create the event object
for j, link in enumerate(links):
link_when = link.date_when
link_end = None
......@@ -287,6 +312,7 @@ def events(request, date):
minutes=link.appointment_type.default_duration)
event = {
'title': link.appointment_type.description,
'status': link.appointment.status,
'short_title': link.appointment_type.code,
'duration': build_duration(link.appointment_type.default_duration),
'subject': unicode(appointment_subject),
......@@ -303,7 +329,7 @@ def events(request, date):
subject_events = subjects[appointment_subject.id]['events']
subject_events.append(event)
generic_appointment_events = get_generic_appointment_events(request, date)
generic_appointment_events = get_generic_appointment_events(request, date, include_all=include_all)
availabilities = []
holidays = []
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment