Ejemplo n.º 1
0
 def bitsByTeacher(self, user):
     return {
         'interview':
         UserBit.objects.filter(UserBit.not_expired(),
                                verb=self.reg_verb,
                                qsc__parent=self.qscs['interview'],
                                user=user),
         'training':
         UserBit.objects.filter(UserBit.not_expired(),
                                verb=self.reg_verb,
                                qsc__parent=self.qscs['training'],
                                user=user),
     }
Ejemplo n.º 2
0
    def teachers(self, QObject=False):
        """Returns lists of teachers who've completed the teacher quiz."""

        qo = Q(
            userbit__verb=self.controller.reg_verb,
            userbit__qsc=self.program_anchor_cached(),
        ) & UserBit.not_expired(prefix='userbit__')
        if QObject is True:
            return {
                'quiz_done': self.getQForUser(qo),
            }
        else:
            return {
                'quiz_done': ESPUser.objects.filter(qo).distinct(),
            }
Ejemplo n.º 3
0
 def _bitsByUser(self, user):
     """Get relevant UserBits (the "completed quiz" ones) for a user."""
     return UserBit.objects.filter(
         Q(user=user, qsc=self.program_anchor, verb=self.reg_verb)
         & UserBit.not_expired())
 def isCompleted(self):
     return bool(
         UserBit.objects.filter(
             Q(user=get_current_request().user,
               qsc=self.program.anchor,
               verb=self.flags_verb) & UserBit.not_expired()))
Ejemplo n.º 5
0
 def event_signup(self, request, tl, one, two, module, extra, prog):
     if request.method == 'POST':
         form = TeacherEventSignupForm(self, request.POST)
         if form.is_valid():
             data = form.cleaned_data
             # Remove old bits
             [
                 ub.expire() for ub in UserBit.objects.filter(
                     Q(qsc__parent=self.qscs['interview'])
                     | Q(qsc__parent=self.qscs['training']),
                     UserBit.not_expired(),
                     user=request.user,
                     verb=self.reg_verb)
             ]
             # Register for interview
             if data['interview']:
                 ub, created = UserBit.objects.get_or_create(
                     user=request.user,
                     qsc=data['interview'],
                     verb=self.reg_verb,
                     defaults={'recursive': False})
                 # Send the directors an e-mail
                 if self.program.director_email and (
                         created or ub.enddate < datetime.now()):
                     event_names = ' '.join([
                         x.description
                         for x in data['interview'].event_set.all()
                     ])
                     send_mail('['+self.program.niceName()+'] Teacher Interview for ' + request.user.first_name + ' ' + request.user.last_name + ': ' + event_names, \
                           """Teacher Interview Registration Notification\n--------------------------------- \n\nTeacher: %s %s\n\nTime: %s\n\n""" % \
                           (request.user.first_name, request.user.last_name, event_names) , \
                           ('%s <%s>' % (request.user.first_name + ' ' + request.user.last_name, request.user.email,)), \
                           [self.program.director_email], True)
                 if not created:
                     ub.enddate = datetime(
                         9999, 1, 1
                     )  # Approximately infinity; see default value of UserBit.enddate
                     ub.save()
             # Register for training
             if data['training']:
                 ub, created = UserBit.objects.get_or_create(
                     user=request.user,
                     qsc=data['training'],
                     verb=self.reg_verb,
                     defaults={'recursive': False})
                 if not created:
                     ub.enddate = datetime(9999, 1,
                                           1)  # Approximately infinity
                     ub.save()
             return self.goToCore(tl)
     else:
         data = {}
         bits = self.bitsByTeacher(request.user)
         if bits['interview'].count() > 0:
             data['interview'] = bits['interview'][0].qsc.id
         if bits['training'].count() > 0:
             data['training'] = bits['training'][0].qsc.id
         form = TeacherEventSignupForm(self, initial=data)
     return render_to_response(self.baseDir() + 'event_signup.html',
                               request, (prog, tl), {
                                   'prog': prog,
                                   'form': form
                               })
Ejemplo n.º 6
0
 def bitsBySlot(self, anchor):
     return UserBit.objects.filter(UserBit.not_expired(),
                                   verb=self.reg_verb,
                                   qsc=anchor)