本文整理汇总了Python中volunteer.models.Volunteer类的典型用法代码示例。如果您正苦于以下问题:Python Volunteer类的具体用法?Python Volunteer怎么用?Python Volunteer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Volunteer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_volunteer_resume_file_url
def test_get_volunteer_resume_file_url(self):
u1 = User.objects.create_user('John')
v1 = Volunteer(
first_name="John",
last_name="Doe",
address="7 Alpine Street",
city="Maplegrove",
state="Wyoming",
country="USA",
phone_number="23454545",
email="[email protected]",
resume_file="MyResume.pdf",
user=u1
)
v1.save()
# test typical cases
self.assertIsNotNone(get_volunteer_resume_file_url(v1.id))
self.assertEqual(
get_volunteer_resume_file_url(v1.id),
v1.resume_file.url
)
# test non-existant cases
self.assertNotEqual(get_volunteer_resume_file_url(v1.id),
"resumes/DifferentResume.pdf"
)
self.assertNotEqual(get_volunteer_resume_file_url(v1.id),
"resumes/AnotherResume.pdf"
)
示例2: test_get_volunteers_ordered_by_first_name
def test_get_volunteers_ordered_by_first_name(self):
u1 = User.objects.create_user('Yoshi')
u2 = User.objects.create_user('Ashley')
u3 = User.objects.create_user('Zelda')
v1 = Volunteer(
first_name="Yoshi",
last_name="Doe",
address="7 Oak Street",
city="Elmgrove",
state="California",
country="USA",
phone_number="23454545",
email="[email protected]",
user=u1
)
v2 = Volunteer(
first_name="Ashley",
last_name="Doe",
address="7 Alpine Street",
city="Maplegrove",
state="Wyoming",
country="USA",
phone_number="23454545",
email="[email protected]",
user=u2
)
v3 = Volunteer(
id=999,
first_name="Zelda",
last_name="Doe",
address="7 Elm Street",
city="Oakgrove",
state="California",
country="USA",
phone_number="23454545",
email="[email protected]",
user=u3
)
v1.save()
v2.save()
v3.save()
# test typical cases
volunteer_list = get_volunteers_ordered_by_first_name()
self.assertIsNotNone(volunteer_list)
self.assertIn(v1, volunteer_list)
self.assertIn(v2, volunteer_list)
self.assertIn(v3, volunteer_list)
self.assertEqual(len(volunteer_list), 3)
# test if in correct order
self.assertEqual(volunteer_list[0], v2)
self.assertEqual(volunteer_list[1], v1)
self.assertEqual(volunteer_list[2], v3)
示例3: test_get_shifts_with_open_slots
def test_get_shifts_with_open_slots(self):
""" Test get_shifts_with_open_slots(j_id) """
u1 = User.objects.create_user("Yoshi")
v1 = Volunteer(
first_name="Yoshi",
last_name="Turtle",
address="Mario Land",
city="Nintendo Land",
state="Nintendo State",
country="Nintendo Nation",
phone_number="2374983247",
email="[email protected]",
user=u1,
)
v1.save()
e1 = Event(name="Open Source Event", start_date="2012-10-22", end_date="2012-10-23")
e1.save()
j1 = Job(
name="Software Developer",
start_date="2012-10-22",
end_date="2012-10-23",
description="A software job",
event=e1,
)
j2 = Job(
name="Systems Administrator",
start_date="2012-9-1",
end_date="2012-10-26",
description="A systems administrator job",
event=e1,
)
j1.save()
j2.save()
s1 = Shift(date="2012-10-23", start_time="9:00", end_time="3:00", max_volunteers=1, job=j1)
s2 = Shift(date="2012-10-23", start_time="10:00", end_time="4:00", max_volunteers=2, job=j1)
s3 = Shift(date="2012-10-23", start_time="12:00", end_time="6:00", max_volunteers=4, job=j2)
s1.save()
s2.save()
s3.save()
self.assertIsNotNone(get_shifts_with_open_slots(j1.id))
self.assertIsNotNone(get_shifts_with_open_slots(j2.id))
示例4: test_has_resume_file
def test_has_resume_file(self):
u1 = User.objects.create_user('John')
u2 = User.objects.create_user('James')
u3 = User.objects.create_user('Jane')
v1 = Volunteer(
first_name="John",
last_name="Doe",
address="7 Alpine Street",
city="Maplegrove",
state="Wyoming",
country="USA",
phone_number="23454545",
email="[email protected]",
resume_file="MyResume.pdf",
user=u1
)
v2 = Volunteer(
first_name="James",
last_name="Doe",
address="7 Alpine Street",
city="Maplegrove",
state="Wyoming",
country="USA",
phone_number="23454545",
email="[email protected]",
user=u2
)
v3 = Volunteer(
first_name="Jane",
last_name="Doe",
address="7 Alpine Street",
city="Maplegrove",
state="Wyoming",
country="USA",
phone_number="23454545",
email="[email protected]",
resume_file="",
user=u3
)
v1.save()
v2.save()
v3.save()
# test typical cases
self.assertTrue(has_resume_file(v1.id))
# test non-existant cases
self.assertFalse(has_resume_file(v2.id))
self.assertFalse(has_resume_file(v3.id))
示例5: test_delete_volunteer
def test_delete_volunteer(self):
u1 = User.objects.create_user('Yoshi')
u2 = User.objects.create_user('Ashley')
u3 = User.objects.create_user('Zelda')
v1 = Volunteer(
first_name="Yoshi",
last_name="Doe",
address="7 Oak Street",
city="Elmgrove",
state="California",
country="USA",
phone_number="23454545",
email="[email protected]",
user=u1
)
v2 = Volunteer(
first_name="Ashley",
last_name="Doe",
address="7 Alpine Street",
city="Maplegrove",
state="Wyoming",
country="USA",
phone_number="23454545",
email="[email protected]",
user=u2
)
v3 = Volunteer(
id=999,
first_name="Zelda",
last_name="Doe",
address="7 Elm Street",
city="Oakgrove",
state="California",
country="USA",
phone_number="23454545",
email="[email protected]",
user=u3
)
v1.save()
v2.save()
v3.save()
self.assertTrue(delete_volunteer(v1.id))
self.assertTrue(delete_volunteer(v2.id))
self.assertTrue(delete_volunteer(v3.id))
self.assertFalse(delete_volunteer(100))
self.assertFalse(delete_volunteer(200))
self.assertFalse(delete_volunteer(300))
示例6: test_get_all_volunteers
def test_get_all_volunteers(self):
""" Tests get_all_volunteers() """
u1 = User.objects.create_user('John')
u2 = User.objects.create_user('James')
u3 = User.objects.create_user('George')
v1 = Volunteer(
first_name="John",
last_name="Doe",
address="7 Alpine Street",
city="Maplegrove",
state="Wyoming",
country="USA",
phone_number="23454545",
email="[email protected]",
user=u1
)
v2 = Volunteer(
first_name="James",
last_name="Doe",
address="7 Oak Street",
city="Elmgrove",
state="California",
country="USA",
phone_number="23454545",
email="[email protected]",
user=u2
)
v3 = Volunteer(
id=999,
first_name="George",
last_name="Doe",
address="7 Elm Street",
city="Oakgrove",
state="California",
country="USA",
phone_number="23454545",
email="[email protected]",
user=u3
)
v1.save()
v2.save()
v3.save()
# test typical cases
self.assertIsNotNone(get_all_volunteers())
示例7: test_delete_shift
def test_delete_shift(self):
""" Test delete_shift(shift_id) """
u1 = User.objects.create_user("Yoshi")
v1 = Volunteer(
first_name="Yoshi",
last_name="Turtle",
address="Mario Land",
city="Nintendo Land",
state="Nintendo State",
country="Nintendo Nation",
phone_number="2374983247",
email="[email protected]",
user=u1,
)
v1.save()
e1 = Event(name="Open Source Event", start_date="2012-10-22", end_date="2012-10-23")
e1.save()
j1 = Job(
name="Software Developer",
start_date="2012-10-22",
end_date="2012-10-23",
description="A software job",
event=e1,
)
j1.save()
s1 = Shift(date="2012-10-23", start_time="1:00", end_time="12:00", max_volunteers=1, job=j1)
s2 = Shift(date="2011-11-11", start_time="11:00", end_time="12:00", max_volunteers=3, job=j1)
s1.save()
s2.save()
self.assertTrue(delete_shift(s1.id))
self.assertFalse(delete_shift(100))
register(v1.id, s2.id)
self.assertFalse(delete_shift(s2.id))
示例8: create_volunteer_with_details_dynamic_password
def create_volunteer_with_details_dynamic_password(volunteer):
"""
Creates and returns volunteer with passed name and dates
"""
u1 = User.objects.create_user(username=volunteer[0], password=volunteer[1])
v1 = Volunteer(
email=volunteer[2],
first_name=volunteer[3],
last_name=volunteer[4],
address=volunteer[5],
city=volunteer[6],
state=volunteer[7],
country=volunteer[8],
phone_number=volunteer[9],
user=u1
)
v1.save()
return v1
示例9: create_volunteer_with_details
def create_volunteer_with_details(volunteer, org_obj):
"""
Creates and returns volunteer with passed name and dates
"""
u1 = User.objects.create_user(username=volunteer[0], password='volunteer')
v1 = Volunteer(
first_name=volunteer[1],
last_name=volunteer[2],
address=volunteer[3],
city=volunteer[4],
state=volunteer[5],
country=volunteer[6],
phone_number=volunteer[7],
email=volunteer[8],
user=u1,
organization=org_obj)
v1.save()
return v1
示例10: test_delete_volunteer_resume
def test_delete_volunteer_resume(self):
""" Tests delete_volunteer_resume(volunteer_id) """
u1 = User.objects.create_user('John')
v1 = Volunteer(
first_name="John",
last_name="Doe",
address="7 Alpine Street",
city="Maplegrove",
state="Wyoming",
country="USA",
phone_number="23454545",
email="[email protected]",
resume_file="MyResume.pdf",
user=u1
)
v1.save()
self.assertTrue(delete_volunteer_resume(v1.id))
self.assertFalse(delete_volunteer(100))
示例11: apply
def apply(request):
form = request.POST
user = request.user
new_application = Volunteer(name=user.first_name + " "+user.last_name, email=user.email, phone=form.get('phone-number'), address=form.get('street-address'), city=form.get('city'), province=form.get('province'), isApproved=False, \
reference1name=form.get('ref1name'), reference1email=form.get('ref1email'), reference1phone=form.get('ref1phone'), \
reference2name=form.get('ref2name'), reference2email=form.get('ref2email'), reference2phone=form.get('ref2phone'), \
experience=form.get('id_experience'), availability=form.get('id_availability'))
if (form):
try:
new_application.save()
except IntegrityError, e:
fail_msg = "Sorry, record shows that your previous application has not been proccessed, please be patient (:"
return render_to_response('volunteer/apply.html', {'message': fail_msg})
email = form.get('email')
domain = request.META['HTTP_HOST']
link = domain + "/applications/" + str(new_application.id) + "/"
message = "To view the application, go to: " + link
send_mail('Writer\'s Exchange Volunteer Application', message, '[email protected]', [NOTIFICATION_EMAIL], fail_silently=False)
success_msg = "Thank you for your application! We will notify you about your application status soon."
return render_to_response('volunteer/apply.html', {'message': success_msg})
示例12: test_edit_shift_hours
def test_edit_shift_hours(self):
u1 = User.objects.create_user("Yoshi")
v1 = Volunteer(
first_name="Yoshi",
last_name="Turtle",
address="Mario Land",
city="Nintendo Land",
state="Nintendo State",
country="Nintendo Nation",
phone_number="2374983247",
email="[email protected]",
user=u1,
)
v1.save()
e1 = Event(name="Open Source Event", start_date="2012-10-22", end_date="2012-10-23")
e1.save()
j1 = Job(
name="Software Developer",
start_date="2012-10-22",
end_date="2012-10-23",
description="A software job",
event=e1,
)
j1.save()
s1 = Shift(date="2012-10-23", start_time="1:00", end_time="12:00", max_volunteers=1, job=j1)
s1.save()
register(v1.id, s1.id)
self.assertIsNotNone(VolunteerShift.objects.get(volunteer_id=v1.id, shift_id=s1.id))
start_time = datetime.time(hour=9, minute=0)
end_time = datetime.time(hour=10, minute=0)
add_shift_hours(v1.id, s1.id, start_time, end_time)
start_time = datetime.time(hour=10, minute=0)
end_time = datetime.time(hour=11, minute=0)
edit_shift_hours(v1.id, s1.id, start_time, end_time)
volunteer_shift = VolunteerShift.objects.get(volunteer_id=v1.id, shift_id=s1.id)
self.assertIsNotNone(volunteer_shift.start_time)
self.assertIsNotNone(volunteer_shift.end_time)
self.assertEqual(volunteer_shift.start_time, start_time)
self.assertEqual(volunteer_shift.end_time, end_time)
start_time = datetime.time(hour=1, minute=0)
end_time = datetime.time(hour=4, minute=0)
edit_shift_hours(v1.id, s1.id, start_time, end_time)
volunteer_shift = VolunteerShift.objects.get(volunteer_id=v1.id, shift_id=s1.id)
self.assertIsNotNone(volunteer_shift.start_time)
self.assertIsNotNone(volunteer_shift.end_time)
self.assertEqual(volunteer_shift.start_time, start_time)
self.assertEqual(volunteer_shift.end_time, end_time)
start_time = datetime.time(hour=4, minute=15)
end_time = datetime.time(hour=12, minute=35)
edit_shift_hours(v1.id, s1.id, start_time, end_time)
volunteer_shift = VolunteerShift.objects.get(volunteer_id=v1.id, shift_id=s1.id)
self.assertIsNotNone(volunteer_shift.start_time)
self.assertIsNotNone(volunteer_shift.end_time)
self.assertEqual(volunteer_shift.start_time, start_time)
self.assertEqual(volunteer_shift.end_time, end_time)
start_time = datetime.time(hour=2, minute=5)
end_time = datetime.time(hour=4, minute=15)
edit_shift_hours(v1.id, s1.id, start_time, end_time)
volunteer_shift = VolunteerShift.objects.get(volunteer_id=v1.id, shift_id=s1.id)
self.assertIsNotNone(volunteer_shift.start_time)
self.assertIsNotNone(volunteer_shift.end_time)
self.assertEqual(volunteer_shift.start_time, start_time)
self.assertEqual(volunteer_shift.end_time, end_time)
start_time = datetime.time(hour=5, minute=0)
end_time = datetime.time(hour=5, minute=30)
edit_shift_hours(v1.id, s1.id, start_time, end_time)
volunteer_shift = VolunteerShift.objects.get(volunteer_id=v1.id, shift_id=s1.id)
self.assertIsNotNone(volunteer_shift.start_time)
self.assertIsNotNone(volunteer_shift.end_time)
self.assertEqual(volunteer_shift.start_time, start_time)
self.assertEqual(volunteer_shift.end_time, end_time)
示例13: test_get_unlogged_shifts_by_volunteer_id
def test_get_unlogged_shifts_by_volunteer_id(self):
u1 = User.objects.create_user("Yoshi")
v1 = Volunteer(
first_name="Yoshi",
last_name="Turtle",
address="Mario Land",
city="Nintendo Land",
state="Nintendo State",
country="Nintendo Nation",
phone_number="2374983247",
email="[email protected]",
user=u1,
)
v1.save()
e1 = Event(name="Open Source Event", start_date="2012-10-22", end_date="2012-10-23")
e1.save()
j1 = Job(
name="Software Developer",
start_date="2012-10-22",
end_date="2012-10-23",
description="A software job",
event=e1,
)
j2 = Job(
name="Systems Administrator",
start_date="2012-9-1",
end_date="2012-10-26",
description="A systems administrator job",
event=e1,
)
j1.save()
j2.save()
s1 = Shift(date="2012-10-23", start_time="9:00", end_time="3:00", max_volunteers=1, job=j1)
s2 = Shift(date="2012-10-23", start_time="10:00", end_time="4:00", max_volunteers=2, job=j1)
s3 = Shift(date="2012-10-23", start_time="12:00", end_time="6:00", max_volunteers=4, job=j2)
s1.save()
s2.save()
s3.save()
# sign up
register(v1.id, s1.id)
register(v1.id, s2.id)
register(v1.id, s3.id)
# test typical case
shift_list = get_unlogged_shifts_by_volunteer_id(v1.id)
self.assertIsNotNone(shift_list)
self.assertNotEqual(shift_list, False)
self.assertEqual(len(shift_list), 3)
self.assertIn(s1, shift_list)
self.assertIn(s2, shift_list)
self.assertIn(s3, shift_list)
示例14: test_get_volunteer_shift_by_id
def test_get_volunteer_shift_by_id(self):
u1 = User.objects.create_user("Yoshi")
u2 = User.objects.create_user("John")
v1 = Volunteer(
first_name="Yoshi",
last_name="Turtle",
address="Mario Land",
city="Nintendo Land",
state="Nintendo State",
country="Nintendo Nation",
phone_number="2374983247",
email="[email protected]",
user=u1,
)
v2 = Volunteer(
first_name="John",
last_name="Doe",
address="7 Alpine Street",
city="Maplegrove",
state="Wyoming",
country="USA",
phone_number="23454545",
email="[email protected]",
user=u2,
)
v1.save()
v2.save()
e1 = Event(name="Open Source Event", start_date="2012-10-22", end_date="2012-10-23")
e1.save()
j1 = Job(
name="Software Developer",
start_date="2012-10-22",
end_date="2012-10-23",
description="A software job",
event=e1,
)
j2 = Job(
name="Systems Administrator",
start_date="2012-9-1",
end_date="2012-10-26",
description="A systems administrator job",
event=e1,
)
j1.save()
j2.save()
s1 = Shift(date="2012-10-23", start_time="9:00", end_time="3:00", max_volunteers=1, job=j1)
s2 = Shift(date="2012-10-23", start_time="10:00", end_time="4:00", max_volunteers=2, job=j1)
s3 = Shift(date="2012-10-23", start_time="12:00", end_time="6:00", max_volunteers=4, job=j2)
s1.save()
s2.save()
s3.save()
# test cases where signed up
register(v1.id, s1.id)
register(v1.id, s2.id)
register(v1.id, s3.id)
register(v2.id, s1.id)
register(v2.id, s2.id)
register(v2.id, s3.id)
self.assertEqual(
get_volunteer_shift_by_id(v1.id, s1.id), VolunteerShift.objects.get(volunteer_id=v1.id, shift_id=s1.id)
)
self.assertEqual(
get_volunteer_shift_by_id(v1.id, s2.id), VolunteerShift.objects.get(volunteer_id=v1.id, shift_id=s2.id)
)
self.assertEqual(
get_volunteer_shift_by_id(v1.id, s3.id), VolunteerShift.objects.get(volunteer_id=v1.id, shift_id=s3.id)
)
# self.assertEqual(get_volunteer_shift_by_id(v2.id, s1.id),
# VolunteerShift.objects.get(volunteer_id=v2.id, shift_id=s1.id))
# why does this throw DoesNotExist?
self.assertEqual(
get_volunteer_shift_by_id(v2.id, s2.id), VolunteerShift.objects.get(volunteer_id=v2.id, shift_id=s2.id)
)
self.assertEqual(
get_volunteer_shift_by_id(v2.id, s3.id), VolunteerShift.objects.get(volunteer_id=v2.id, shift_id=s3.id)
)
示例15: test_is_signed_up
def test_is_signed_up(self):
u1 = User.objects.create_user("Yoshi")
u2 = User.objects.create_user("John")
v1 = Volunteer(
first_name="Yoshi",
last_name="Turtle",
address="Mario Land",
city="Nintendo Land",
state="Nintendo State",
country="Nintendo Nation",
phone_number="2374983247",
email="[email protected]",
user=u1,
)
v2 = Volunteer(
first_name="John",
last_name="Doe",
address="7 Alpine Street",
city="Maplegrove",
state="Wyoming",
country="USA",
phone_number="23454545",
email="[email protected]",
user=u2,
)
v1.save()
v2.save()
e1 = Event(name="Open Source Event", start_date="2012-10-22", end_date="2012-10-23")
e1.save()
j1 = Job(
name="Software Developer",
start_date="2012-10-22",
end_date="2012-10-23",
description="A software job",
event=e1,
)
j2 = Job(
name="Systems Administrator",
start_date="2012-9-1",
end_date="2012-10-26",
description="A systems administrator job",
event=e1,
)
j1.save()
j2.save()
s1 = Shift(date="2012-10-23", start_time="9:00", end_time="3:00", max_volunteers=1, job=j1)
s2 = Shift(date="2012-10-23", start_time="10:00", end_time="4:00", max_volunteers=2, job=j1)
s3 = Shift(date="2012-10-23", start_time="12:00", end_time="6:00", max_volunteers=4, job=j2)
s1.save()
s2.save()
s3.save()
# test cases where not signed up yet
self.assertFalse(is_signed_up(v1.id, s1.id))
self.assertFalse(is_signed_up(v1.id, s2.id))
self.assertFalse(is_signed_up(v1.id, s3.id))
# test cases where signed up
register(v1.id, s1.id)
register(v1.id, s2.id)
register(v1.id, s3.id)
self.assertTrue(is_signed_up(v1.id, s1.id))
self.assertTrue(is_signed_up(v1.id, s2.id))
self.assertTrue(is_signed_up(v1.id, s3.id))
# test case where more than one volunteer signs up for the same shift
self.assertFalse(is_signed_up(v2.id, s1.id))
self.assertFalse(is_signed_up(v2.id, s2.id))
self.assertFalse(is_signed_up(v2.id, s3.id))
register(v2.id, s2.id)
register(v2.id, s3.id)
self.assertFalse(is_signed_up(v2.id, s1.id))
self.assertTrue(is_signed_up(v2.id, s2.id))
self.assertTrue(is_signed_up(v2.id, s3.id))