Example #1
0
File: views.py Project: emef/shift
def open_jobs_shift(request, shift_id):
    shift = get_object_or_404(Shift, id=shift_id)
    candidates = shift.candidates(settings.MAX_CANDIDATES)
    data = { 'shift': shift, 'candidates': candidates }
    
    if request.method == 'POST':
        try:
            standby = map(int, request.POST.getlist('standby'))
        except KeyError, ValueError:
            raise Http404

        # remove old offers
        shift.offers.all().delete()
        
        for id in standby:
            offer = ShiftOffer(contractor_id=id, shift=shift)
            offer.save()
            #send_confirmation_email(offer)
            
        shift.status = choice_rassoc(SHIFT_PENDING, SHIFT_STATUS_CHOICES)
        shift.save()
        
        if len(shift.job.open_shifts()) == 0:
            shift.job.status = choice_rassoc(JOB_PENDING, JOB_STATUS_CHOICES)
            shift.job.save()

        return redirect('/shift-leader/pending-jobs/shift/%s' % shift.id)
Example #2
0
File: views.py Project: emef/shift
def pending_jobs_shift(request, shift_id):
    shift = get_object_or_404(Shift, pk=shift_id)
    
    errors = []
    if request.method == 'POST':
        if 'hire' in request.POST:
            try: 
                id = int(request.POST['hire'])
                contractor = Contractor.objects.get(id=id)
                shift.contractor_id = id
                
                if 'standby' in request.POST:
                    standby = map(int, request.POST.getlist('standby'))
                    
                    for sc in Contractor.objects.filter(id__in=standby):
                        shift.standby_contractors.add(sc)
                    
                shift.offers.all().delete()
                contractor.offers.all().delete()
                
                shift.status = choice_rassoc(SHIFT_ASSIGNED, SHIFT_STATUS_CHOICES)
                shift.save()

                if len(shift.job.pending_shifts()) == 0:
                    shift.job.status = choice_rassoc(JOB_ASSIGNED, JOB_STATUS_CHOICES)
                    shift.job.save()

                return redirect('/shift-leader/pending-jobs/')
                
                    
            except ValueError:
                errors.append('You must select a contractor')
            
    
    confirmed = []
    unknown = []
    for offer in shift.offers.all():
        if offer.confirmed == True:
            confirmed.append(offer.contractor)
        elif offer.confirmed == None:
            unknown.append(offer.contractor)
    return render_page(request, 'shiftleader/pending_jobs_shift.html', locals())
Example #3
0
File: views.py Project: emef/shift
def pending_jobs(request):
    pending_id = choice_rassoc(JOB_PENDING, JOB_STATUS_CHOICES)
    qs = Job.objects.select_related().all()
    jobs = []
    for j in qs:
        pending_shifts = j.pending_shifts()
        if len(pending_shifts):
            jobs.append({'job': j, 'shifts': pending_shifts})
    job_url = '/shift-leader/pending-jobs/job/'
    shift_url = '/shift-leader/pending-jobs/shift/'
    
    return render_page(request, 'jobs_list.html', locals())
Example #4
0
File: views.py Project: emef/shift
def open_jobs_list(request):
    open_id = choice_rassoc(JOB_OPEN, JOB_STATUS_CHOICES)
    qs = Job.objects.select_related().all()
    jobs = []
    for j in qs:
        open_shifts = j.open_shifts()
        if len(open_shifts):
            jobs.append({'job': j, 'shifts': open_shifts})
    job_url = '/shift-leader/open-jobs/job/'
    shift_url = '/shift-leader/open-jobs/shift/'
    
    return render_page(request, 'jobs_list.html', locals())
Example #5
0
 def mk_attribute(self, field_name, field_type):
     if isinstance(field_type, tuple):
         choices = str(field_type)
         field_type = CHOICE_FIELD
     else:
         choices = None
         
     field_id = choice_rassoc(field_type, FIELD_TYPE_CHOICES)
     
     attr = Attribute.objects.create(field_name=field_name,
                                     field_type=field_id,
                                     is_private=False,
                                     choices_str=choices)
Example #6
0
File: models.py Project: emef/shift
 def mk_val(self, val):
     attr_val = ContractorAttributeVal(attribute=self)
     field_type = choice_assoc(self.field_type, FIELD_TYPE_CHOICES)
     if field_type == INT_FIELD:
         attr_val.int_val = int(from_measurement(val))
     elif field_type == FLOAT_FIELD:
         attr_val.float_val = float(from_measurement(val))
     elif field_type == BOOL_FIELD:
         attr_val.bool_val = (val.lower() == 'y')
     elif field_type == CHOICE_FIELD:
         attr_val.choice_val = choice_rassoc(val, self.choices)
         if attr_val.choice_val == None:
             raise ValueError('Invalid choice')
     elif field_type == CHAR_FIELD:
         attr_val.char_val = str(val)
     return attr_val
Example #7
0
File: models.py Project: emef/shift
 def pending_shifts(self):
     pending_int = choice_rassoc(SHIFT_PENDING, SHIFT_STATUS_CHOICES)
     return filter(lambda s: s.status == pending_int, self.shifts.all())
Example #8
0
File: models.py Project: emef/shift
 def open_shifts(self):
     open_int = choice_rassoc(SHIFT_OPEN, SHIFT_STATUS_CHOICES)
     return filter(lambda s: s.status == open_int, self.shifts.all())