Ejemplo n.º 1
0
def agenda_edit(request, meeting_id):
    group = get_current_group(request)
    if group == None:	
        return HttpResponseRedirect(reverse('index'))
        
    meeting = Meeting.objects.get(pk=int(meeting_id))
    if meeting.group != group:
        return HttpResponseRedirect(reverse('index'))

    doc_type = 'agenda'
    request_type = 'refresh'
    task_list_headings = ('Description',
                          'Assigned to',
                          'Deadline')
    items = meeting.item_set.filter(group=group).order_by('item_no')
    overdue_tasks_list = get_overdue_tasks_list(group=group,
                                                meeting=meeting,
                                                doc_type=doc_type)
    pending_tasks_list = get_outstanding_tasks_list(group=group,
                                                    meeting=meeting,
                                                    doc_type=doc_type)
    completed_tasks_list = get_completed_tasks_list(group=group,
                                                    meeting=meeting,
                                                    doc_type=doc_type)

    if request.method == "POST" and 'ajax_button' in request.POST:
        request_type = 'ajax'
        if request.POST['ajax_button'] != 'page_refresh':              
            save_formlist(request, group, items, 'items', doc_type)
            meeting_form = save_meeting_form(request, group, meeting, doc_type)            
        if request.POST['ajax_button']=='add_item':
            add_item(group, meeting, items, doc_type)
        if request.POST['ajax_button'][0:11] =='delete_item':
            delete_item(request, group, meeting)
        if request.POST['ajax_button'] == 'move_item':
            move_item(request, group, meeting)                          
        items = meeting.item_set.filter(group=group).order_by('item_no')

    item_formlist = build_formlist(group, items, 'items', doc_type)
    
    meeting_form = AgendaMeetingForm(group=group, instance=meeting,
                                     label_suffix='')
    meeting_duration = get_formatted_meeting_duration(meeting_id)
    meeting_end_time = calculate_meeting_end_time(meeting)
    
    templates = get_templates(request_type, doc_type)
    responses = []
    menu = {'parent': 'meetings',
            'child': 'current_meetings',
            'tips': 'create_agenda'}
    for template in templates:
        part_response = render(request, template, {
                               'menu': menu,
                               'completed_tasks_list': completed_tasks_list,
                               'doc_type': doc_type,
                               'group': group,
                               'item_formlist': item_formlist,
                               'items': items,
                               'meeting': meeting,
                               'meeting_duration': meeting_duration,
                               'meeting_end_time': meeting_end_time,
                               'meeting_form': meeting_form,
                               'meeting_id': meeting_id,                      
                               'overdue_tasks_list': overdue_tasks_list,
                               'pending_tasks_list': pending_tasks_list,
                               'task_list_headings': task_list_headings,
                               })
        responses.append(part_response)
    response = get_response(responses, request_type)
    
    return response
Ejemplo n.º 2
0
def create_pdf(request, group, meeting, doc_type):
    """
    Constructs the PDF document.
    """
    # Set up the document framework
    group_name = group.name
    buffer = BytesIO()
    doc = BaseDocTemplate(buffer,
        rightMargin=20*mm,
        leftMargin=20*mm,
        topMargin=20*mm,
        bottomMargin=20*mm,
        title = fit_to_table_cell(group_name, 90*mm) + "  |  Meeting no.: " +
            meeting.meeting_no,
        pagesize=A4,
        allowSplitting = 1,)
    body_frame = Frame(doc.leftMargin,
        doc.bottomMargin,
        doc.width,
        doc.height,
        leftPadding=0,
        bottomPadding=0,
        rightPadding=0,
        topPadding=0)
    template = PageTemplate(frames=body_frame, onPage=footer)
    doc.addPageTemplates([template])
    Document = []

    # Add main heading to document
    create_document_header(meeting, group_name, doc_type, Document)

    # Add meeting details to document
    create_details_table(meeting, doc_type, Document)

    # Add items to document
    items = meeting.item_set.filter(group=group).order_by('item_no')
    if doc_type == 'agenda':
        create_agenda_item_table(items, Document)
    if doc_type == 'minutes':
        create_minutes_item_table(items, group, Document)

    # Add next meeting table to minutes
    if doc_type == 'minutes':
        create_next_meeting_table(meeting, Document)

    # Add new task summary to minutes
    if doc_type == 'minutes':
        new_tasks_list = Task.lists.all_tasks().filter(group=group,
                                                            meeting=meeting)
        create_task_table(
            'New tasks assigned in this meeting (ordered by deadline)',
            new_tasks_list, 'new', meeting, doc_type, Document)

    # Add task review
    overdue_tasks = get_overdue_tasks_list(group=group,
                                               meeting=meeting,
                                               doc_type=doc_type)
    outstanding_tasks = get_outstanding_tasks_list(group=group,
                                                   meeting=meeting,
                                                   doc_type=doc_type)
    completed_tasks = get_completed_tasks_list(group=group,
                                                 meeting=meeting,
                                                 doc_type=doc_type)
    if doc_type == 'agenda':
        if meeting.date_scheduled < date.today():
            list_date = meeting.date_scheduled.strftime("%d %b %Y")
        else:
            list_date = date.today().strftime("%d %b %Y")

        completed_tasks_heading = 'Existing tasks:&nbsp;&nbsp;' + \
                                  'Completed since last meeting' + \
                                  ' (this list current at ' + \
                                  list_date + ')'
    elif doc_type == 'minutes':
        completed_tasks_heading = 'Existing tasks:&nbsp;&nbsp;' + \
                                  'Completed since last meeting'
    if (doc_type == 'agenda') or meeting.existing_tasks_in_minutes:
        create_task_table(
            'Existing tasks:&nbsp;&nbsp;Overdue',
            overdue_tasks, 'overdue', meeting, doc_type, Document)
        create_task_table(
            'Existing tasks:&nbsp;&nbsp;Incomplete and not overdue',
            outstanding_tasks, 'outstanding', meeting, doc_type, Document)
        create_task_table(
            completed_tasks_heading, completed_tasks, 'completed', meeting,
            doc_type, Document)

    # Build the PDF
    doc.build(Document)

    # Get the PDF
    pdf = buffer.getvalue()
    buffer.close()

    # Define locations to save files to
    pdf_path = get_pdf_path()
    preview_path = get_preview_path()

    # Define name of PDF file
    base_file_name = get_base_file_name(request, group, meeting, doc_type)
    pdf_name = base_file_name + '.pdf'

    # Delete any old PDF versions for this meeting
    path_to_pdf = pdf_path + pdf_name
    path_to_previews = preview_path + base_file_name + '*'

    call('rm ' + path_to_pdf , shell=True)
    call('rm ' + path_to_previews , shell=True)

    # Save the PDF temporarily without assigning a version to it
    f = open(path_to_pdf, 'w')
    f.write(pdf)
    f.close()

    # Generate the preview images
    pages = create_images_from_pdf(base_file_name)
    return pages