本文整理汇总了Python中mig_main.models.AcademicTerm类的典型用法代码示例。如果您正苦于以下问题:Python AcademicTerm类的具体用法?Python AcademicTerm怎么用?Python AcademicTerm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AcademicTerm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_members
def get_members(init_term=None, include_electees=True,include_stopped_electing=False,include_actives=True,include_grads=True,include_ugrads=True,include_alums=False,only_around=False,only_active_status=False,only_da=False,only_pa=False):
members = MemberProfile.objects.all()
#handle status partitions
if not include_electees:
members=members.exclude(status__name='Electee')
elif not include_stopped_electing:
members=members.exclude(still_electing=False,status__name='Electee')
if not include_actives:
members=members.exclude(status__name='Active')
#handle standing partitions
if not include_grads:
members=members.exclude(standing__name="Graduate")
if not include_ugrads:
members=members.exclude(standing__name='Undergraduate')
if not include_alums:
members=members.exclude(standing__name='Alumni')
last_two_terms = [AcademicTerm.get_current_term(), get_previous_full_term(AcademicTerm.get_current_term())]
if only_around:
recent_progress=ProgressItem.objects.filter(term__in=last_two_terms)
members=members.filter(progressitem__in=recent_progress)
if only_active_status:
recent_active = Distinction.objects.filter(term__in=last_two_terms,distinction_type__name='Active')
members=members.filter(distinction__in=recent_active)
if only_da:
recent_active = Distinction.objects.filter(term__in=last_two_terms,distinction_type__name='Distinguished Active')
members=members.filter(distinction__in=recent_active)
if only_pa:
recent_active = Distinction.objects.filter(term__in=last_two_terms,distinction_type__name='Prestigious Active')
members=members.filter(distinction__in=recent_active)
if init_term:
members=members.filter(init_term=init_term,init_chapter__state='MI',init_chapter__letter='G')
return members.distinct()
示例2: leadership_for_term
def leadership_for_term(request, term_id):
"""
Shows the officers for the specified term. The packing logic that assembles
officers into teams for dispaly is contained in the pack_officers_for_term
function.
"""
term = get_object_or_404(AcademicTerm, id=term_id)
officers = pack_officers_for_term(AcademicTerm.objects.get(id=term_id))
officer_set = Officer.objects.filter(term=term).values('id')
template = loader.get_template('about/leadership.html')
context_dict = {
"officers": officers,
'committee_members': CommitteeMember.objects.filter(term=term),
'officer_ids': officer_set,
'request': request,
'terms': AcademicTerm.get_rchron_before()[:5],
'requested_term': term,
'is_current': (term_id == AcademicTerm.get_current_term().id),
'subnav': 'leadership',
}
context_dict.update(get_common_context(request))
context_dict.update(get_permissions(request.user))
context = RequestContext(request, context_dict)
return HttpResponse(template.render(context))
示例3: manually_edit_electee_group_membership
def manually_edit_electee_group_membership(request):
if not Permissions.can_manage_electee_progress(request.user):
request.session['error_message']='You are not authorized to edit electee teams'
return redirect('electees:view_electee_groups')
e_groups = ElecteeGroup.objects.filter(term=AcademicTerm.get_current_term())
prefix = 'manual_groups'
term =AcademicTerm.get_current_term()
formset=ManualElecteeGroupMembersFormSet(request.POST or None,prefix=prefix,queryset=ElecteeGroup.objects.filter(term=term))
if request.method=='POST':
if formset.is_valid():
formset.save()
request.session['success_message']='Electee team membership updated successfully'
return redirect('electees:view_electee_groups')
else:
request.session['error_message']='Form is invalid. Please correct the noted errors.'
template = loader.get_template('generic_formset.html')
context_dict = {
'formset':formset,
'prefix':prefix,
'subsubnav':'members',
'has_files':False,
'submit_name':'Update Electee Team Membership',
'form_title':'Add Electee Team Members',
'help_text':'Add members to electee teams. This is for initial addition only, for edits use the drag-and-drop interface.',
'can_add_row':False,
'base':'electees/base_electees.html',
}
context_dict.update(get_common_context(request))
context_dict.update(get_permissions(request.user))
context = RequestContext(request, context_dict)
return HttpResponse(template.render(context))
示例4: test_officer_ajax
def test_officer_ajax(self):
old_term = AcademicTerm.objects.get(semester_type__name='Fall',
year=2012)
current_term = AcademicTerm.get_current_term()
officers = Officer.objects.all()
officers[2].term.clear()
officers[2].term.add(old_term)
for officer in officers:
view_url = reverse('about:officer', args=[officer.id])
resp = self.client.get(view_url,
HTTP_X_REQUESTED_WITH='XMLHttpRequest')
self.assertEqual(resp.status_code, 200)
position = unicode(officer.position)
if officer.position.name == 'Advisor':
self.assertFalse(position in resp.content,
msg='%s name is in response.' % position)
else:
self.assertTrue(position in resp.content,
msg='%s name not in response' % position)
officer_name = officer.user.get_firstlast_name()
self.assertTrue(officer_name in resp.content,
msg='%s user name not in response' % position)
if (current_term in officer.term.all()) and not\
(position == 'Advisor'):
self.assertTrue(officer.position.email in resp.content,
msg='%s position email absent' % position)
self.assertFalse(officer.user.get_email() in resp.content,
msg='%s user email present' % position)
else:
self.assertFalse(officer.position.email in resp.content,
msg='%s position email present' % position)
self.assertTrue(officer.user.get_email() in resp.content,
msg='%s personal email absent' % position)
officers[2].term.clear()
officers[2].term.add(AcademicTerm.get_current_term())
示例5: edit_electee_process_visibility
def edit_electee_process_visibility(request):
if not Permissions.can_manage_electee_progress(request.user):
request.session['error_message']='You are not authorized to edit the electee process visibility settings.'
return redirect('electees:view_electee_groups')
current_vis = ElecteeProcessVisibility.objects.get_or_create(term=AcademicTerm.get_current_term())
VisibilityForm = modelform_factory(ElecteeProcessVisibility,exclude=['term'])
prefix='visibility'
form = VisibilityForm(request.POST or None ,prefix=prefix,instance=current_vis[0])
if request.method =='POST':
if form.is_valid():
form.save()
request.session['success_message']='Electee settings updated successfully'
return redirect('electees:manage_survey')
else:
request.session['error_message']='Form is invalid. Please correct the noted errors.'
template = loader.get_template('generic_form.html')
context_dict = {
'form':form,
'prefix':prefix,
'has_files':False,
'submit_name':'Update Visibility Settings',
'form_title':'Update Electee Visibility Settings for %s'%(unicode(AcademicTerm.get_current_term())),
'help_text':'Change whether certain electee items are visible to all actives.',
'base':'electees/base_electees.html',
'back_button':{'link':reverse('electees:manage_survey'),'text':'To Survey Manager'},
}
context_dict.update(get_common_context(request))
context_dict.update(get_permissions(request.user))
context = RequestContext(request, context_dict)
return HttpResponse(template.render(context))
示例6: outreach_event
def outreach_event(request, url_stem):
request.session['current_page'] = request.path
outreach_event = get_object_or_404(OutreachEventType, url_stem=url_stem)
relevant_officers = Officer.objects.filter(
user__uniqname=request.user.username,
term=AcademicTerm.get_current_term(),
position__in=outreach_event.officers_can_edit.all()
)
events = CalendarEvent.objects.filter(
term=AcademicTerm.get_current_term(),
event_type=outreach_event.event_category,
eventshift__end_time__gte=timezone.now()
).annotate(
earliest_shift=Min('eventshift__start_time')
).order_by('earliest_shift')
template = loader.get_template('outreach/outreach_template.html')
context_dict = {
'events': events,
'subnav': url_stem,
'title': outreach_event.title,
'text': outreach_event.text,
'has_cal_events': outreach_event.has_calendar_events,
'event_category': outreach_event.event_category.name,
'can_edit_outreach_event': (request.user.is_superuser or
relevant_officers.exists()),
'event_timeline': outreach_event.outreachevent_set.all().order_by(
'-pin_to_top',
'-id'
),
}
context_dict.update(get_common_context(request))
context_dict.update(get_permissions(request.user))
context = RequestContext(request, context_dict)
return HttpResponse(template.render(context))
示例7: update_person
def update_person(request):
""" If person exists, pre-fill information
If person has profile but not BS profile, pre-fill some of it, and on
submit link together
If person has nothing, will need to create and link everything on submit
"""
if not Permissions.can_process_bookswap(request.user):
request.session['error_message'] = messages.BOOKSWAP_NO_PERM
return get_previous_page(request, alternate='bookswap:admin_index')
had_profile = request.session.pop('had_profile', False)
uniqname = request.session.pop('uniqname', '')
if had_profile:
bsp = BookSwapPerson.objects.get(user_profile__uniqname=uniqname)
form = BookSwapPersonForm(request.POST or None, instance=bsp)
else:
initial = {
'UMID': request.session.pop('UMID', ''),
'uniqname': uniqname,
'barcode': request.session.pop('barcode', ''),
}
form = BookSwapPersonFormNoProfile(request.POST or None, initial=initial)
if request.method == 'POST':
if form.is_valid():
bsp = form.save()
uniqname = bsp.user_profile.uniqname
request.session['success_message'] = ('User created/updated.')
if BookSwapStatus.can_receive(AcademicTerm.get_current_term()):
return redirect('bookswap:receive_book_start', uniqname=uniqname)
elif BookSwapStatus.can_sell(AcademicTerm.get_current_term()):
return redirect('bookswap:sell_book_start', uniqname=uniqname)
else:
request.session['info_message'] = ('Book Swap not open for '
'receiving or selling')
return redirect('bookswap:admin_index')
else:
request.session['error_message'] = messages.GENERIC_SUBMIT_ERROR
request.session['had_profile'] = had_profile
request.session['uniqname'] = uniqname
else:
request.session['had_profile'] = had_profile
request.session['uniqname'] = uniqname
template = loader.get_template('generic_form.html')
context_dict = {
'form': form,
'subnav': 'admin',
'has_files': False,
'submit_name': 'Create/update user',
'form_title': 'Create/update the user information',
'help_text': ('Please confirm that the following is correct and '
'update as necessary. Note that for sellers an address '
'is required.'),
'base': 'bookswap/base_bookswap.html',
}
context_dict.update(get_permissions(request.user))
context_dict.update(get_common_context(request))
context = RequestContext(request, context_dict)
return HttpResponse(template.render(context))
示例8: mindset
def mindset(request):
request.session['current_page']=request.path
template = loader.get_template('outreach/MindSET.html')
k_12_officers = Officer.objects.filter(position__name='K-12 Outreach Officer').order_by('-term__year','term__semester_type__name')
officers_unique=[]
id_set = set()
positions=OfficerPosition.objects.filter(name='K-12 Outreach Officer')
current_officers=k_12_officers.filter(term=AcademicTerm.get_current_term())
if positions.exists:
position=positions[0]
else:
position=None
for officer in k_12_officers:
if officer.user.uniqname in id_set:
continue
else:
id_set|=set([officer.user.uniqname])
if not current_officers.filter(user__uniqname=officer.user.uniqname).exists():
officers_unique.append(officer)
mindset_main_photo = OutreachPhoto.objects.filter(photo_type__name='MindSET_Main')
mindset_slideshow_photos = OutreachPhoto.objects.filter(photo_type__name='MindSET_Slideshow',active=True)
if mindset_main_photo.exists():
main_photo=mindset_main_photo[0]
else:
main_photo=None
mindset_parking_photo = OutreachPhoto.objects.filter(photo_type__name='MindSET_Map')
if mindset_parking_photo.exists():
parking_photo=mindset_parking_photo[0]
else:
parking_photo=None
events = CalendarEvent.objects.filter(term=AcademicTerm.get_current_term(),event_type__name='MindSET').annotate(earliest_shift=Min('eventshift__start_time')).order_by('earliest_shift')
context_dict = {
'events':events,
'main_photo':main_photo,
'parking_photo':parking_photo,
'modules':MindSETModule.objects.all(),
'k_12_officers':officers_unique,
'position':position,
'current_officers':current_officers,
'volunteer_files':VolunteerFile.objects.all(),
'slideshow_photos':mindset_slideshow_photos,
'subnav':'mindset',
}
context_dict.update(get_common_context(request))
context_dict.update(get_permissions(request.user))
context = RequestContext(request, context_dict)
return HttpResponse(template.render(context))
示例9: get_previous_full_term
def get_previous_full_term(term):
new_type = None
new_year = 0;
if term.semester_type.name=='Winter':
new_year=term.year-1
new_type = SemesterType.objects.get(name='Fall')
else:
new_year = term.year
new_type = SemesterType.objects.get(name='Winter')
if AcademicTerm.objects.filter(year=new_year,semester_type=new_type).exists():
return AcademicTerm.objects.get(year=new_year,semester_type=new_type)
else:
a = AcademicTerm(year=new_year,semester_type=new_type)
a.save()
return a
示例10: get_next_full_term
def get_next_full_term(term):
new_type = None
new_year = 0
if term.semester_type.name == "Fall":
new_year = term.year + 1
new_type = SemesterType.objects.get(name="Winter")
else:
new_year = term.year
new_type = SemesterType.objects.get(name="Fall")
if AcademicTerm.objects.filter(year=new_year, semester_type=new_type).exists():
return AcademicTerm.objects.get(year=new_year, semester_type=new_type)
else:
a = AcademicTerm(year=new_year, semester_type=new_type)
a.save()
return a
示例11: get_previous_officer_positions
def get_previous_officer_positions(cls,user):
profile = cls.get_profile(user)
if not profile:
return Officer.objects.none()
term = get_previous_full_term(AcademicTerm.get_current_term())
positions = Officer.objects.filter(user=profile,term = term,position__position_type='O')
return positions
示例12: edit_electee_resources
def edit_electee_resources(request):
if not Permissions.can_manage_electee_progress(request.user):
request.session['error_message']='You are not authorized to edit electee resources.'
return redirect('electees:view_electee_groups')
ResourceFormSet = modelformset_factory(ElecteeResource,exclude=('term',),can_delete=True)
term =AcademicTerm.get_current_term()
if request.method =='POST':
formset = ResourceFormSet(request.POST,request.FILES,prefix='resources',queryset=ElecteeResource.objects.filter(term=term))
if formset.is_valid():
instances=formset.save(commit=False)
for obj in formset.deleted_objects:
obj.delete()
for instance in instances:
instance.term=term
instance.save()
request.session['success_message']='Electee resources updated successfully'
return redirect('electees:view_electee_groups')
else:
request.session['error_message']='Form is invalid. Please correct the noted errors.'
else:
formset = ResourceFormSet(prefix='resources',queryset=ElecteeResource.objects.filter(term=term))
template = loader.get_template('generic_formset.html')
context_dict = {
'formset':formset,
'prefix':'resources',
'has_files':True,
'submit_name':'Update Electee Resources',
'form_title':'Update/Add/Remove Electee Resources for %s'%(unicode(term)),
'help_text':'These are the full packets and their constituent parts. If you need a part that isn\'t listed here, contact the web chair.',
'can_add_row':True,
'base':'electees/base_electees.html',
}
context_dict.update(get_common_context(request))
context_dict.update(get_permissions(request.user))
return HttpResponse(template.render(context_dict, request))
示例13: default_term
def default_term():
""" Returns the current term.
Fixes a serialization issue that results from circular references in
migrations.
"""
return AcademicTerm.get_current_term().id
示例14: __init__
def __init__(self, *args, **kwargs):
term = kwargs.pop('term', AcademicTerm.get_current_term())
initial=[]
for distinction in DistinctionType.objects.filter(status_type__name='Active'):
actives_already_received_distinction = MemberProfile.objects.filter(
distinction__distinction_type=distinction,
distinction__term=term
)
actives = distinction.get_actives_with_status(term)
for active in actives:
if active in actives_already_received_distinction:
continue
if distinction.name == 'Active':
gift = 'N/A'
else:
gift = 'Not specified'
initial.append(
{
'member': active,
'distinction_type': distinction,
'gift': gift,
'approve': False
}
)
kwargs['initial'] = initial
super(BaseAddActiveStatusFormSet,
self).__init__(*args, **kwargs)
self.extra = len(initial)+1
self.form.base_fields['distinction_type'].queryset =\
DistinctionType.objects.filter(status_type__name='Active')
示例15: get_project_report_term
def get_project_report_term():
today = date.today()
current_term = AcademicTerm.get_current_term()
this_fall = Q(year=today.year, semester_type__name='Fall')
last_fall = Q(year=today.year-1, semester_type__name='Fall')
next_winter = Q(year=today.year+1, semester_type__name='Winter')
this_winter = Q(year=today.year, semester_type__name='Winter')
this_summer = Q(year=today.year, semester_type__name='Summer')
last_summer = Q(year=today.year-1, semester_type__name='Summer')
if today.month >= 9:
# the project reports were already turned in, only care about the fall
return AcademicTerm.objects.filter(
this_fall |
next_winter |
this_summer)
elif today.month >=5:
# the project reports might be turned in. Show all
return AcademicTerm.objects.filter(
this_fall |
next_winter |
this_summer |
this_winter |
last_summer |
last_fall)
else: # report not turned in yet
return AcademicTerm.objects.filter(
this_winter |
last_summer |
last_fall)