Esempio n. 1
0
    def setUp(self):
        self.user = get_user_model().objects.create_user(
            username='******',
            email='*****@*****.**',
            password='******',
            first_name='Bentley',
            last_name='Bent')

        self.committee = OfficerPosition.objects.get(short_name='it')

        self.term = Term(term=Term.SPRING, year=2012, current=True)
        self.term.save()

        self.project_report = ProjectReport(term=self.term,
                                            author=self.user,
                                            committee=self.committee,
                                            title='Test',
                                            date=timezone.now().date())
        self.project_report.save()

        self.mox = mox.Mox()
        self.tz = timezone.get_current_timezone()
Esempio n. 2
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)
Esempio n. 3
0
    def setUp(self):
        self.user = get_user_model().objects.create_user(
            username='******',
            email='*****@*****.**',
            password='******',
            first_name='Bentley',
            last_name='Bent')

        self.committee = OfficerPosition.objects.get(short_name='it')

        self.term = Term(term=Term.SPRING, year=2012, current=True)
        self.term.save()

        self.project_report = ProjectReport(
            term=self.term,
            author=self.user,
            committee=self.committee,
            title='Test',
            date=timezone.now().date())
        self.project_report.save()

        self.mox = mox.Mox()
        self.tz = timezone.get_current_timezone()
Esempio n. 4
0
class ProjectReportTest(TestCase):
    fixtures = ['officer_position.yaml']

    def setUp(self):
        self.user = get_user_model().objects.create_user(
            username='******',
            email='*****@*****.**',
            password='******',
            first_name='Bentley',
            last_name='Bent')

        self.committee = OfficerPosition.objects.get(short_name='it')

        self.term = Term(term=Term.SPRING, year=2012, current=True)
        self.term.save()

        self.project_report = ProjectReport(
            term=self.term,
            author=self.user,
            committee=self.committee,
            title='Test',
            date=timezone.now().date())
        self.project_report.save()

        self.mox = mox.Mox()
        self.tz = timezone.get_current_timezone()

    def tearDown(self):
        self.mox.UnsetStubs()

    def test_completed_time(self):
        self.mox.StubOutWithMock(timezone, 'now')

        mock_time = timezone.make_aware(
            datetime.datetime(2012, 01, 01, 01, 01, 01), self.tz)
        timezone.now().MultipleTimes().AndReturn(mock_time)

        self.mox.ReplayAll()

        self.assertFalse(self.project_report.complete)
        self.assertIsNone(self.project_report.first_completed_at)

        self.project_report.complete = True
        self.project_report.save()

        self.assertEquals(self.project_report.first_completed_at, mock_time)
        self.assertTrue(self.project_report.complete)

        # Make sure that we can unset the completed_at date if it's no longer
        # complete.
        self.project_report.complete = False
        self.project_report.save()
        self.assertFalse(self.project_report.complete)
        self.assertIsNone(self.project_report.first_completed_at)

        self.mox.VerifyAll()

    def test_complete_time_no_overwrite(self):
        original_time = timezone.make_aware(
            datetime.datetime(2012, 01, 01, 01, 01, 01), self.tz)

        self.project_report.complete = True
        self.project_report.first_completed_at = original_time
        self.project_report.save()

        # Make sure that a save doesn't change anything if there is already a
        # time recorded.
        self.assertEquals(self.project_report.first_completed_at,
                          original_time)
        self.assertTrue(self.project_report.complete)

    def test_word_count(self):
        self.project_report.description = 'one two'
        self.project_report.purpose = 'three four'
        self.project_report.organization = 'five six'
        self.project_report.cost = 'seven eight'
        self.project_report.problems = 'nine'
        self.project_report.results = 'ten'

        self.assertEquals(self.project_report.word_count(), 10)
Esempio n. 5
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. 6
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. 7
0
class ProjectReportTest(TestCase):
    fixtures = ['officer_position.yaml']

    def setUp(self):
        self.user = get_user_model().objects.create_user(
            username='******',
            email='*****@*****.**',
            password='******',
            first_name='Bentley',
            last_name='Bent')

        self.committee = OfficerPosition.objects.get(short_name='it')

        self.term = Term(term=Term.SPRING, year=2012, current=True)
        self.term.save()

        self.project_report = ProjectReport(term=self.term,
                                            author=self.user,
                                            committee=self.committee,
                                            title='Test',
                                            date=timezone.now().date())
        self.project_report.save()

        self.mox = mox.Mox()
        self.tz = timezone.get_current_timezone()

    def tearDown(self):
        self.mox.UnsetStubs()

    def test_completed_time(self):
        self.mox.StubOutWithMock(timezone, 'now')

        mock_time = timezone.make_aware(
            datetime.datetime(2012, 01, 01, 01, 01, 01), self.tz)
        timezone.now().MultipleTimes().AndReturn(mock_time)

        self.mox.ReplayAll()

        self.assertFalse(self.project_report.complete)
        self.assertIsNone(self.project_report.first_completed_at)

        self.project_report.complete = True
        self.project_report.save()

        self.assertEquals(self.project_report.first_completed_at, mock_time)
        self.assertTrue(self.project_report.complete)

        # Make sure that we can unset the completed_at date if it's no longer
        # complete.
        self.project_report.complete = False
        self.project_report.save()
        self.assertFalse(self.project_report.complete)
        self.assertIsNone(self.project_report.first_completed_at)

        self.mox.VerifyAll()

    def test_complete_time_no_overwrite(self):
        original_time = timezone.make_aware(
            datetime.datetime(2012, 01, 01, 01, 01, 01), self.tz)

        self.project_report.complete = True
        self.project_report.first_completed_at = original_time
        self.project_report.save()

        # Make sure that a save doesn't change anything if there is already a
        # time recorded.
        self.assertEquals(self.project_report.first_completed_at,
                          original_time)
        self.assertTrue(self.project_report.complete)

    def test_word_count(self):
        self.project_report.description = 'one two'
        self.project_report.purpose = 'three four'
        self.project_report.organization = 'five six'
        self.project_report.cost = 'seven eight'
        self.project_report.problems = 'nine'
        self.project_report.results = 'ten'

        self.assertEquals(self.project_report.word_count(), 10)