def show_success_pdf(request): """ Given there is valid information in the session this view sends an encrypted mail to C3S staff with the users data set and returns a PDF for the user. It is called after visiting the verification URL/page/view in def success_verify_email below. """ #check if user has used form or 'guessed' this URL if ('appstruct' in request.session): # we do have valid info from the form in the session #print("-- valid session with data found") # send mail to accountants // prepare a mailer mailer = get_mailer(request) # prepare mail appstruct = request.session['appstruct'] message_recipient = request.registry.settings['c3smembership.mailaddr'] appstruct['message_recipient'] = message_recipient the_mail = accountant_mail(appstruct) mailer.send(the_mail) return generate_pdf(request.session['appstruct']) # 'else': send user to the form #print("-- no valid session with data found") return HTTPFound(location=request.route_url('join'))
def regenerate_pdf(request): """ staffers can regenerate a users pdf """ _code = request.matchdict['code'] _member = C3sMember.get_by_code(_code) if _member is None: # that memberid did not produce good results return HTTPFound( # back to base request.route_url('dashboard_only')) _appstruct = { 'firstname': _member.firstname, 'lastname': _member.lastname, 'address1': _member.address1, 'address2': _member.address2, 'postcode': _member.postcode, 'city': _member.city, 'email': _member.email, 'email_confirm_code': _member.email_confirm_code, 'country': _member.country, '_LOCALE_': _member.locale, 'membership_type': _member.membership_type, 'num_shares': _member.num_shares, 'date_of_birth': _member.date_of_birth, 'date_of_submission': _member.date_of_submission, } log.info( "%s regenerated the PDF for code %s" % ( authenticated_userid(request), _code)) return generate_pdf(_appstruct)
def regenerate_pdf(request): """ Staffers can regenerate an applicants PDF and send it to her. """ code = request.matchdict['code'] member = C3sMember.get_by_code(code) if member is None: return get_dashboard_redirect(request) membership_application = request.registry.membership_application.get( member.id) appstruct = { 'firstname': member.firstname, 'lastname': member.lastname, 'address1': member.address1, 'address2': member.address2, 'postcode': member.postcode, 'city': member.city, 'email': member.email, 'email_confirm_code': membership_application['payment_token'], 'country': member.country, 'locale': member.locale, 'membership_type': membership_application['membership_type'], 'num_shares': membership_application['shares_quantity'], 'date_of_birth': member.date_of_birth, 'date_of_submission': membership_application['date_of_submission'], } LOG.info("%s regenerated the PDF for code %s", authenticated_userid(request), code) return generate_pdf(appstruct)
def regenerate_pdf(request): """ Staffers can regenerate an applicants PDF and send it to her. """ code = request.matchdict['code'] member = C3sMember.get_by_code(code) if member is None: return get_dashboard_redirect(request) appstruct = { 'firstname': member.firstname, 'lastname': member.lastname, 'address1': member.address1, 'address2': member.address2, 'postcode': member.postcode, 'city': member.city, 'email': member.email, 'email_confirm_code': member.email_confirm_code, 'country': member.country, '_LOCALE_': member.locale, 'membership_type': member.membership_type, 'num_shares': member.num_shares, 'date_of_birth': member.date_of_birth, 'date_of_submission': member.date_of_submission, } LOG.info( "%s regenerated the PDF for code %s", authenticated_userid(request), code) return generate_pdf(appstruct)
def show_success_pdf(request): """ Generates the membership application PDF to be signed by the applicant. """ # check if user has used form or 'guessed' this URL if 'appstruct' in request.session: return generate_pdf(request, request.session['appstruct']) return HTTPFound(location=request.route_url('join'))
def show_success_pdf(request): """ Given there is valid information in the session this view sends an encrypted mail to C3S staff with the users data set and returns a PDF for the user. It is called after visiting the verification URL/page/view in def success_verify_email below. """ # check if user has used form or 'guessed' this URL if 'appstruct' in request.session: # we do have valid info from the form in the session # print("-- valid session with data found") # send mail to accountants // prepare a mailer mailer = get_mailer(request) # prepare mail appstruct = request.session['appstruct'] message_recipient = request.registry.settings['c3smembership.mailaddr'] appstruct['message_recipient'] = message_recipient the_mail = accountant_mail(appstruct) if 'true' in request.registry.settings['testing.mail_to_console']: print(the_mail.body) else: try: mailer.send(the_mail) except: # if mailout fails for some reason (gnupg, whatever), we need # 1) a mail to staff, so we take notice and fix it # 2) a message to $user, so she does not worry staff_mail = Message( subject=_("[yes][ALERT] check the logs!"), sender="*****@*****.**", recipients=['*****@*****.**'], body=""" problems! problems! this is {} a user could not download her pdf, because.... maybe gnupg failed? something else? go fix it! """.format(request.registry.settings['c3smembership.url'])) mailer.send(staff_mail) request.session.flash( u"Oops. we hit a bug. Staff will be " u"informed. We will come back to you " u"once we fixed it!", 'message_to_user' # msg queue f. user ) return HTTPFound(request.route_url('error_page')) return generate_pdf(request.session['appstruct']) # 'else': send user to the form # print("-- no valid session with data found") return HTTPFound(location=request.route_url('join'))
def show_success_pdf(request): """ Given there is valid information in the session this view sends an encrypted mail to C3S staff with the users data set and returns a PDF for the user. It is called after visiting the verification URL/page/view in def success_verify_email below. """ # check if user has used form or 'guessed' this URL if 'appstruct' in request.session: # we do have valid info from the form in the session # print("-- valid session with data found") # send mail to accountants // prepare a mailer mailer = get_mailer(request) # prepare mail appstruct = request.session['appstruct'] message_recipient = request.registry.settings['c3smembership.mailaddr'] appstruct['message_recipient'] = message_recipient the_mail = accountant_mail(appstruct) if 'true' in request.registry.settings['testing.mail_to_console']: print(the_mail.body) else: try: mailer.send(the_mail) except: # if mailout fails for some reason (gnupg, whatever), we need # 1) a mail to staff, so we take notice and fix it # 2) a message to $user, so she does not worry staff_mail = Message(subject=_("[yes][ALERT] check the logs!"), sender="*****@*****.**", recipients=['*****@*****.**'], body=""" problems! problems! this is {} a user could not download her pdf, because.... maybe gnupg failed? something else? go fix it! """.format(request.registry.settings['c3smembership.url'])) mailer.send(staff_mail) request.session.flash( _(u"Oops. we hit a bug. Staff will be " u"informed. We will come back to you " u"once we fixed it!", 'message_to_user') # msg queue f. user ) return HTTPFound(request.route_url('error_page')) return generate_pdf(request.session['appstruct']) # 'else': send user to the form # print("-- no valid session with data found") return HTTPFound(location=request.route_url('join'))
def test_generate_pdf_en(self): """ Test pdf generation and resulting pdf size """ from c3smembership.utils import generate_pdf mock_appstruct = { 'firstname': u'Anne', 'lastname': u'Gilles', 'email': u'*****@*****.**', 'email_confirm_code': u'1234567890', 'date_of_birth': '1987-06-05', 'address1': 'addr one', 'address2': 'addr two', 'postcode': u'54321', 'city': u'Müsterstädt', 'country': u'some country', 'member_of_colsoc': 'member_of_colsoc', 'name_of_colsoc': 'Foo Colsoc', 'membership_type': u'investing', 'num_shares': '42', '_LOCALE_': 'en', 'date_of_submission': '2013-09-09 08:44:47.251588', } # a skipTest iff pdftk is not installed import subprocess from subprocess import CalledProcessError try: res = subprocess.check_call( ["which", "pdftk"], stdout=None) if res == 0: # go ahead with the tests result = generate_pdf(mock_appstruct) self.assertEquals(result.content_type, 'application/pdf') # print("size of pdf: " + str(len(result.body))) # check pdf size self.assertTrue(210000 > len(result.body) > 50000) # TODO: check pdf for contents except CalledProcessError, cpe: # pragma: no cover print("pdftk not installed. skipping test!") print(cpe)
def test_generate_pdf_en(self): """ Test pdf generation and resulting pdf size """ from c3smembership.utils import generate_pdf mock_appstruct = { 'firstname': u'Anne', 'lastname': u'Gilles', 'email': u'*****@*****.**', 'email_confirm_code': u'1234567890', 'date_of_birth': '1987-06-05', 'address1': 'addr one', 'address2': 'addr two', 'postcode': u'54321', 'city': u'Müsterstädt', 'country': u'some country', 'member_of_colsoc': 'member_of_colsoc', 'name_of_colsoc': 'Foo Colsoc', 'membership_type': u'investing', 'num_shares': '42', 'locale': 'en', 'date_of_submission': '2013-09-09 08:44:47.251588', } # a skipTest iff pdftk is not installed import subprocess from subprocess import CalledProcessError try: res = subprocess.check_call(["which", "pdftk"], stdout=None) if res == 0: # go ahead with the tests result = generate_pdf(mock_appstruct) self.assertEquals(result.content_type, 'application/pdf') # print("size of pdf: " + str(len(result.body))) # check pdf size self.assertTrue(210000 > len(result.body) > 50000) # TODO: check pdf for contents except CalledProcessError, cpe: # pragma: no cover print("pdftk not installed. skipping test!") print(cpe)
def show_success_pdf(request): """ This view just returns a PDF, given there is valid info in session """ #check if user has used form or 'guessed' this URL if ('appstruct' in request.session): # we do have valid info from the form in the session #print("-- valid session with data found") # send mail to accountants // prepare a mailer mailer = get_mailer(request) # prepare mail appstruct = request.session['appstruct'] the_mail = accountant_mail(appstruct) mailer.send(the_mail) return generate_pdf(request.session['appstruct']) # 'else': send user to the form #print("-- no valid session with data found") return HTTPFound(location=request.route_url('join'))
def test_generate_pdf_en(self): """ Test pdf generation and resulting pdf size """ from c3smembership.utils import generate_pdf mock_appstruct = { 'firstname': u'Anne', 'lastname': u'Gilles', 'email': u'*****@*****.**', 'email_confirm_code': u'1234567890', 'date_of_birth': '1987-06-05', 'address1': 'addr one', 'address2': 'addr two', 'postcode': u'54321', 'city': u'Müsterstädt', 'country': u'some country', 'member_of_colsoc': 'member_of_colsoc', 'name_of_colsoc': 'Foo Colsoc', 'membership_type': u'investing', 'num_shares': '42', 'locale': 'en', 'date_of_submission': '2013-09-09 08:44:47.251588', } # a skipTest iff pdftk is not installed import subprocess from subprocess import CalledProcessError try: res = subprocess.check_call( ['which', 'pdftk'], stdout=open(os.devnull, 'w')) if res == 0: # go ahead with the tests request = testing.DummyRequest() result = generate_pdf(request, mock_appstruct) self.assertEquals(result.content_type, 'application/pdf') # check pdf size self.assertTrue(210000 > len(result.body) > 50000) except CalledProcessError: pass
def show_success_pdf(request): """ Given there is valid information in the session this view sends an encrypted mail to C3S staff with the users data set and returns a PDF for the user. """ #check if user has used form or 'guessed' this URL if ('appstruct' in request.session): # we do have valid info from the form in the session #print("-- valid session with data found") # send mail to accountants // prepare a mailer mailer = get_mailer(request) # prepare mail appstruct = request.session['appstruct'] message_recipient = request.registry.settings['c3smembership.mailaddr'] appstruct['message_recipient'] = message_recipient the_mail = accountant_mail(appstruct) mailer.send(the_mail) return generate_pdf(request.session['appstruct']) # 'else': send user to the form #print("-- no valid session with data found") return HTTPFound(location=request.route_url('join'))
def regenerate_pdf(request): """ Staffers can regenerate an applicants PDF and send it to her. """ code = request.matchdict['code'] member = C3sMember.get_by_code(code) if member is None: request.session.flash( 'A member with code {} does not exist'.format(code), 'danger') return get_dashboard_redirect(request) membership_application = request.registry.membership_application.get( member.id) appstruct = { 'firstname': member.firstname, 'lastname': member.lastname, 'address1': member.address1, 'address2': member.address2, 'postcode': member.postcode, 'city': member.city, 'email': member.email, 'email_confirm_code': membership_application['payment_token'], 'country': member.country, 'locale': member.locale, 'membership_type': membership_application['membership_type'], 'num_shares': membership_application['shares_quantity'], 'date_of_birth': member.date_of_birth, 'date_of_submission': membership_application['date_of_submission'], } LOG.info( "%s regenerated the PDF for code %s", authenticated_userid(request), code) return generate_pdf(request, appstruct)