示例#1
0
文件: models.py 项目: Flogerbe/coach
    def publish(self, users):
        '''
    Publish a plan to specified users
    No verification on the users belonging
     to the creator here
    '''
        if not self.start:
            raise Exception("No start date on plan.")

        # Build the pdf export
        export = PlanPdfExporter(self)
        pdf = export.render()

        for u in users.all():
            # Save plan application
            pa, _ = PlanApplied.objects.get_or_create(user=u, plan=self)

            # Apply the sessions
            nb_applied = 0
            for s in self.sessions.all():
                try:
                    s.apply(pa)
                    nb_applied += 1
                except Exception, e:
                    print 'Failed to apply plan session #%d : %s' % (s.pk, e)

            # Send an email to each user
            if nb_applied > 0:
                self.notify_athlete(u, pdf)
示例#2
0
    def render_to_response(self, context, *args, **kwargs):
        plan = context['plan']

        # Init response
        resp = HttpResponse(content_type='application/pdf')
        resp[
            'Content-Disposition'] = 'attachment; filename="Plan %s - RunReport.pdf"' % plan.name

        # Build pdf directly into response stream
        export = PlanPdfExporter(plan)
        export.render(resp)

        return resp