当前位置: 首页>>代码示例>>Python>>正文


Python C3sMember.get_by_id方法代码示例

本文整理汇总了Python中c3smembership.data.model.base.c3smember.C3sMember.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python C3sMember.get_by_id方法的具体用法?Python C3sMember.get_by_id怎么用?Python C3sMember.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在c3smembership.data.model.base.c3smember.C3sMember的用法示例。


在下文中一共展示了C3sMember.get_by_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_gen_cert_special_chars

# 需要导入模块: from c3smembership.data.model.base.c3smember import C3sMember [as 别名]
# 或者: from c3smembership.data.model.base.c3smember.C3sMember import get_by_id [as 别名]
    def test_gen_cert_special_chars(self):
        """
        test the certificate generation with awkward characters in datasets
        because LaTeX interprets some characters as special characters.
        """
        member1 = C3sMember.get_by_id(1)
        request = testing.DummyRequest()
        request.validated_matchdict = {
            'member': member1,
            'token': 'hotzenplotz',
        }

        result = generate_certificate(request)

        self.assertEqual(result.status_code, 404)  # not found

        request.validated_matchdict = {
            'member': member1,
            'token': 'hotzenplotz123',
        }
        member = C3sMember.get_by_id(1)
        member.firstname = u"Foobar Corp & Co."
        member.lastname = u"Your Number #1"
        member.certificate_token = u'hotzenplotz123'
        member.membership_accepted = True

        # # need to get the date right!
        member.certificate_email_date = datetime.now(
        ) - timedelta(weeks=1)

        result = generate_certificate(request)
        self.assertEqual(result.status_code, 200)
        self.assertTrue(MIN_PDF_SIZE < len(result.body) < MAX_PDF_SIZE)
        self.assertEqual(result.content_type, 'application/pdf')
开发者ID:C3S,项目名称:c3sMembership,代码行数:36,代码来源:test_membership_certificate.py

示例2: test_send_certificate_email_de

# 需要导入模块: from c3smembership.data.model.base.c3smember import C3sMember [as 别名]
# 或者: from c3smembership.data.model.base.c3smember.C3sMember import get_by_id [as 别名]
    def test_send_certificate_email_de(self):
        """
        test the send_certificate_email view (german)
        """
        request = testing.DummyRequest()
        request.validated_matchdict = {'member': C3sMember.get_by_id(1)}

        mailer = get_mailer(request)
        member1 = C3sMember.get_by_id(1)

        member1.membership_accepted = True
        member1.membership_loss_date = None
        result = send_certificate_email(request)
        self.assertEqual(result.status_code, 302)

        self.assertEqual(len(mailer.outbox), 1)
        self.assertEqual(
            mailer.outbox[0].subject,
            u"C3S-Mitgliedsbescheinigung"
        )
        self.assertTrue(
            u"Hallo SomeFirstnäme SomeLastnäme," in mailer.outbox[0].body)
        self.assertTrue(
            u"Deine persönliche Mitgliederbescheinig" in mailer.outbox[0].body)

        member1.membership_accepted = True
        member1.membership_loss_date = date.today() + timedelta(days=1)
        result = send_certificate_email(request)
        self.assertEqual(result.status_code, 302)

        self.assertEqual(len(mailer.outbox), 2)
开发者ID:C3S,项目名称:c3sMembership,代码行数:33,代码来源:test_membership_certificate.py

示例3: test_calculate_partial_dues18

# 需要导入模块: from c3smembership.data.model.base.c3smember import C3sMember [as 别名]
# 或者: from c3smembership.data.model.base.c3smember.C3sMember import get_by_id [as 别名]
    def test_calculate_partial_dues18(self):
        """
        A test to check if partial dues are calculated the right way.

        "Partial dues" means you have to pay for half a year only, for example.
        """
        from c3smembership.presentation.views.dues_2018 import (
            calculate_partial_dues18)
        member = C3sMember.get_by_id(1)
        res = calculate_partial_dues18(member)
        assert res == (u'q1_2018', D('50'))

        # english member
        member_en = C3sMember.get_by_id(2)
        res = calculate_partial_dues18(member_en)
        assert res == (u'q1_2018', D('50'))

        member_en.membership_date = date(2018, 6, 1)
        res = calculate_partial_dues18(member_en)
        assert res == (u'q2_2018', D('37.50'))

        member_en.membership_date = date(2018, 9, 1)
        res = calculate_partial_dues18(member_en)
        assert res == (u'q3_2018', D('25'))

        member_en.membership_date = date(2018, 11, 1)
        res = calculate_partial_dues18(member_en)
        assert res == (u'q4_2018', D('12.50'))
开发者ID:C3S,项目名称:c3sMembership,代码行数:30,代码来源:test_membership_dues_2018.py

示例4: test_generate_certificate_de

# 需要导入模块: from c3smembership.data.model.base.c3smember import C3sMember [as 别名]
# 或者: from c3smembership.data.model.base.c3smember.C3sMember import get_by_id [as 别名]
    def test_generate_certificate_de(self):
        """
        test the certificate download view (german)
        """
        member1 = C3sMember.get_by_id(1)
        request = testing.DummyRequest()
        request.validated_matchdict = {
            'member': member1,
            'token': 'hotzenplotz',
        }

        result = generate_certificate(request)

        self.assertEqual(result.status_code, 404)  # not found

        request.validated_matchdict = {
            'member': member1,
            'token': 'hotzenplotz123',
        }
        member = C3sMember.get_by_id(1)
        member.certificate_token = u'hotzenplotz123'
        member.membership_accepted = True

        result = generate_certificate(request)
        self.assertEqual(result.status_code, 404)  # not found

        # test: email/token is too old
        member.certificate_email_date = datetime.now(
        ) - timedelta(weeks=3)
        result = generate_certificate(request)
        self.assertEqual(result.status_code, 404)  # not found

        # need to get the date right!
        member.certificate_email_date = datetime.now(
        ) - timedelta(weeks=1)
        result = generate_certificate(request)

        self.assertEqual(result.status_code, 200)
        self.assertTrue(MIN_PDF_SIZE < len(result.body) < MAX_PDF_SIZE)
        self.assertEqual(result.content_type, 'application/pdf')

        # edge case: member has one share
        member.certificate_token = u'hotzenplotz123'
        member.num_shares = 1

        result = generate_certificate(request)
        self.assertTrue(MIN_PDF_SIZE < len(result.body) < MAX_PDF_SIZE)
        self.assertEqual(result.content_type, 'application/pdf')

        # edge case: member has one share
        member.certificate_token = u'hotzenplotz123'
        member.is_legalentity = True

        result = generate_certificate(request)

        self.assertTrue(MIN_PDF_SIZE < len(result.body) < MAX_PDF_SIZE)
        self.assertEqual(result.content_type, 'application/pdf')
开发者ID:C3S,项目名称:c3sMembership,代码行数:59,代码来源:test_membership_certificate.py

示例5: make_dues18_invoice_no_pdf

# 需要导入模块: from c3smembership.data.model.base.c3smember import C3sMember [as 别名]
# 或者: from c3smembership.data.model.base.c3smember.C3sMember import get_by_id [as 别名]
def make_dues18_invoice_no_pdf(request):
    """
    Show the invoice to a member verified by a URL token
    """
    token = request.matchdict['code']
    invoice_number = request.matchdict['i']
    invoice = DuesInvoiceRepository.get_by_number(
        invoice_number.lstrip('0'), 2018)

    member = None
    token_is_invalid = True
    older_than_a_year = True
    if invoice is not None:
        member = C3sMember.get_by_id(invoice.member_id)
        token_is_invalid = token != invoice.token
        older_than_a_year = (
            date.today() - invoice.invoice_date.date() > timedelta(days=365))

    if invoice is None or token_is_invalid or invoice.is_reversal:
        request.session.flash(
            u"No invoice found!",
            'warning'
        )
        return HTTPFound(request.route_url('error'))

    if older_than_a_year or member.dues18_paid:
        request.session.flash(
            u'This invoice cannot be downloaded anymore. '
            u'Please contact [email protected] for further information.',
            'warning'
        )
        return HTTPFound(request.route_url('error'))

    return get_dues18_invoice(invoice, request)
开发者ID:C3S,项目名称:c3sMembership,代码行数:36,代码来源:dues_2018.py

示例6: test_generate_certificate_en

# 需要导入模块: from c3smembership.data.model.base.c3smember import C3sMember [as 别名]
# 或者: from c3smembership.data.model.base.c3smember.C3sMember import get_by_id [as 别名]
    def test_generate_certificate_en(self):
        """
        test the certificate download view (english)
        """
        member2 = C3sMember.get_by_id(2)
        request = testing.DummyRequest()
        request.validated_matchdict = {
            'member': member2,
            'token': 'hotzenplotz',
        }

        result = generate_certificate(request)

        # check: this is *not* found because the token is *invalid*
        self.assertEqual(result.status_code, 404)

        request.validated_matchdict = {
            'member': member2,
            'token': 'hotzenplotz123',
        }
        member2.certificate_token = u'hotzenplotz123'
        member2.certificate_email_date = datetime.now() - timedelta(weeks=1)
        member2.membership_accepted = True
        member2.membership_loss_date = date.today() + timedelta(days=1)
        result = generate_certificate(request)
        self.assertEqual(result.status_code, 200)

        member2.certificate_email_date = datetime.now() - timedelta(weeks=1)
        member2.membership_accepted = True
        member2.membership_loss_date = None
        result = generate_certificate(request)

        self.assertTrue(MIN_PDF_SIZE < len(result.body) < MAX_PDF_SIZE)
        self.assertEqual(result.content_type, 'application/pdf')
开发者ID:C3S,项目名称:c3sMembership,代码行数:36,代码来源:test_membership_certificate.py

示例7: test_send_certificate_email_en

# 需要导入模块: from c3smembership.data.model.base.c3smember import C3sMember [as 别名]
# 或者: from c3smembership.data.model.base.c3smember.C3sMember import get_by_id [as 别名]
    def test_send_certificate_email_en(self):
        """
        test the send_certificate_email view (english)
        """
        member2 = C3sMember.get_by_id(2)

        self.config.add_route('join', 'join')
        self.config.add_route('dashboard', 'dashboard')
        self.config.add_route('certificate_pdf', 'certificate_pdf')
        self.config.add_route(
            'membership_listing_backend', 'membership_listing_backend')
        request = testing.DummyRequest()
        request.validated_matchdict = {'member': member2}

        mailer = get_mailer(request)
        result = send_certificate_email(request)
        self.assertEqual(result.status_code, 302)
        self.assertTrue('membership_listing_backend' in result.location)
        self.assertEqual(len(mailer.outbox), 1)

        request.referer = 'dashboard'

        result = send_certificate_email(request)
        self.assertEqual(result.status_code, 302)

        self.assertEqual(len(mailer.outbox), 2)
        self.assertEqual(
            mailer.outbox[1].subject,
            u"C3S membership certificate"
        )
        self.assertTrue(
            u"Hello AAASomeFirstnäme XXXSomeLastnäme,"
            in mailer.outbox[1].body)
        self.assertTrue(
            u"your personal membership certificate" in mailer.outbox[1].body)
开发者ID:C3S,项目名称:c3sMembership,代码行数:37,代码来源:test_membership_certificate.py

示例8: test_api_userinfo

# 需要导入模块: from c3smembership.data.model.base.c3smember import C3sMember [as 别名]
# 或者: from c3smembership.data.model.base.c3smember.C3sMember import get_by_id [as 别名]
    def test_api_userinfo(self):
        """
        Test the api_userinfo service.

        * must be a PUT, not a GET request
        * the auth header must be present
        * returns None if members refcode does not match
        * returns firstname, lastname, email, membership type
        """
        # try a GET -- must fail
        res = self.testapp.get('/lm', status=405)
        self.assertTrue('405 Method Not Allowed' in res.body)
        self.assertTrue('The method GET is not allowed for this resource.'
                        in res.body)

        # try a PUT -- fails under certain conditions
        with self.assertRaises(ValueError):
            res = self.testapp.put('/lm', status=200)
            # ValueError: No JSON object could be decoded

        # try a PUT -- fails under certain conditions
        with self.assertRaises(KeyError):
            res = self.testapp.put_json(
                '/lm', dict(id=1))  # status=200)
            # KeyError: 'token'
        # missing auth token -- must fail
        with self.assertRaises(KeyError):
            res = self.testapp.put_json(
                '/lm', dict(token=1))  # status=200)
            # KeyError: 'HTTP_X_MESSAGING_TOKEN'

        # try false auth token -- must fail: 401 unauthorized
        _headers = {'X-messaging-token': 'bar'}
        res = self.testapp.put_json(
            '/lm', dict(token=1), headers=_headers, status=401)

        # now use the correct auth token
        _auth_info = {'X-messaging-token': 'SECRETAUTHTOKEN'}

        # ..but a non-existing refcode
        # returns no user (None)
        res = self.testapp.put_json(
            '/lm', dict(token='foo'), headers=_auth_info, status=200)
        # body: {"lastname": "None", "firstname": "None"}
        self.assertTrue(json.loads(res.body)['firstname'], "None")
        self.assertTrue(json.loads(res.body)['lastname'], "None")

        self.testapp.reset()

        member1 = C3sMember.get_by_id(1)  # load member from DB for crosscheck

        # now try a valid refcode
        res2 = self.testapp.put_json(
            '/lm', dict(token='MEMBERS_TOKEN'),
            headers=_auth_info, status=200)
        self.assertTrue(json.loads(res2.body)['firstname'], member1.firstname)
        self.assertTrue(json.loads(res2.body)['lastname'], member1.lastname)
        self.assertTrue(json.loads(res2.body)['email'], member1.email)
        self.assertTrue(
            json.loads(res2.body)['mtype'], member1.membership_type)
开发者ID:C3S,项目名称:c3sMembership,代码行数:62,代码来源:test_api_views.py

示例9: test_string_start_quarter_dues18

# 需要导入模块: from c3smembership.data.model.base.c3smember import C3sMember [as 别名]
# 或者: from c3smembership.data.model.base.c3smember.C3sMember import get_by_id [as 别名]
    def test_string_start_quarter_dues18(self):
        """
        Tests for the strings used for partial time spans.
        """
        from c3smembership.presentation.views.dues_2018 import (
            string_start_quarter_dues18,
        )
        member = C3sMember.get_by_id(1)

        member.dues18_start = 'q1_2018'
        res = string_start_quarter_dues18(member)
        assert(u'für das ganze Jahr' in res)
        member.dues18_start = 'q2_2018'
        res = string_start_quarter_dues18(member)
        assert('Quartal 2' in res)
        member.dues18_start = 'q3_2018'
        res = string_start_quarter_dues18(member)
        assert('Quartal 3' in res)
        member.dues18_start = 'q4_2018'
        res = string_start_quarter_dues18(member)
        assert('Quartal 4' in res)

        member.locale = u'en'
        member.dues18_start = 'q1_2018'
        res = string_start_quarter_dues18(member)
        assert('for the whole year' in res)
        member.dues18_start = 'q2_2018'
        res = string_start_quarter_dues18(member)
        assert('2nd quarter' in res)
        member.dues18_start = 'q3_2018'
        res = string_start_quarter_dues18(member)
        assert('3rd quarter' in res)
        member.dues18_start = 'q4_2018'
        res = string_start_quarter_dues18(member)
        assert('4th quarter' in res)
开发者ID:C3S,项目名称:c3sMembership,代码行数:37,代码来源:test_membership_dues_2018.py

示例10: test_shares_edit

# 需要导入模块: from c3smembership.data.model.base.c3smember import C3sMember [as 别名]
# 或者: from c3smembership.data.model.base.c3smember.C3sMember import get_by_id [as 别名]
    def test_shares_edit(self):
        '''
        tests for the shares_edit view
        '''
        # unauthorized access must be prevented
        res = self.testapp.reset()  # delete cookie
        res = self.testapp.get('/shares_edit/1', status=403)
        assert('Access was denied to this resource' in res.body)
        res = self.testapp.get('/login', status=200)
        self.failUnless('login' in res.body)
        # try valid user
        form = res.form
        form['login'] = u'rut'
        form['password'] = u'berries'
        res2 = form.submit('submit', status=302)
        # # being logged in ...
        res3 = res2.follow()  # being redirected to dashboard with parameters
        self.failUnless('Acquisition of membership' in res3.body)

        # no member in DB, so redirecting to dashboard
        res = self.testapp.get('/shares_edit/1', status=302)
        res2 = res.follow()

        self.make_member_with_shares()

        # now there is a member with shares in the DB
        #
        # lets try invalid input
        res = self.testapp.get('/shares_edit/foo', status=302)
        res2 = res.follow()
        self.failUnless('Members' in res2.body)

        # now try valid id
        res = self.testapp.get('/shares_edit/1', status=200)
        self.failUnless('Edit Details for Shares' in res.body)

        # now we change details, really editing that member
        form = res.form

        if DEBUG:
            print "form.fields: {}".format(form.fields)

        self.assertTrue('2' in form['number'].value)
        self.assertTrue(datetime.today().strftime(
            '%Y-%m-%d') in form['date_of_acquisition'].value)
        # print(form['date_of_acquisition'].value)
        form['number'] = u'3'
        form['date_of_acquisition'] = u'2015-01-02'

        # try to submit now. this must fail,
        # because the date of birth is wrong
        # ... and other dates are missing
        res2 = form.submit('submit', status=200)

        # check data in DB
        _m1 = C3sMember.get_by_id(1)
        self.assertTrue(_m1.shares[0].number is 3)
        self.assertTrue(str(
            _m1.shares[0].date_of_acquisition) in str(datetime(2015, 1, 2)))
开发者ID:C3S,项目名称:c3sMembership,代码行数:61,代码来源:test_shares_webtest.py

示例11: make_invoice_pdf_pdflatex

# 需要导入模块: from c3smembership.data.model.base.c3smember import C3sMember [as 别名]
# 或者: from c3smembership.data.model.base.c3smember.C3sMember import get_by_id [as 别名]
def make_invoice_pdf_pdflatex(invoice):
    """
    This function uses pdflatex to create a PDF
    as receipt for the members membership dues.

    default output is the current invoice.
    if i_no is suplied, the relevant invoice number is produced
    """

    dues19_archive_invoice = get_dues19_archive_invoice(invoice)
    if dues19_archive_invoice is not None:
        return dues19_archive_invoice

    member = C3sMember.get_by_id(invoice.member_id)

    template_name = 'invoice_de' if 'de' in member.locale else 'invoice_en'
    bg_pdf = PDF_BACKGROUNDS['blank']
    tpl_tex = LATEX_TEMPLATES[template_name]

    # on invoice, print start quarter or "reduced". prepare string:
    if (not invoice.is_reversal and
            invoice.is_altered and
            invoice.preceding_invoice_no is not None):
        is_altered_str = u'angepasst' if (
            'de' in member.locale) else u'altered'

    invoice_no = str(invoice.invoice_no).zfill(4)
    invoice_date = invoice.invoice_date.strftime('%d. %m. %Y')

    # set variables for tex command
    dues_start = DUES_CALCULATOR.get_description(
        DUES_CALCULATOR.calculate_quarter(member),
        member.locale)

    tex_vars = {
        'personalFirstname': member.firstname,
        'personalLastname': member.lastname,
        'personalAddressOne': member.address1,
        'personalAddressTwo': member.address2,
        'personalPostCode': member.postcode,
        'personalCity': member.city,
        'personalMShipNo': unicode(member.membership_number),
        'invoiceNo': invoice_no,
        'invoiceDate': invoice_date,
        'account': unicode(
            -member.dues15_balance - member.dues16_balance -
            member.dues17_balance - member.dues18_balance -
            member.dues19_balance),
        'duesStart':  is_altered_str if (
            invoice.is_altered) else dues_start,
        'duesAmount': unicode(invoice.invoice_amount),
        'lang': 'de',
        'pdfBackground': bg_pdf,
    }

    return create_pdf(tex_vars, tpl_tex, invoice)
开发者ID:C3S,项目名称:c3sMembership,代码行数:58,代码来源:dues_2019.py

示例12: test_gen_cert_staff_int

# 需要导入模块: from c3smembership.data.model.base.c3smember import C3sMember [as 别名]
# 或者: from c3smembership.data.model.base.c3smember.C3sMember import get_by_id [as 别名]
    def test_gen_cert_staff_int(self):
        """
        Integration test the generate_certificate_staff view

        1. Validation failure, no a number
        2. Validation failure, no member found
        3. Validation failure, membership not granted
        4. Validation success
        """
        member = Mock()
        member_information = Mock()
        self.config.registry.member_information = member_information

        # 1. Validation failure, no a number
        result = self.testapp.get('/certificate_pdf_staff/asdf')

        self.assertEqual(
            self.error_handler.calls.pop()['errors']['member_id'],
            '"asdf" is not a number')
        self.assertEqual(result.status_code, 302)
        self.assertTrue('membership_listing_backend' in result.location)

        # 2. Validation failure, no member found
        member_information.get_member_by_id.side_effect = [None]

        result = self.testapp.get('/certificate_pdf_staff/1')

        self.assertEqual(
            self.error_handler.calls.pop()['errors']['member_id'],
            'Member ID 1 does not exist.')
        self.assertEqual(result.status_code, 302)
        self.assertTrue('membership_listing_backend' in result.location)

        # 3. Validation failure, membership not granted
        member.is_member.side_effect = [False]
        member_information.get_member_by_id.side_effect = [member]

        result = self.testapp.get('/certificate_pdf_staff/1')

        self.assertEqual(
            self.error_handler.calls.pop()['errors']['member_id'],
            'Member with member ID 1 has not been granted membership')
        self.assertEqual(result.status_code, 302)
        self.assertTrue('membership_listing_backend' in result.location)

        # 4. Validation success
        member1 = C3sMember.get_by_id(1)
        member1.membership_accepted = True
        member_information.get_member_by_id.side_effect = [member1]

        result = self.testapp.get('/certificate_pdf_staff/1')

        self.assertEqual(result.status_code, 200)
        self.assertTrue(MIN_PDF_SIZE < len(result.body) < MAX_PDF_SIZE)
开发者ID:C3S,项目名称:c3sMembership,代码行数:56,代码来源:test_membership_certificate.py

示例13: dues18_notice

# 需要导入模块: from c3smembership.data.model.base.c3smember import C3sMember [as 别名]
# 或者: from c3smembership.data.model.base.c3smember.C3sMember import get_by_id [as 别名]
def dues18_notice(request):
    """
    notice of arrival for transferral of dues
    """
    member_id = request.matchdict.get('member_id')
    member = C3sMember.get_by_id(member_id)  # is in database
    if (member is None or
            not member.membership_accepted or
            not member.dues18_invoice):
        request.session.flash(
            u"Member not found or not a member or no invoice to pay for",
            'dues18_message_to_staff'  # message queue for staff
        )
        return HTTPFound(
            request.route_url('detail', member_id=member.id) + '#dues18')

    # sanity check: the given amount is a positive decimal
    try:
        paid_amount = D(request.POST['amount'])
        assert not paid_amount.is_signed()
        if DEBUG:
            print("DEBUG: payment of {}".format(paid_amount))
    except (KeyError, AssertionError):  # pragma: no cover
        request.session.flash(
            (u"Invalid amount to pay: '{}' "
             u"Use the dot ('.') as decimal mark, e.g. '23.42'".format(
                 request.POST['amount'])),
            'dues18notice_message_to_staff'  # message queue for user
        )
        return HTTPFound(
            request.route_url('detail', member_id=member.id) + '#dues18')

    # sanity check: the given date is a valid date
    try:
        paid_date = datetime.strptime(
            request.POST['payment_date'], '%Y-%m-%d')

        if DEBUG:
            print("DEBUG: payment received on {}".format(paid_date))
    except (KeyError, AssertionError):  # pragma: no cover
        request.session.flash(
            (u"Invalid date for payment: '{}' "
             u"Use YYYY-MM-DD, e.g. '2018-09-11'".format(
                 request.POST['payment_date'])),
            'dues18notice_message_to_staff'  # message queue for user
        )
        return HTTPFound(
            request.route_url('detail', member_id=member.id) + '#dues18')

    # persist info about payment
    member.set_dues18_payment(paid_amount, paid_date)

    return HTTPFound(
        request.route_url('detail', member_id=member.id) + '#dues18')
开发者ID:C3S,项目名称:c3sMembership,代码行数:56,代码来源:dues_2018.py

示例14: test_generate_certificate_staff

# 需要导入模块: from c3smembership.data.model.base.c3smember import C3sMember [as 别名]
# 或者: from c3smembership.data.model.base.c3smember.C3sMember import get_by_id [as 别名]
    def test_generate_certificate_staff(self):
        """
        test the certificate generation option in the backend
        """
        request = testing.DummyRequest()
        request.validated_matchdict = {
            'member': C3sMember.get_by_id(1)
        }

        result = generate_certificate_staff(request)
        self.assertTrue(MIN_PDF_SIZE < len(result.body) < MAX_PDF_SIZE)
        self.assertEqual(result.content_type, 'application/pdf')
开发者ID:C3S,项目名称:c3sMembership,代码行数:14,代码来源:test_membership_certificate.py

示例15: make_dues16_invoice_no_pdf

# 需要导入模块: from c3smembership.data.model.base.c3smember import C3sMember [as 别名]
# 或者: from c3smembership.data.model.base.c3smember.C3sMember import get_by_id [as 别名]
def make_dues16_invoice_no_pdf(request):
    """
    Create invoice PDFs on-the-fly.

    This view checks supplied information (in URL) against info in database
    and returns
    - an error message OR
    - a PDF as receipt

    === ===========================================================
    URL http://app:port/dues_invoice_no/EMAIL/CAQJGCGUFW/C3S-dues16-0001.pdf
    === ===========================================================

    """
    token = request.matchdict['code']
    invoice_number = request.matchdict['i']
    invoice = DuesInvoiceRepository.get_by_number(
        invoice_number.lstrip('0'), 2016)

    member = None
    token_is_invalid = True
    older_than_a_year = True
    if invoice is not None:
        member = C3sMember.get_by_id(invoice.member_id)
        token_is_invalid = token != invoice.token
        older_than_a_year = (
            date.today() - invoice.invoice_date.date() > timedelta(days=365))

    if invoice is None or token_is_invalid or invoice.is_reversal:
        request.session.flash(
            u"No invoice found!",
            'warning'
        )
        return HTTPFound(request.route_url('error'))

    if older_than_a_year or member.dues18_paid:
        request.session.flash(
            u'This invoice cannot be downloaded anymore. '
            u'Please contact [email protected] for further information.',
            'warning'
        )
        return HTTPFound(request.route_url('error'))

    pdf_file = make_invoice_pdf_pdflatex(member, invoice)
    response = Response(content_type='application/pdf')
    pdf_file.seek(0)  # rewind to beginning
    response.app_iter = open(pdf_file.name, "r")
    return response
开发者ID:C3S,项目名称:c3sMembership,代码行数:50,代码来源:dues_2016.py


注:本文中的c3smembership.data.model.base.c3smember.C3sMember.get_by_id方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。