Exemplo n.º 1
0
    def form_valid(self, form):
        self.object = form.save()

        event = self.object
        wr = self.other_object

        person = wr.host()
        if person:
            Task.objects.create(event=event,
                                person=person,
                                role=Role.objects.get(name="host"))

        if PostWorkshopAction.check(event):
            objs = dict(event=event, request=wr)
            jobs, rqjobs = ActionManageMixin.add(
                action_class=PostWorkshopAction,
                logger=logger,
                scheduler=scheduler,
                triggers=Trigger.objects.filter(
                    active=True,
                    action="week-after-workshop-completion",
                ),
                context_objects=objs,
                object_=event,
                request=self.request,
            )

        wr.state = "a"
        wr.event = event
        wr.save()
        return super().form_valid(form)
Exemplo n.º 2
0
    def testCheckConditionsCircuits(self):
        """Make sure `check` works for "Circuits" workshops too."""
        e = Event.objects.create(
            slug="test-event",
            host=Organization.objects.first(),
            administrator=Organization.objects.get(domain="librarycarpentry.org"),
            start=date.today() + timedelta(days=7),
            end=date.today() + timedelta(days=8),
        )
        e.tags.set(Tag.objects.filter(name__in=["automated-email"]))
        p = Person.objects.create(
            personal="Harry", family="Potter", email="*****@*****.**"
        )
        r = Role.objects.create(name="host")
        Task.objects.create(event=e, person=p, role=r)

        # 1st case: fail
        self.assertEqual(PostWorkshopAction.check(e), False)

        # 2nd case: success
        e.tags.add(Tag.objects.get(name="Circuits"))
        self.assertEqual(PostWorkshopAction.check(e), True)
Exemplo n.º 3
0
    def testCheckConditions(self):
        """Make sure `check` works for various input data."""
        # totally fake Task, Role and Event data
        e = Event.objects.create(
            slug="test-event",
            host=Organization.objects.first(),
            administrator=Organization.objects.get(
                domain="librarycarpentry.org"),
            start=date.today() + timedelta(days=7),
            end=date.today() + timedelta(days=8),
        )
        e.tags.set(
            Tag.objects.filter(name__in=["LC", "TTT", "automated-email"]))
        p = Person.objects.create(personal="Harry",
                                  family="Potter",
                                  email="*****@*****.**")
        r = Role.objects.create(name="host")
        Task.objects.create(event=e, person=p, role=r)

        # 1st case: everything is good
        self.assertEqual(PostWorkshopAction.check(e), True)

        # 2nd case: event has no start date
        # result: OK
        e.start = None
        e.save()
        self.assertEqual(PostWorkshopAction.check(e), True)

        # 3rd case: event has no end date
        # result: FAIL
        e.end = None
        e.save()
        self.assertEqual(PostWorkshopAction.check(e), False)

        # bring back the good date
        e.end = date.today() + timedelta(days=8)
        e.save()
        self.assertEqual(PostWorkshopAction.check(e), True)

        # 4th case: event is tagged with one (or more) excluding tags
        # result: FAIL
        for tag in ["cancelled", "stalled", "unresponsive"]:
            e.tags.add(Tag.objects.get(name=tag))
            self.assertEqual(PostWorkshopAction.check(e), False)
            e.tags.remove(Tag.objects.get(name=tag))

        # retest to make sure it's back to normal
        self.assertEqual(PostWorkshopAction.check(e), True)

        # 5th case: no host/instructor tasks
        # This is tricky case. Sometimes the workshop can be defined before
        # there are any instructor/host tasks.
        # result: OK
        r.name = "helper"
        r.save()
        self.assertEqual(PostWorkshopAction.check(e), True)
        r.name = "instructor"  # additionally check for instructor role
        r.save()

        # retest to make sure it's back to normal
        # (note: role was changed to "instructor")
        self.assertEqual(PostWorkshopAction.check(e), True)

        # 6th case: wrong administrator (Instructor Training)
        # result: FAIL
        e.administrator = Organization.objects.get(domain="carpentries.org")
        e.save()
        self.assertEqual(PostWorkshopAction.check(e), False)

        # retest to make sure it's back to normal
        e.administrator = Organization.objects.get(
            domain="librarycarpentry.org")
        self.assertEqual(PostWorkshopAction.check(e), True)