Exemple #1
0
def event_view(request, event_id):
    event = Event.objects.get(pk=event_id)

    ctx = {
        'event': event
        }
    user = request.user
    if user.is_authenticated():
        application = Application.objects.filter(user=user,
            event=event_id)
        already_applied = application.count() > 0 #len == 1
        is_applicant_user = is_applicant(user)
        if is_applicant_user:
            if not already_applied:
                if request.method == 'POST':
                    form = ApplicationForm(request.POST)
                    if form.is_valid():
                        instance = form.save(commit=False)
                        instance.user = user
                        instance.event = event
                        instance.status = 0
                        instance.save()
                else:
                    form = ApplicationForm()
                ctx['form'] = form
            else:
                ctx['application'] = application[0]
        ctx['already_applied'] = already_applied
        ctx['is_applicant_user'] = is_applicant_user

    return render(request, 'events/event.html', ctx)
Exemple #2
0
def test_application_form_no_newsletter():
    event = Event.objects.create(name='Test',
                                 city='Test',
                                 country='Test',
                                 is_page_live=True,
                                 page_url='test')
    form = Form.objects.create(event=event)

    # Override default questions, we need just the e-mail
    form.question_set.all().delete()
    question = Question.objects.create(title="Your e-mail address:",
                                       question_type="email",
                                       form=form,
                                       order=1)

    assert Application.objects.count() == 0

    form_data = {
        'newsletter_optin': 'no',
        'g-recaptcha-response': 'PASSED',
        f'question_{question.pk}': '*****@*****.**'
    }

    application_form = ApplicationForm(form_data, form=form)
    assert application_form.is_valid()

    application_form.save()
    assert Application.objects.count() == 1
    application = Application.objects.get()
    assert application.newsletter_optin is False
Exemple #3
0
def edit_application(request, id=None):
    application = get_object_or_404(Application, id=id)
    form = ApplicationForm(request.Post or None, instance=application)
    if form.is_valid():
        form.save()
    return render(request, 'applications/application_form.htlm',
                  {'form': form})
Exemple #4
0
    def post(self, request, *args, **kwargs):
        try:
            opening = Opening.objects.get(id=self.kwargs['opening_id'])
        except Opening.DoesNotExist:
            raise Http404

        if not opening.published_date:
            raise Http404

        form = ApplicationForm(request.POST, request.FILES, opening=opening)

        if form.is_valid():
            applicant = form.save()
            send_customised_email("application_received",
                    company=opening.company,
                    to=applicant.email,
                    context=dict(applicant_first_name=applicant.first_name,
                                 applicant_last_name=applicant.last_name,
                                 company=mark_safe(opening.company.name),
                                 opening=mark_safe(opening.title))
            )
            return redirect('public:confirmation', opening_id=opening.id)
        else:
            context = {
                'opening': opening,
                'company': opening.company,
                'form': form
            }
            return self.render_to_response(context)
Exemple #5
0
    def test_forms(self):
        self.group = ApplicationGroup.objects.create(name='devops',
                                                     text_main='asd')

        data = {
            'name': 'Testesson Test',
            'email': '*****@*****.**',
            'phone': '12312312',
            'study': 'informatikk',
            'year': 2,
            'group_choice': [
                1,
            ],
            'knowledge_of_hs': 'blabla',
            'about': 'blabla',
            'application_text': 'blabla'
        }

        self.form = ApplicationForm(data)
        self.form.save()
        self.form.send_email()

        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(mail.outbox[0].subject,
                         '[Hackerspace NTNU] Søknad er registrert!')
        self.assertEqual(mail.outbox[0].to[0], data.get('email'))
Exemple #6
0
    def post(self, request, *args, **kwargs):
        try:
            opening = Opening.objects.get(id=self.kwargs['opening_id'])
        except Opening.DoesNotExist:
            raise Http404

        if not opening.published_date:
            raise Http404

        form = ApplicationForm(request.POST, request.FILES, opening=opening)

        if form.is_valid():
            applicant = form.save()
            send_customised_email(
                "application_received",
                company=opening.company,
                to=applicant.email,
                context=dict(applicant_first_name=applicant.first_name,
                             applicant_last_name=applicant.last_name,
                             company=mark_safe(opening.company.name),
                             opening=mark_safe(opening.title)))
            return redirect('public:confirmation', opening_id=opening.id)
        else:
            context = {
                'opening': opening,
                'company': opening.company,
                'form': form
            }
            return self.render_to_response(context)
Exemple #7
0
    def test_application_without_questions_valid(self):
        opening = OpeningFactory()

        files = {'resume': self._get_temporary_file()}
        form = ApplicationForm(self.form_data, files, opening=opening)

        self.assertTrue(form.is_valid())
Exemple #8
0
    def test_application_without_questions_invalid(self):
        opening = OpeningFactory()
        invalid = dict(self.form_data)
        del invalid['first_name']

        files = {'resume': self._get_temporary_file()}
        form = ApplicationForm(invalid, files, opening=opening)
        self.assertFalse(form.is_valid())
Exemple #9
0
    def test_application_with_questions_valid(self):
        opening = OpeningWithQuestionFactory()
        data = dict(self.form_data)
        data.update(self.question_data)

        files = {'resume': self._get_temporary_file()}
        form = ApplicationForm(data, files, opening=opening)

        self.assertTrue(form.is_valid())
Exemple #10
0
    def test_application_with_missing_required_valid(self):
        opening = OpeningWithQuestionFactory()
        data = dict(self.form_data)
        data.update(self.question_data)
        del data['question-1']

        files = {'resume': self._get_temporary_file()}
        form = ApplicationForm(data, files, opening=opening)

        self.assertFalse(form.is_valid())
Exemple #11
0
def create(request):
    form = ApplicationForm(request.POST)
    form.owner = request.user
    if form.is_valid():
        form.save()
    else:
        # report errors (just the text)
        for k, v in form.errors.iteritems():
            messages.add_message(request, messages.ERROR, v[0].capitalize())
    return redirect(reverse("applications.views.index"))
Exemple #12
0
def create(request):
    form = ApplicationForm()
    if request.method == 'POST':
        form = ApplicationForm(request.POST)
        form.owner = request.user
        if form.is_valid():
            app = form.save()
            return redirect(reverse('applications.views.index'))
    ctx = {
        'form': form
    }
    return render_to_response('applications/create_application.html', ctx,
        context_instance=RequestContext(request))
Exemple #13
0
    def test_should_not_create_new_applicant_if_exists(self):
        ApplicantFactory(email='*****@*****.**')
        company = CompanyFactory()
        opening = OpeningFactory(company=company)
        InterviewStageFactory(tag='RECEIVED', company=company)

        files = {'resume': self._get_temporary_file()}
        form = ApplicationForm(self.form_data, files, opening=opening)
        self.assertTrue(form.is_valid())

        form.save()

        self.assertEqual(Applicant.objects.count(), 1)
Exemple #14
0
    def test_application_form_prevent_duplicate_emails(self):
        form_questions = [{
            "title": "Your e-mail address:",
            "question_type": "email",
        }]
        # Override default questions, we need just the e-mail
        self.form.question_set.all().delete()
        for i, question in enumerate(form_questions, start=1):
            question['form'] = self.form
            question['order'] = i
            Question.objects.create(**question)

        self.assertEqual(Application.objects.count(), 0)
        questions = self.form.question_set.all()

        form_data = {
            'newsletter_optin': 'yes',
            'g-recaptcha-response': 'PASSED'
        }
        for question in questions:
            if question.title == "Your e-mail address:":
                form_data.update(
                    {'question_{}'.format(question.pk): '*****@*****.**'})
                continue

        form = ApplicationForm(form_data, form=self.form)

        self.assertTrue(form.is_valid())
        form.save()
        self.assertEqual(Application.objects.count(), 1)
        form = ApplicationForm(form_data, form=self.form)
        self.assertFalse(form.is_valid())
Exemple #15
0
    def test_save_with_company_stage(self):
        ApplicantFactory(email='*****@*****.**')
        company1 = CompanyFactory()
        company2 = CompanyFactory()
        opening = OpeningFactory(company=company1)
        stage_company1 = InterviewStageFactory(tag='RECEIVED', company=company1)
        stage_company2 = InterviewStageFactory(tag='RECEIVED', company=company2)

        files = {'resume': self._get_temporary_file()}
        form = ApplicationForm(self.form_data, files, opening=opening)
        self.assertTrue(form.is_valid())

        form.save()

        self.assertEqual(Applicant.objects.count(), 1)
Exemple #16
0
def details(request, app_uuid=None):
    app = Application.objects.get(uuid=app_uuid)
    form = ApplicationForm(instance=app)
    if request.method == 'POST':
        form = ApplicationForm(request.POST, instance=app)
        if form.is_valid():
            form.save()
            try:
                app.update_config()
                messages.add_message(request, messages.INFO,
                    _('Application updated'))
                return redirect(reverse('applications.views.index'))
            except KeyError, e:
                messages.add_message(request, messages.ERROR,
                    _('Error updating hipache.  Invalid container port') + \
                        ': {}'.format(e[0]))
Exemple #17
0
 def test_form_save_creates_object(self):
     data = {
         'first_names': 'Alice',
         'last_names': 'In Chains',
         'primary_phone': '809-000-0023',
         'national_id_number': '123-456789-0',
         'national_id_type': 0,
         'address_line_one': 'Wonderland, mad hatter\'s house',
         'email': '*****@*****.**',
         'birth_date': '1998-11-10',
         'gender': 1,
     }
     form = ApplicationForm(data=data)
     print(form.errors.as_data())
     instance = form.save()
     self.assertEqual(Application.objects.first(), instance)
Exemple #18
0
def manage_application(request, event):
    if request.method == 'POST':
        form = ApplicationForm(request.POST)
        if form.is_valid():
            instance = form.save(commit=False)
            instance.user = request.user
            #FIXME 
            instance.event = event
            instance.status = 0 #pending
            instance.save()
    else:
        form = ApplicationForm()

    return render_to_response("applications/application_form.html", 
        {"form": form},
        context_instance=RequestContext(request)
        )
Exemple #19
0
def test_application_form_no_questions():
    event = Event.objects.create(name='Test',
                                 city='Test',
                                 country='Test',
                                 is_page_live=True,
                                 page_url='test')
    form = Form.objects.create(event=event)

    # Override default questions, we need just the e-mail
    form.question_set.all().delete()

    assert Application.objects.count() == 0

    form_data = {'newsletter_optin': 'yes', 'g-recaptcha-response': 'PASSED'}

    application_form = ApplicationForm(form_data, form=form)
    assert application_form.is_valid()
Exemple #20
0
def index(request):
    ctx = {
        'applications': Application.objects.filter(Q(owner=None) |
            Q(owner=request.user)),
        'form_application': ApplicationForm(),
    }
    return render_to_response('applications/index.html', ctx,
        context_instance=RequestContext(request))
Exemple #21
0
def regular_application(request):
    application = ApplicationFormModel.objects.get(user_id=request.user.id)

    if request.method == 'POST':

        application_form = ApplicationForm(request.POST, instance=application)

        if application_form.is_valid():
            application_form.save()
            return HttpResponseRedirect('/')
        else:
            print('forms not valid')

    # dictionary of all user application fields
    application_dict = application.__dict__
    # fields to exclude from form:
    excluded_fields = {'id', 'user_id', '_state'}
    # dictionary of fields to include on form
    application_fields = {
        k: v
        for (k, v) in application_dict.items() if k not in excluded_fields
    }

    # generate dictionary that includes all needed keys and default values:
    default_dict = {}
    default_dict['user'] = request.user.id
    for k, v in application_fields.items():
        default_dict[k] = v

    application_form = ApplicationForm(initial=default_dict)

    return render(request, 'regular_application.html', {
        'application_form': application_form,
    })
Exemple #22
0
def create(request):
    form = ApplicationForm()
    if request.method == 'POST':
        form = ApplicationForm(request.POST)
        form.owner = request.user
        if form.is_valid():
            form.save()
            return redirect(reverse('applications.views.index'))
    ctx = {
        'form': form
    }
    return render_to_response('applications/create_application.html', ctx,
        context_instance=RequestContext(request))
Exemple #23
0
    def get(self, request, *args, **kwargs):
        applicant_id = kwargs.get('applicant_id')
        applicant_obj = get_object_or_404(ApplicantProfile, id=applicant_id)
        application_form = ApplicationForm()

        context = {
            'title': 'Apply',
            'applicant_id': applicant_id,
            'application_form': application_form
        }

        return render(request, 'applicant/applications/apply.html', context)
Exemple #24
0
    def test_application_form_prevent_duplicate_emails(self):
        form_questions = [
            {
                "title": "Your e-mail address:",
                "question_type": "email",
            }
        ]
        # Override default questions, we need just the e-mail
        self.form.question_set.all().delete()
        for i, question in enumerate(form_questions, start=1):
            question['form'] = self.form
            question['order'] = i
            Question.objects.create(**question)

        self.assertEqual(Application.objects.count(), 0)
        questions = self.form.question_set.all()

        form_data = {
            'newsletter_optin': 'yes',
            'g-recaptcha-response': 'PASSED'
        }
        for question in questions:
            if question.title == "Your e-mail address:":
                form_data.update({
                    'question_{}'.format(question.pk): '*****@*****.**'
                })
                continue

        form = ApplicationForm(form_data, form=self.form)

        self.assertTrue(form.is_valid())
        form.save()
        self.assertEqual(Application.objects.count(), 1)
        form = ApplicationForm(form_data, form=self.form)
        self.assertFalse(form.is_valid())
Exemple #25
0
    def test_subsequent_applications_fail(self):
        form = ApplicationForm(
            data={
                'first_names': self.profile.first_names,
                'last_names': self.profile.last_names,
                'primary_phone': self.profile.primary_phone,
                'national_id_number': self.profile.natid,
                'address_line_one': 'ma-haus',
                'email': self.profile.email,
            })
        form.save()

        form2 = ApplicationForm(
            data={
                'first_names': self.profile.first_names,
                'last_names': self.profile.last_names,
                'primary_phone': self.profile.primary_phone,
                'national_id_number': self.profile.natid,
                'address_line_one': 'ma-haus',
                'email': self.profile.email,
            })

        self.assertRaises(ValidationError, form2.save)
Exemple #26
0
class ApplicationFormViewTest(TestCase):
    def setUp(self):
        self.client = Client()
        self.response = self.client.get(
            reverse('application:application_form'))

    def test_context(self):
        self.assertIsNotNone(self.response.context['start_date'])
        self.assertIsNotNone(self.response.context['end_date'])

    def test_forms(self):
        self.group = ApplicationGroup.objects.create(name='devops',
                                                     text_main='asd')

        data = {
            'name': 'Testesson Test',
            'email': '*****@*****.**',
            'phone': '12312312',
            'study': 'informatikk',
            'year': 2,
            'group_choice': [
                1,
            ],
            'knowledge_of_hs': 'blabla',
            'about': 'blabla',
            'application_text': 'blabla'
        }

        self.form = ApplicationForm(data)
        self.form.save()
        self.form.send_email()

        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(mail.outbox[0].subject,
                         '[Hackerspace NTNU] Søknad er registrert!')
        self.assertEqual(mail.outbox[0].to[0], data.get('email'))
Exemple #27
0
def create(request):
    form = ApplicationForm(request.POST)
    form.owner = request.user
    if form.is_valid():
        form.save()
    else:
        # report errors (just the text)
        for k, v in form.errors.iteritems():
            messages.add_message(request, messages.ERROR, v[0].capitalize())
    return redirect(reverse('applications.views.index'))
Exemple #28
0
    def test_should_not_be_valid_if_resume_not_pdf(self):
        opening = OpeningFactory()

        files = {'resume': self._get_temporary_file(type='evil/hacker')}
        form = ApplicationForm(self.form_data, files, opening=opening)
        self.assertFalse(form.is_valid())

        files = {'resume': self._get_temporary_file(extension='py')}
        form = ApplicationForm(self.form_data, files, opening=opening)
        self.assertFalse(form.is_valid())
Exemple #29
0
    def get(self, request, *args, **kwargs):
        try:
            opening = Opening.objects.get(id=self.kwargs['opening_id'])
        except Opening.DoesNotExist:
            raise Http404

        if not opening.published_date:
            raise Http404

        context = {
            'opening': opening,
            'company': opening.company,
            'form': ApplicationForm(opening=opening)
        }

        return self.render_to_response(context)
Exemple #30
0
    def test_should_be_valid_if_resume_is_doc_docx(self):
        opening = OpeningFactory()
        files = {'resume': self._get_temporary_file(
          type='application/msword', extension='.DOC')}
        form = ApplicationForm(self.form_data, files, opening=opening)
        self.assertTrue(form.is_valid())

        files = {'resume': self._get_temporary_file(
          type='application/vnd.oasis.opendocument.text', extension='.dOcX')}
        form = ApplicationForm(self.form_data, files, opening=opening)
        self.assertTrue(form.is_valid())
Exemple #31
0
def details(request, app_uuid=None):
    app = Application.objects.get(uuid=app_uuid)
    form = ApplicationForm(instance=app)
    if request.method == 'POST':
        form = ApplicationForm(request.POST, instance=app)
        if form.is_valid():
            form.save()
            try:
                app.update_config()
                messages.add_message(request, messages.INFO,
                                     _('Application updated'))
                return redirect(reverse('applications.views.index'))
            except KeyError, e:
                messages.add_message(request, messages.ERROR,
                    _('Error updating hipache.  Invalid container port') + \
                        ': {}'.format(e[0]))
Exemple #32
0
def create_application(request):
    if request.method == 'POST':
        form = ApplicationForm(request.POST)
        if form.is_valid():
            application = form.save(commit=False)
            application.save()
    else:
        form = ApplicationForm()
    return render(request,
                  'applications/application_form.html',
                  context={
                      'form': form,
                      'COMPANY_NAME': settings.BRAND_DICT['COMPANY_NAME'],
                  })
Exemple #33
0
    if request.method == 'POST':
        form = ApplicationForm(request.POST, instance=app)
        if form.is_valid():
            form.save()
            try:
                app.update_config()
                messages.add_message(request, messages.INFO,
                                     _('Application updated'))
                return redirect(reverse('applications.views.index'))
            except KeyError, e:
                messages.add_message(request, messages.ERROR,
                    _('Error updating hipache.  Invalid container port') + \
                        ': {}'.format(e[0]))
    ctx = {
        'application': app,
        'form': ApplicationForm(instance=app),
    }
    return render_to_response('applications/application_details.html',
                              ctx,
                              context_instance=RequestContext(request))


@login_required
def _details(request, app_uuid=None):
    app = Application.objects.get(uuid=app_uuid)
    attached_container_ids = [x.container_id for x in app.containers.all()]
    initial = {
        'name': app.name,
        'description': app.description,
        'domain_name': app.domain_name,
        'backend_port': app.backend_port,
Exemple #34
0
    def post(self, request, *args, **kwargs):
        applicant_id = kwargs.get('applicant_id')
        application_form = ApplicationForm(request.POST)

        if application_form.is_valid():
            institute_id = request.POST.get('institute')
            institute_obj = get_object_or_404(InstitutionProfile,
                                              id=institute_id)
            applicant_obj = get_object_or_404(ApplicantProfile,
                                              id=applicant_id)

            if institute_obj.gender == '1' and applicant_obj.gender == '2':
                messages.error(
                    request,
                    f"{institute_obj.institute_name} Is Only Allow Male Student"
                )
                return redirect('applications:apply', applicant_obj.id)
            if institute_obj.gender == '2' and applicant_obj.gender == '1':
                messages.error(
                    request,
                    f"{institute_obj.institute_name} Is Only Allow Female Student"
                )
                return redirect('applications:apply', applicant_obj.id)

            check_application = Application.objects.filter(
                applicant=applicant_obj, institute=institute_obj).first()

            if check_application and check_application.paid:
                messages.info(
                    request,
                    f"You Already Apply For {institute_obj.institute_name}.Please Wiat For Admit Card"
                )
                return redirect('applications:application_list')
            if check_application and not check_application.paid:
                messages.info(
                    request,
                    f"You Already Apply For {institute_obj.institute_name}.Please Pay The Fees"
                )
                return redirect('applications:application_list')

            check_session = AdmissionSession.objects.filter(
                institute=institute_obj, status=True).first()

            if not check_session:
                messages.error(
                    request,
                    f"Now Admission Is Closed For {institute_obj.institute_name}"
                )
                return redirect('applications:apply', applicant_obj.id)

            if check_session.level == '1' and request.POST.get('level') == '2':
                messages.error(
                    request,
                    f"{institute_obj.institute_name} Only Avialable For Bachelor Admission"
                )
                return redirect('applications:apply', applicant_obj.id)

            if check_session.level == '2' and request.POST.get('level') == '1':
                messages.error(
                    request,
                    f"{institute_obj.institute_name} Only Avialable For Masters Admission"
                )
                return redirect('applications:apply', applicant_obj.id)

            subject_obj = get_object_or_404(InstitutionSubject,
                                            id=request.POST.get('subject'))

            if subject_obj.level == '1' and request.POST.get('level') == '2':
                messages.error(
                    request,
                    f"{subject_obj.subject_name} In {institute_obj.institute_name} Only Avialable For Bachelor"
                )
                return redirect('applications:apply', applicant_obj.id)

            if subject_obj.level == '2' and request.POST.get('level') == '1':
                messages.error(
                    request,
                    f"{subject_obj.subject_name} In {institute_obj.institute_name} Only Avialable For Masters"
                )
                return redirect('applications:apply', applicant_obj.id)

            application_form_obj = application_form.save(commit=False)
            application_form_obj.owner = request.user
            application_form_obj.applicant = applicant_obj
            application_form_obj.save()
            messages.success(
                request,
                f"Apply For {applicant_obj.student_name} In {institute_obj.institute_name} Is Successfully Completed"
            )
            return redirect('applications:application_list')
        else:
            context = {
                'title': 'Apply',
                'applicant_id': applicant_id,
                'application_form': application_form
            }
            return render(request, 'applicant/applications/apply.html',
                          context)