Exemple #1
0
def fetch_calendar():
    server = ShorthandServer(current_app.config['config_path'])

    directory_filter = get_request_argument(request.args,
                                            name='directory_filter')
    if directory_filter == 'ALL':
        directory_filter = None

    calendar = server.get_calendar(directory_filter=directory_filter)
    return json.dumps(calendar)
Exemple #2
0
def show_home_page():
    server = ShorthandServer(current_app.config['config_path'])
    default_directory = server.get_config().get('default_directory')
    todos = server.get_todos(todo_status='incomplete',
                             directory_filter=default_directory)
    questions = server.get_questions(question_status='unanswered',
                                     directory_filter=default_directory)
    summary = server.get_calendar()
    events = []
    colors = {
        'section': 'black',
        'incomplete_todo': 'red',
        'completed_todo': 'blue',
        'skipped_todo': 'grey',
        'question': 'purple',
        'answer': 'green',
    }
    for year, year_data in summary.items():
        for month, month_data in year_data.items():
            for day, day_data in month_data.items():
                for event in day_data:
                    formatted_event = {
                        'title': event['event'],
                        'start': f'{year}-{month}-{day}',
                        'url': f'/render?path={event["file_path"]}'
                        f'#line-number-{event["line_number"]}',
                        'type': event['type']
                    }
                    if formatted_event['type'] in colors.keys():
                        formatted_event['color'] = colors[
                            formatted_event['type']]
                    events.append(formatted_event)

    return render_template('home.j2',
                           num_todos=len(todos),
                           num_questions=len(questions),
                           events=json.dumps(events),
                           static_content=static_content)