本文整理汇总了Python中c3smembership.data.model.base.c3smember.C3sMember类的典型用法代码示例。如果您正苦于以下问题:Python C3sMember类的具体用法?Python C3sMember怎么用?Python C3sMember使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了C3sMember类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_gen_cert_special_chars
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')
示例2: test_send_certificate_email_de
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)
示例3: member_list_print_view
def member_list_print_view(request):
"""
This view produces printable HTML output, i.e. HTML without links
It was used before the PDF-generating view above existed
"""
all_members = C3sMember.member_listing(
'lastname', how_many=C3sMember.get_number(), offset=0, order=u'asc')
member_list = []
count = 0
for member in all_members:
if member.is_member():
# check membership number
try:
assert(member.membership_number is not None)
except AssertionError:
if DEBUG: # pragma: no cover
print u"failed at id {} lastname {}".format(
member.id, member.lastname)
member_list.append(member)
count += 1
# sort members alphabetically
import locale
locale.setlocale(locale.LC_ALL, "de_DE.UTF-8")
member_list.sort(key=lambda x: x.firstname, cmp=locale.strcoll)
member_list.sort(key=lambda x: x.lastname, cmp=locale.strcoll)
return {
'members': member_list,
'count': count,
'_today': date.today(),
}
示例4: test_calculate_partial_dues18
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'))
示例5: test_generate_certificate_de
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')
示例6: test_generate_certificate_en
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')
示例7: test_send_certificate_email_en
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)
示例8: dashboard
def dashboard(request):
"""
The Dashboard.
This view lets accountants view
the **list of applications for membership**.
Some details can be seen (name, email, link to more details)
as well as their membership application *progress*:
- has their signature arrived?
- how about the payment?
- have reminders been sent? receptions confirmed?
There are also links to *edit* or *delete* one of the datasets.
Once all requirements are fulfilled,
an application can be turned into a membership from here:
a button shows up.
"""
pagination = request.pagination
try:
members = C3sMember.nonmember_listing(
pagination.paging.content_offset,
pagination.paging.page_size,
pagination.sorting.sort_property,
pagination.sorting.sort_direction)
except (InvalidPropertyException, InvalidSortDirection):
raise ParameterValidationException(
'Page does not exist.',
request.route_url(request.matched_route.name))
return {
'members': members,
}
示例9: test_api_userinfo
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)
示例10: test_string_start_quarter_dues18
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)
示例11: membership_listing_backend
def membership_listing_backend(request):
"""
This view lets accountants view all members.
the list is HTML with clickable links,
not good for printout.
"""
memberships = C3sMember.get_members(
request.pagination.sorting.sort_property,
how_many=request.pagination.paging.page_size,
offset=request.pagination.paging.content_offset,
order=request.pagination.sorting.sort_direction)
general_assembly_invitation = request.registry.general_assembly_invitation
latest_general_assembly = general_assembly_invitation \
.get_latest_general_assembly()
invitations = None
if latest_general_assembly is not None:
invitations = {}
for membership in memberships:
invitations[membership.membership_number] = \
general_assembly_invitation.get_member_invitation(
membership,
latest_general_assembly.number)
return {
'members': memberships,
'invitations': invitations,
'latest_general_assembly': latest_general_assembly,
}
示例12: make_dues18_invoice_no_pdf
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)
示例13: test_shares_edit
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)))
示例14: dashboard_content_size_provider
def dashboard_content_size_provider(request):
"""
Provide non-member listing count as a content size provider to pagination
"""
# pylint: disable=unused-argument
# TODO: Architectural cleanup necessary as the presentation layer
# is directly accessing the data layer. It should instead access the
# business layer.
return C3sMember.nonmember_listing_count()
示例15: make_invoice_pdf_pdflatex
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)