def delete_event(request): delete_type = request.POST.get('delete_type', None) if delete_type: if delete_type == 'delete_non_recurring_event': event_instance_id = request.POST.get('event_instance_id', None) if delete_non_recurring_event(event_instance_id): response = {'success': True} else: response = {'success': False, 'errors': ['Unable to delete event']} elif delete_type == 'delete_single_recurring_event': event_instance_id = request.POST.get('event_instance_id', None) if delete_single_recurring_event(event_instance_id): response = {'success': True} else: response = {'success': False, 'errors': ['Unable to delete event']} elif delete_type == 'delete_all_recurring_events': schedule_skeleton_id = request.POST.get('schedule_skeleton_id', None) if delete_all_recurring_events(schedule_skeleton_id): response = {'success': True} else: response = {'success': False, 'errors': ['Unable to delete event']} else: response = {'success': False, 'errors': ['Must provide delete_type']} return render_json(response)
def list_events(request): user = request.user search_keywords = request.GET.get('search_keywords', None) tags = request.GET.get('tags', None) start_date = convert_string_to_datetime(request.GET.get('start_date', None)) future_query = convert_string_to_boolean(request.GET.get('future_query', None)) pagination_count = request.GET.get('pagination_count', None) state = request.GET.get('state', None) events_info = get_events_info(user, search_keywords, tags, start_date, future_query, pagination_count, state) response = { 'success': True, 'event_instance_list': events_info['event_instance_list'], 'schedule_skeleton_map': events_info['schedule_skeletons_dict'], 'total_event_count': events_info['total_event_count'], 'future_event_count': events_info['future_event_count'], 'request': { 'tag_list': tags.split(",") if tags else None, 'search_keywords': search_keywords, 'future_query': future_query, 'state': state, }, } return render_json(response)
def mark_event(request): event_instance_id = request.POST.get('event_instance_id', None) is_complete = request.POST.get('is_complete', None) if event_instance_id and is_complete: try: user = request.user event_instance = EventInstance.objects.get(id=event_instance_id, schedule_skeleton__user=user) event_instance.is_complete = convert_string_to_boolean(is_complete) event_instance.save() response = {'success': True} except EventInstance.DoesNotExist: response = {'success': False, 'errors': ['Provided event_instance_id is not valid for logged in user']} else: response = {'success': False, 'errors': ['Must provide event_instance_id and is_complete for marking event']} return render_json(response)
def update_event(request): update_type = request.POST.get('update_type', None) event_instance_id = request.POST.get('event_instance_id', None) schedule_skeleton_id = request.POST.get('schedule_skeleton_id', None) new_time_start = convert_string_to_datetime(request.POST.get('time_start', None)) new_time_end = convert_string_to_datetime(request.POST.get('time_end', None)) new_is_all_day = convert_string_to_boolean(request.POST.get('is_all_day', False)) new_is_recurring = convert_string_to_boolean(request.POST.get('is_recurring', False)) new_interval_type = request.POST.get('interval_type', '') new_interval_end_date = convert_string_to_datetime(request.POST.get('interval_end_date', None)) new_title = request.POST.get('title', None) new_description = request.POST.get('description', None) new_tag = request.POST.get('tag', None) if event_instance_id: if update_type == "update_single_event_instance": if update_single_event_instance(event_instance_id, new_title, new_description, new_tag, new_time_start, new_time_end, new_is_all_day): response = {'success': True} else: response = {'success': False, 'errors': ['Event update failed.']} elif update_type == "update_all_event_instances": if update_all_events(event_instance_id, schedule_skeleton_id, new_title, new_description, new_tag, new_time_start, new_time_end, new_is_all_day, new_is_recurring, new_interval_type, new_interval_end_date): response = {'success': True} else: response = {'success': False, 'errors': ['Event update failed.']} else: response = {'success': False, 'errors': ['Must provide update_type']} else: response = {'success': False, 'errors': ['Must provide event_instance_id']} return render_json(response)
def create_event(request): time_start = convert_string_to_datetime(request.POST.get('time_start', None)) time_end = convert_string_to_datetime(request.POST.get('time_end', None)) is_all_day = convert_string_to_boolean(request.POST.get('is_all_day', False)) is_recurring = convert_string_to_boolean(request.POST.get('is_recurring', False)) interval_type = request.POST.get('interval_type', '') interval_end_date = convert_string_to_datetime(request.POST.get('interval_end_date', None)) title = request.POST.get('title', None) description = request.POST.get('description', None) tag = request.POST.get('tag', None) if time_start: user = request.user schedule_skeleton = create_schedule_skeleton(user, time_start, time_end, is_all_day, is_recurring, interval_type, interval_end_date) create_event_instances(schedule_skeleton, title, description, tag) response = {'success': True} else: response = {'success': False, 'errors': ['Event start time is not provided']} return render_json(response)