Пример #1
0
def run_full_csv(group=None):
    response = HttpResponse(mimetype='text/csv')
    response['Content-Disposition'] = 'attachment; filename=champ_activities_%d-%d-%d.csv' % (date.today().month, date.today().day, date.today().year)
    
    writer = csv.writer(response)
    writer.writerow(['Chapter', 'Activity', 'Description', 'Full Date', 'Month',
                     'Planning Year', '# Volunteers', 'Prep Hours', 'Execution Hours',
                     'Goals', 'Outcomes', 'Created', 'Created By', 'Modified',
                     'Modified By', 'Confirmed?', '# Purposes', 'Purpose(s)',
                     
                     'ML?', 'SO?', 'Functioning?', 'Engagement?', 'Advocacy?',
                     'Publicity?', 'Fundraising?', 'WO?', 'CE?',
                      
                     'ML - Type', 'ML - LP Related', 'ML - Curriculum', 
                     'ML - Resources By', 'ML - Duration', 'ML - Attendence',
                     'ML - New Attendence',
                     
                     'SO - School Name', 'SO - Teacher Name', 'SO - Teacher Email',
                     'SO - Teacher Phone', 'SO- Num Presentations', 'SO - Num Students',
                     'SO - Grades', 'SO - Class', 'SO - Workshop',
                     'SO - Num Facilitators', 'SO - Num New Facilitators',
                     
                     'Functioning - Type', 'Functioning - Location', 'Functioning - Purpose',
                     'Functioning - Attendence', 'Functioning - Duration',
                     
                     'Engagement - Type', 'Engagement - Location', 'Engagement - Purpose',
                     'Engagement - Subject', 'Engagement - Level1', 'Engagement - Level2',
                     'Engagement - Level3',
                     
                     'Advocacy - Type', 'Advocacy - Units', 'Advocacy - DecisionMaker',
                     'Advocacy - Position', 'Advocacy - EWB', 'Advocacy - Purpose',
                     'Advocacy - Learned',
                     
                     'Publicity - Outlet', 'Publicity - Type', 'Publicity - Location',
                     'Publicity - Issue', 'Publicity - Circulation',
                     
                     'Fundraising - Goal', 'Fundraising - Revenue', 'Fundraising - Repeat',
                     
                     'WO - Company', 'WO - City', 'WO - Presenters', 'WO - Ambassador',
                     'WO - Email', 'WO - Phone', 'WO - NumPresentations',
                     'WO - Attendence', 'WO - Type',
                     
                     'CE - Name', 'CE - Code', 'CE - NumStudents', 'CE - ClassHours',
                     'CE - Professor', 'CE - Activity'])
    
    activities = Activity.objects.filter(visible=True)
    if group:
        activities = activities.filter(group=group)
        
    for a in activities:
        impact, func, ml, so, pe, pa, wo, ce, pub, fund = a.get_metrics(pad=True)
        
        row = [a.group.name, a.name]
        if impact:
            row.append(impact.description)
        else:
            row.append('')
            
        row.extend([a.date, a.date.strftime('%B'), schoolyear.school_year_name(a.date), a.numVolunteers, a.prepHours, a.execHours])
        
        if impact:
            row.extend([impact.goals, impact.outcome])
        else:
            row.extend(['', ''])
            
        row.extend([a.created_date, a.creator.visible_name(),
                    a.modified_date, a.editor.visible_name()])
        if a.confirmed:
            row.append('confirmed')
        else:
            row.append('unconfirmed')
            
        row.append(len(a.get_metrics()) - 1)
        purposes = ''
        for m in a.get_metrics():
            if not m.metricname == 'all':
                purposes = purposes + m.metricname + '-'
        if len(purposes):
            purposes = purposes[0:-1]
        row.append(purposes)
        
        if ml:
            row.append('1')
        else:
            row.append('0')
        if so:
            row.append('1')
        else:
            row.append('0')
        if func:
            row.append('1')
        else:
            row.append('0')
        if pe:
            row.append('1')
        else:
            row.append('0')
        if pa:
            row.append('1')
        else:
            row.append('0')
        if pub:
            row.append('1')
        else:
            row.append('0')
        if fund:
            row.append('1')
        else:
            row.append('0')
        if wo:
            row.append('1')
        else:
            row.append('0')
        if ce:
            row.append('1')
        else:
            row.append('0')
        
        if ml:
            row.append(ml.type)
            if ml.learning_partner:
                row.append('1')
            else:
                row.append('0')
            row.extend([ml.curriculum, ml.resources_by, ml.duration, ml.attendance, ml.new_attendance])
        else:
            row.extend(['', '', '', '', '', '', ''])
            
        if so:
            row.extend([so.school_name, so.teacher_name, so.teacher_email, so.teacher_phone, so.presentations, so.students, so.grades, so.subject, so.workshop, so.facilitators, so.new_facilitators])
        else:
            row.extend(['', '', '', '', '', '', '', '', '', '', ''])
            
        if func:
            row.extend([func.type, func.location, func.purpose, func.attendance, func.duration])
        else:
            row.extend(['', '', '', '', ''])
        
        if pe:
            row.extend([pe.type, pe.location, pe.purpose, pe.subject, pe.level1, pe.level2, pe.level3])
        else:
            row.extend(['', '', '', '', '', '', ''])
            
        if pa:
            row.extend([pa.type, pa.units, pa.decision_maker, pa.position, pa.ewb, pa.purpose, pa.learned])
        else:
            row.extend(['', '', '', '', '', '', ''])

        if pub:
            row.extend([pub.outlet, pub.type, pub.location, '', pub.circulation])
        else:
            row.extend(['', '', '', '', ''])
            
        if fund:
            row.extend([fund.goal, fund.revenue, ''])
        else:
            row.extend(['', '', ''])
            
        if wo:
            row.extend([wo.company, wo.city, wo.presenters, wo.ambassador, wo.email, wo.phone, wo.presentations, wo.attendance, wo.type])
        else:
            row.extend(['', '', '', '', '', '', '', '', ''])
            
        if ce:
            row.extend([ce.name, ce.code, ce.students, ce.hours, ce.professor, ce.ce_activity])
        else:
            row.extend(['', '', '', '', '', ''])

        writer.writerow([fix_encoding(s) for s in row])
            
    return response
Пример #2
0
def run_full_csv(group=None):
    response = HttpResponse(mimetype='text/csv')
    response['Content-Disposition'] = 'attachment; filename=champ_activities_%d-%d-%d.csv' % (date.today().month, date.today().day, date.today().year)
    
    writer = csv.writer(response)
    writer.writerow(['Chapter', 'Activity', 'Description', 'Full Date', 'Month',
                     'Planning Year', '# Volunteers', 'Prep Hours', 'Execution Hours',
                     'Goals', 'Outcomes', 'Created', 'Created By', 'Modified',
                     'Modified By', 'Confirmed?', '# Purposes', 'Purpose(s)',
                     
                     'ML?', 'SO?', 'Functioning?', 'Engagement?', 'Advocacy meetings?', 'Letter writing?',
                     'Publicity?', 'Fundraising?', 'WO?', 'CE?',
                      
                     'ML - Type', 'ML - LP Related', 'ML - Focus', 
                     'ML - Source', 'ML - Duration', 'ML - Attendence',
                     'ML - New Attendence',
                     
                     'SO - School Name', 'SO - Teacher Name', 'SO - Teacher Email',
                     'SO - Teacher Phone', 'SO- Num Presentations', 'SO - Num Students',
                     'SO - Grades', 'SO - Class', 'SO - Workshop',
                     'SO - Num Facilitators', 'SO - Num New Facilitators',
                     
                     'Functioning - Type', 'Functioning - Location', 'Functioning - Purpose',
                     'Functioning - Attendence', 'Functioning - Duration',
                     
                     'Engagement - Type', 'Engagement - Location', 'Engagement - Purpose',
                     'Engagement - Subject', 'Engagement - Level1', 'Engagement - Level2',
                     'Engagement - Level3',
                     
                     'Advocacy - Type', 'Advocacy - Units', 'Advocacy - DecisionMaker',
                     'Advocacy - Position', 'Advocacy - EWB', 'Advocacy - Purpose',
                     'Advocacy - Learned',

                     'Letters - signatures', 'Letters - to decisionmakers', 'Letters - to media', 'Letters - other',
                     
                     'Publicity - Outlet', 'Publicity - Type', 'Publicity - Location',
                     'Publicity - Issue', 'Publicity - Circulation',
                     
                     'Fundraising - Goal', 'Fundraising - Revenue', 'Fundraising - Repeat',
                     
                     'WO - Company', 'WO - City', 'WO - Presenters', 'WO - Ambassador',
                     'WO - Email', 'WO - Phone', 'WO - NumPresentations',
                     'WO - Attendence', 'WO - Type',
                     
                     'CE - Name', 'CE - Code', 'CE - NumStudents', 'CE - ClassHours',
                     'CE - Professor', 'CE - Activity'])
    
    start = date(2009, 9, 1)
    end = date.today()
    activities = Activity.objects.filter(visible=True, date__range=(start, end))
    if group:
        activities = activities.filter(group=group)
        
    for a in activities:
        impact, func, ml, so, pe, pa, adv, wo, ce, pub, fund = a.get_metrics(pad=True)
        
        row = [a.group.name, a.name]
        if impact:
            row.append(impact.description)
        else:
            row.append('')
            
        formatted_time = ''
        if a.date:
            formatted_time = a.date.strftime('%B')
        row.extend([a.date, formatted_time, schoolyear.school_year_name(a.date), a.numVolunteers, a.prepHours, a.execHours])
        
        if impact:
            row.extend([impact.goals, impact.outcome])
        else:
            row.extend(['', ''])
            
        row.extend([a.created_date, a.creator.visible_name(),
                    a.modified_date, a.editor.visible_name()])
        if a.confirmed:
            row.append('confirmed')
        else:
            row.append('unconfirmed')
            
        row.append(len(a.get_metrics()) - 1)
        purposes = ''
        for m in a.get_metrics():
            if not m.metricname == 'all':
                purposes = purposes + m.metricname + '-'
        if len(purposes):
            purposes = purposes[0:-1]
        row.append(purposes)
        
        if ml:
            row.append('1')
        else:
            row.append('0')
        if so:
            row.append('1')
        else:
            row.append('0')
        if func:
            row.append('1')
        else:
            row.append('0')
        if pe:
            row.append('1')
        else:
            row.append('0')
        if pa:
            row.append('1')
        else:
            row.append('0')
        if adv:
            row.append('1')
        else:
            row.append('0')
        if pub:
            row.append('1')
        else:
            row.append('0')
        if fund:
            row.append('1')
        else:
            row.append('0')
        if wo:
            row.append('1')
        else:
            row.append('0')
        if ce:
            row.append('1')
        else:
            row.append('0')
        
        if ml:
            row.append(ml.type)
            if ml.learning_partner:
                row.append('1')
            else:
                row.append('0')
            row.extend([ml.curriculum, ml.resources_by, ml.duration, ml.attendance, ml.new_attendance])
        else:
            row.extend(['', '', '', '', '', '', ''])
            
        if so:
            row.extend([so.school_name, so.teacher_name, so.teacher_email, so.teacher_phone, so.presentations, so.students, so.grades, so.subject, so.workshop, so.facilitators, so.new_facilitators])
        else:
            row.extend(['', '', '', '', '', '', '', '', '', '', ''])
            
        if func:
            row.extend([func.type, func.location, func.purpose, func.attendance, func.duration])
        else:
            row.extend(['', '', '', '', ''])
        
        if pe:
            row.extend([pe.type, pe.location, pe.purpose, pe.subject, pe.level1, pe.level2, pe.level3])
        else:
            row.extend(['', '', '', '', '', '', ''])
            
        if pa:
            row.extend([pa.type, pa.units, pa.decision_maker, pa.position, pa.ewb, pa.purpose, pa.learned])
        else:
            row.extend(['', '', '', '', '', '', ''])

        if adv:
            row.extend([adv.signatures, adv.letters, adv.editorials, adv.other])
        else:
            row.extend(['', '', '', ''])

        if pub:
            row.extend([pub.outlet, pub.type, pub.location, '', pub.circulation])
        else:
            row.extend(['', '', '', '', ''])
            
        if fund:
            row.extend([fund.goal, fund.revenue, ''])
        else:
            row.extend(['', '', ''])
            
        if wo:
            row.extend([wo.company, wo.city, wo.presenters, wo.ambassador, wo.email, wo.phone, wo.presentations, wo.attendance, wo.type])
        else:
            row.extend(['', '', '', '', '', '', '', '', ''])
            
        if ce:
            row.extend([ce.name, ce.code, ce.students, ce.hours, ce.professor, ce.ce_activity])
        else:
            row.extend(['', '', '', '', '', ''])

        writer.writerow([fix_encoding(s) for s in row])
            
    return response