Example #1
0
    def setUpTestData(cls):
        u"""Set up data for all tests."""
        cls.organization = Organization.objects.create(
            name=u'',
            address=u'',
            description=u'',
        )
        cls.organization.save()

        common_offer_data = {
            'organization': cls.organization,
            'description': u'',
            'requirements': u'',
            'time_commitment': u'',
            'benefits': u'',
            'location': u'',
            'title': u'volontulo offer',
            'time_period': u'',
            'started_at': '2105-10-24 09:10:11',
            'finished_at': '2105-11-28 12:13:14',
            'offer_status': 'unpublished',
            'recruitment_status': 'closed',
            'action_status': 'ongoing',
        }

        cls.inactive_offer = Offer.objects.create(status_old='NEW',
                                                  **common_offer_data)
        cls.inactive_offer.save()
        cls.active_offer = Offer.objects.create(status_old='ACTIVE',
                                                **common_offer_data)
        cls.active_offer.save()

        volunteer_user = User.objects.create_user(u'*****@*****.**',
                                                  u'*****@*****.**',
                                                  u'123volunteer')
        volunteer_user.save()
        cls.volunteer = UserProfile(user=volunteer_user)
        cls.volunteer.save()

        organization_user = User.objects.create_user(
            u'*****@*****.**', u'*****@*****.**',
            u'123org')
        organization_user.save()
        cls.organization_profile = UserProfile(user=organization_user, )
        cls.organization_profile.save()
        # pylint: disable=no-member
        cls.organization_profile.organizations.add(cls.organization)

        admin_user = User.objects.create_user(u'*****@*****.**',
                                              u'*****@*****.**',
                                              u'123admin')
        admin_user.save()
        cls.admin = UserProfile(
            user=admin_user,
            is_administrator=True,
        )
        cls.admin.save()
Example #2
0
    def post(cls, request):
        u"""Method handles creation of new user.

        :param request: WSGIRequest instance
        """
        # validation of register form:
        user_form = UserForm(request.POST)
        if not user_form.is_valid():
            messages.error(
                request,
                u'Wprowadzono nieprawidłowy email, hasło lub nie wyrażono '
                u'zgody na przetwarzanie danych osobowych.')
            return cls.get(request, user_form)

        username = request.POST.get('email')
        password = request.POST.get('password')

        ctx = {}

        # attempt of new user creation:
        try:
            user = User.objects.create_user(
                username=username,
                email=username,
                password=password,
            )
            user.is_active = False
            user.save()
            profile = UserProfile(user=user)
            ctx['uuid'] = profile.uuid
            profile.save()
        except IntegrityError:
            # if attempt failed, because user already exists we need show
            # error message:
            messages.info(request, u'Użytkownik o podanym emailu już istnieje')
            return cls.get(request, user_form)

        # sending email to user:
        send_mail(request, 'registration', [user.email], context=ctx)

        # automatically login new user:
        user = auth.authenticate(username=username, password=password)
        auth.login(request, user)

        # show info about successful creation of new user and redirect to
        # homepage:
        messages.success(request, u'Rejestracja przebiegła pomyślnie')
        messages.info(
            request, u'Na podany przy rejestracji email został wysłany link '
            u'aktywacyjny. Aby w pełni wykorzystać konto należy je aktywować '
            u'poprzez kliknięcie linku lub wklejenie go w przeglądarce.')
        return redirect('homepage')
Example #3
0
    def setUpTestData(cls):
        """Set up data for all tests."""
        organization = Organization.objects.create(
            name='Organization Name',
            address='',
            description='',
        )
        organization.save()
        administrator = User.objects.create_user(
            '*****@*****.**',
            '*****@*****.**',
            '123admin'
        )
        administrator.save()
        cls.administrator_profile = UserProfile(
            user=administrator,
            is_administrator=True,
        )
        cls.administrator_profile.save()
        cls.offer = Offer.objects.create(
            organization=organization,
            description='',
            requirements='',
            time_commitment='',
            benefits='',
            location='',
            title='volontulo offer',
            time_period='',
            status_old='NEW',
            started_at='2105-10-24 09:10:11',
            finished_at='2105-11-28 12:13:14',
            offer_status='unpublished',
            recruitment_status='open',
            action_status='ongoing',
        )
        cls.offer.save()

        volunteers = [User.objects.create_user(
            'v{}@example.com'.format(i),
            'v{}@example.com'.format(i),
            'v{}'.format(i),
        ) for i in range(10)]
        for i in range(10):
            volunteers[i].save()
        cls.volunteers_profiles = [
            UserProfile(user=volunteers[i]) for i in range(10)
        ]
        for i in range(10):
            cls.volunteers_profiles[i].save()
        for i in range(0, 10, 2):
            cls.offer.volunteers.add(cls.volunteers_profiles[i].user)
Example #4
0
    def post(cls, request):
        """Method handles creation of new user.

        :param request: WSGIRequest instance
        """
        # validation of register form:
        user_form = UserForm(request.POST)
        if not user_form.is_valid():
            messages.error(
                request,
                "Wprowadzono nieprawidłowy email, hasło lub nie wyrażono " "zgody na przetwarzanie danych osobowych.",
            )
            return cls.get(request, user_form)

        username = request.POST.get("email")
        password = request.POST.get("password")

        ctx = {}

        # attempt of new user creation:
        try:
            user = User.objects.create_user(username=username, email=username, password=password)
            user.is_active = False
            user.save()
            profile = UserProfile(user=user)
            ctx["uuid"] = profile.uuid
            profile.save()
        except IntegrityError:
            # if attempt failed, because user already exists we need show
            # error message:
            messages.info(request, "Użytkownik o podanym emailu już istnieje")
            return cls.get(request, user_form)

        # sending email to user:
        send_mail(request, "registration", [user.email], context=ctx)

        # automatically login new user:
        user = auth.authenticate(username=username, password=password)
        auth.login(request, user)

        # show info about successful creation of new user and redirect to
        # homepage:
        messages.success(request, "Rejestracja przebiegła pomyślnie")
        messages.info(
            request,
            "Na podany przy rejestracji email został wysłany link "
            "aktywacyjny. Aby w pełni wykorzystać konto należy je aktywować "
            "poprzez kliknięcie linku lub wklejenie go w przeglądarce.",
        )
        return redirect("homepage")
Example #5
0
    def get(request, slug, id_):  # pylint: disable=unused-argument
        """View responsible for showing join form for particular offer."""
        if request.user.is_authenticated():
            has_applied = Offer.objects.filter(
                volunteers=request.user,
                volunteers__offer=id_,
            ).count()
            if has_applied:
                messages.error(
                    request, "Już wyraziłeś chęć uczestnictwa w tej ofercie.")
                return redirect('offers_list')

        offer = Offer.objects.get(id=id_)
        try:
            main_image = OfferImage.objects.get(offer=offer, is_main=True)
        except OfferImage.DoesNotExist:
            main_image = ''

        context = {
            'form': OfferApplyForm(),
            'offer': offer,
            'MEDIA_URL': settings.MEDIA_URL,
            'main_image': main_image,
        }

        context['volunteer_user'] = UserProfile()
        if request.user.is_authenticated():
            context['volunteer_user'] = request.user.userprofile

        return render(request, 'offers/offer_apply.html', context)
Example #6
0
    def setUpTestData(cls):
        u"""Set up data for all tests."""
        organization = Organization.objects.create(
            name=u'',
            address=u'',
            description=u'',
        )
        organization.save()

        cls.offer = Offer.objects.create(
            organization=organization,
            description=u'',
            requirements=u'',
            time_commitment=u'',
            benefits=u'',
            location=u'',
            title=u'volontulo offer',
            time_period=u'',
            status_old='NEW',
            started_at='2015-10-10 21:22:23',
            finished_at='2015-12-12 11:12:13',
        )
        cls.offer.save()

        cls.volunteer = User.objects.create_user(
            u'*****@*****.**',
            u'*****@*****.**',
            u'vol123',
        )
        cls.volunteer.save()
        cls.volunteer_profile = UserProfile(user=cls.volunteer)
        cls.volunteer_profile.save()
Example #7
0
 def setUpTestData(cls):
     u"""Set up data for all tests."""
     cls.organization = Organization.objects.create(
         name=u'',
         address=u'',
         description=u'',
     )
     cls.organization.save()
     cls.organization_user_email = u'*****@*****.**'
     cls.organization_user_password = u'123org'
     organization_user = User.objects.create_user(
         cls.organization_user_email, cls.organization_user_email,
         cls.organization_user_password)
     organization_user.save()
     cls.organization_profile = UserProfile(user=organization_user)
     cls.organization_profile.save()
     # pylint: disable=no-member
     cls.organization_profile.organizations.add(cls.organization)
     cls.offer = Offer.objects.create(
         organization=cls.organization,
         description=u'',
         requirements=u'',
         time_commitment=u'',
         benefits=u'',
         location=u'',
         title=u'volontulo offer',
         time_period=u'',
         status_old='NEW',
         started_at='2015-10-10 21:22:23',
         finished_at='2015-12-12 11:12:13',
         offer_status='published',
         recruitment_status='open',
         action_status='ongoing',
     )
     cls.offer.save()
Example #8
0
    def setUpTestData(cls):
        """Set up data for all tests."""
        cls.organization = Organization.objects.create(
            name='Organization Name',
            address='',
            description='',
        )
        cls.organization.save()
        organization_user = User.objects.create_user(
            '*****@*****.**',
            '*****@*****.**',
            '123org'
        )
        organization_user.save()
        cls.organization_profile = UserProfile(
            user=organization_user,
        )
        cls.organization_profile.save()
        cls.organization_profile.organizations.add(cls.organization)

        no_org_user = User.objects.create_user(
            '*****@*****.**',
            '*****@*****.**',
            '123no_org'
        )
        UserProfile.objects.create(
            user=no_org_user,
        )
    def setUpTestData(cls):
        """Set up data for all tests."""
        for i in range(1, 6):
            Organization.objects.create(
                name='Organization {0} name'.format(i),
                address='Organization {0} address'.format(i),
                description='Organization {0} description'.format(i),
            )

        organizations = Organization.objects.all()
        for idx, org in enumerate(organizations):
            for i in range(1, 6):
                user = User.objects.create_user(
                    'volunteer{0}{1}@example.com'.format(idx + 1, i),
                    'volunteer{0}{1}@example.com'.format(idx + 1, i),
                    'password',
                )
                userprofile = UserProfile(user=user)
                userprofile.save()
                userprofile.organizations.add(org)
                userprofile.save()

        for idx, org in enumerate(organizations):
            for i in range(0, idx + 1):
                Offer.objects.create(
                    organization=org,
                    benefits='Offer {0}-{1} benefits'.format(idx + 1, i),
                    location='Offer {0}-{1} location'.format(idx + 1, i),
                    title='Offer {0}-{1} title'.format(idx + 1, i),
                    time_period='',
                    description='',
                    requirements='',
                    time_commitment='',
                    offer_status='published',
                    recruitment_status='closed',
                    action_status='finished',
                    started_at='2010-10-10 10:10:10',
                    finished_at='2012-12-12 12:12:12'
                )
Example #10
0
def register_view(request):
    """REST API register view."""
    if request.user.is_authenticated():
        return Response(status=status.HTTP_400_BAD_REQUEST)

    email = request.data.get('email')
    password = request.data.get('password')
    try:
        user = User.objects.create_user(
            username=email,
            email=email,
            password=password,
            is_active=False,
        )
        user.save()
    except IntegrityError:
        return Response(status=status.HTTP_201_CREATED)

    profile = UserProfile(user=user)
    ctx = {'token': profile.uuid}
    profile.save()
    send_mail(request, 'registration', [user.email], context=ctx)

    return Response(status=status.HTTP_201_CREATED)
Example #11
0
 def setUpTestData(cls):
     u"""Set up data for all tests."""
     cls.organization = Organization.objects.create(
         name=u'',
         address=u'',
         description=u'',
     )
     cls.organization.save()
     organization_user = User.objects.create_user(
         u'*****@*****.**', u'*****@*****.**',
         u'123org')
     organization_user.save()
     cls.organization_profile = UserProfile(user=organization_user, )
     cls.organization_profile.save()
     # pylint: disable=no-member
     cls.organization_profile.organizations.add(cls.organization)
Example #12
0
 def handle(self, *args, **options):
     """Create Volontulo admin."""
     try:
         user = User.objects.create_user(
             username=options['username'],
             email=options['username'],
             password=options['password'],
             is_superuser=options['django_admin'],
             is_staff=options['django_admin'],
             is_active=True,
         )
     except IntegrityError:
         self.stdout.write(self.style.ERROR('User already exists'))
     else:
         user.save()
         UserProfile(
             user=user,
             is_administrator=True,
         ).save()
         self.stdout.write(self.style.SUCCESS('User successfully created'))
Example #13
0
    def setUpTestData(cls):
        """Set up data for all tests."""
        for i in range(1, 6):
            Organization.objects.create(
                name='Organization {0} name'.format(i),
                address='Organization {0} address'.format(i),
                description='Organization {0} description'.format(i),
            )

        organizations = Organization.objects.all()
        for idx, org in enumerate(organizations):
            for i in range(1, 6):
                user = User.objects.create_user(
                    'volunteer{0}{1}@example.com'.format(idx + 1, i),
                    'volunteer{0}{1}@example.com'.format(idx + 1, i),
                    'password',
                )
                userprofile = UserProfile(user=user)
                userprofile.save()
                userprofile.organizations.add(org)
                userprofile.save()

        for idx, org in enumerate(organizations):
            for i in range(0, idx + 1):
                Offer.objects.create(
                    organization=org,
                    benefits='Offer {0}-{1} benefits'.format(idx + 1, i),
                    location='Offer {0}-{1} location'.format(idx + 1, i),
                    title='Offer {0}-{1} title'.format(idx + 1, i),
                    time_period='',
                    description='',
                    requirements='',
                    time_commitment='',
                    offer_status='published',
                    recruitment_status='closed',
                    action_status='finished',
                    started_at='2010-10-10 10:10:10',
                    finished_at='2012-12-12 12:12:12'
                )
Example #14
0
    def post(request, slug, id_):  # pylint: disable=unused-argument
        """View responsible for saving join for particular offer."""
        form = OfferApplyForm(request.POST)
        offer = Offer.objects.get(id=id_)
        if form.is_valid():
            if request.user.is_authenticated():
                user = request.user
            else:
                user = User.objects.filter(
                    email=request.POST.get('email')).exists()

                if user:
                    messages.info(request,
                                  "Zaloguj się, aby zapisać się do oferty.")
                    return redirect('{login}?next={path}'.format(
                        login=reverse('login'), path=request.path))

                messages.info(request,
                              "Zarejestruj się, aby zapisać się do oferty.")
                return redirect('register')

            has_applied = Offer.objects.filter(
                volunteers=user,
                volunteers__offer=id_,
            ).count()
            if has_applied:
                messages.error(
                    request, "Już wyraziłeś chęć uczestnictwa w tej ofercie.")
                return redirect('offers_list')

            offer.volunteers.add(user)
            offer.save()
            send_mail(
                request, 'offer_application', [
                    userprofile.user.email
                    for userprofile in offer.organization.userprofiles.all()
                ],
                dict(
                    email=request.POST.get('email'),
                    phone_no=request.POST.get('phone_no'),
                    fullname=request.POST.get('fullname'),
                    comments=request.POST.get('comments'),
                    offer=offer,
                ))
            messages.success(request,
                             "Zgłoszenie chęci uczestnictwa zostało wysłane.")
            return redirect(
                'offers_view',
                slug=slugify(offer.title),
                id_=offer.id,
            )
        else:
            errors = "<br />".join(form.errors)
            messages.error(request,
                           "Formularz zawiera nieprawidłowe dane" + errors)
            volunteer_user = UserProfile()
            if request.user.is_authenticated():
                volunteer_user = request.user.userprofile
            return render(request, 'offers/offer_apply.html', {
                'offer': offer,
                'form': form,
                'volunteer_user': volunteer_user,
            })
Example #15
0
    def post(request, slug, id_):  # pylint: disable=unused-argument
        u"""View responsible for saving join for particular offer."""
        form = OfferApplyForm(request.POST)
        offer = Offer.objects.get(id=id_)
        if form.is_valid():
            if request.user.is_authenticated():
                user = request.user
            else:
                try:
                    user = User.objects.create_user(
                        username=request.POST.get('email'),
                        email=request.POST.get('email'),
                        password=User.objects.make_random_password(),
                    )
                    profile = UserProfile(user=user)
                    profile.save()
                except IntegrityError:
                    messages.info(
                        request, u'Użytkownik o podanym emailu już istnieje.'
                        u' Zaloguj się.')
                    return render(
                        request, 'offers/offer_apply.html', {
                            'offer': offer,
                            'form': form,
                            'volunteer_user': UserProfile(),
                        })

            has_applied = Offer.objects.filter(
                volunteers=user,
                volunteers__offer=id_,
            ).count()
            if has_applied:
                messages.error(
                    request, u'Już wyraziłeś chęć uczestnictwa w tej ofercie.')
                return redirect('offers_list')

            offer_content_type = ContentType.objects.get(app_label='volontulo',
                                                         model='offer')

            offer.volunteers.add(user)
            UserBadges.apply_participant_badge(
                offer_content_type,
                user.userprofile,
            )
            offer.save()

            send_mail(
                request, 'offer_application', [
                    user.email,
                    request.POST.get('email'),
                ],
                dict(
                    email=request.POST.get('email'),
                    phone_no=request.POST.get('phone_no'),
                    fullname=request.POST.get('fullname'),
                    comments=request.POST.get('comments'),
                    offer=offer,
                ))
            messages.success(
                request, u'Zgłoszenie chęci uczestnictwa zostało wysłane.')
            return redirect(
                'offers_view',
                slug=slugify(offer.title),
                id_=offer.id,
            )
        else:
            errors = '<br />'.join(form.errors)
            messages.error(request,
                           u'Formularz zawiera nieprawidłowe dane' + errors)
            volunteer_user = UserProfile()
            if request.user.is_authenticated():
                volunteer_user = request.user.userprofile
            return render(request, 'offers/offer_apply.html', {
                'offer': offer,
                'form': form,
                'volunteer_user': volunteer_user,
            })