Ejemplo n.º 1
0
class EventModelNonLegacyCopy(TestCase):
    def setUp(self):
        self.sample_copy = (
            u"<p>Simple &amp; tidy HTML/unicode \u00a9\u014dpy\n</p>\n"
            u"<p>With a <a href='http://example.com/foo/'>link!</a>"
            u"<p>And another! <a href='https://example.com/bar/'>link!</a>"
            u" and some equivalent things; &pound; &#163; \u00a3<br></p>")
        self.event = Event(name="Test event",
                           legacy_copy=False,
                           copy=self.sample_copy)
        self.event.save()

    def test_simple(self):
        # Test copy goes in and out without being mangled
        reloaded = Event.objects.get(id=self.event.pk)
        self.assertEqual(reloaded.copy, self.sample_copy)

    def test_html_copy(self):
        self.assertEqual(self.event.copy_html, self.sample_copy)

    def test_plaintext_copy(self):
        expected = (u"Simple & tidy HTML/unicode \u00a9\u014dpy \n\n"
                    u"With a link!: http://example.com/foo/\n\n"
                    u"And another! link!: https://example.com/bar/"
                    u" and some equivalent things; \u00a3 \u00a3 \u00a3  \n\n")
        self.assertEqual(self.event.copy_plaintext, expected)
Ejemplo n.º 2
0
class EventModelLegacyCopy(TestCase):
    def setUp(self):
        self.sample_copy = (
            u"Simple &amp; tidy legacy \u00a9\u014dpy\n\n"
            u"With an unardorned link: http://example.com/foo/"
            u" https://example.com/foo/"
            u" and some equivalent things; &pound; &#163; \u00a3..."
            u" and <this> \"'<troublemaker>'\"")
        self.event = Event(name="Test event",
                           legacy_copy=True,
                           copy=self.sample_copy)
        self.event.save()

    def test_simple(self):
        # Test copy goes in and out without being mangled
        reloaded = Event.objects.get(id=self.event.pk)
        self.assertEqual(reloaded.copy, self.sample_copy)

    def test_html_copy(self):
        expected = (
            u"Simple &amp; tidy legacy \u00a9\u014dpy <br><br>"
            u'With an unardorned link: '
            u'<a href="http://example.com/foo/">http://example.com/foo/</a>'
            u' <a href="https://example.com/foo/">https://example.com/foo/</a>'
            u" and some equivalent things; &pound; &#163; \u00a3..."
            u" and <this> \"'<troublemaker>'\"")
        self.assertEqual(self.event.copy_html, expected)

    def test_plaintext_copy(self):
        expected = (u"Simple & tidy legacy \u00a9\u014dpy\n\n"
                    u"With an unardorned link: http://example.com/foo/"
                    u" https://example.com/foo/"
                    u" and some equivalent things; \u00a3 \u00a3 \u00a3..."
                    u" and <this> \"'<troublemaker>'\"")
        self.assertEqual(self.event.copy_plaintext, expected)
Ejemplo n.º 3
0
class EventModelNonLegacyCopy(TestCase):

    def setUp(self):
        self.sample_copy = (
            u"<p>Simple &amp; tidy HTML/unicode \u00a9\u014dpy\n</p>\n"
            u"<p>With a <a href='http://example.com/foo/'>link!</a>"
            u"<p>And another! <a href='https://example.com/bar/'>link!</a>"
            u" and some equivalent things; &pound; &#163; \u00a3<br></p>"
        )
        self.event = Event(name="Test event", legacy_copy=False, copy=self.sample_copy)
        self.event.save()

    def test_simple(self):
        # Test copy goes in and out without being mangled
        reloaded = Event.objects.get(id=self.event.pk)
        self.assertEqual(reloaded.copy, self.sample_copy)

    def test_html_copy(self):
        self.assertEqual(self.event.copy_html, self.sample_copy)

    def test_plaintext_copy(self):
        expected = (
            u"Simple & tidy HTML/unicode \u00a9\u014dpy \n\n"
            u"With a link!: http://example.com/foo/\n\n"
            u"And another! link!: https://example.com/bar/"
            u" and some equivalent things; \u00a3 \u00a3 \u00a3  \n\n"
        )
        self.assertEqual(self.event.copy_plaintext, expected)
Ejemplo n.º 4
0
    def test_set_tags_no_template(self):
        # No template set, call reset_tags
        new_event = Event(name=u"Event Title", )
        new_event.save()
        self.assertEqual(new_event.tags.count(), 0)

        new_event.reset_tags_to_default()

        self.assertEqual(new_event.tags.count(), 0)
Ejemplo n.º 5
0
 def test_set_from_template_no_pricing(self):
     # No pricing specified when creating the event, and no pricing
     # specified in the template:
     new_event = Event(
         name=u"Event Title",
         template=self.tmpl3,
     )
     self.assertEqual(new_event.pricing, u"")
     new_event.save()
     self.assertEqual(new_event.pricing, u"")
Ejemplo n.º 6
0
 def test_no_template(self):
     # Pricing specified when creating the event, and no pricing specified
     # in the template:
     new_event = Event(
         name=u"Event Title",
         pricing=u"Actual pricing",
     )
     self.assertEqual(new_event.pricing, u"Actual pricing")
     new_event.save()
     self.assertEqual(new_event.pricing, u"Actual pricing")
Ejemplo n.º 7
0
 def test_set_pricing_from_template(self):
     # No pricing specified when creating the event, and pricing specified
     # in the template:
     new_event = Event(
         name=u"Event Title",
         template=self.tmpl1,
     )
     self.assertEqual(new_event.pricing, u"Entry: \u00a35 / \u20ac10")
     new_event.save()
     self.assertEqual(new_event.pricing, u"Entry: \u00a35 / \u20ac10")
Ejemplo n.º 8
0
 def test_no_template(self):
     # Pricing specified when creating the event, and no pricing specified
     # in the template:
     new_event = Event(
         name=u"Event Title",
         pricing=u"Actual pricing",
     )
     self.assertEqual(new_event.pricing, u"Actual pricing")
     new_event.save()
     self.assertEqual(new_event.pricing, u"Actual pricing")
Ejemplo n.º 9
0
 def test_set_from_template_no_pricing(self):
     # No pricing specified when creating the event, and no pricing
     # specified in the template:
     new_event = Event(
         name=u"Event Title",
         template=self.tmpl3,
     )
     self.assertEqual(new_event.pricing, u"")
     new_event.save()
     self.assertEqual(new_event.pricing, u"")
Ejemplo n.º 10
0
 def test_set_pricing_from_template(self):
     # No pricing specified when creating the event, and pricing specified
     # in the template:
     new_event = Event(
         name=u"Event Title",
         template=self.tmpl1,
     )
     self.assertEqual(new_event.pricing, u"Entry: \u00a35 / \u20ac10")
     new_event.save()
     self.assertEqual(new_event.pricing, u"Entry: \u00a35 / \u20ac10")
Ejemplo n.º 11
0
 def test_dont_set_pricing_from_template(self):
     # Pricing specified when creating the event, and pricing specified in
     # the template:
     new_event = Event(
         name=u"Event Title",
         pricing=u"Actual pricing",
         template=self.tmpl1,
     )
     self.assertEqual(new_event.pricing, u"Actual pricing")
     new_event.save()
     self.assertEqual(new_event.pricing, u"Actual pricing")
Ejemplo n.º 12
0
 def test_dont_set_pricing_from_template(self):
     # Pricing specified when creating the event, and pricing specified in
     # the template:
     new_event = Event(
         name=u"Event Title",
         pricing=u"Actual pricing",
         template=self.tmpl1,
     )
     self.assertEqual(new_event.pricing, u"Actual pricing")
     new_event.save()
     self.assertEqual(new_event.pricing, u"Actual pricing")
Ejemplo n.º 13
0
    def test_set_tags_no_template(self):
        # No template set, call reset_tags
        new_event = Event(
            name=u"Event Title",
        )
        new_event.save()
        self.assertEqual(new_event.tags.count(), 0)

        new_event.reset_tags_to_default()

        self.assertEqual(new_event.tags.count(), 0)
Ejemplo n.º 14
0
    def test_set_no_tags_from_template(self):
        new_event = Event(
            name=u"Event Title",
            template=self.tmpl3,
        )
        new_event.save()
        # Tags shouldn't have been set yet:
        self.assertEqual(new_event.tags.count(), 0)

        new_event.reset_tags_to_default()

        # Still no tags
        self.assertEqual(new_event.tags.count(), 0)
Ejemplo n.º 15
0
    def test_set_no_tags_from_template(self):
        new_event = Event(
            name=u"Event Title",
            template=self.tmpl3,
        )
        new_event.save()
        # Tags shouldn't have been set yet:
        self.assertEqual(new_event.tags.count(), 0)

        new_event.reset_tags_to_default()

        # Still no tags
        self.assertEqual(new_event.tags.count(), 0)
Ejemplo n.º 16
0
    def test_set_one_tag_from_template(self):
        new_event = Event(
            name=u"Event Title",
            template=self.tmpl1,
        )
        new_event.save()
        # Tags shouldn't have been set yet:
        self.assertEqual(new_event.tags.count(), 0)

        new_event.reset_tags_to_default()

        self.assertEqual(new_event.tags.count(), 1)
        self.assertEqual(new_event.tags.all()[0].name, u"tag one")
        self.assertEqual(new_event.tags.all()[0].slug, u"tag-one")
Ejemplo n.º 17
0
    def test_set_one_tag_from_template(self):
        new_event = Event(
            name=u"Event Title",
            template=self.tmpl1,
        )
        new_event.save()
        # Tags shouldn't have been set yet:
        self.assertEqual(new_event.tags.count(), 0)

        new_event.reset_tags_to_default()

        self.assertEqual(new_event.tags.count(), 1)
        self.assertEqual(new_event.tags.all()[0].name, u"tag one")
        self.assertEqual(new_event.tags.all()[0].slug, u"tag-one")
Ejemplo n.º 18
0
    def test_set_two_tags_from_template(self):
        new_event = Event(
            name=u"Event Title",
            template=self.tmpl2,
        )
        new_event.save()
        # Tags shouldn't have been set yet:
        self.assertEqual(new_event.tags.count(), 0)

        new_event.reset_tags_to_default()

        self.assertEqual(new_event.tags.count(), 2)
        self.assertEqual(new_event.tags.all()[0].name, u"tag one")
        self.assertEqual(new_event.tags.all()[0].slug, u"tag-one")
        self.assertEqual(new_event.tags.all()[1].name, u"\u0167ag \u0165hre\u0119")
        self.assertEqual(new_event.tags.all()[1].slug, u"ag-three")
Ejemplo n.º 19
0
    def test_set_two_tags_from_template(self):
        new_event = Event(
            name=u"Event Title",
            template=self.tmpl2,
        )
        new_event.save()
        # Tags shouldn't have been set yet:
        self.assertEqual(new_event.tags.count(), 0)

        new_event.reset_tags_to_default()

        self.assertEqual(new_event.tags.count(), 2)
        self.assertEqual(new_event.tags.all()[0].name, u"tag one")
        self.assertEqual(new_event.tags.all()[0].slug, u"tag-one")
        self.assertEqual(new_event.tags.all()[1].name,
                         u"\u0167ag \u0165hre\u0119")
        self.assertEqual(new_event.tags.all()[1].slug, u"ag-three")
Ejemplo n.º 20
0
class EventModelLegacyCopy(TestCase):

    def setUp(self):
        self.sample_copy = (
            u"Simple &amp; tidy legacy \u00a9\u014dpy\n\n"
            u"With an unardorned link: http://example.com/foo/"
            u" https://example.com/foo/"
            u" and some equivalent things; &pound; &#163; \u00a3..."
            u" and <this> \"'<troublemaker>'\""
        )
        self.event = Event(name="Test event",
                           legacy_copy=True, copy=self.sample_copy)
        self.event.save()

    def test_simple(self):
        # Test copy goes in and out without being mangled
        reloaded = Event.objects.get(id=self.event.pk)
        self.assertEqual(reloaded.copy, self.sample_copy)

    def test_html_copy(self):
        expected = (
            u"Simple &amp; tidy legacy \u00a9\u014dpy <br><br>"
            u'With an unardorned link: '
            u'<a href="http://example.com/foo/">http://example.com/foo/</a>'
            u' <a href="https://example.com/foo/">https://example.com/foo/</a>'
            u" and some equivalent things; &pound; &#163; \u00a3..."
            u" and <this> \"'<troublemaker>'\""
        )
        self.assertEqual(self.event.copy_html, expected)

    def test_plaintext_copy(self):
        expected = (
            u"Simple & tidy legacy \u00a9\u014dpy\n\n"
            u"With an unardorned link: http://example.com/foo/"
            u" https://example.com/foo/"
            u" and some equivalent things; \u00a3 \u00a3 \u00a3..."
            u" and <this> \"'<troublemaker>'\""
        )
        self.assertEqual(self.event.copy_plaintext, expected)
Ejemplo n.º 21
0
def add_event(request):
    # Called GET, with a "date" parameter of the form day-month-year:
    #     returns 'form_new_event_and_showing' with given date filled in.
    # Called POST, with various data in request:
    #     creates new event, and number_of_showings, calls return_to_editindex
    #

    if request.method == 'POST':
        # Get event data, plus template and showing time and number of showing
        # days from form. Uses template to set rota roles and tags.
        form = diary_forms.NewEventForm(request.POST)
        if form.is_valid():
            # Event constructor will pull things from the template as
            # appropriate (excluding many/many relation which can only be set
            # after saving)
            new_event = Event(name=form.cleaned_data['event_name'],
                              template=form.cleaned_data['event_template'],
                              duration=form.cleaned_data['duration'],
                              outside_hire=form.cleaned_data['outside_hire'],
                              private=form.cleaned_data['private'])
            # Set event tags to those from its template:
            new_event.save()
            new_event.reset_tags_to_default()
            # create number_of_days showings, each offset by one more from the
            # date/time given in start parameter, and each with rota roles from
            # the template
            start = form.cleaned_data['start']
            for day_count in range(0, form.cleaned_data['number_of_days']):
                day_offset = datetime.timedelta(days=day_count)
                new_showing = Showing(
                    event=new_event,
                    start=(start + day_offset),
                    discounted=form.cleaned_data['discounted'],
                    confirmed=form.cleaned_data['confirmed'],
                    booked_by=form.cleaned_data['booked_by'],
                )
                if settings.MULTIROOM_ENABLED:
                    new_showing.room = form.cleaned_data['room']
                new_showing.save()
                # Set showing roles to those from its template:
                new_showing.reset_rota_to_default()

            messages.add_message(
                request, messages.SUCCESS,
                u"Added event '{0}' with showing on {1}".format(
                    new_event.name,
                    new_showing.start.strftime("%d/%m/%y at %H:%M")))
            return _return_to_editindex(request)
        else:
            # If form was not valid, re-render the form (which will highlight
            # errors)
            context = {'form': form}
            return render(request, 'form_new_event_and_showing.html', context)

    elif request.method == 'GET':
        # GET: Show form blank, with date filled in from GET date and start
        # parameters:
        # Marshal date and time out of the GET request:
        default_date = (django.utils.timezone.now().date() +
                        datetime.timedelta(1))
        date = request.GET.get('date', default_date.strftime("%d-%m-%Y"))
        date = date.split("-")

        # Default start time is 8pm (shouldn't this be a setting?)
        time = request.GET.get('time', "20:00")
        time = time.split(":")
        # Default duration is one hour:
        duration = request.GET.get('duration', "3600")

        room = request.GET.get('room', None)

        if len(time) != 2 or len(date) != 3:
            return HttpResponse("Invalid start date or time",
                                status=400,
                                content_type="text/plain")
        try:
            date = [int(n, 10) for n in date]
            time = [int(n, 10) for n in time]
            duration = datetime.timedelta(seconds=int(duration, 10))
            event_start = timezone.get_current_timezone().localize(
                datetime.datetime(hour=time[0],
                                  minute=time[1],
                                  day=date[0],
                                  month=date[1],
                                  year=date[2]))
            if settings.MULTIROOM_ENABLED and room:
                room = Room.objects.get(id=room)
        except (ValueError, TypeError, Room.DoesNotExist):
            return HttpResponse("Illegal time, date, duration or room",
                                status=400,
                                content_type="text/plain")

        # Create form, render template:
        form = diary_forms.NewEventForm(initial={
            'start': event_start,
            'duration': duration,
            'room': room,
        })
        context = {'form': form}
        return render(request, 'form_new_event_and_showing.html', context)
Ejemplo n.º 22
0
    def _setup_test_data(self):

        self._fake_now = pytz.timezone("Europe/London").localize(datetime(2013, 6, 1, 11, 00))

        # Roles:
        r1 = Role(name=u"Role 1 (standard)", read_only=False, standard=True)
        r1.save()
        r2 = Role(name=u"Role 2 (nonstandard)", read_only=False, standard=False)
        r2.save()
        r3 = Role(name=u"Role 3", read_only=False, standard=False)
        r3.save()

        # Tags:
        t1 = EventTag(name=u"tag one", slug=u"tag-one", read_only=False)
        t1.save()
        t2 = EventTag(name=u"tag two", slug=u"tag-two", read_only=False)
        t2.save()
        # 'ag-three' is what slugify() gives for that name:
        t3 = EventTag(name=u"\u0167ag \u0165hre\u0119", slug=u"ag-three", read_only=False)
        t3.save()

        """
        Event  outside_hire   private   Tags
        ---------------------------------------
        e1     True           False
        e2     False          False
        e3     False          False    t2
        e4     False          False    t2
        e5     False          True
        e6     True           True     t3

        Showing  Event  Date    Confirmed  Hidden  Cancelled  Discount|E: outside  private
        --------------------------------------------------------------|-------------------
        e2s1       e2    1/4/13   F          F       F          F     |   F        F
        e2s2       e2    2/4/13   T          F       F          F     |   F        F
        e2s3       e2    3/4/13   T          F       T          F     |   F        F
        e2s4       e2    4/4/13   T          T       F          F     |   F        F
        e2s5       e2    5/4/13   T          T       T          F     |   F        F

        s2       e3    13/4/13  T          F       F          F       |   F        F
        s3       e4    9/6/13   T          F       F          F       |   F        F
        s4       e4    14/9/13  F          F       F          F       |   F        F
        s5       e5    14/2/13  T          F       F          F       |   F        T
        s6       e1    15/2/13  T          T       F          F       |   F        F
        """

        # Events:
        e1 = Event(
            name="Event one title",
            copy="Event one copy",
            copy_summary="Event one copy summary",
            duration="01:30:00",
            outside_hire=True,
        )
        e1.save()

        e2 = Event(
            name="Event two title",
            copy="Event\n two\n copy",  # newlines will be stripped at legacy conversion
            copy_summary="Event two\n copy summary",
            duration="01:30:00",
            legacy_id="100",
            legacy_copy=True,
        )
        e2.save()

        e3 = Event(
            name="Event three title",
            copy="Event three Copy",
            copy_summary="Copy three summary",
            duration="03:00:00",
            notes="Notes",
        )
        e3.save()
        e3.tags = [t2, ]
        e3.save()

        e4 = Event(
            name=u"Event four titl\u0113",
            copy=u"Event four C\u014dpy",
            copy_summary=u"\u010copy four summary",
            terms=u"Terminal price: \u00a31 / \u20ac3",
            duration="01:00:00",
            notes="\u0147otes on event fou\u0159",
        )
        e4.save()
        e4.tags = [t2, ]
        e4.save()

        e5 = Event(
            name=u"PRIVATE Event FIVE titl\u0113!",
            copy=u"PRIVATE Event 5ive C\u014dpy",
            copy_summary=u"\u010copy five summary",
            terms=u"More terms; price: \u00a32 / \u20ac5",
            duration="10:00:00",
            notes="\u0147otes on event five",
            private=True
        )
        e5.save()

        e6 = Event(
            name=u"PRIVATE OUTSIDE Event (Six)",
            copy=u"PRIVATE OUTSIDE Event 6ix copy",
            copy_summary=u"OUTSIDE PRIVATE \u010copy six summary",
            terms=u"Ever More terms; price: \u00a32 / \u20ac5",
            duration="4:00:00",
            notes="\u0147otes on private/outwide event six",
            outside_hire=True,
            private=True
        )
        e6.save()
        e6.tags = [t3, ]
        e6.save()

        # Showings:
        self.e2s1 = Showing(  # pk :1
            start=pytz.timezone("Europe/London").localize(datetime(2013, 4, 1, 19, 00)),
            event=e2, booked_by="User",
            confirmed=False, hide_in_programme=False, cancelled=False, discounted=False)
        self.e2s1.save(force=True)
        self.e2s2 = Showing(  # pk :2
            start=pytz.timezone("Europe/London").localize(datetime(2013, 4, 2, 19, 00)),
            event=e2, booked_by="User",
            confirmed=True, hide_in_programme=False, cancelled=False, discounted=False)
        self.e2s2.save(force=True)
        e2s3 = Showing(  # pk :3
            start=pytz.timezone("Europe/London").localize(datetime(2013, 4, 3, 19, 00)),
            event=e2, booked_by="User",
            confirmed=True, hide_in_programme=False, cancelled=True, discounted=False)
        e2s3.save(force=True)
        e2s4 = Showing(  # pk :4
            start=pytz.timezone("Europe/London").localize(datetime(2013, 4, 4, 19, 00)),
            event=e2, booked_by="User",
            confirmed=True, hide_in_programme=True, cancelled=False, discounted=False)
        e2s4.save(force=True)
        e2s5 = Showing(  # pk :5
            start=pytz.timezone("Europe/London").localize(datetime(2013, 4, 5, 19, 00)),
            event=e2, booked_by="User",
            confirmed=True, hide_in_programme=True, cancelled=True, discounted=False)
        e2s5.save(force=True)

        s2 = Showing(
            start=pytz.timezone("Europe/London").localize(datetime(2013, 4, 13, 18, 00)),
            event=e3,
            booked_by="User Two",
            confirmed=True
        )
        s2.save(force=True)  # Force start date in the past

        # When the clock is patched to claim that it's 1/6/2013, this showing
        # will be in the future:
        self.e4s3 = Showing(
            start=pytz.timezone("Europe/London").localize(datetime(2013, 6, 9, 18, 00)),
            event=e4,
            booked_by=u"\u0102nother \u0170ser",
            confirmed=True
        )
        self.e4s3.save(force=True)  # Force start date in the past

        s4 = Showing(
            start=pytz.timezone("Europe/London").localize(datetime(2013, 9, 14, 18, 00)),
            event=e4,
            booked_by="User Two",
            hide_in_programme=True,
            confirmed=False
        )
        s4.save(force=True)  # Force start date in the past

        s5 = Showing(
            start=pytz.timezone("Europe/London").localize(datetime(2013, 2, 14, 18, 00)),
            event=e5,
            booked_by="Yet another user",
            confirmed=True,
        )
        s5.save(force=True)

        s6 = Showing(
            start=pytz.timezone("Europe/London").localize(datetime(2013, 2, 15, 18, 00)),
            event=e1,
            booked_by="Blah blah",
            confirmed=True,
            hide_in_programme=True,
        )
        s6.save(force=True)

        # Rota items:
        RotaEntry(showing=self.e2s1, role=r2, rank=1).save()
        RotaEntry(showing=self.e2s1, role=r3, rank=1).save()
        RotaEntry(showing=s2, role=r1, rank=1).save()
        RotaEntry(showing=s2, role=r1, rank=2).save()
        RotaEntry(showing=s2, role=r1, rank=3).save()
        RotaEntry(showing=s2, role=r1, rank=4).save()
        RotaEntry(showing=s2, role=r1, rank=5).save()
        RotaEntry(showing=s2, role=r1, rank=6).save()
        RotaEntry(showing=self.e4s3, role=r2, rank=1).save()

        # Ideas:
        i = DiaryIdea(
            ideas="April 2013 ideas",
            month=date(year=2013, month=4, day=1)
        )
        i.save()
        i = DiaryIdea(
            ideas="May 2013 ideas",
            month=date(year=2013, month=5, day=1)
        )
        i.save()

        # Templates:
        tmpl = EventTemplate(name="Template 1")
        tmpl.save()
        tmpl.roles = [r1]
        tmpl.tags = [t1]
        tmpl.save()

        tmpl = EventTemplate(name="Template 2")
        tmpl.save()
        tmpl.roles = [r2]
        tmpl.tags = [t2]
        tmpl.save()

        tmpl = EventTemplate(name="Template 3")
        tmpl.save()
        tmpl.roles = [r1, r2, r3]
        tmpl.save()

        # Members:
        m1 = Member(name="Member One", email="*****@*****.**", number="1",
                    postcode="BS1 1AA")
        m1.save()
        m2 = Member(name="Two Member", email="*****@*****.**", number="2",
                    postcode="")
        m2.save()
        m3 = Member(name="Volunteer One", email="*****@*****.**", number="3",
                    phone="0800 000 000", address="1 Road", posttown="Town",
                    postcode="BS6 123", country="UK", website="http://foo.test/")
        m3.save()
        m4 = Member(name="Volunteer Two", email="", number="4",
                    phone="", altphone="", address="", posttown="", postcode="",
                    country="", website="http://foo.test/")
        m4.save()
        m5 = Member(name="Volunteer Three", email="*****@*****.**", number="4",
                    phone="", altphone="", address="", posttown="", postcode="",
                    country="", website="")
        m5.save()

        # Volunteers:
        v1 = Volunteer(member=m3)
        v1.save()
        v1.roles = [r1, r3]
        v1.save()

        v2 = Volunteer(member=m4)
        v2.save()

        v3 = Volunteer(member=m5)
        v3.save()
        v3.roles = [r3]
        v3.save()

        # System user:
        user_rw = auth_models.User.objects.create_user('admin', 'toolkit_admin@localhost', 'T3stPassword!')
        # Create dummy ContentType:
        ct = contenttypes.models.ContentType.objects.get_or_create(
            model='',
            app_label='toolkit'
        )[0]
        # Create 'write' permission:
        write_permission = auth_models.Permission.objects.get_or_create(
            name='Write access to all toolkit content',
            content_type=ct,
            codename='write'
        )[0]
        # Give "admin" user the write permission:
        user_rw.user_permissions.add(write_permission)
Ejemplo n.º 23
0
def add_event(request):
    # Called GET, with a "date" parameter of the form day-month-year:
    #     returns 'form_new_event_and_showing' with given date filled in.
    # Called POST, with various data in request:
    #     creates new event, and number_of_showings, calls return_to_editindex
    #

    if request.method == 'POST':
        # Get event data, plus template and showing time and number of showing
        # days from form. Uses template to set rota roles and tags.
        form = diary_forms.NewEventForm(request.POST)
        if form.is_valid():
            new_event = Event(
                name=form.cleaned_data['event_name'],
                template=form.cleaned_data['event_template'],
                duration=form.cleaned_data['duration'],
                outside_hire=form.cleaned_data['outside_hire'],
                private=form.cleaned_data['private'])
            # Set event tags to those from its template:
            new_event.save()
            new_event.reset_tags_to_default()
            # create number_of_days showings, each offset by one more from the
            # date/time given in start parameter, and each with rota roles from
            # the template
            start = form.cleaned_data['start']
            for day_count in range(0, form.cleaned_data['number_of_days']):
                day_offset = datetime.timedelta(days=day_count)
                new_showing = Showing(
                    event=new_event,
                    start=(start + day_offset),
                    discounted=form.cleaned_data['discounted'],
                    confirmed=form.cleaned_data['confirmed'],
                    booked_by=form.cleaned_data['booked_by'],
                )
                new_showing.save()
                # Set showing roles to those from its template:
                new_showing.reset_rota_to_default()

            messages.add_message(
                request, messages.SUCCESS,
                u"Added event '{0}' with showing on {1}".format(
                    new_event.name,
                    new_showing.start.strftime("%d/%m/%y at %H:%M")))
            return _return_to_editindex(request)
        else:
            # If form was not valid, re-render the form (which will highlight
            # errors)
            context = {'form': form}
            return render(request, 'form_new_event_and_showing.html', context)

    elif request.method == 'GET':
        # GET: Show form blank, with date filled in from GET date parameter:
        # Marshal date out of the GET request:
        default_date = django.utils.timezone.now().date() + datetime.timedelta(
            1)
        date = request.GET.get('date', default_date.strftime("%d-%m-%Y"))
        date = date.split("-")
        if len(date) != 3:
            return HttpResponse(
                "Invalid start date", status=400, content_type="text/plain")
        try:
            date[0] = int(date[0], 10)
            date[1] = int(date[1], 10)
            date[2] = int(date[2], 10)
            event_start = timezone.get_current_timezone().localize(
                datetime.datetime(
                    hour=20,
                    minute=0,
                    day=date[0],
                    month=date[1],
                    year=date[2]))
        except (ValueError, TypeError):
            return HttpResponse(
                "Illegal date", status=400, content_type="text/plain")
        # Create form, render template:
        form = diary_forms.NewEventForm(initial={'start': event_start})
        context = {'form': form}
        return render(request, 'form_new_event_and_showing.html', context)
Ejemplo n.º 24
0
class DiaryTestsMixin(object):

    def setUp(self):
        self._setup_test_data()
        self._setup_test_users()

        return super(DiaryTestsMixin, self).setUp()

    # Useful method:
    def assert_return_to_index(self, response):
        # Check status=200 and expected text included:
        self.assertContains(
            response,
            "<!DOCTYPE html><html>"
            "<head><title>-</title></head>"
            "<body onload='self.close(); opener.location.reload(true);'>Ok</body>"
            "</html>"
        )

    def assert_has_message(self, response, msg, level):
        self.assertContains(
            response,
            u'<li class="{0}">{1}</li>'.format(level, msg)
        )

    def _setup_test_data(self):

        self._fake_now = pytz.timezone("Europe/London").localize(datetime(2013, 6, 1, 11, 00))

        # Roles:
        r1 = Role(name=u"Role 1 (standard)", read_only=False, standard=True)
        r1.save()
        r2 = Role(name=u"Role 2 (nonstandard)", read_only=False, standard=False)
        r2.save()
        r3 = Role(name=u"Role 3", read_only=False, standard=False)
        r3.save()

        # Tags:
        t1 = EventTag(name=u"tag one", slug=u"tag-one", read_only=False)
        t1.save()
        t2 = EventTag(name=u"tag two", slug=u"tag-two", read_only=False)
        t2.save()
        # 'ag-three' is what slugify() gives for that name:
        t3 = EventTag(name=u"\u0167ag \u0165hre\u0119", slug=u"ag-three", read_only=False)
        t3.save()

        """
        Event  outside_hire   private   Tags
        ---------------------------------------
        e1     True           False
        e2     False          False
        e3     False          False    t2
        e4     False          False    t2
        e5     False          True
        e6     True           True     t3

        Showing  Event  Date    Confirmed  Hidden  Cancelled  Discount|E: outside  private
        --------------------------------------------------------------|-------------------
        e2s1       e2    1/4/13   F          F       F          F     |   F        F
        e2s2       e2    2/4/13   T          F       F          F     |   F        F
        e2s3       e2    3/4/13   T          F       T          F     |   F        F
        e2s4       e2    4/4/13   T          T       F          F     |   F        F
        e2s5       e2    5/4/13   T          T       T          F     |   F        F

        s2       e3    13/4/13  T          F       F          F       |   F        F
        s3       e4    9/6/13   T          F       F          F       |   F        F
        s4       e4    14/9/13  F          F       F          F       |   F        F
        s5       e5    14/2/13  T          F       F          F       |   F        T
        s6       e1    15/2/13  T          T       F          F       |   F        F
        """

        # Events:
        e1 = Event(
            name="Event one title",
            pricing="PRICING_ONE",
            copy="Event one copy",
            pre_title="PRETITLE One",
            post_title="POSTTITLE One",
            film_information="FILM_INFO_One",
            copy_summary="Event one copy summary",
            duration="01:30:00",
            outside_hire=True,
        )
        e1.save()

        self.e2 = Event(
            name="Event two title",
            copy="Event\n two\n copy",  # newlines will be stripped at legacy conversion
            pricing="Pricing TWO",
            copy_summary="Event two\n copy summary",
            duration="01:30:00",
            legacy_id="100",
            legacy_copy=True,
        )
        self.e2.save()

        e3 = Event(
            name="Event three title",
            pricing="Pricing THREE",
            copy="Event three Copy",
            pre_title="PRETITLE THREE",
            post_title="POSTTITLE THREE",
            film_information="FILM_INFO_THREE",
            copy_summary="Copy three summary",
            duration="03:00:00",
            notes="Notes",
        )
        e3.save()
        e3.tags = [t2, ]
        e3.save()

        e4 = Event(
            name=u"Event four titl\u0113",
            copy=u"Event four C\u014dpy",
            pricing=u"\u00a3milliion per thing",
            pre_title=u"Pretitle four",
            post_title=u"Posttitle four",
            film_information=u"Film info for four",
            copy_summary=u"\u010copy four summary",
            terms=u"Terminal price: \u00a31 / \u20ac3",
            duration="01:00:00",
            notes="\u0147otes on event fou\u0159",
        )
        e4.save()
        e4.tags = [t2, ]
        e4.save()

        e5 = Event(
            name=u"PRIVATE Event FIVE titl\u0113!",
            copy=u"PRIVATE Event 5ive C\u014dpy",
            copy_summary=u"\u010copy five summary",
            terms=u"More terms; price: \u00a32 / \u20ac5",
            duration="10:00:00",
            notes="\u0147otes on event five",
            private=True
        )
        e5.save()

        e6 = Event(
            name=u"PRIVATE OUTSIDE Event (Six)",
            copy=u"PRIVATE OUTSIDE Event 6ix copy",
            copy_summary=u"OUTSIDE PRIVATE \u010copy six summary",
            terms=u"Ever More terms; price: \u00a32 / \u20ac5",
            duration="4:00:00",
            notes="\u0147otes on private/outwide event six",
            outside_hire=True,
            private=True
        )
        e6.save()
        e6.tags = [t3, ]
        e6.save()

        # Showings:
        self.e2s1 = Showing(  # pk :1
            start=pytz.timezone("Europe/London").localize(datetime(2013, 4, 1, 19, 00)),
            event=self.e2, booked_by="User",
            confirmed=False, hide_in_programme=False, cancelled=False, discounted=False)
        self.e2s1.save(force=True)
        self.e2s2 = Showing(  # pk :2
            start=pytz.timezone("Europe/London").localize(datetime(2013, 4, 2, 19, 00)),
            event=self.e2, booked_by="User",
            confirmed=True, hide_in_programme=False, cancelled=False, discounted=False)
        self.e2s2.save(force=True)
        e2s3 = Showing(  # pk :3
            start=pytz.timezone("Europe/London").localize(datetime(2013, 4, 3, 19, 00)),
            event=self.e2, booked_by="User",
            confirmed=True, hide_in_programme=False, cancelled=True, discounted=False)
        e2s3.save(force=True)
        e2s4 = Showing(  # pk :4
            start=pytz.timezone("Europe/London").localize(datetime(2013, 4, 4, 19, 00)),
            event=self.e2, booked_by="User",
            confirmed=True, hide_in_programme=True, cancelled=False, discounted=False)
        e2s4.save(force=True)
        e2s5 = Showing(  # pk :5
            start=pytz.timezone("Europe/London").localize(datetime(2013, 4, 5, 19, 00)),
            event=self.e2, booked_by="User",
            confirmed=True, hide_in_programme=True, cancelled=True, discounted=False)
        e2s5.save(force=True)

        s2 = Showing(
            start=pytz.timezone("Europe/London").localize(datetime(2013, 4, 13, 18, 00)),
            event=e3,
            booked_by="User Two",
            confirmed=True
        )
        s2.save(force=True)  # Force start date in the past

        # When the clock is patched to claim that it's 1/6/2013, this showing
        # will be in the future:
        self.e4s3 = Showing(
            start=pytz.timezone("Europe/London").localize(datetime(2013, 6, 9, 18, 00)),
            event=e4,
            booked_by=u"\u0102nother \u0170ser",
            confirmed=True,
            rota_notes="Some notes about the Rota!",
        )
        self.e4s3.save(force=True)  # Force start date in the past

        s4 = Showing(
            start=pytz.timezone("Europe/London").localize(datetime(2013, 9, 14, 18, 00)),
            event=e4,
            booked_by="User Two",
            hide_in_programme=True,
            confirmed=False
        )
        s4.save(force=True)  # Force start date in the past

        s5 = Showing(
            start=pytz.timezone("Europe/London").localize(datetime(2013, 2, 14, 18, 00)),
            event=e5,
            booked_by="Yet another user",
            confirmed=True,
        )
        s5.save(force=True)

        s6 = Showing(
            start=pytz.timezone("Europe/London").localize(datetime(2013, 2, 15, 18, 00)),
            event=e1,
            booked_by="Blah blah",
            confirmed=True,
            hide_in_programme=True,
        )
        s6.save(force=True)

        # Rota items:
        RotaEntry(showing=self.e2s1, role=r2, rank=1).save()
        RotaEntry(showing=self.e2s1, role=r3, rank=1).save()
        RotaEntry(showing=s2, role=r1, rank=1).save()
        RotaEntry(showing=s2, role=r1, rank=2).save()
        RotaEntry(showing=s2, role=r1, rank=3).save()
        RotaEntry(showing=s2, role=r1, rank=4).save()
        RotaEntry(showing=s2, role=r1, rank=5).save()
        RotaEntry(showing=s2, role=r1, rank=6).save()
        RotaEntry(showing=self.e4s3, role=r2, rank=1).save()

        # Ideas:
        i = DiaryIdea(
            ideas="April 2013 ideas",
            month=date(year=2013, month=4, day=1)
        )
        i.save()
        i = DiaryIdea(
            ideas="May 2013 ideas",
            month=date(year=2013, month=5, day=1)
        )
        i.save()

        # Templates:
        # One role, one tag, pricing
        self.tmpl1 = EventTemplate(name="Template 1")
        self.tmpl1.save()
        self.tmpl1.roles = [r1]
        self.tmpl1.tags = [t1]
        self.tmpl1.pricing = u"Entry: \u00a35 / \u20ac10"
        self.tmpl1.save()

        # Two roles, two tags
        self.tmpl2 = EventTemplate(name="Template 2")
        self.tmpl2.save()
        self.tmpl2.roles = [r1, r2]
        self.tmpl2.tags = [t1, t3]
        self.tmpl2.save()

        # No roles, no tags, no pricing
        self.tmpl3 = EventTemplate(name="Template 3")
        self.tmpl3.save()

        # Members:
        m1 = Member(name="Member One", email="*****@*****.**", number="1",
                    postcode="BS1 1AA")
        m1.save()
        m2 = Member(name="Two Member", email="*****@*****.**", number="2",
                    postcode="")
        m2.save()
        m3 = Member(name="Volunteer One", email="*****@*****.**", number="3",
                    phone="0800 000 000", address="1 Road", posttown="Town",
                    postcode="BS6 123", country="UK", website="http://foo.test/")
        m3.save()
        m4 = Member(name="Volunteer Two", email="", number="4",
                    phone="", altphone="", address="", posttown="", postcode="",
                    country="", website="http://foo.test/")
        m4.save()
        m5 = Member(name="Volunteer Three", email="*****@*****.**", number="4",
                    phone="", altphone="", address="", posttown="", postcode="",
                    country="", website="")
        m5.save()

        # Volunteers:
        v1 = Volunteer(member=m3)
        v1.save()
        v1.roles = [r1, r3]
        v1.save()

        v2 = Volunteer(member=m4)
        v2.save()

        v3 = Volunteer(member=m5)
        v3.save()
        v3.roles = [r3]
        v3.save()

    def _setup_test_users(self):
        # Read/write user:
        user_rw = auth_models.User.objects.create_user('admin', 'toolkit_admin@localhost', 'T3stPassword!')
        # read only user:
        user_r = auth_models.User.objects.create_user('read_only', 'toolkit_admin@localhost', 'T3stPassword!1')
        # no permission user:
        auth_models.User.objects.create_user('no_perm', 'toolkit_admin@localhost', 'T3stPassword!2')
        # rota edit only user:
        user_rota = auth_models.User.objects.create_user('rota_editor', 'toolkit_admin@localhost', 'T3stPassword!3')

        # Create dummy ContentType:
        ct = contenttypes.models.ContentType.objects.get_or_create(
            model='',
            app_label='toolkit'
        )[0]
        # Create 'read' and 'write' permissions:
        write_permission = auth_models.Permission.objects.get_or_create(
            name='Write access to all toolkit content',
            content_type=ct,
            codename='write'
        )[0]

        read_permission = auth_models.Permission.objects.get_or_create(
            name='Read access to all toolkit content',
            content_type=ct,
            codename='read'
        )[0]

        # retrieve permission for editing diary.models.RotaEntry rows:
        diary_content_type = contenttypes.models.ContentType.objects.get(
            app_label='diary',
            model='rotaentry',
        )

        edit_rota_permission = auth_models.Permission.objects.get(
            codename='change_rotaentry',
            content_type=diary_content_type
        )

        # Set user permissions, r/w:
        user_rw.user_permissions.add(write_permission)
        user_rw.user_permissions.add(read_permission)
        # read only:
        user_r.user_permissions.add(read_permission)
        # rota_editor:
        user_rota.user_permissions.add(edit_rota_permission)
Ejemplo n.º 25
0
    def _setup_test_data(self):

        self._fake_now = pytz.timezone(
            "Europe/London").localize(datetime(2013, 6, 1, 11, 00))

        # Roles:
        r1 = Role(name=u"Role 1 (standard)", read_only=False, standard=True)
        r1.save()
        r2 = Role(name=u"Role 2 (nonstandard)",
                  read_only=False, standard=False)
        r2.save()
        r3 = Role(name=u"Role 3", read_only=False, standard=False)
        r3.save()

        # Tags:
        t1 = EventTag(name=u"tag one", slug=u"tag-one", read_only=False)
        t1.save()
        t2 = EventTag(name=u"tag two", slug=u"tag-two",
                      promoted=True, sort_order=2, read_only=False)
        t2.save()
        # 'ag-three' is what slugify() gives for that name:
        t3 = EventTag(name=u"tag three",
                      slug=u"tag-three", sort_order=1, promoted=True,
                      read_only=False)
        t3.save()

        Room(name="Room one", colour="#Ff0000").save()
        self.room_2 = Room(name="Room two", colour="#00abcd")
        self.room_2.save()

        # Event  outside_hire   private   Tags
        # ---------------------------------------
        # e1     True           False
        # e2     False          False
        # e3     False          False    t2
        # e4     False          False    t2
        # e5     False          True
        # e6     True           True     t3

        # Showing Event  Date    Confirmed  Hiddn  Cnclld  Dscnt|E: oside pvate
        # ------------------------------------------------------|--------------
        # e2s1    e2    1/4/13   F          F      F      F     |   F      F
        # e2s2    e2    2/4/13   T          F      F      F     |   F      F
        # e2s3    e2    3/4/13   T          F      T      F     |   F      F
        # e2s4    e2    4/4/13   T          T      F      F     |   F      F
        # e2s5    e2    5/4/13   T          T      T      F     |   F      F

        # s2      e3    13/4/13  T          F      F      F     |   F      F
        # s3      e4    9/6/13   T          F      F      F     |   F      F
        # s4      e4    14/9/13  F          F      F      F     |   F      F
        # s5      e5    14/2/13  T          F      F      F     |   F      T
        # s6      e1    15/2/13  T          T      F      F     |   F      F

        # Events:
        e1 = Event(
            name="Event one title",
            pricing="PRICING_ONE",
            copy="Event one copy",
            pre_title="PRETITLE One",
            post_title="POSTTITLE One",
            film_information="FILM_INFO_One",
            copy_summary="Event one copy summary",
            duration="01:30:00",
            outside_hire=True,
        )
        e1.save()

        self.e2 = Event(
            name="Event two title",
            # newlines will be stripped at legacy conversion:
            copy="Event\n two\n copy",
            pricing="Pricing TWO",
            copy_summary="Event two\n copy summary",
            duration="01:30:00",
            legacy_id="100",
            legacy_copy=True,
        )
        self.e2.save()

        e3 = Event(
            name="Event three title",
            pricing="Pricing THREE",
            copy="Event three Copy",
            pre_title="PRETITLE THREE",
            post_title="POSTTITLE THREE",
            film_information="FILM_INFO_THREE",
            copy_summary="Copy three summary",
            duration="03:00:00",
            notes="Notes",
        )
        e3.save()
        e3.tags.set([t2, ])
        e3.save()

        e4 = Event(
            name=u"Event four titl\u0113",
            copy=u"Event four C\u014dpy",
            pricing=u"\u00a3milliion per thing",
            pre_title=u"Pretitle four",
            post_title=u"Posttitle four",
            film_information=u"Film info for four",
            copy_summary=u"\u010copy four summary",
            terms=u"Terminal price: \u00a31 / \u20ac3",
            duration="01:00:00",
            notes=u"\u0147otes on event fou\u0159",
        )
        e4.save()
        e4.tags.set([t2, ])
        e4.save()

        e5 = Event(
            name=u"PRIVATE Event FIVE titl\u0113!",
            copy=u"PRIVATE Event 5ive C\u014dpy",
            copy_summary=u"\u010copy five summary",
            terms=u"More terms; price: \u00a32 / \u20ac5",
            duration="10:00:00",
            notes=u"\u0147otes on event five",
            private=True
        )
        e5.save()

        e6 = Event(
            name=u"PRIVATE OUTSIDE Event (Six)",
            copy=u"PRIVATE OUTSIDE Event 6ix copy",
            copy_summary=u"OUTSIDE PRIVATE \u010copy six summary",
            terms=u"Ever More terms; price: \u00a32 / \u20ac5",
            duration="4:00:00",
            notes=u"\u0147otes on private/outwide event six",
            outside_hire=True,
            private=True
        )
        e6.save()
        e6.tags.set([t3, ])
        e6.save()

        # Showings:
        self.e2s1 = Showing(  # pk :1
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 4, 1, 19, 00)),
            event=self.e2, booked_by="User",
            confirmed=False, hide_in_programme=False,
            cancelled=False, discounted=False)
        self.e2s1.save(force=True)
        self.e2s2 = Showing(  # pk :2
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 4, 2, 19, 00)),
            event=self.e2, booked_by="User",
            confirmed=True, hide_in_programme=False,
            cancelled=False, discounted=False)
        self.e2s2.save(force=True)
        e2s3 = Showing(  # pk :3
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 4, 3, 19, 00)),
            event=self.e2, booked_by="User",
            confirmed=True, hide_in_programme=False,
            cancelled=True, discounted=False)
        e2s3.save(force=True)
        e2s4 = Showing(  # pk :4
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 4, 4, 19, 00)),
            event=self.e2, booked_by="User",
            confirmed=True, hide_in_programme=True,
            cancelled=False, discounted=False)
        e2s4.save(force=True)
        e2s5 = Showing(  # pk :5
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 4, 5, 19, 00)),
            event=self.e2, booked_by="User",
            confirmed=True, hide_in_programme=True,
            cancelled=True, discounted=False)
        e2s5.save(force=True)

        s2 = Showing(
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 4, 13, 18, 00)),
            event=e3,
            booked_by="User Two",
            confirmed=True
        )
        s2.save(force=True)  # Force start date in the past

        # When the clock is patched to claim that it's 1/6/2013, this showing
        # will be in the future:
        self.e4s3 = Showing(
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 6, 9, 18, 00)),
            event=e4,
            booked_by=u"\u0102nother \u0170ser",
            confirmed=True,
            rota_notes="Some notes about the Rota!",
        )
        self.e4s3.save(force=True)  # Force start date in the past

        s4 = Showing(
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 9, 14, 18, 00)),
            event=e4,
            booked_by="User Two",
            hide_in_programme=True,
            confirmed=False
        )
        s4.save(force=True)  # Force start date in the past

        s5 = Showing(
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 2, 14, 18, 00)),
            event=e5,
            booked_by="Yet another user",
            confirmed=True,
        )
        s5.save(force=True)

        s6 = Showing(
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 2, 15, 18, 00)),
            event=e1,
            booked_by="Blah blah",
            confirmed=True,
            hide_in_programme=True,
        )
        s6.save(force=True)

        # Rota items:
        RotaEntry(showing=self.e2s1, role=r2, rank=1).save()
        RotaEntry(showing=self.e2s1, role=r3, rank=1).save()
        RotaEntry(showing=s2, role=r1, rank=1).save()
        RotaEntry(showing=s2, role=r1, rank=2).save()
        RotaEntry(showing=s2, role=r1, rank=3).save()
        RotaEntry(showing=s2, role=r1, rank=4).save()
        RotaEntry(showing=s2, role=r1, rank=5).save()
        RotaEntry(showing=s2, role=r1, rank=6).save()
        RotaEntry(showing=self.e4s3, role=r2, rank=1).save()

        # Ideas:
        i = DiaryIdea(
            ideas="April 2013 ideas",
            month=date(year=2013, month=4, day=1)
        )
        i.save()
        i = DiaryIdea(
            ideas="May 2013 ideas",
            month=date(year=2013, month=5, day=1)
        )
        i.save()

        # Templates:
        # One role, one tag, pricing
        self.tmpl1 = EventTemplate(name="Template 1")
        self.tmpl1.save()
        self.tmpl1.roles.set([r1])
        self.tmpl1.tags.set([t1])
        self.tmpl1.pricing = u"Entry: \u00a35 / \u20ac10"
        self.tmpl1.save()

        # Two roles, two tags
        self.tmpl2 = EventTemplate(name="Template 2")
        self.tmpl2.save()
        self.tmpl2.roles.set([r1, r2])
        self.tmpl2.tags.set([t1, t3])
        self.tmpl2.save()

        # No roles, no tags, no pricing
        self.tmpl3 = EventTemplate(name="Template 3")
        self.tmpl3.save()

        # Members:
        m1 = Member(name="Member One", email="*****@*****.**", number="1",
                    postcode="BS1 1AA")
        m1.save()
        m2 = Member(name="Two Member", email="*****@*****.**", number="2",
                    postcode="")
        m2.save()
        m3 = Member(name="Volunteer One", email="*****@*****.**", number="3",
                    phone="0800 000 000", address="1 Road", posttown="Town",
                    postcode="BS6 123", country="UK",
                    website="http://foo.test/")
        m3.save()
        m4 = Member(name="Volunteer Two", email="", number="4",
                    phone="", altphone="", address="", posttown="",
                    postcode="", country="", website="http://foo.test/")
        m4.save()
        m5 = Member(name="Volunteer Three", email="*****@*****.**",
                    number="4", phone="", altphone="", address="", posttown="",
                    postcode="", country="", website="")
        m5.save()

        # Volunteers:
        v1 = Volunteer(member=m3)
        v1.save()
        v1.roles.set([r1, r3])
        v1.save()

        v2 = Volunteer(member=m4)
        v2.save()

        v3 = Volunteer(member=m5)
        v3.save()
        v3.roles.set([r3])
        v3.save()
Ejemplo n.º 26
0
    def _setup_test_data(self):

        self._fake_now = pytz.timezone(
            "Europe/London").localize(datetime(2013, 6, 1, 11, 00))

        # Roles:
        r1 = Role(name=u"Role 1 (standard)", read_only=False, standard=True)
        r1.save()
        r2 = Role(name=u"Role 2 (nonstandard)",
                  read_only=False, standard=False)
        r2.save()
        r3 = Role(name=u"Role 3", read_only=False, standard=False)
        r3.save()

        # Tags:
        t1 = EventTag(name=u"tag one", slug=u"tag-one", read_only=False)
        t1.save()
        t2 = EventTag(name=u"tag two", slug=u"tag-two",
                      promoted=True, sort_order=2, read_only=False)
        t2.save()
        # 'ag-three' is what slugify() gives for that name:
        t3 = EventTag(name=u"\u0167ag \u0165hre\u0119",
                      slug=u"ag-three", sort_order=1, promoted=True,
                      read_only=False)
        t3.save()

        Room(name="Room one", colour="#Ff0000").save()
        self.room_2 = Room(name="Room two", colour="#00abcd")
        self.room_2.save()

        # Event  outside_hire   private   Tags
        # ---------------------------------------
        # e1     True           False
        # e2     False          False
        # e3     False          False    t2
        # e4     False          False    t2
        # e5     False          True
        # e6     True           True     t3

        # Showing Event  Date    Confirmed  Hiddn  Cnclld  Dscnt|E: oside pvate
        # ------------------------------------------------------|--------------
        # e2s1    e2    1/4/13   F          F      F      F     |   F      F
        # e2s2    e2    2/4/13   T          F      F      F     |   F      F
        # e2s3    e2    3/4/13   T          F      T      F     |   F      F
        # e2s4    e2    4/4/13   T          T      F      F     |   F      F
        # e2s5    e2    5/4/13   T          T      T      F     |   F      F

        # s2      e3    13/4/13  T          F      F      F     |   F      F
        # s3      e4    9/6/13   T          F      F      F     |   F      F
        # s4      e4    14/9/13  F          F      F      F     |   F      F
        # s5      e5    14/2/13  T          F      F      F     |   F      T
        # s6      e1    15/2/13  T          T      F      F     |   F      F

        # Events:
        e1 = Event(
            name="Event one title",
            pricing="PRICING_ONE",
            copy="Event one copy",
            pre_title="PRETITLE One",
            post_title="POSTTITLE One",
            film_information="FILM_INFO_One",
            copy_summary="Event one copy summary",
            duration="01:30:00",
            outside_hire=True,
        )
        e1.save()

        self.e2 = Event(
            name="Event two title",
            # newlines will be stripped at legacy conversion:
            copy="Event\n two\n copy",
            pricing="Pricing TWO",
            copy_summary="Event two\n copy summary",
            duration="01:30:00",
            legacy_id="100",
            legacy_copy=True,
        )
        self.e2.save()

        e3 = Event(
            name="Event three title",
            pricing="Pricing THREE",
            copy="Event three Copy",
            pre_title="PRETITLE THREE",
            post_title="POSTTITLE THREE",
            film_information="FILM_INFO_THREE",
            copy_summary="Copy three summary",
            duration="03:00:00",
            notes="Notes",
        )
        e3.save()
        e3.tags.set([t2, ])
        e3.save()

        e4 = Event(
            name=u"Event four titl\u0113",
            copy=u"Event four C\u014dpy",
            pricing=u"\u00a3milliion per thing",
            pre_title=u"Pretitle four",
            post_title=u"Posttitle four",
            film_information=u"Film info for four",
            copy_summary=u"\u010copy four summary",
            terms=u"Terminal price: \u00a31 / \u20ac3",
            duration="01:00:00",
            notes=u"\u0147otes on event fou\u0159",
        )
        e4.save()
        e4.tags.set([t2, ])
        e4.save()

        e5 = Event(
            name=u"PRIVATE Event FIVE titl\u0113!",
            copy=u"PRIVATE Event 5ive C\u014dpy",
            copy_summary=u"\u010copy five summary",
            terms=u"More terms; price: \u00a32 / \u20ac5",
            duration="10:00:00",
            notes=u"\u0147otes on event five",
            private=True
        )
        e5.save()

        e6 = Event(
            name=u"PRIVATE OUTSIDE Event (Six)",
            copy=u"PRIVATE OUTSIDE Event 6ix copy",
            copy_summary=u"OUTSIDE PRIVATE \u010copy six summary",
            terms=u"Ever More terms; price: \u00a32 / \u20ac5",
            duration="4:00:00",
            notes=u"\u0147otes on private/outwide event six",
            outside_hire=True,
            private=True
        )
        e6.save()
        e6.tags.set([t3, ])
        e6.save()

        # Showings:
        self.e2s1 = Showing(  # pk :1
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 4, 1, 19, 00)),
            event=self.e2, booked_by="User",
            confirmed=False, hide_in_programme=False,
            cancelled=False, discounted=False)
        self.e2s1.save(force=True)
        self.e2s2 = Showing(  # pk :2
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 4, 2, 19, 00)),
            event=self.e2, booked_by="User",
            confirmed=True, hide_in_programme=False,
            cancelled=False, discounted=False)
        self.e2s2.save(force=True)
        e2s3 = Showing(  # pk :3
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 4, 3, 19, 00)),
            event=self.e2, booked_by="User",
            confirmed=True, hide_in_programme=False,
            cancelled=True, discounted=False)
        e2s3.save(force=True)
        e2s4 = Showing(  # pk :4
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 4, 4, 19, 00)),
            event=self.e2, booked_by="User",
            confirmed=True, hide_in_programme=True,
            cancelled=False, discounted=False)
        e2s4.save(force=True)
        e2s5 = Showing(  # pk :5
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 4, 5, 19, 00)),
            event=self.e2, booked_by="User",
            confirmed=True, hide_in_programme=True,
            cancelled=True, discounted=False)
        e2s5.save(force=True)

        s2 = Showing(
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 4, 13, 18, 00)),
            event=e3,
            booked_by="User Two",
            confirmed=True
        )
        s2.save(force=True)  # Force start date in the past

        # When the clock is patched to claim that it's 1/6/2013, this showing
        # will be in the future:
        self.e4s3 = Showing(
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 6, 9, 18, 00)),
            event=e4,
            booked_by=u"\u0102nother \u0170ser",
            confirmed=True,
            rota_notes="Some notes about the Rota!",
        )
        self.e4s3.save(force=True)  # Force start date in the past

        s4 = Showing(
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 9, 14, 18, 00)),
            event=e4,
            booked_by="User Two",
            hide_in_programme=True,
            confirmed=False
        )
        s4.save(force=True)  # Force start date in the past

        s5 = Showing(
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 2, 14, 18, 00)),
            event=e5,
            booked_by="Yet another user",
            confirmed=True,
        )
        s5.save(force=True)

        s6 = Showing(
            start=pytz.timezone(
                "Europe/London").localize(datetime(2013, 2, 15, 18, 00)),
            event=e1,
            booked_by="Blah blah",
            confirmed=True,
            hide_in_programme=True,
        )
        s6.save(force=True)

        # Rota items:
        RotaEntry(showing=self.e2s1, role=r2, rank=1).save()
        RotaEntry(showing=self.e2s1, role=r3, rank=1).save()
        RotaEntry(showing=s2, role=r1, rank=1).save()
        RotaEntry(showing=s2, role=r1, rank=2).save()
        RotaEntry(showing=s2, role=r1, rank=3).save()
        RotaEntry(showing=s2, role=r1, rank=4).save()
        RotaEntry(showing=s2, role=r1, rank=5).save()
        RotaEntry(showing=s2, role=r1, rank=6).save()
        RotaEntry(showing=self.e4s3, role=r2, rank=1).save()

        # Ideas:
        i = DiaryIdea(
            ideas="April 2013 ideas",
            month=date(year=2013, month=4, day=1)
        )
        i.save()
        i = DiaryIdea(
            ideas="May 2013 ideas",
            month=date(year=2013, month=5, day=1)
        )
        i.save()

        # Templates:
        # One role, one tag, pricing
        self.tmpl1 = EventTemplate(name="Template 1")
        self.tmpl1.save()
        self.tmpl1.roles.set([r1])
        self.tmpl1.tags.set([t1])
        self.tmpl1.pricing = u"Entry: \u00a35 / \u20ac10"
        self.tmpl1.save()

        # Two roles, two tags
        self.tmpl2 = EventTemplate(name="Template 2")
        self.tmpl2.save()
        self.tmpl2.roles.set([r1, r2])
        self.tmpl2.tags.set([t1, t3])
        self.tmpl2.save()

        # No roles, no tags, no pricing
        self.tmpl3 = EventTemplate(name="Template 3")
        self.tmpl3.save()

        # Members:
        m1 = Member(name="Member One", email="*****@*****.**", number="1",
                    postcode="BS1 1AA")
        m1.save()
        m2 = Member(name="Two Member", email="*****@*****.**", number="2",
                    postcode="")
        m2.save()
        m3 = Member(name="Volunteer One", email="*****@*****.**", number="3",
                    phone="0800 000 000", address="1 Road", posttown="Town",
                    postcode="BS6 123", country="UK",
                    website="http://foo.test/")
        m3.save()
        m4 = Member(name="Volunteer Two", email="", number="4",
                    phone="", altphone="", address="", posttown="",
                    postcode="", country="", website="http://foo.test/")
        m4.save()
        m5 = Member(name="Volunteer Three", email="*****@*****.**",
                    number="4", phone="", altphone="", address="", posttown="",
                    postcode="", country="", website="")
        m5.save()

        # Volunteers:
        v1 = Volunteer(member=m3)
        v1.save()
        v1.roles.set([r1, r3])
        v1.save()

        v2 = Volunteer(member=m4)
        v2.save()

        v3 = Volunteer(member=m5)
        v3.save()
        v3.roles.set([r3])
        v3.save()
Ejemplo n.º 27
0
def add_event(request):
    # Called GET, with a "date" parameter of the form day-month-year:
    #     returns 'form_new_event_and_showing' with given date filled in.
    # Called POST, with various data in request:
    #     creates new event, and number_of_showings, calls return_to_editindex
    #

    if request.method == 'POST':
        # Get event data, plus template and showing time and number of showing
        # days from form. Uses template to set rota roles and tags.
        form = diary_forms.NewEventForm(request.POST)
        if form.is_valid():
            # Event constructor will pull things from the template as
            # appropriate (excluding many/many relation which can only be set
            # after saving)
            new_event = Event(name=form.cleaned_data['event_name'],
                              template=form.cleaned_data['event_template'],
                              duration=form.cleaned_data['duration'],
                              outside_hire=form.cleaned_data['outside_hire'],
                              private=form.cleaned_data['private'])
            # Set event tags to those from its template:
            new_event.save()
            new_event.reset_tags_to_default()
            # create number_of_days showings, each offset by one more from the
            # date/time given in start parameter, and each with rota roles from
            # the template
            start = form.cleaned_data['start']
            for day_count in range(0, form.cleaned_data['number_of_days']):
                day_offset = datetime.timedelta(days=day_count)
                new_showing = Showing(
                        event=new_event,
                        start=(start + day_offset),
                        discounted=form.cleaned_data['discounted'],
                        # confirmed=form.cleaned_data['confirmed'],
                        booked_by=form.cleaned_data['booked_by'],
                        )
                if settings.MULTIROOM_ENABLED:
                    new_showing.room = form.cleaned_data['room']
                new_showing.save()
                # Set showing roles to those from its template:
                new_showing.reset_rota_to_default()

            messages.add_message(
                request, messages.SUCCESS,
                u"Added event '{0}' with showing on {1}"
                .format(
                    new_event.name,
                    new_showing.start.strftime("%d/%m/%y at %H:%M")
                )
            )
            return _return_to_editindex(request)
        else:
            # If form was not valid, re-render the form (which will highlight
            # errors)
            context = {'form': form}
            return render(request, 'form_new_event_and_showing.html', context)

    elif request.method == 'GET':
        # GET: Show form blank, with date filled in from GET date and start
        # parameters:
        # Marshal date and time out of the GET request:
        default_date = (django.utils.timezone.now().date() +
                        datetime.timedelta(1))
        date = request.GET.get('date', default_date.strftime("%d-%m-%Y"))
        date = date.split("-")

        # Default start time is 8pm (shouldn't this be a setting?)
        time = request.GET.get('time', "20:00")
        time = time.split(":")
        # Default duration is one hour:
        duration = request.GET.get('duration', "3600")

        room = request.GET.get('room', None)

        if len(time) != 2 or len(date) != 3:
            return HttpResponse("Invalid start date or time",
                                status=400, content_type="text/plain")
        try:
            date = [int(n, 10) for n in date]
            time = [int(n, 10) for n in time]
            duration = datetime.timedelta(seconds=int(duration, 10))
            event_start = timezone.get_current_timezone().localize(
                datetime.datetime(hour=time[0], minute=time[1],
                                  day=date[0], month=date[1], year=date[2])
            )
            if settings.MULTIROOM_ENABLED and room:
                room = Room.objects.get(id=room)
        except (ValueError, TypeError, Room.DoesNotExist):
            return HttpResponse("Illegal time, date, duration or room",
                                status=400, content_type="text/plain")

        # Create form, render template:
        form = diary_forms.NewEventForm(initial={
            'start': event_start,
            'duration': duration,
            'room': room,
        })
        context = {'form': form}
        return render(request, 'form_new_event_and_showing.html', context)