def create_event(title, visible=True):
            ev = Event()
            ev.title = title
            ev.type = '4'
            ev.visible = visible
            ev.status = '1'
            ev.author_id = 1
            ev.save()

            return ev
 def test_get_event_for_moderation_returns_event_if_it_exists_and_user_has_perms(self):
     event = factories.EventFactory()
     user_w_perms = UserFactory()
     permission = Permission.objects.get(codename='manage_events')
     user_w_perms.user_permissions.add(permission)
     ret = Event.get_event_for_moderation_or_404(event.id, user_w_perms)
     self.assertEqual(event, ret)
Exemple #3
0
def edit_event(request, event_id=None):
    is_edit = True
    event = Event.get_event_for_moderation_or_404(event_id, request.user)
    form = EventForm(data=request.POST or None,
                     instance=event,
                     user=request.user)
    formset = TermFormSet(request.POST or None, instance=event)
    reservation = event.reservation

    if form.is_valid():
        event = form.save(commit=False)
        if not event.id:
            event.author = request.user
        event.reservation = reservation
        if formset.is_valid():
            event.save()
            formset.save()

            if Term.objects.filter(event=event).count() == 0:
                event.remove()
                messages.success(request, 'Usunięto wydarzenie')
                return reservations(request)

            messages.success(request, 'Zmieniono zdarzenie')
            return redirect(event)
    errors = True

    return TemplateResponse(request, 'schedule/reservation.html', locals())
Exemple #4
0
def decision(request, event_id):
    event = Event.get_event_for_moderation_only_or_404(event_id, request.user)
    form = DecisionForm(request.POST, instance=event)
    event_status = event.status
    conflicts = event.get_conflicted()
    if conflicts:
        event.term_set.update(ignore_conflicts=True)

    if form.is_valid():
        if event_status == form.cleaned_data['status']:
            messages.error(request, "Status wydarzenia nie został zmieniony")
        else:
            event_obj = form.save()
            msg = EventModerationMessage()
            msg.author = request.user
            msg.message = "Status wydarzenia został zmieniony na " + \
                str(event_obj.get_status_display())
            msg.event = event_obj
            msg.save()
            messages.success(request, "Status wydarzenia został zmieniony")
            if event_obj.status == Event.STATUS_ACCEPTED:
                for conflict in conflicts:
                    messages.warning(request,
                                     "Powstał konflikt: " + conflict.title)
    else:
        messages.error(request, form.non_field_errors())

    return redirect(reverse('events:show', args=[str(event.id)]))
Exemple #5
0
def event(request, event_id):
    from apps.schedule.models.message import EventModerationMessage, EventMessage

    event = Event.get_event_or_404(event_id, request.user)
    moderation_messages = EventModerationMessage.get_event_messages(event)
    event_messages = EventMessage.get_event_messages(event)

    return TemplateResponse(request, 'schedule/event.html', locals())
 def test_get_all(self):
     events = factories.EventFactory.create_batch(random.randint(50, 100))
     events.append(self.event)
     get_all_res = Event.get_all()
     self.assertEqual(len(events), len(get_all_res))
     get_all_res_pk = [x.pk for x in get_all_res]
     for i in range(0, len(events)):
         self.assertTrue(events[i].pk in get_all_res_pk)
 def test_get_exams(self):
     events = factories.EventFactory.create_batch(random.randint(50, 100))
     events.append(self.event)
     get_exams_res = Event.get_exams()
     filtered_events = [x for x in events if x.type == Event.TYPE_EXAM]
     self.assertEqual(len(get_exams_res), len(filtered_events))
     get_exams_pk = [x.pk for x in get_exams_res]
     for i in range(0, len(filtered_events)):
         self.assertTrue(filtered_events[i].pk in get_exams_pk)
 def test_get_all_without_courses(self):
     events = factories.EventFactory.create_batch(random.randint(50, 100))
     events.append(self.event)
     get_all_wo_courses_res = Event.get_all_without_courses()
     events_wo_courses = [x for x in events if x.type != Event.TYPE_CLASS]
     self.assertEqual(len(events_wo_courses), len(get_all_wo_courses_res))
     get_all_res_pk = [x.pk for x in get_all_wo_courses_res]
     for i in range(0, len(events_wo_courses)):
         self.assertTrue(events_wo_courses[i].pk in get_all_res_pk)
Exemple #9
0
def change_interested(request, event_id):
    event = Event.get_event_or_404(event_id, request.user)
    if request.user in event.interested.all():
        event.interested.remove(request.user)
        messages.success(request, 'Nie obsereujesz już wydarzenia')
    else:
        event.interested.add(request.user)
        messages.success(request, 'Obserwujesz wydarzenie')

    return redirect(event)
 def test_get_for_user(self):
     users = UserFactory.create_batch(8)
     users += self.users
     events = factories.EventFactory.create_batch(random.randint(50, 100),
                                                  author=random.choice(users))
     events.append(self.event)
     user = random.choice(users)
     events_for_user = Event.get_for_user(user)
     filtered_events = [x for x in events if x.author == user]
     self.assertEqual(len(filtered_events), len(events_for_user))
     filtered_pk = [x.pk for x in filtered_events]
     for i in range(0, len(events_for_user)):
         self.assertTrue(events_for_user[i].pk in filtered_pk)
Exemple #11
0
def moderation_message(request, event_id):
    event = Event.get_event_for_moderation_or_404(event_id, request.user)
    form = EventModerationMessageForm(request.POST)
    if form.is_valid():
        moderation_message = form.save(commit=False)
        moderation_message.event = event
        moderation_message.author = request.user
        moderation_message.save()

        messages.success(request, "Wiadomość została wysłana")
        messages.info(request, "Wiadomość została również wysłana emailem")

        return redirect(reverse('events:show', args=[str(event.id)]))

    raise Http404
Exemple #12
0
def reservation(request, event_id=None):
    form = EventForm(data=request.POST or None, user=request.user)

    if form.is_valid():
        event = form.save(commit=False)
        event.author = request.user
        formset = TermFormSet(request.POST or None, instance=event)
        if formset.is_valid():
            event.save()
            formset.save()

            return redirect(event)
        errors = True
    else:
        formset = TermFormSet(data=request.POST or None, instance=Event())

    return TemplateResponse(request, 'schedule/reservation.html', locals())
Exemple #13
0
def decision(request, event_id):
    from .models.message import EventModerationMessage

    event = Event.get_event_for_moderation_only_or_404(event_id, request.user)

    form = DecisionForm(request.POST, instance=event)

    event_status = event.status

    if form.is_valid():
        if event_status == form.cleaned_data['status']:
            messages.error(request, 'Status wydarzenia nie został zmieniony')
        else:
            event_obj = form.save()
            msg = EventModerationMessage()
            msg.author = request.user
            msg.message = 'Status wydarzenia został zmieniony na ' + \
                str(event_obj.get_status_display())
            msg.event = event_obj
            msg.save()
            messages.success(request, 'Status wydarzenia został zmieniony')

    return redirect(reverse('events:show', args=[str(event.id)]))
Exemple #14
0
def reservations(request):
    events = EventFilter(request.GET, queryset=Event.get_all_without_courses())
    qs = Paginator(events.qs, 10).get_page(request.GET.get('page', 1))
    title = 'Zarządzaj rezerwacjami'
    return TemplateResponse(request, 'schedule/reservations.html', locals())
Exemple #15
0
def history(request):
    events = EventFilter(request.GET,
                         queryset=Event.get_for_user(request.user))
    qs = Paginator(events.qs, 10).get_page(request.GET.get('page', 1))
    title = 'Moje rezerwacje'
    return TemplateResponse(request, 'schedule/history.html', locals())
 def test_get_event_for_moderation_returns_event_if_it_exists_and_user_is_the_author(self):
     user = UserFactory()
     event = factories.EventFactory(author=user)
     ret = Event.get_event_for_moderation_or_404(event.id, user)
     self.assertEqual(event, ret)
Exemple #17
0
 def items(self):
     return Event.get_exams()[:10]
 def test_get_for_moderation_only_returns_event_if_user_has_perms(self):
     ev = factories.EventFactory()
     perm = Permission.objects.get(codename='manage_events')
     user = UserFactory()
     user.user_permissions.add(perm)
     self.assertEqual(Event.get_event_for_moderation_only_or_404(ev.id, user), ev)
    def create_event(self, author_id):
        from .term import Term
        from .event import Event

        Event.objects.filter(reservation=self).delete()

        semester = self.semester

        ev = Event()
        ev.title = self.title
        ev.description = 'Rezerwacja cykliczna - ' + self.title
        ev.reservation = self
        ev.type = Event.TYPE_GENERIC
        ev.visible = True
        ev.status = Event.STATUS_ACCEPTED
        ev.author_id = author_id
        ev.save()

        term_days = semester.get_all_days_of_week(
            day_of_week=self.dayOfWeek,
            start_date=max(datetime.now().date(), semester.lectures_beginning))

        for day in term_days:
            term = Term()
            term.event = ev
            term.day = day
            term.start = self.start_time
            term.end = self.end_time
            term.room = self.classroom
            term.save()
 def test_get_event_or_404_returns_event_if_exists_and_user_can_see(self):
     employee = Employee.objects.get().user
     event = factories.EventFactory(author=employee)
     ret = Event.get_event_or_404(event.id, employee)
     self.assertEqual(event, ret)