Esempio n. 1
0
    def save(self, *args, **kwargs):
        event = super(EventForm, self).save(*args, **kwargs)
        needs_pr = self.cleaned_data['needs_pr']
        if needs_pr:
            if event.project_report is None:
                # Create PR
                project_report = ProjectReport()
            else:
                # Update PR
                project_report = event.project_report

            project_report.term = event.term
            project_report.date = event.end_datetime.date()
            project_report.title = event.name
            project_report.author = event.contact
            project_report.committee = event.committee
            project_report.save()
            event.project_report = project_report
            event.save(update_fields=['project_report'])
        elif event.project_report is not None:
            # Event does not need project report, so delete PR after removing
            # the foreign key from the event.
            project_report = event.project_report
            event.project_report = None
            event.save(update_fields=['project_report'])
            project_report.delete()
        return event
Esempio n. 2
0
    def save(self, *args, **kwargs):
        event = super(EventForm, self).save(*args, **kwargs)
        needs_pr = self.cleaned_data['needs_pr']
        update_text = self.cleaned_data['update_text']
        if needs_pr:
            if event.project_report is None:
                # Create PR
                project_report = ProjectReport()
            else:
                # Update PR
                project_report = event.project_report

            project_report.term = event.term
            project_report.date = event.end_datetime.date()
            project_report.title = event.name
            project_report.author = event.contact
            project_report.committee = event.committee
            project_report.save()
            event.project_report = project_report
            event.save(update_fields=['project_report'])
        elif event.project_report is not None:
            # Event does not need project report, so delete PR after removing
            # the foreign key from the event.
            project_report = event.project_report
            event.project_report = None
            event.save(update_fields=['project_report'])
            project_report.delete()
        send_update_default = False
        send_update = self.cleaned_data.get('send_update', send_update_default)
        if send_update:
            event_signups = event.eventsignup_set.filter(
                unsignup=False).order_by('name')
            bcc_list = []
            for signup in event_signups:
                if signup.user:
                    bcc_list.append(signup.user.email)
                else:
                    bcc_list.append(signup.email)
            from_email = event.contact.userprofile.get_preferred_email()
            subject = '[TBP] Important Update for {}'.format(event.name)
            context = {
                'event': event,
                'author': event.contact.userprofile.get_common_name(),
                'update_text': update_text
            }
            body = render_to_string('events/email_update.txt', context)
            message = EmailMultiAlternatives(from_email=from_email,
                                             subject=subject,
                                             body=body,
                                             bcc=bcc_list)
            message.attach_alternative(
                render_to_string('events/email_update.html', context),
                'text/html')
            message.content_subtype = 'html'
            message.send(fail_silently=True)

        return event
Esempio n. 3
0
def event_revive(request, event_pk):
    """Revive a previously cancelled event."""
    try:
        event = Event.objects.get(pk=event_pk)
    except:
        return json_response(status=404)
    event.cancelled = False
    event.save()
    if event.project_report is None:
        project_report = ProjectReport()
    else:
        project_report = event.project_report
    project_report.term = event.term
    project_report.date = event.end_datetime.date()
    project_report.title = event.name
    project_report.author = event.contact
    project_report.committee = event.committee
    project_report.save()
    event.project_report = project_report
    event.save(update_fields=['project_report'])
    return redirect('events:detail', event_pk=event.pk)