def get(self, request):
""""Handles GET requests."""
user_profile = models.UserProfile.objects.get(user=request.user)
if not user_profile.user.is_staff:
return response.Response('', status=status.HTTP_404_NOT_FOUND)
# We create a convoluted queryset so that towers that have never synced
# (last_active = None) sort after active and inactive towers.
the_past = datetime.datetime.now() - datetime.timedelta(days=10*365)
towers = models.BTS.objects.all().annotate(
new_last_active=Coalesce('last_active', Value(the_past))).order_by(
'-new_last_active')
# Attach UserProfiles to each tower in the queryset.
for tower in towers:
tower_user_profiles = models.UserProfile.objects.filter(
network=tower.network)
for tower_user_profile in tower_user_profiles:
if hasattr(tower, 'user_email'):
tower.user_email += ',' + tower_user_profile.user.email
else:
tower.user_email = tower_user_profile.user.email
# Configure the table of towers.
tower_table = django_tables.StaffTowerTable(list(towers))
towers_per_page = 8
paginate = False
if towers.count() > towers_per_page:
paginate = {'per_page': towers_per_page}
tables.RequestConfig(request, paginate=paginate).configure(
tower_table)
context = {
'networks': get_objects_for_user(request.user, 'view_network', klass=models.Network),
'user_profile': user_profile,
'towers': towers,
'tower_table': tower_table,
}
# Render the template.
towers_template = template.loader.get_template(
'dashboard/staff/towers.html')
html = towers_template.render(context, request)
return http.HttpResponse(html)
staff.py 文件源码
python
阅读 18
收藏 0
点赞 0
评论 0
评论列表
文章目录