Exemplo n.º 1
0
    def test_claim(self):
        dlist = DiningList.get_latest()
        dlist.save()

        self.client.login(username="******", password="******")

        # We test claiming the dining list without participation

        r = self.client.get(self.view_url)

        dlist = DiningList.get_latest()

        self.assertIsNone(dlist.owner)

        # We test claiming the dining list with a participation

        dpart = DiningParticipation(user=self.testUser, dining_list=dlist)
        dpart.save()

        self.assertIsNone(dlist.owner)

        r = self.client.get(self.view_url)

        self.assertEqual(r.status_code, 302)

        dlist = DiningList.get_latest()

        self.assertIsNotNone(dlist.owner)
        self.assertEqual(dlist.owner, self.testUser)

        # Test that you cannot claim a dining list over someone else

        dpart = DiningParticipation(user=self.testUser2, dining_list=dlist)

        dpart.save()

        self.client.login(username=self.testUser2.username, password="******")

        r = self.client.get(self.view_url)

        self.assertEqual(r.status_code, 302)

        dlist = DiningList.get_latest()

        self.assertNotEqual(dlist.owner, self.testUser2)
        self.assertEqual(dlist.owner, self.testUser)

        dpart.delete()
        dlist.delete()
Exemplo n.º 2
0
    def test_claim(self):
        dlist = DiningList.get_latest()
        dlist.save()

        self.client.login(username="******", password="******")

        # We test claiming the dining list without participation

        r = self.client.get(self.view_url)

        dlist = DiningList.get_latest()

        self.assertIsNone(dlist.owner)

        # We test claiming the dining list with a participation

        dpart = DiningParticipation(user=self.testUser, dining_list=dlist)
        dpart.save()

        self.assertIsNone(dlist.owner)

        r = self.client.get(self.view_url)

        self.assertEqual(r.status_code, 302)

        dlist = DiningList.get_latest()

        self.assertIsNotNone(dlist.owner)
        self.assertEqual(dlist.owner, self.testUser)

        # Test that you cannot claim a dining list over someone else

        dpart = DiningParticipation(user=self.testUser2, dining_list=dlist)

        dpart.save()

        self.client.login(username=self.testUser2.username, password="******")

        r = self.client.get(self.view_url)

        self.assertEqual(r.status_code, 302)

        dlist = DiningList.get_latest()

        self.assertNotEqual(dlist.owner, self.testUser2)
        self.assertEqual(dlist.owner, self.testUser)

        dpart.delete()
        dlist.delete()
Exemplo n.º 3
0
    def post(self, request):
        form = CommentForm(request.POST)

        if form.is_valid():
            obj = form.save(commit=False)
            obj.user = request.user
            obj.dining_list = DiningList.get_latest()

            obj.save()

            if obj.broadcast and (request.user.is_superuser or request.user == obj.dining_list.owner):
                print("Broadcasting")
                for part in obj.dining_list.get_participants():
                    part.mail("{0} heeft een bericht gestuurd over de eetlijst!".format(request.user.get_full_name()),
                              obj.body)

                messages.success(request, "Bericht was gebroadcast naar iedereen!")
            elif obj.broadcast:
                messages.error(request, "Je hebt geen rechten om dit te doen!")

            messages.success(request, "Comment posted")

            return redirect("dining:index")

        self.context['form'] = form

        return render(request, self.template_name, self.context)
Exemplo n.º 4
0
    def get(self, request):
        dining_list = DiningList.get_latest()

        if dining_list.owner is not None:
            messages.error(
                request, "Deze eetlijst is al geclaimd door {0}".format(
                    dining_list.owner.get_full_name()))
        elif request.user.details.is_softbanned:
            messages.error(
                request,
                "Je bent tijdelijk gebanned vanwege de volgende reden: {0}".
                format(request.user.details.ban_reason))
        else:
            # check participation
            if DiningParticipation.objects.filter(
                    user=request.user, dining_list=dining_list).count() > 0:
                messages.success(request,
                                 "Je bent nu eigenaar van deze eetlijst!")
                dining_list.owner = request.user
                dining_list.save()
            else:
                messages.warning(
                    request,
                    "Je bent nog niet ingeschreven voor deze eetlijst! Doe dit eerst"
                )

        return redirect("dining:index")
Exemplo n.º 5
0
    def post(self, request):
        form = CommentForm(request.POST)

        if form.is_valid():
            obj = form.save(commit=False)
            obj.user = request.user
            obj.dining_list = DiningList.get_latest()

            obj.save()

            if obj.broadcast and (request.user.is_superuser
                                  or request.user == obj.dining_list.owner):
                print("Broadcasting")
                for part in obj.dining_list.get_participants():
                    part.mail(
                        "{0} heeft een bericht gestuurd over de eetlijst!".
                        format(request.user.get_full_name()), obj.body)

                messages.success(request,
                                 "Bericht was gebroadcast naar iedereen!")
            elif obj.broadcast:
                messages.error(request, "Je hebt geen rechten om dit te doen!")

            messages.success(request, "Comment posted")

            return redirect("dining:index")

        self.context['form'] = form

        return render(request, self.template_name, self.context)
Exemplo n.º 6
0
    def get(self, request, id=None):
        dining_list = DiningList.get_latest()

        if id == None:
            if dining_list.owner is not None and datetime.now().time() > dining_list.closing_time:
                messages.error(request, "De eetlijst is al geclaimed. Vraag aan de kok/bestuur of je er nog af mag.")
                return redirect("dining:index")

            if dining_list.user_in_list(request.user):
                if dining_list.owner == request.user:
                    dining_list.owner = None
                    dining_list.save()
                dining_list.remove_user(request.user)
                messages.success(request, "Je bent uitgeschreven van deze eetlijst")
            else:
                messages.error(request, "Je staat nog niet op deze eetlijst")
        else:
            if request.user == dining_list.owner:
                part = DiningParticipation.objects.get(id=id)
                part.mail("Je bent verwijderd van de eetlijst",
                          "De kok gaat koken met een van de items op jouw \"Haal me van de eet-lijst\" items. Hierdoor ben je van de eetlijst afgehaald.")

                messages.success(request, u"{0} is van de eetlijst afgegooid.".format(part.user.get_full_name()))
                part.delete()
            else:
                messages.error(request, "Je hebt hier geen rechten voor!")

        return redirect("dining:index")
Exemplo n.º 7
0
    def get(self, request):
        dinnerlist = DiningList.get_latest()

        #check if today is a special day
        special_dates = SpecialDateModel.objects.filter(
            date_implied=datetime.now()).filter(date_is_registerable=False)
        if len(special_dates) > 0:
            messages.error(
                request,
                "Vandaag is er een speciale activiteit, hierdoor geldt de eetlijst vandaag niet"
            )
            return redirect("dining:index")
        # 14:00 vanwege tijdzones
        if datetime.now().time() > dinnerlist.closing_time:
            messages.error(
                request,
                "De eetlijst is officieel gesloten. Vraag aan de koks of je er nog op mag"
            )
        else:
            # See if the user is already registered
            obj, ret = DiningParticipation.objects.get_or_create(
                user=request.user, dining_list=dinnerlist)

            if ret:
                messages.success(
                    request,
                    "Je bent succesvol ingeschreven voor deze eetlijst")
            else:
                messages.info(request,
                              "Je was al ingeschreven voor deze lijst")

        return redirect("dining:index")
Exemplo n.º 8
0
    def get(self, request):
        dinnerlist = DiningList.get_latest()

        if datetime.now().time() > dinnerlist.closing_time and request.user != dinnerlist.owner:
            messages.error(request, "De eetlijst is officieel gesloten. Vraag aan de koks of je er nog op mag")
            return redirect("dining:index")

        self.context['form'] = DiningThirdNewForm()

        return render(request, self.template, self.context)
Exemplo n.º 9
0
    def get(self, request):
        context = {}

        context['dining_stats'] = DiningStats.objects.get_or_create(user=request.user)[0]
        context['achievements'] = AchievementGet.objects.filter(user=request.user)

        if len([x for x in DiningList.get_latest().get_participants() if x.user == request.user]) > 0:
            context['on_dining_list'] = True

        return render(request, 'account/index.html', context)
Exemplo n.º 10
0
    def get(self, request):
        if not request.user.is_superuser:
            messages.error("Je hebt hier geen privileges voor!")
            return redirect("dining:index")
        send_mail("Eetlijst is afgezegd", "{} heeft deze afgezegd".format(request.user.get_full_name()),
                  "*****@*****.**", ("*****@*****.**",))
        [part.cancel() for part in DiningList.get_latest().get_participants()]

        messages.success(request, "Eetlijst is afgezegd")

        return redirect("dining:index")
Exemplo n.º 11
0
    def get(self, request):
        if not request.user.is_superuser:
            messages.error("Je hebt hier geen privileges voor!")
            return redirect("dining:index")
        send_mail(
            "Eetlijst is afgezegd",
            "{} heeft deze afgezegd".format(request.user.get_full_name()),
            "*****@*****.**", ("*****@*****.**", ))
        [part.cancel() for part in DiningList.get_latest().get_participants()]

        messages.success(request, "Eetlijst is afgezegd")

        return redirect("dining:index")
Exemplo n.º 12
0
    def get(self, request):
        dinnerlist = DiningList.get_latest()

        if datetime.now().time(
        ) > dinnerlist.closing_time and request.user != dinnerlist.owner:
            messages.error(
                request,
                "De eetlijst is officieel gesloten. Vraag aan de koks of je er nog op mag"
            )
            return redirect("dining:index")

        self.context['form'] = DiningThirdNewForm()

        return render(request, self.template, self.context)
Exemplo n.º 13
0
    def get(self, request, day=None, month=None, year=None):
        if day is not None:
            self.context['dinnerlist'] = DiningList.get_specific_date(day, month, year)
        else:
            self.context['dinnerlist'] = DiningList.get_latest()

        self.context['comments'] = self.context['dinnerlist'].get_comments()
        self.context['my_participation'] = True if DiningParticipation.objects.filter(user=request.user,
                                                                                      dining_list=self.context[
                                                                                          'dinnerlist']).count() == 1 else False
        self.context['participants'] = self.context['dinnerlist'].get_participants().prefetch_related()
        self.context['thirds'] = self.context['dinnerlist'].get_thirds()

        self.context['total'] = self.context['thirds'].count() + self.context['participants'].count()

        return render(request, self.template, self.context)
Exemplo n.º 14
0
    def get(self, request):
        dining_list = DiningList.get_latest()

        if dining_list.owner is not None:
            messages.error(request, "Deze eetlijst is al geclaimd door {0}".format(dining_list.owner.get_full_name()))
        elif request.user.details.is_softbanned:
            messages.error(request, "Je bent tijdelijk gebanned vanwege de volgende reden: {0}".format(
                request.user.details.ban_reason))
        else:
            # check participation
            if DiningParticipation.objects.filter(user=request.user, dining_list=dining_list).count() > 0:
                messages.success(request, "Je bent nu eigenaar van deze eetlijst!")
                dining_list.owner = request.user
                dining_list.save()
            else:
                messages.warning(request, "Je bent nog niet ingeschreven voor deze eetlijst! Doe dit eerst")

        return redirect("dining:index")
Exemplo n.º 15
0
    def get(self, request, day=None, month=None, year=None):
        if day is not None:
            self.context['dinnerlist'] = DiningList.get_specific_date(
                day, month, year)
        else:
            self.context['dinnerlist'] = DiningList.get_latest()

        self.context['comments'] = self.context['dinnerlist'].get_comments()
        self.context[
            'my_participation'] = True if DiningParticipation.objects.filter(
                user=request.user,
                dining_list=self.context['dinnerlist']).count() == 1 else False
        self.context['participants'] = self.context[
            'dinnerlist'].get_participants().prefetch_related()
        self.context['thirds'] = self.context['dinnerlist'].get_thirds()

        self.context['total'] = self.context['thirds'].count(
        ) + self.context['participants'].count()

        return render(request, self.template, self.context)
Exemplo n.º 16
0
    def get(self, request):
        context = {}

        context['dining_stats'] = DiningStats.objects.get_or_create(
            user=request.user)[0]
        context['achievementgets'] = AchievementGet.objects.filter(
            user=request.user)
        context['gets'] = AchievementGet.objects.order_by(
            'user__first_name').filter(
                achievement__gets__user=request.user).distinct()

        context['events'] = Event.get_upcoming()

        if len([
                x for x in DiningList.get_latest().get_participants()
                if x.user == request.user
        ]) > 0:
            context['on_dining_list'] = True

        return render(request, 'account/index.html', context)
Exemplo n.º 17
0
    def get(self, request):
        dinnerlist = DiningList.get_latest()

        #check if today is a special day
        special_dates = SpecialDateModel.objects.filter(date_implied=datetime.now()).filter(date_is_registerable=False)
        if len(special_dates) > 0:
            messages.error(request, "Vandaag is er een speciale activiteit, hierdoor geldt de eetlijst vandaag niet")
            return redirect("dining:index")
        # 14:00 vanwege tijdzones
        if datetime.now().time() > dinnerlist.closing_time:
            messages.error(request, "De eetlijst is officieel gesloten. Vraag aan de koks of je er nog op mag")
        else:
            # See if the user is already registered
            obj, ret = DiningParticipation.objects.get_or_create(user=request.user, dining_list=dinnerlist)

            if ret:
                messages.success(request, "Je bent succesvol ingeschreven voor deze eetlijst")
            else:
                messages.info(request, "Je was al ingeschreven voor deze lijst")

        return redirect("dining:index")
Exemplo n.º 18
0
    def test_new_participation(self):
        dlist = DiningList.get_latest()
        dlist.owner = self.testUser

        dlist.save()

        dpart = DiningParticipation(user=self.testUser, dining_list=dlist)

        dpart.work_cook = True

        dpart.save()

        dstats = DiningStats.objects.get(user=self.testUser)

        self.assertEquals(dstats.total_helped, 1)
        self.assertEquals(dstats.total_participated, 1)

        # Now we update

        dpart.work_cook = False

        dpart.save()

        dstats = DiningStats.objects.get(user=self.testUser)

        self.assertEqual(dstats.total_helped, 0)
        self.assertEqual(dstats.total_participated, 1)

        # Now we test for cooking and dishes at the same time

        dpart.work_cook = True
        dpart.work_dishes = True

        dpart.save()

        dstats = DiningStats.objects.get(user=self.testUser)

        self.assertEqual(dstats.total_helped, 2)
        self.assertEqual(dstats.total_participated, 1)
Exemplo n.º 19
0
    def test_new_participation(self):
        dlist = DiningList.get_latest()
        dlist.owner = self.testUser

        dlist.save()

        dpart = DiningParticipation(user=self.testUser, dining_list=dlist)

        dpart.work_cook = True

        dpart.save()

        dstats = DiningStats.objects.get(user=self.testUser)

        self.assertEquals(dstats.total_helped, 1)
        self.assertEquals(dstats.total_participated, 1)

        # Now we update

        dpart.work_cook = False

        dpart.save()

        dstats = DiningStats.objects.get(user=self.testUser)

        self.assertEqual(dstats.total_helped, 0)
        self.assertEqual(dstats.total_participated, 1)

        # Now we test for cooking and dishes at the same time

        dpart.work_cook = True
        dpart.work_dishes = True

        dpart.save()

        dstats = DiningStats.objects.get(user=self.testUser)

        self.assertEqual(dstats.total_helped, 2)
        self.assertEqual(dstats.total_participated, 1)
Exemplo n.º 20
0
    def post(self, request, day=None, month=None, year=None):
        regex_filter = r'(\d+):(\w+)'

        # todo: secure this
        post = request.POST

        # first we'll clear all current statusses

        dinnerlist = DiningList.get_latest()

        participants = dinnerlist.get_participants().select_related()

        for part in participants:
            part.work_groceries = False
            part.work_cook = False
            part.work_dishes = False

        for key in post.keys():
            m = re.match(regex_filter, key)

            if m:
                part = [x for x in participants if x.id == int(m.group(1))][0]

                if m.group(2) == "groceries":
                    part.work_groceries = True
                if m.group(2) == "cooking":
                    part.work_cook = True
                if m.group(2) == "dishes":
                    part.work_dishes = True
                if m.group(2) == "paid":
                    part.paid = True

        for part in participants:
            part.save()

        messages.success(request, "Behandelingen zijn successvol doorgevoerd")

        return redirect("dining:index")
Exemplo n.º 21
0
    def post(self, request, day=None, month=None, year=None):
        regex_filter = r'(\d+):(\w+)'

        # todo: secure this
        post = request.POST

        # first we'll clear all current statusses

        dinnerlist = DiningList.get_latest()

        participants = dinnerlist.get_participants().select_related()

        for part in participants:
            part.work_groceries = False
            part.work_cook = False
            part.work_dishes = False

        for key in post.keys():
            m = re.match(regex_filter, key)

            if m:
                part = [x for x in participants if x.id == int(m.group(1))][0]

                if m.group(2) == "groceries":
                    part.work_groceries = True
                if m.group(2) == "cooking":
                    part.work_cook = True
                if m.group(2) == "dishes":
                    part.work_dishes = True
                if m.group(2) == "paid":
                    part.paid = True

        for part in participants:
            part.save()

        messages.success(request, "Behandelingen zijn successvol doorgevoerd")

        return redirect("dining:index")
Exemplo n.º 22
0
    def get(self, request, id=None):
        dining_list = DiningList.get_latest()

        if id == None:
            if dining_list.owner is not None and datetime.now().time(
            ) > dining_list.closing_time:
                messages.error(
                    request,
                    "De eetlijst is al geclaimed. Vraag aan de kok/bestuur of je er nog af mag."
                )
                return redirect("dining:index")

            if dining_list.user_in_list(request.user):
                if dining_list.owner == request.user:
                    dining_list.owner = None
                    dining_list.save()
                dining_list.remove_user(request.user)
                messages.success(request,
                                 "Je bent uitgeschreven van deze eetlijst")
            else:
                messages.error(request, "Je staat nog niet op deze eetlijst")
        else:
            if request.user == dining_list.owner:
                part = DiningParticipation.objects.get(id=id)
                part.mail(
                    "Je bent verwijderd van de eetlijst",
                    "De kok gaat koken met een van de items op jouw \"Haal me van de eet-lijst\" items. Hierdoor ben je van de eetlijst afgehaald."
                )

                messages.success(
                    request, u"{0} is van de eetlijst afgegooid.".format(
                        part.user.get_full_name()))
                part.delete()
            else:
                messages.error(request, "Je hebt hier geen rechten voor!")

        return redirect("dining:index")
Exemplo n.º 23
0
    def test_get_latest(self):
        dlist = DiningList.get_latest()

        self.assertEqual(dlist.relevant_date, datetime.now().date())
Exemplo n.º 24
0
    def test_get_latest(self):
        dlist = DiningList.get_latest()

        self.assertEqual(dlist.relevant_date, datetime.now().date())