本文整理汇总了Python中c3smembership.models.C3sMember.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python C3sMember.get_by_id方法的具体用法?Python C3sMember.get_by_id怎么用?Python C3sMember.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类c3smembership.models.C3sMember
的用法示例。
在下文中一共展示了C3sMember.get_by_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_calculate_partial_dues15
# 需要导入模块: from c3smembership.models import C3sMember [as 别名]
# 或者: from c3smembership.models.C3sMember import get_by_id [as 别名]
def test_calculate_partial_dues15(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.views.membership_dues import (
calculate_partial_dues15)
member = C3sMember.get_by_id(1)
res = calculate_partial_dues15(member)
# print res
# print member.membership_date
assert res == (u'q1_2015', D('50'))
# english member
member_en = C3sMember.get_by_id(2)
res = calculate_partial_dues15(member_en)
# print res
assert res == (u'q1_2015', D('50'))
member_en.membership_date = date(2015, 6, 1)
res = calculate_partial_dues15(member_en)
# print res
assert res == (u'q2_2015', D('37.50'))
member_en.membership_date = date(2015, 9, 1)
res = calculate_partial_dues15(member_en)
# print res
assert res == (u'q3_2015', D('25'))
member_en.membership_date = date(2015, 11, 1)
res = calculate_partial_dues15(member_en)
# print res
assert res == (u'q4_2015', D('12.50'))
示例2: mail_payment_confirmation
# 需要导入模块: from c3smembership.models import C3sMember [as 别名]
# 或者: from c3smembership.models.C3sMember import get_by_id [as 别名]
def mail_payment_confirmation(request):
"""
send a mail to membership applicant
informing her about reception of payment
"""
_id = request.matchdict['memberid']
_member = C3sMember.get_by_id(_id)
if _member.locale == 'de':
_subject = u'[C3S AFM] Wir haben Deine Zahlung erhalten. Dankeschön!'
else:
_subject = u'[C3S AFM] We have received your payment. Thanks!'
message = Message(
subject=_subject,
sender='[email protected]',
recipients=[_member.email],
body=make_payment_confirmation_emailbody(_member)
)
#print(message.body)
mailer = get_mailer(request)
mailer.send(message)
_member.payment_confirmed = True
_member.payment_confirmed_date = datetime.now()
return HTTPFound(request.route_url('dashboard',
number=request.cookies['on_page'],
order=request.cookies['order'],
orderby=request.cookies['orderby'],
)
)
示例3: switch_sig
# 需要导入模块: from c3smembership.models import C3sMember [as 别名]
# 或者: from c3smembership.models.C3sMember import get_by_id [as 别名]
def switch_sig(request):
"""
This view lets accountants switch member signature info
has their signature arrived?
"""
memberid = request.matchdict['memberid']
#log.info("the id: %s" % memberid)
# store the dashboard page the admin came from
dashboard_page = request.cookies['on_page']
order = request.cookies['order']
order_by = request.cookies['orderby']
_member = C3sMember.get_by_id(memberid)
if _member.signature_received is True:
_member.signature_received = False
_member.signature_received_date = datetime(1970, 1, 1)
elif _member.signature_received is False:
_member.signature_received = True
_member.signature_received_date = datetime.now()
log.info(
"signature status of member.id %s changed by %s to %s" % (
_member.id,
request.user.login,
_member.signature_received
)
)
return HTTPFound(
request.route_url('dashboard',
number=dashboard_page, order=order, orderby=order_by))
示例4: send_certificate_email
# 需要导入模块: from c3smembership.models import C3sMember [as 别名]
# 或者: from c3smembership.models.C3sMember import get_by_id [as 别名]
def send_certificate_email(request):
"""
Send email to a member with a link
so the member can get her membership certificate.
"""
_special_condition = False # for redirects to referrer
mid = request.matchdict["id"]
member = C3sMember.get_by_id(mid)
if isinstance(member, NoneType) or not member.is_member():
return Response("that id does not exist or is not an accepted member. go back", status="404 Not Found")
# create a token for the certificate
member.certificate_token = make_random_token()
email_subject, email_body = make_membership_certificate_email(request, member)
the_message = Message(subject=email_subject, sender="[email protected]", recipients=[member.email], body=email_body)
send_message(request, the_message)
member.certificate_email = True
member.certificate_email_date = datetime.now()
try: # pragma: no cover
if "detail" in request.referrer:
_special_condition = True
except TypeError: # pragma: no cover
pass
if _special_condition: # pragma: no cover
return HTTPFound(location=request.referrer + "#certificate")
else:
return get_memberhip_listing_redirect(request, member.id)
示例5: mail_payment_reminder
# 需要导入模块: from c3smembership.models import C3sMember [as 别名]
# 或者: from c3smembership.models.C3sMember import get_by_id [as 别名]
def mail_payment_reminder(request):
"""
send a mail to membership applicant
reminding her about lack of signature
"""
_id = request.matchdict['memberid']
_member = C3sMember.get_by_id(_id)
message = Message(
subject=u"C3S: don't forget to pay your shares / Bitte Anteile bezahlen",
sender='[email protected]',
#bcc=[request.registry.settings['reminder_blindcopy']],
recipients=[_member.email],
body=make_payment_reminder_emailbody(_member)
)
mailer = get_mailer(request)
mailer.send(message)
try: # if value is int
_member.sent_payment_reminder += 1
except: # pragma: no cover
# if value was None (after migration of DB schema)
_member.sent_payment_reminder = 1
_member.sent_payment_reminder_date = datetime.now()
return HTTPFound(request.route_url(
'dashboard',
number=request.cookies['on_page'],
order=request.cookies['order'],
orderby=request.cookies['orderby']) + '#member_' + str(_member.id)
)
示例6: switch_pay
# 需要导入模块: from c3smembership.models import C3sMember [as 别名]
# 或者: from c3smembership.models.C3sMember import get_by_id [as 别名]
def switch_pay(request):
"""
This view lets accountants switch member signature info
has their signature arrived?
"""
memberid = request.matchdict['memberid']
dashboard_page = request.cookies['on_page']
order = request.cookies['order']
order_by = request.cookies['orderby']
_member = C3sMember.get_by_id(memberid)
if _member.payment_received is True: # change to NOT SET
_member.payment_received = False
_member.payment_received_date = datetime(1970, 1, 1)
elif _member.payment_received is False: # set to NOW
_member.payment_received = True
_member.payment_received_date = datetime.now()
log.info(
"payment info of member.id %s changed by %s to %s" % (
_member.id,
request.user.login,
_member.payment_received
)
)
return HTTPFound(
request.route_url('dashboard',
number=dashboard_page, order=order, orderby=order_by))
示例7: test_shares_edit
# 需要导入模块: from c3smembership.models import C3sMember [as 别名]
# 或者: from c3smembership.models.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('Dashboard' 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('Dashboard' 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)))
示例8: test_send_certificate_email_english
# 需要导入模块: from c3smembership.models import C3sMember [as 别名]
# 或者: from c3smembership.models.C3sMember import get_by_id [as 别名]
def test_send_certificate_email_english(self):
"""
test the send_certificate_email view (english)
"""
if DEBUG:
print('test_send_certificate_email_english')
from c3smembership.membership_certificate import send_certificate_email
self.config.add_route('join', '/')
self.config.add_route('dashboard', '/')
self.config.add_route('certificate_pdf', '/')
self.config.add_route('membership_listing_backend', '/')
from pyramid_mailer import get_mailer
request = testing.DummyRequest()
request.matchdict = {
'id': '2',
'name': 'foobar',
'token': 'hotzenplotz' # WRONG/INVALID token
}
request.cookies['on_page'] = 1
request.cookies['order'] = 'asc'
request.cookies['orderby'] = 'id'
mailer = get_mailer(request)
result = send_certificate_email(request)
# print result
self.assertTrue(result.status_code == 404) # not found
self.assertEqual(len(mailer.outbox), 0)
request.matchdict = {
'id': '2',
'name': 'foobar',
'token': 'hotzenplotz123'
}
member2 = C3sMember.get_by_id(2)
member2.membership_accepted = True
# the request needs stuff to be in the cookie (for redirects)
request.cookies['m_on_page'] = 23
request.cookies['m_order'] = 'asc'
request.cookies['m_orderby'] = 'id'
request.referrer = 'dashboard'
result = send_certificate_email(request)
# print result
self.assertTrue(result.status_code == 302) # redirect
self.assertEqual(len(mailer.outbox), 1)
self.assertEqual(
mailer.outbox[0].subject,
u"C3S membership certificate"
)
# print mailer.outbox[0].body
self.assertTrue(
u"Hello AAASomeFirstnäme XXXSomeLastnäme,"
in mailer.outbox[0].body)
self.assertTrue(
u"your personal membership certificate" in mailer.outbox[0].body)
示例9: dues16_notice
# 需要导入模块: from c3smembership.models import C3sMember [as 别名]
# 或者: from c3smembership.models.C3sMember import get_by_id [as 别名]
def dues16_notice(request):
"""
notice of arrival for transferral of dues
"""
# member: sanity checks
try:
member_id = request.matchdict['member_id']
member = C3sMember.get_by_id(member_id) # is in database
assert member.membership_accepted # is a member
assert 'investing' not in member.membership_type # is normal member
except (KeyError, AssertionError): # pragma: no cover
request.session.flash(
u"No member OR not accepted OR not normal member",
'dues16notice_message_to_staff' # message queue for staff
)
return HTTPFound(
request.route_url('detail', memberid=member.id) + '#dues16')
# 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'])),
'dues16notice_message_to_staff' # message queue for user
)
return HTTPFound(
request.route_url('detail', memberid=member.id) + '#dues16')
# 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. '2016-09-11'".format(
request.POST['payment_date'])),
'dues16notice_message_to_staff' # message queue for user
)
return HTTPFound(
request.route_url('detail', memberid=member.id) + '#dues16')
# persist info about payment
member.set_dues16_payment(paid_amount, paid_date)
return HTTPFound(
request.route_url('detail', memberid=member.id) + '#dues16')
示例10: mail_mtype_fixer_link
# 需要导入模块: from c3smembership.models import C3sMember [as 别名]
# 或者: from c3smembership.models.C3sMember import get_by_id [as 别名]
def mail_mtype_fixer_link(request):
'''
send email to member to set her membership type details by visiting a form
'''
afmid = request.matchdict['afmid']
afm = C3sMember.get_by_id(afmid)
if isinstance(afm, NoneType):
request.session.flash(
'id not found. no mail sent.',
'messages')
return HTTPFound(request.route_url('dashboard',
number=request.cookies['on_page'],
order=request.cookies['order'],
orderby=request.cookies['orderby']))
import random
import string
_looong_token = u''.join(
random.choice(
string.ascii_uppercase + string.digits) for x in range(13))
_url = (request.registry.settings['c3smembership.url'] +
'/mtype/' + afm.email_confirm_code +
'/' + _looong_token + '/' + afm.email)
from .mail_mtype_util import make_mtype_email_body
_body = make_mtype_email_body(afm, _url)
log.info("mailing membership status form link to AFM # %s" % afm.id)
if afm.locale == 'de':
_subject = u'[C3S] Hilfe benötigt: Dein Mitgliedschaftsstatus'
else:
_subject = u'[C3S] Help needed: Your Membership Status'
message = Message(
subject=_subject,
sender='[email protected]',
recipients=[
afm.email,
request.registry.settings['c3smembership.mailaddr']],
body=_body
)
#print(message.subject)
#print(message.body)
mailer = get_mailer(request)
mailer.send(message)
afm.mtype_confirm_token = _looong_token
afm.mtype_email_date = datetime.now()
afm.membership_type = u'pending'
return HTTPFound(request.route_url('dashboard',
number=request.cookies['on_page'],
order=request.cookies['order'],
orderby=request.cookies['orderby']) +
'#member_' + str(afm.id))
示例11: test_generate_certificate_english
# 需要导入模块: from c3smembership.models import C3sMember [as 别名]
# 或者: from c3smembership.models.C3sMember import get_by_id [as 别名]
def test_generate_certificate_english(self):
"""
test the certificate download view (english)
"""
from c3smembership.membership_certificate import generate_certificate
request = testing.DummyRequest()
request.matchdict = {
'id': '2',
'name': 'foobar',
'token': 'hotzenplotz'
}
result = generate_certificate(request)
if DEBUG:
print(result)
# check: this is *not* found because the token is *invalid*
self.assertTrue(result.status_code == 404) # not found
request.matchdict = {
'id': '2',
'name': 'foobar',
'token': 'hotzenplotz123'
}
member2 = C3sMember.get_by_id(2)
member2.certificate_token = u'hotzenplotz123'
# now the database matches the matchdict
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, 404)
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)
if DEBUG: # pragma: no cover
print("size of resulting certificate PDF here: {}".format(
len(result.body)))
print("min and max: {} {}".format(
_min_PDF_size, _max_PDF_size))
self.assertTrue(_min_PDF_size < len(result.body) < _max_PDF_size)
self.assertTrue(result.content_type == 'application/pdf')
示例12: delete_entry
# 需要导入模块: from c3smembership.models import C3sMember [as 别名]
# 或者: from c3smembership.models.C3sMember import get_by_id [as 别名]
def delete_entry(request):
"""
This view lets accountants delete entries (doublettes)
"""
memberid = request.matchdict["memberid"]
dashboard_page = request.cookies["on_page"]
_member = C3sMember.get_by_id(memberid)
C3sMember.delete_by_id(_member.id)
log.info("member.id %s was deleted by %s" % (_member.id, request.user.login))
return HTTPFound(request.route_url("dashboard", number=dashboard_page))
示例13: test_api_userinfo
# 需要导入模块: from c3smembership.models import C3sMember [as 别名]
# 或者: from c3smembership.models.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 (email_invite_token_bcgv16)
# 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()
m1 = C3sMember.get_by_id(1) # load member from DB for crosscheck
# now try a valid refcode (email_invite_token_bcgv16)
res2 = self.testapp.put_json("/lm", dict(token=m1.email_invite_token_bcgv16), headers=_auth_info, status=200)
self.assertTrue(json.loads(res2.body)["firstname"], m1.firstname)
self.assertTrue(json.loads(res2.body)["lastname"], m1.lastname)
self.assertTrue(json.loads(res2.body)["email"], m1.email)
self.assertTrue(json.loads(res2.body)["mtype"], m1.membership_type)
示例14: invite_member_BCGV
# 需要导入模块: from c3smembership.models import C3sMember [as 别名]
# 或者: from c3smembership.models.C3sMember import get_by_id [as 别名]
def invite_member_BCGV(request):
'''
Send email to member with link to ticketing.
=== =====================================
URL http://app:port/invite_member/{m_id}
=== =====================================
'''
mid = request.matchdict['m_id']
_m = C3sMember.get_by_id(mid)
if isinstance(_m, NoneType):
request.session.flash(
'id not found. no mail sent.',
'messages')
return get_dashboard_redirect(request)
# prepare a random token iff none is set
if _m.email_invite_token_bcgv16 is None:
_m.email_invite_token_bcgv16 = make_random_token()
_url = (
request.registry.settings['ticketing.url'] +
'/lu/' + _m.email_invite_token_bcgv16 +
'/' + _m.email)
email_subject, email_body = make_bcga16_invitation_email(_m, _url)
log.info("mailing event invitation to to member id %s" % _m.id)
message = Message(
subject=email_subject,
sender='[email protected]',
recipients=[_m.email],
body=email_body,
extra_headers={
'Reply-To': '[email protected]',
}
)
print_mail = True if 'true' in request.registry.settings[
'testing.mail_to_console'] else False
if print_mail: # pragma: no cover
print(message.body.encode('utf-8'))
else:
# print "sending mail"
mailer = get_mailer(request)
mailer.send(message)
# _m._token = _looong_token
_m.email_invite_flag_bcgv16 = True
_m.email_invite_date_bcgv16 = datetime.now()
return get_dashboard_redirect(request, _m.id)
示例15: test_merge_member_view
# 需要导入模块: from c3smembership.models import C3sMember [as 别名]
# 或者: from c3smembership.models.C3sMember import get_by_id [as 别名]
def test_merge_member_view(self):
'''
Tests for the merge_member_view
'''
res = self.testapp.reset() # delete cookies
afm = C3sMember.get_by_id(2) # an application
m = C3sMember.get_by_id(1) # an accepted member
self.assertTrue(afm.membership_accepted is False)
self.assertEqual(afm.num_shares, 2)
self.assertEqual(afm.shares, [])
self.assertTrue(m.membership_accepted is True)
self.assertEqual(m.num_shares, 23)
self.assertEqual(len(m.shares), 2) # 2 shares packages
# try unauthenticated access -- must fail!
res = self.testapp.get(
'/merge_member/{afm_id}/{mid}'.format(
afm_id=afm.id,
mid=m.id),
status=403)
self.failUnless('Access was denied to this resource' in res.body)
# authenticate/authorize
self._MemberTestsBase__login()
res = self.testapp.get(
'/merge_member/{afm_id}/{mid}'.format(
afm_id=afm.id,
mid=m.id),
status=302) # redirect!
self.assertTrue(afm.membership_accepted is False)
self.assertTrue(m.membership_accepted is True)
self.assertEqual(m.num_shares, 25)
self.assertEqual(len(m.shares), 3) # 2 shares packages