def formfield_for_foreignkey(self, db_field, request, **kwargs): if db_field.name == 'job' and request.user.has_perm( 'juntagrico.is_area_admin') and (not ( request.user.is_superuser or request.user.has_perm('juntagrico.is_operations_group'))): kwargs['queryset'] = JobDao.jobs_by_ids( JobDao.ids_for_area_by_contact(request.user.member)) return super(admin.ModelAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
def home(request): ''' Overview on juntagrico ''' next_jobs = set(JobDao.get_current_jobs()[:7]) pinned_jobs = set(JobDao.get_pinned_jobs()) next_promotedjobs = set(JobDao.get_promoted_jobs()) renderdict = get_menu_dict(request) renderdict['messages'].extend(home_messages(request)) renderdict.update({ 'jobs': sorted(next_jobs.union(pinned_jobs).union(next_promotedjobs), key=lambda job: job.time), 'areas': ActivityAreaDao.all_visible_areas_ordered(), }) return render(request, 'home.html', renderdict)
def contact_member(request, member_id, job_id): ''' member contact form ''' member = request.user.member contact_member = get_object_or_404(Member, id=int(member_id)) is_sent = False if request.method == 'POST': # send mail to member attachments = [] append_attachements(request, attachments) send_contact_member_form(request.POST.get('subject'), request.POST.get('message'), member, contact_member, request.POST.get('copy'), attachments) is_sent = True job = JobDao.job_by_id(job_id) renderdict = get_menu_dict(request) renderdict.update({ 'admin': request.user.is_staff or job.type.activityarea.coordinator == member, 'usernameAndEmail': member.first_name + ' ' + member.last_name + '<' + member.email + '>', 'member_id': member_id, 'member_name': contact_member.first_name + ' ' + contact_member.last_name, 'is_sent': is_sent, 'job_id': job_id }) return render(request, 'contact_member.html', renderdict)
def handle(self, *args, **options): now = timezone.now() end = now + datetime.timedelta(days=2) for job in JobDao.jobs_to_remind(now, end): membernotification.job_reminder(job.participant_emails, job) job.reminder_sent = True job.save() print(('reminder sent for job ' + str(job.id)))
def get_queryset(self, request): qs = super().get_queryset(request) if request.user.has_perm('juntagrico.is_area_admin') and ( not (request.user.is_superuser or request.user.has_perm('juntagrico.is_operations_group'))): return qs.filter(job__id__in=JobDao.ids_for_area_by_contact( request.user.member)) return qs
def all_jobs(request): ''' All jobs to be sorted etc. ''' renderdict = get_menu_dict(request, 'jobs') jobs = JobDao.jobs_ordered_by_time() renderdict.update({'jobs': jobs}) return render(request, 'jobs.html', renderdict)
def jobs(request): ''' All jobs to be sorted etc. ''' renderdict = get_menu_dict(request, 'jobs') jobs = JobDao.get_jobs_for_current_day() renderdict.update({'jobs': jobs, 'show_all': True}) return render(request, 'jobs.html', renderdict)
def formfield_for_foreignkey(self, db_field, request, **kwargs): if db_field.name == "job" and request.user.has_perm( "juntagrico.is_area_admin") and (not ( request.user.is_superuser or request.user.has_perm("juntagrico.is_operations_group"))): kwargs["queryset"] = JobDao.objects.filter( id__in=JobDao.ids_for_area_by_contact(request.user.member)) return super(admin.ModelAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
def show_area(request, area_id): ''' Details for an area ''' area = get_object_or_404(ActivityArea, id=int(area_id)) job_types = JobTypeDao.types_by_area(area_id) otjobs = JobDao.get_current_one_time_jobs().filter(activityarea=area_id) rjobs = JobDao.get_current_recuring_jobs().filter(type__in=job_types) jobs = list(rjobs) if len(otjobs) > 0: jobs.extend(list(otjobs)) jobs.sort(key=lambda job: job.time) area_checked = request.user.member in area.members.all() renderdict = get_menu_dict(request) renderdict.update({ 'area': area, 'jobs': jobs, 'area_checked': area_checked, }) return render(request, 'area.html', renderdict)
def home(request): """ Overview on juntagrico """ next_jobs = set(JobDao.get_current_jobs()[:7]) pinned_jobs = set(JobDao.get_pinned_jobs()) next_pormotedjobs = set(JobDao.get_promoted_jobs()) renderdict = get_menu_dict(request) renderdict.update({ 'jobs': sorted(next_jobs.union(pinned_jobs).union(next_pormotedjobs), key=lambda job: job.time), 'teams': ActivityAreaDao.all_visible_areas_ordered(), 'messages': messages(request), }) return render(request, "home.html", renderdict)
def team(request, area_id): ''' Details for a team ''' job_types = JobTypeDao.types_by_area(area_id) otjobs = JobDao.get_current_one_time_jobs().filter(activityarea=area_id) rjobs = JobDao.get_current_recuring_jobs().filter(type__in=job_types) jobs = list(rjobs) if len(otjobs) > 0: jobs.extend(list(otjobs)) jobs.sort(key=lambda job: job.time) renderdict = get_menu_dict(request) renderdict.update({ 'team': get_object_or_404(ActivityArea, id=int(area_id)), 'jobs': jobs, }) return render(request, 'team.html', renderdict)
def assingments_all(request): ''' All jobs to be sorted etc. ''' renderdict = get_menu_dict(request) jobs = JobDao.jobs_ordered_by_time() renderdict.update({ 'jobs': jobs, 'menu': { 'jobs': 'active' }, }) return render(request, 'jobs.html', renderdict)
def transform_job_type(self, 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 b in AssignmentDao.assignments_for_job(rj.id): b.job = oj b.save() rj.delete() inst.delete()
def handle(self, *args, **options): now = timezone.now() end = now + datetime.timedelta(days=2) for job in JobDao.jobs_to_remind(now, end): participants = [] emails = [] for assignment in AssignmentDao.assignments_for_job(job.id): if assignment.member is not None: participants.append(str(assignment.member)) emails.append(assignment.member.email) send_job_reminder(emails, job, ', '.join(participants)) job.reminder_sent = True job.save() print(('reminder sent for job ' + str(job.id)))
def assignments(request): ''' All jobs to be sorted etc. ''' renderdict = get_menu_dict(request) jobs = JobDao.get_current_jobs() renderdict.update({ 'jobs': jobs, 'show_all': True, 'menu': { 'jobs': 'active' }, }) return render(request, 'jobs.html', renderdict)
def contact_member(request, member_id, job_id): """ member contact form """ member = request.user.member contact_member = get_object_or_404(Member, id=int(member_id)) is_sent = False if request.method == "POST": # send mail to member index = 1 attachments = [] while request.FILES.get("image-" + str(index)) is not None: attachments.append(request.FILES.get("image-" + str(index))) index += 1 send_contact_member_form(request.POST.get("subject"), request.POST.get("message"), member, contact_member, request.POST.get("copy"), attachments) is_sent = True job = JobDao.job_by_id(job_id) renderdict = get_menu_dict(request) renderdict.update({ 'admin': request.user.is_staff or job.type.activityarea.coordinator == member, 'usernameAndEmail': member.first_name + " " + member.last_name + "<" + member.email + ">", 'member_id': member_id, 'member_name': contact_member.first_name + " " + contact_member.last_name, 'is_sent': is_sent, 'job_id': job_id }) return render(request, "contact_member.html", renderdict)
def get_menu_dict(request): member = request.user.member next_jobs = JobDao.upcomming_jobs_for_member(member) 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(), 'admin_subscription_menus': addons.config.get_admin_subscription_menu(), 'user_menus': addons.config.get_user_menus(), 'messages': [], }) return menu_dict