def memberjobs(request): ''' All jobs of current user ''' member = request.user.member allassignments = AssignmentDao.assignments_for_member(member) renderdict = get_menu_dict(request, 'jobs') renderdict.update({'assignments': allassignments}) return render(request, 'memberjobs.html', renderdict)
def pastjobs(request): ''' All past jobs of current user ''' member = request.user.member allassignments = AssignmentDao.assignments_for_member(member) past_assingments = [] for assignment in allassignments: if assignment.job.time < timezone.now(): past_assingments.append(assignment) renderdict = get_menu_dict(request) renderdict.update({ 'assignments': past_assingments, 'menu': { 'participation': 'active' }, }) return render(request, 'pastjobs.html', renderdict)
def get_menu_dict(request): member = request.user.member next_jobs = [] def filter_to_past_assignments(assignments): res = [] for assignment in assignments: if assignment.job.time.year == date.today( ).year and assignment.job.time < timezone.now(): res.append(assignment) return res subscription_size = 0 if member.subscription is not None: partner_assignments = [] for subscription_member in member.subscription.recipients(): if subscription_member == member: continue partner_assignments.extend( filter_to_past_assignments( AssignmentDao.assignments_for_member(subscription_member))) userassignments = filter_to_past_assignments( AssignmentDao.assignments_for_member(member)) subscription_size = member.subscription.required_assignments() assignmentsrange = list( range( 0, max(subscription_size, len(userassignments) + len(partner_assignments)))) for assignment in AssignmentDao.assignments_for_member( member).order_by("job__time"): if assignment.job.time > timezone.now(): next_jobs.append(assignment.job) else: assignmentsrange = None partner_assignments = [] userassignments = [] next_jobs = [] depot_admin = DepotDao.depots_for_contact(request.user.member) area_admin = ActivityAreaDao.areas_by_coordinator(request.user.member) menu_dict = { 'user': request.user, 'assignmentsrange': assignmentsrange, 'userassignments_total': len(userassignments), 'userassignemnts_core': len([ assignment for assignment in userassignments if assignment.is_core() ]), 'partner_assignments_total': len(userassignments) + len(partner_assignments), 'partner_assignments_core': len(userassignments) + len([ assignment for assignment in partner_assignments if assignment.is_core() ]), 'subscription_size': subscription_size, 'next_jobs': next_jobs, 'can_filter_members': request.user.has_perm('juntagrico.can_filter_members'), 'can_filter_subscriptions': request.user.has_perm('juntagrico.can_filter_subscriptions'), 'can_send_mails': request.user.has_perm('juntagrico.can_send_mails'), 'operation_group': request.user.has_perm('juntagrico.is_operations_group'), 'depot_admin': depot_admin, 'area_admin': area_admin, 'show_core': ActivityAreaDao.all_core_areas().count() > 0, 'show_extras': JobExtraDao.all_job_extras().count() > 0, 'depot_list_url': settings.MEDIA_URL + settings.MEDIA_ROOT + "/dpl.pdf", } enrich_menu_dict(request, menu_dict) return menu_dict