本文整理汇总了Python中coredata.models.Unit.sub_units方法的典型用法代码示例。如果您正苦于以下问题:Python Unit.sub_units方法的具体用法?Python Unit.sub_units怎么用?Python Unit.sub_units使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类coredata.models.Unit
的用法示例。
在下文中一共展示了Unit.sub_units方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: student_appointments
# 需要导入模块: from coredata.models import Unit [as 别名]
# 或者: from coredata.models.Unit import sub_units [as 别名]
def student_appointments(request, userid):
student = get_object_or_404(Person, find_userid_or_emplid(userid))
appointments = RAAppointment.objects.filter(person=student, unit__in=Unit.sub_units(request.units), deleted=False).order_by("-created_at")
grads = GradStudent.objects.filter(person=student, program__unit__in=Unit.sub_units(request.units))
context = {'appointments': appointments, 'student': student,
'grads': grads}
return render(request, 'ra/student_appointments.html', context)
示例2: add_booking
# 需要导入模块: from coredata.models import Unit [as 别名]
# 或者: from coredata.models.Unit import sub_units [as 别名]
def add_booking(request, location_slug, from_index=0):
location = get_object_or_404(Location, slug=location_slug, unit__in=Unit.sub_units(request.units))
editor = get_object_or_404(Person, userid=request.user.username)
if request.method == 'POST':
form = BookingRecordForm(request.POST)
if form.is_valid():
booking = form.save(commit=False)
booking.location = location
booking.save(editor=editor)
location.mark_conflicts()
messages.add_message(request,
messages.SUCCESS,
'Booking was created')
l = LogEntry(userid=request.user.username,
description="Added booking %s for location %s" % (booking, location),
related_object=booking)
l.save()
if from_index == '1':
return HttpResponseRedirect(reverse('space:index'))
return view_location(request, location_slug)
else:
form.fields['start_time'].help_text = "Any previous bookings without an end time will also get its " \
"end time set to this."
else:
form = BookingRecordForm()
form.fields['start_time'].help_text = "Any previous bookings without an end time will also get its " \
"end time set to this."
return render(request, 'space/new_booking.html', {'form': form, 'location': location, 'from_index': from_index})
示例3: person_info
# 需要导入模块: from coredata.models import Unit [as 别名]
# 或者: from coredata.models.Unit import sub_units [as 别名]
def person_info(request):
"""
Get more info about this person, for AJAX updates on new RA form
"""
result = {'programs': []}
emplid = request.GET.get('emplid', None)
if not emplid or not emplid.isdigit() or len(emplid) != 9:
pass
else:
programs = []
# GradPrograms
emplid = request.GET['emplid']
grads = GradStudent.objects.filter(person__emplid=emplid, program__unit__in=Unit.sub_units(request.units))
for gs in grads:
pdata = {
'program': gs.program.label,
'unit': gs.program.unit.name,
'status': gs.get_current_status_display(),
}
programs.append(pdata)
result['programs'] = programs
# other SIMS info
try:
otherinfo = more_personal_info(emplid, needed=['citizen', 'visa'])
result.update(otherinfo)
except SIMSProblem, e:
result['error'] = e.message
示例4: download_locations
# 需要导入模块: from coredata.models import Unit [as 别名]
# 或者: from coredata.models.Unit import sub_units [as 别名]
def download_locations(request):
units = Unit.sub_units(request.units)
locations = Location.objects.visible(units).select_related('unit', 'room_type')\
.prefetch_related('safety_items', 'bookings', 'bookings__person')
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'inline; filename="locations-%s.csv"' % \
(datetime.datetime.now().strftime('%Y%m%d'))
writer = csv.writer(response)
writer.writerow(['Unit', 'Campus', 'Building', 'Floor', 'Room Number', 'Square Meters', 'Room Type Description',
'Room Type Code', 'COU Code Description', 'Space Factor', 'COU Code Value', 'Infrastructure',
'Room Capacity', 'Category', 'Occupancy', 'Own/Leased', 'Safety Infrastructure Items', 'Comments',
'Current Booking', 'Active Grad Student(s)'])
for l in locations:
bookings = l.get_current_bookings()
grad_count = None
if bookings:
grad_count = 0
for b in bookings:
booker = b.person
grad_count += Supervisor.objects.filter(supervisor=booker, removed=False,
student__current_status='ACTI').count()
writer.writerow([l.unit.name, l.get_campus_display(), l.get_building_display(), l.floor, l.room_number,
l.square_meters, l.room_type.long_description, l.room_type.code,
l.room_type.COU_code_description, l.room_type.space_factor, l.room_type.COU_code_value,
l.get_infrastructure_display(), l.room_capacity, l.get_category_display(), l.occupancy_count,
l.get_own_or_lease_display(), l.safety_items_display(), l.comments,
l.get_current_bookings_str(), grad_count])
return response
示例5: config_display
# 需要导入模块: from coredata.models import Unit [as 别名]
# 或者: from coredata.models.Unit import sub_units [as 别名]
def config_display(cls, units):
committees = list(cls.all_config_fields(Unit.sub_units(units), 'committees'))
unit_lookup = CommitteeMemberHandler._unit_lookup()
for c in committees:
c[3] = unit_lookup[c[3]]
context = Context({'committees': committees})
return cls.DISPLAY_TEMPLATE.render(context)
示例6: download_booking_attachment
# 需要导入模块: from coredata.models import Unit [as 别名]
# 或者: from coredata.models.Unit import sub_units [as 别名]
def download_booking_attachment(request, booking_slug, attachment_id):
booking = get_object_or_404(BookingRecord, slug=booking_slug, location__unit__in=Unit.sub_units(request.units))
attachment = get_object_or_404(BookingRecordAttachment, booking_record=booking, pk=attachment_id)
filename = attachment.contents.name.rsplit('/')[-1]
resp = StreamingHttpResponse(attachment.contents.chunks(), content_type=attachment.mediatype)
resp['Content-Disposition'] = 'attachment; filename="' + filename + '"'
resp['Content-Length'] = attachment.contents.size
return resp
示例7: __init__
# 需要导入模块: from coredata.models import Unit [as 别名]
# 或者: from coredata.models.Unit import sub_units [as 别名]
def __init__(self, request, *args, **kwargs):
super(AssetChangeForm, self).__init__(*args, **kwargs)
# The following two lines look stupid, but they are not. request.units contains a set of units.
# in order to be used this way, we need an actual queryset.
#
# In this case, we also include subunits. If you manage assets for a parent unit, chances are you may be
# adding/removing them for events in your children units.
unit_ids = [unit.id for unit in Unit.sub_units(request.units)]
units = Unit.objects.filter(id__in=unit_ids)
示例8: delete_unit_role
# 需要导入模块: from coredata.models import Unit [as 别名]
# 或者: from coredata.models.Unit import sub_units [as 别名]
def delete_unit_role(request, role_id):
role = get_object_or_404(Role, pk=role_id, unit__in=Unit.sub_units(request.units), role__in=UNIT_ROLES)
messages.success(request, 'Deleted role %s for %s.' % (role.get_role_display(), role.person.name()))
#LOG EVENT#
l = LogEntry(userid=request.user.username,
description=("deleted role: %s for %s in %s") % (role.get_role_display(), role.person.name(), role.unit),
related_object=role.person)
l.save()
role.delete()
return HttpResponseRedirect(reverse(unit_role_list))
示例9: delete_room_safety_item
# 需要导入模块: from coredata.models import Unit [as 别名]
# 或者: from coredata.models.Unit import sub_units [as 别名]
def delete_room_safety_item(request, safety_item_slug):
safety_item = get_object_or_404(RoomSafetyItem, unit__in=Unit.sub_units(request.units), slug=safety_item_slug)
if request.method == 'POST':
safety_item.delete()
messages.add_message(request,
messages.SUCCESS,
'Safety item was deleted')
l = LogEntry(userid=request.user.username,
description="Deleted safety item %s" % safety_item,
related_object=safety_item)
l.save()
return HttpResponseRedirect(reverse('space:manage_safety_items'))
示例10: delete_booking_attachment
# 需要导入模块: from coredata.models import Unit [as 别名]
# 或者: from coredata.models.Unit import sub_units [as 别名]
def delete_booking_attachment(request, booking_slug, attachment_id):
booking = get_object_or_404(BookingRecord, slug=booking_slug, location__unit__in=Unit.sub_units(request.units))
attachment = get_object_or_404(BookingRecordAttachment, booking_record=booking, pk=attachment_id)
attachment.hide()
messages.add_message(request,
messages.SUCCESS,
'Attachment was deleted')
l = LogEntry(userid=request.user.username,
description="Deleted attachment in booking %s" % booking,
related_object=attachment)
l.save()
return HttpResponseRedirect(reverse('space:view_booking', kwargs={'booking_slug': booking.slug}))
示例11: delete_roomtype
# 需要导入模块: from coredata.models import Unit [as 别名]
# 或者: from coredata.models.Unit import sub_units [as 别名]
def delete_roomtype(request, roomtype_id):
roomtype = get_object_or_404(RoomType, pk=roomtype_id, unit__in=Unit.sub_units(request.units))
if request.method == 'POST':
roomtype.hidden = True
roomtype.save()
messages.add_message(request,
messages.SUCCESS,
'Room type was deleted')
l = LogEntry(userid=request.user.username,
description="Deleted roomtype %s" % roomtype,
related_object=roomtype)
l.save()
return HttpResponseRedirect(reverse('space:list_roomtypes'))
示例12: delete_location
# 需要导入模块: from coredata.models import Unit [as 别名]
# 或者: from coredata.models.Unit import sub_units [as 别名]
def delete_location(request, location_id):
location = get_object_or_404(Location, pk=location_id, unit__in=Unit.sub_units(request.units))
if request.method == 'POST':
location.hidden = True
location.save()
messages.add_message(request,
messages.SUCCESS,
'Location was deleted')
l = LogEntry(userid=request.user.username,
description="Deleted location %s" % location,
related_object=location)
l.save()
return HttpResponseRedirect(reverse('space:index'))
示例13: browse
# 需要导入模块: from coredata.models import Unit [as 别名]
# 或者: from coredata.models.Unit import sub_units [as 别名]
def browse(request):
units = Unit.sub_units(request.units)
hiring_choices = [('all', 'All')] + possible_supervisors(units)
project_choices = [('all', 'All')] + [(p.id, unicode(p)) for p in Project.objects.filter(unit__in=units, hidden=False)]
account_choices = [('all', 'All')] + [(a.id, unicode(a)) for a in Account.objects.filter(unit__in=units, hidden=False)]
if 'data' in request.GET:
# AJAX query for data
ras = RAAppointment.objects.filter(unit__in=units, deleted=False) \
.select_related('person', 'hiring_faculty', 'project', 'account')
if 'hiring_faculty' in request.GET and request.GET['hiring_faculty'] != 'all':
ras = ras.filter(hiring_faculty__id=request.GET['hiring_faculty'])
if 'project' in request.GET and request.GET['project'] != 'all':
ras = ras.filter(project__id=request.GET['project'], project__unit__in=units)
if 'account' in request.GET and request.GET['account'] != 'all':
ras = ras.filter(account__id=request.GET['account'], account__unit__in=units)
truncated = False
if ras.count() > 200:
ras = ras[:200]
truncated = True
data = []
for ra in ras:
radata = {
'slug': ra.slug,
'name': ra.person.sortname(),
'hiring': ra.hiring_faculty.sortname(),
'project': unicode(ra.project),
'project_hidden': ra.project.hidden,
'account': unicode(ra.account),
'account_hidden': ra.account.hidden,
'start': datefilter(ra.start_date, settings.GRAD_DATE_FORMAT),
'end': datefilter(ra.end_date, settings.GRAD_DATE_FORMAT),
'amount': '$'+unicode(ra.lump_sum_pay),
}
data.append(radata)
response = HttpResponse(content_type="application/json")
json.dump({'truncated': truncated, 'data': data}, response, indent=1)
return response
else:
# request for page
form = RABrowseForm()
form.fields['hiring_faculty'].choices = hiring_choices
form.fields['account'].choices = account_choices
form.fields['project'].choices = project_choices
context = {
'form': form
}
return render(request, 'ra/browse.html', context)
示例14: delete_booking
# 需要导入模块: from coredata.models import Unit [as 别名]
# 或者: from coredata.models.Unit import sub_units [as 别名]
def delete_booking(request, booking_id):
booking = get_object_or_404(BookingRecord, pk=booking_id, location__unit__in=Unit.sub_units(request.units))
editor = get_object_or_404(Person, userid=request.user.username)
if request.method == 'POST':
booking.hidden = True
booking.save(editor=editor)
booking.location.mark_conflicts()
messages.add_message(request,
messages.SUCCESS,
'Booking was deleted')
l = LogEntry(userid=request.user.username,
description="Deleted booking %s" % booking,
related_object=booking)
l.save()
return view_location(request, booking.location.slug)
示例15: send_memo
# 需要导入模块: from coredata.models import Unit [as 别名]
# 或者: from coredata.models.Unit import sub_units [as 别名]
def send_memo(request, booking_slug, from_index=0):
booking = get_object_or_404(BookingRecord, slug=booking_slug, location__unit__in=Unit.sub_units(request.units))
editor = get_object_or_404(Person, userid=request.user.username)
booking_memo = BookingMemo(booking_record=booking, created_by=editor)
booking_memo.email_memo()
booking_memo.save()
messages.add_message(request,
messages.SUCCESS,
'Memo was sent')
l = LogEntry(userid=request.user.username,
description="Send memo to %s" % booking.person,
related_object=booking_memo)
l.save()
if from_index == '1':
return HttpResponseRedirect(reverse('space:view_location', kwargs={'location_slug': booking.location.slug}))
return HttpResponseRedirect(reverse('space:view_booking', kwargs={'booking_slug': booking.slug}))