def handle(self, *args, **options):
   event_name = options['event_name'][0]
   if options['flush']:
     self.stdout.write('Removing all assignments in event %s...' % event_name)
     self.stdout.write('%s assignments in the database' % Assignment.objects.all().count())
     assignments = Assignment.objects.filter(applicant__event__name=event_name)
     self.stdout.write('%s assignments in the event %s' % (assignments.count(), event_name))
     assignments.delete()
     self.stdout.write('%s assignments left in the database' % Assignment.objects.all().count())
   if options['assignments']:
     self.stdout.write('%s assignments in the database' % Assignment.objects.all().count())
     with open(options['assignments'], 'r') as f:
       applicant = ''
       for i, line in enumerate(f):
         if i % 4 == 0:
           continue
         if i % 4 == 1:
           applicant = line
         if i % 4 == 2:
           applicant = normalize_name('%s%s' % (applicant, line))
         if i % 4 == 3:
           try:
             app = Applicant.objects.get(norm_name=applicant, event__name=event_name)
             scholar = McUser.objects.get(norm_name=normalize_name(line))
             assignment = Assignment(scholar=scholar, applicant=app)
             assignment.save()
           except Applicant.DoesNotExist:
             print 'could not find applicant %s' % applicant
     self.stdout.write('%s assignments in the database' % Assignment.objects.all().count())
def interviewer_feedback(request, event_name, name):
    try:
        applicant = Applicant.objects.get(norm_name=normalize_name(name),
                                          event__name=event_name)
    except Applicant.DoesNotExist:
        raise Http404('Applicant does not exist.')
    try:
        feedback = InterviewerFeedback.objects.get(applicant=applicant,
                                                   scholar=request.user.mcuser)
    except InterviewerFeedback.DoesNotExist:
        feedback = InterviewerFeedback()
        feedback.applicant = applicant
        feedback.scholar = request.user.mcuser
    if request.method == 'POST':
        form = InterviewerFeedbackForm(request.POST, instance=feedback)
        if (form.is_valid()):
            form.save()
            return redirect('feedback:index', event_name)
    else:
        form = InterviewerFeedbackForm(instance=feedback)

    context = {
        'applicant': applicant,
        'form': form,
        'state': get_state(),
        'template': interviewer_form.template,
        'event_name': event_name,
    }
    return render(request, 'feedback/interviewer_feedback.html', context)
def interviewer_feedback(request, event_name, name):
  try:
    applicant = Applicant.objects.get(norm_name=normalize_name(name), event__name=event_name)
  except Applicant.DoesNotExist:
    raise Http404('Applicant does not exist.')
  try:
    feedback = InterviewerFeedback.objects.get(applicant=applicant, scholar=request.user.mcuser)
  except InterviewerFeedback.DoesNotExist:
    feedback = InterviewerFeedback()
    feedback.applicant = applicant
    feedback.scholar = request.user.mcuser
  if request.method == 'POST':
    form = InterviewerFeedbackForm(request.POST, instance=feedback)
    if (form.is_valid()):
      form.save()
      return redirect('feedback:index', event_name)
  else:
    form = InterviewerFeedbackForm(instance=feedback)

  context = {
      'applicant': applicant,
      'form': form,
      'state': get_state(),
      'template': interviewer_form.template,
      'event_name': event_name,
      }
  return render(request, 'feedback/interviewer_feedback.html', context)
 def handle(self, *args, **options):
     event_name = options['event_name'][0]
     if options['flush']:
         self.stdout.write('Removing all assignments in event %s...' %
                           event_name)
         self.stdout.write('%s assignments in the database' %
                           Assignment.objects.all().count())
         assignments = Assignment.objects.filter(
             applicant__event__name=event_name)
         self.stdout.write('%s assignments in the event %s' %
                           (assignments.count(), event_name))
         assignments.delete()
         self.stdout.write('%s assignments left in the database' %
                           Assignment.objects.all().count())
     if options['assignments']:
         self.stdout.write('%s assignments in the database' %
                           Assignment.objects.all().count())
         with open(options['assignments'], 'r') as f:
             applicant = ''
             for i, line in enumerate(f):
                 if i % 4 == 0:
                     continue
                 if i % 4 == 1:
                     applicant = line
                 if i % 4 == 2:
                     applicant = normalize_name('%s%s' % (applicant, line))
                 if i % 4 == 3:
                     try:
                         app = Applicant.objects.get(norm_name=applicant,
                                                     event__name=event_name)
                         scholar = McUser.objects.get(
                             norm_name=normalize_name(line))
                         assignment = Assignment(scholar=scholar,
                                                 applicant=app)
                         assignment.save()
                     except Applicant.DoesNotExist:
                         print 'could not find applicant %s' % applicant
         self.stdout.write('%s assignments in the database' %
                           Assignment.objects.all().count())
def shortlist_applicant(request, event_name, name):
  try:
    applicant = Applicant.objects.get(norm_name=normalize_name(name), event__name=event_name)
  except Applicant.DoesNotExist:
    raise Http404('Applicant does not exist.')
  if request.method == 'POST':
    try:
      s = Shortlist.objects.get(applicant=applicant, scholar=request.user.mcuser)
      s.delete()
      return JsonResponse({'msg': 'unlisted'})
    except Shortlist.DoesNotExist:
      s = Shortlist(applicant=applicant, scholar=request.user.mcuser)
      s.save()
      return JsonResponse({'msg': 'listed'})
  return HttpResponse('Please POST')
def shortlist_applicant(request, event_name, name):
    try:
        applicant = Applicant.objects.get(norm_name=normalize_name(name),
                                          event__name=event_name)
    except Applicant.DoesNotExist:
        raise Http404('Applicant does not exist.')
    if request.method == 'POST':
        try:
            s = Shortlist.objects.get(applicant=applicant,
                                      scholar=request.user.mcuser)
            s.delete()
            return JsonResponse({'msg': 'unlisted'})
        except Shortlist.DoesNotExist:
            s = Shortlist(applicant=applicant, scholar=request.user.mcuser)
            s.save()
            return JsonResponse({'msg': 'listed'})
    return HttpResponse('Please POST')
def favorite_applicant(request, event_name, name):
  try:
    applicant = Applicant.objects.get(norm_name=normalize_name(name), event__name=event_name)
  except Applicant.DoesNotExist:
    raise Http404('Applicant does not exist.')
  if request.method == 'POST':
    try:
      fav = Favorite.objects.get(applicant=applicant, scholar=request.user.mcuser)
      fav.delete()
      return JsonResponse({'msg': 'unstarred'})
    except Favorite.DoesNotExist:
      favs = Favorite.objects.filter(scholar=request.user.mcuser, applicant__event__name=event_name)
      if favs.count() < 5:
        fav = Favorite(applicant=applicant, scholar=request.user.mcuser)
        fav.save()
        return JsonResponse({'msg': 'starred'})
      return JsonResponse({'msg': 'max stars given'})
  return HttpResponse('Please POST')
def applicant_profile(request, event_name, name):
    try:
        applicant = Applicant.objects.get(norm_name=normalize_name(name),
                                          event__name=event_name)
    except Applicant.DoesNotExist:
        raise Http404('Applicant does not exist.')
    try:
        event = Event.objects.get(name=event_name)
    except Event.DoesNotExist:
        raise Http404('Event does not exist')
    try:
        feedback = Feedback.objects.get(applicant=applicant,
                                        scholar=request.user.mcuser)
    except Feedback.DoesNotExist:
        feedback = Feedback()
        feedback.applicant = applicant
        feedback.scholar = request.user.mcuser
    if request.method == 'POST':
        form = FeedbackForm(request.POST, instance=feedback)
        if (form.is_valid()):
            form.save()
            if request.is_ajax():
                return JsonResponse({'msg': 'saved successfully'})
            return redirect('feedback:index', event_name)
    else:
        form = FeedbackForm(instance=feedback)
    all_feedback = Feedback.objects.filter(applicant=applicant)
    is_interviewer = request.user.mcuser in event.interviewers.all()
    is_assigned = Assignment.objects.filter(scholar=request.user.mcuser,
                                            applicant=applicant).exists()

    context = {
        'feedback': all_feedback,
        'applicant': applicant,
        'form': form,
        'state': get_state(),
        'event_name': event_name,
        'survey_link': event.survey_link,
        'is_interviewer': is_interviewer and is_assigned,
        'favorited': favorited(request.user.mcuser, applicant)
    }
    return render(request, 'feedback/applicant.html', context)
def edit_applicant(request, event_name, name):
    try:
        applicant = Applicant.objects.get(norm_name=normalize_name(name),
                                          event__name=event_name)
    except Applicant.DoesNotExist:
        raise Http404('Applicant does not exist.')
    if request.method == 'POST':
        form = ApplicantForm(request.POST, request.FILES, instance=applicant)
        if (form.is_valid()):
            app = form.save(commit=False)
            app.save()
            log_slack('Applicant %s/%s edited by %s' %
                      (name, app.get_full_name(),
                       request.user.mcuser.get_full_name()))
            return redirect('feedback:applicant_profile', event_name,
                            app.norm_name)
    else:
        form = ApplicantForm(instance=applicant)
    context = {'applicant': applicant, 'form': form, 'event_name': event_name}
    return render(request, 'feedback/edit_applicant.html', context)
Exemple #10
0
def edit_applicant(request, event_name, name):
  try:
    applicant = Applicant.objects.get(norm_name=normalize_name(name), event__name=event_name)
  except Applicant.DoesNotExist:
    raise Http404('Applicant does not exist.')
  if request.method == 'POST':
    form = ApplicantForm(request.POST, request.FILES, instance=applicant)
    if (form.is_valid()):
      app = form.save(commit=False)
      app.save()
      log_slack('Applicant %s/%s edited by %s' % (name, app.get_full_name(), request.user.mcuser.get_full_name()))
      return redirect('feedback:applicant_profile', event_name, app.norm_name)
  else:
    form = ApplicantForm(instance=applicant)
  context = {
      'applicant': applicant,
      'form': form,
      'event_name': event_name
      }
  return render(request, 'feedback/edit_applicant.html', context)
 def assign(self, event_name, users_file):
   self.stdout.write('%s assignments in the database' % Assignment.objects.all().count())
   applicants = Applicant.objects.filter(event__name=event_name)[::1]
   self.stdout.write('%s applicants in the database' % len(applicants))
   with open(users_file, 'r') as f:
     users = [normalize_name(u) for _, u in enumerate(f)]
   self.stdout.write('%s' % users)
   current_list = copy.deepcopy(applicants)
   for u in users:
     user = McUser.objects.get(norm_name=u)
     self.stdout.write(user.get_full_name())
     for _ in xrange(8):
       if len(current_list) == 0:
         current_list = copy.deepcopy(applicants)
       index = random.randint(0, len(current_list)-1)
       applicant = current_list[index]
       assignment = Assignment(scholar=user, applicant=applicant) 
       assignment.save()
       self.stdout.write(' - %s' % applicant.get_full_name())
       del current_list[index]
   self.stdout.write('%s assignments in the database' % Assignment.objects.all().count()) 
Exemple #12
0
def favorite_applicant(request, event_name, name):
    try:
        applicant = Applicant.objects.get(norm_name=normalize_name(name),
                                          event__name=event_name)
    except Applicant.DoesNotExist:
        raise Http404('Applicant does not exist.')
    if request.method == 'POST':
        try:
            fav = Favorite.objects.get(applicant=applicant,
                                       scholar=request.user.mcuser)
            fav.delete()
            return JsonResponse({'msg': 'unstarred'})
        except Favorite.DoesNotExist:
            favs = Favorite.objects.filter(scholar=request.user.mcuser,
                                           applicant__event__name=event_name)
            if favs.count() < 5:
                fav = Favorite(applicant=applicant,
                               scholar=request.user.mcuser)
                fav.save()
                return JsonResponse({'msg': 'starred'})
            return JsonResponse({'msg': 'max stars given'})
    return HttpResponse('Please POST')
Exemple #13
0
def applicant_profile(request, event_name, name):
  try:
    applicant = Applicant.objects.get(norm_name=normalize_name(name), event__name=event_name)
  except Applicant.DoesNotExist:
    raise Http404('Applicant does not exist.')
  try:
    event = Event.objects.get(name=event_name)
  except Event.DoesNotExist:
    raise Http404('Event does not exist')
  try:
    feedback = Feedback.objects.get(applicant=applicant, scholar=request.user.mcuser)
  except Feedback.DoesNotExist:
    feedback = Feedback()
    feedback.applicant = applicant
    feedback.scholar = request.user.mcuser
  if request.method == 'POST':
    form = FeedbackForm(request.POST, instance=feedback)
    if (form.is_valid()):
      form.save()
      if request.is_ajax():
        return JsonResponse({'msg': 'saved successfully'})
      return redirect('feedback:index', event_name)
  else:
    form = FeedbackForm(instance=feedback)
  all_feedback = Feedback.objects.filter(applicant=applicant)
  is_interviewer = request.user.mcuser in event.interviewers.all()
  is_assigned = Assignment.objects.filter(scholar=request.user.mcuser, applicant=applicant).exists()

  context = {
      'feedback': all_feedback,
      'applicant': applicant,
      'form': form,
      'state': get_state(),
      'event_name': event_name,
      'survey_link': event.survey_link,
      'is_interviewer': is_interviewer and is_assigned,
      'favorited': favorited(request.user.mcuser, applicant)
      }
  return render(request, 'feedback/applicant.html', context)
Exemple #14
0
 def handle(self, *args, **options):
     event_name = options['event_name'][0]
     try:
         event = Event.objects.get(name=event_name)
     except Event.DoesNotExist:
         self.stdout.write('event does not exist')
         return
     if options['flush']:
         self.stdout.write('Removing all applicants in event %s...' %
                           event_name)
         self.stdout.write('%s users in the database' %
                           Applicant.objects.all().count())
         applicants = Applicant.objects.filter(event__name=event_name)
         self.stdout.write('%s users in the event %s' %
                           (applicants.count(), event_name))
         applicants.delete()
         self.stdout.write('%s users left in the database' %
                           Applicant.objects.all().count())
     if options['applicants']:
         if not os.path.exists('tmp'):
             os.makedirs('tmp')
         with open(options['applicants'], 'rU') as csvfile:
             applicants = list(csv.reader(csvfile))
             event = Event.objects.get_or_create(
                 name=options['event_name'][0])[0]
             for applicant in applicants[1:]:
                 self.add_applicant(
                     {
                         key: value
                         for (key, value) in zip(applicants[0], applicant)
                     }, event_name)
     if options['testing']:
         for _ in xrange(10):
             applicant = Applicant()
             applicant.first_name = randomString(10)
             applicant.last_name = randomString(10)
             applicant.high_school = '%s High School ' % randomString(8)
             applicant.hometown = randomString(7)
             applicant.hometown_state = random.choice(US_STATES)[0]
             applicant.gender = random.choice(['Mr.', 'Ms.'])
             applicant.event = event
             applicant.save()
             self.stdout.write('Created user %s' %
                               applicant.get_full_name())
     if options['feedback']:
         scholars = McUser.objects.all()
         applicants = Applicant.objects.all()
         for scholar in scholars:
             chance = random.random() / 3
             for applicant in applicants:
                 if random.random() < chance:
                     try:
                         f = Feedback.objects.get(scholar=scholar,
                                                  applicant=applicant)
                     except Feedback.DoesNotExist:
                         f = Feedback(scholar=scholar, applicant=applicant)
                     f.rating = random.choice([0, 1, 2, 3, 4, 5])
                     f.interest = random.choice([0, 1, 3, 4, 5])
                     f.comments = randomWords(random.randint(4, 15))
                     f.save()
     if options['pics']:
         for f in os.listdir('tmp'):
             f_split = f.split('.')[0].split(',')
             scholar_name = normalize_name('%s%s' %
                                           (f_split[1], f_split[0]))
             try:
                 app = Applicant.objects.get(norm_name=scholar_name,
                                             event__name=event_name)
             except Applicant.DoesNotExist:
                 self.stdout.write('Could not find user %s for pic %s' %
                                   (scholar_name, f))
                 continue
             extension = f.split('.')[-1]
             file_name = '%s,%s-fw.%s' % (app.last_name, app.first_name,
                                          extension)
             with open('tmp/%s' % f, 'rb') as img_file:
                 app.actual_pic.save(file_name, File(img_file), save=True)
             app.save()
             self.stdout.write('Saved pic %s for %s' % (f, scholar_name))
 def handle(self, *args, **options):
   event_name = options['event_name'][0]
   try:
     event = Event.objects.get(name=event_name) 
   except Event.DoesNotExist:
     self.stdout.write('event does not exist')
     return
   if options['flush']:
     self.stdout.write('Removing all applicants in event %s...' % event_name)
     self.stdout.write('%s users in the database' % Applicant.objects.all().count())
     applicants = Applicant.objects.filter(event__name=event_name)
     self.stdout.write('%s users in the event %s' % (applicants.count(), event_name))
     applicants.delete()
     self.stdout.write('%s users left in the database' % Applicant.objects.all().count())
   if options['applicants']:
     if not os.path.exists('tmp'):
       os.makedirs('tmp')
     with open(options['applicants'], 'rU') as csvfile:
       applicants = list(csv.reader(csvfile))
       event = Event.objects.get_or_create(name=options['event_name'][0])[0]
       for applicant in applicants[1:]:
         self.add_applicant({key: value for (key, value) in zip(applicants[0], applicant)}, event_name)
   if options['testing']:
     for _ in xrange(10):
       applicant = Applicant()
       applicant.first_name = randomString(10)
       applicant.last_name = randomString(10)
       applicant.high_school = '%s High School ' % randomString(8)
       applicant.hometown = randomString(7)
       applicant.hometown_state = random.choice(US_STATES)[0]
       applicant.gender = random.choice(['Mr.', 'Ms.'])
       applicant.event = event
       applicant.save()
       self.stdout.write('Created user %s' % applicant.get_full_name())
   if options['feedback']:
     scholars = McUser.objects.all()
     applicants = Applicant.objects.all()
     for scholar in scholars:
       chance = random.random() / 3
       for applicant in applicants:
         if random.random() < chance:
           try:
             f = Feedback.objects.get(scholar=scholar, applicant=applicant)
           except Feedback.DoesNotExist:
             f = Feedback(scholar=scholar, applicant=applicant)
           f.rating = random.choice([0, 1, 2, 3, 4, 5])
           f.interest = random.choice([0, 1, 3, 4, 5])
           f.comments = randomWords(random.randint(4, 15))
           f.save()
   if options['pics']:
     for f in os.listdir('tmp'):
       f_split = f.split('.')[0].split(',')
       scholar_name = normalize_name('%s%s' % (f_split[1], f_split[0]))
       try:
         app = Applicant.objects.get(norm_name=scholar_name, event__name=event_name)
       except Applicant.DoesNotExist:
         self.stdout.write('Could not find user %s for pic %s' % (scholar_name, f))
         continue
       extension = f.split('.')[-1]
       file_name = '%s,%s-fw.%s' % (app.last_name, app.first_name, extension)
       with open('tmp/%s' % f, 'rb') as img_file:
         app.actual_pic.save(file_name, File(img_file), save=True)
       app.save()
       self.stdout.write('Saved pic %s for %s' % (f, scholar_name))
 def save(self, *args, **kwargs):
   self.norm_name = normalize_name(self.get_full_name())
   super(Applicant, self).save(*args, **kwargs)