def get_menu_dict(request): member = request.user.member next_jobs = [a.job for a in AssignmentDao.upcomming_assignments_for_member(member).order_by('job__time')] required_assignments = 0 if member.subscription is not None: partner_assignments = [] for subscription_member in member.subscription.recipients_all: if subscription_member == member: continue partner_assignments.extend( AssignmentDao.assignments_for_member_current_business_year(subscription_member)) userassignments = AssignmentDao.assignments_for_member_current_business_year( member) required_assignments = member.subscription.required_assignments else: partner_assignments = [] userassignments = [] userassignments_total = int(sum(a.amount for a in userassignments)) userassignemnts_core = int( sum(a.amount for a in userassignments if a.is_core())) partner_assignments_total = int(sum(a.amount for a in partner_assignments)) partner_assignments_core = int( sum(a.amount for a in partner_assignments if a.is_core())) assignmentsrange = list(range( 0, max(required_assignments, userassignments_total+partner_assignments_total))) depot_admin = DepotDao.depots_for_contact(request.user.member) area_admin = ActivityAreaDao.areas_by_coordinator(request.user.member) menu_dict = get_page_dict(request) menu_dict.update({ 'user': request.user, 'assignmentsrange': assignmentsrange, 'userassignments_bound': userassignments_total, 'userassignemnts_core_bound': userassignemnts_core, 'partner_assignments_bound': userassignments_total + partner_assignments_total, 'partner_assignments_core_bound': userassignments_total + partner_assignments_core, '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'), 'has_extra_subscriptions': ExtraSubscriptionCategoryDao.all_categories_ordered().count() > 0, 'depot_admin': depot_admin, 'area_admin': area_admin, 'show_core': ActivityAreaDao.all_core_areas().count() > 0, 'show_extras': JobExtraDao.all_job_extras().count() > 0, 'show_deliveries': len(DeliveryDao.deliveries_by_subscription(request.user.member.subscription)) > 0, 'admin_menus': addons.config.get_admin_menus(), 'user_menus': addons.config.get_user_menus(), 'messages': [], }) return menu_dict
def transform_job_type(self, request, queryset): for inst in queryset.all(): i = 0 for rj in JobDao.recurings_by_type(inst.id): oj = OneTimeJob() attribute_copy(inst, oj) attribute_copy(rj, oj) oj.name += str(i) i += 1 oj.save() for je in JobExtraDao.by_type(inst.id): je.recuring_type = None je.onetime_type = oj je.pk = None je.save() for b in AssignmentDao.assignments_for_job(rj.id): b.job = oj b.save() rj.delete() for je in JobExtraDao.by_type(inst.id): je.delete() inst.delete()
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