Exemple #1
0
    def grouptextpanel(self, request, tl, one, two, module, extra, prog):
        if not self.is_configured():
            return render_to_response(self.baseDir() + 'not_configured.html',
                                      request, {})

        usc = UserSearchController()
        context = {}
        context['program'] = prog

        if request.method == "POST":
            data = {}
            for key in request.POST:
                data[key] = request.POST[key]
            filterObj = UserSearchController().filter_from_postdata(prog, data)

            context['filterid'] = filterObj.id
            context['num_users'] = ESPUser.objects.filter(
                filterObj.get_Q()).distinct().count()
            context['est_time'] = float(context['num_users']) * 1.0 / len(
                settings.TWILIO_ACCOUNT_NUMBERS)
            return render_to_response(self.baseDir() + 'options.html', request,
                                      context)

        context.update(
            usc.prepare_context(prog,
                                target_path='/manage/%s/grouptextpanel' %
                                prog.url))
        return render_to_response(self.baseDir() + 'search.html', request,
                                  context)
Exemple #2
0
    def selectList(self, request, tl, one, two, module, extra, prog):
        """ Select a group of users and generate a list of information
            about them using the generateList view above. """
        usc = UserSearchController()

        context = {}
        context['program'] = prog

        #   If list information was submitted, generate a query filter and
        #   show options for generating a user list
        if request.method == 'POST':
            #   Turn multi-valued QueryDict into standard dictionary
            data = {}
            for key in request.POST:
                data[key] = request.POST[key]
            filterObj = usc.filter_from_postdata(prog, data)

            #   Display list generation options
            form = ListGenForm()
            context.update({
                'form': form,
                'filterid': filterObj.id,
                'num_users': ESPUser.objects.filter(filterObj.get_Q()).distinct().count()
            })
            return render_to_response(self.baseDir()+'options.html', request, context)

        #   Otherwise, render a page that shows the list selection options
        context.update(usc.prepare_context(prog, target_path='/manage/%s/selectList' % prog.url))
        return render_to_response(self.baseDir()+'search.html', request, context)
Exemple #3
0
    def commpanel(self, request, tl, one, two, module, extra, prog):

        usc = UserSearchController()

        context = {}
        context['program'] = prog

        #   If list information was submitted, continue to prepare a message
        if request.method == 'POST':
            #   Turn multi-valued QueryDict into standard dictionary
            data = {}
            for key in request.POST:
                data[key] = request.POST[key]

            ##  Handle normal list selecting submissions
            if ('base_list' in data
                    and 'recipient_type' in data) or ('combo_base_list'
                                                      in data):

                filterObj = usc.filter_from_postdata(prog, data)

                if data['use_checklist'] == '1':
                    (response, unused) = get_user_checklist(
                        request,
                        ESPUser.objects.filter(filterObj.get_Q()).distinct(),
                        filterObj.id,
                        '/manage/%s/commpanel_old' % prog.getUrlBase())
                    return response

                context['filterid'] = filterObj.id
                context['listcount'] = ESPUser.objects.filter(
                    filterObj.get_Q()).distinct().count()
                return render_to_response(self.baseDir() + 'step2.html',
                                          request, (prog, tl), context)

            ##  Prepare a message starting from an earlier request
            elif 'msgreq_id' in data:
                msgreq = MessageRequest.objects.get(id=data['msgreq_id'])
                context['filterid'] = msgreq.recipients.id
                context['listcount'] = msgreq.recipients.getList(
                    ESPUser).count()
                context['from'] = msgreq.sender
                context['subject'] = msgreq.subject
                context['replyto'] = msgreq.special_headers_dict.get(
                    'Reply-To', '')
                context['body'] = msgreq.msgtext
                return render_to_response(self.baseDir() + 'step2.html',
                                          request, (prog, tl), context)

            else:
                raise ESPError(
                    True
                ), 'What do I do without knowing what kind of users to look for?'

        #   Otherwise, render a page that shows the list selection options
        context.update(usc.prepare_context(prog))

        return render_to_response(self.baseDir() + 'commpanel_new.html',
                                  request, (prog, tl), context)
Exemple #4
0
def search_for_user(request, user_type='Any', extra='', returnList = False):
    """ Interface to search for a user. If you need a user, just use this.
        Returns (user or response, user returned?) """
    
    users = None
    error = False

    usc = UserSearchController()
    if isinstance(user_type, basestring):
        user_query = usc.query_from_criteria(user_type, request.GET)
        QSUsers = ESPUser.objects.filter(user_query).distinct()
    elif isinstance(user_type, QuerySet):
        QSUsers = usc.filter_from_criteria(user_type, request.GET)
    else:
        raise ESPError(True), 'Invalid user_type: %s' % type(user_type)
    
    #   We need to ask for more user input if no filtering options were selected
    if not usc.updated:
        users = None
    else:
        users = [ ESPUser(user) for user in QSUsers ]
    
    if users is not None and len(users) == 0:
        error = True
        users = None

    if users is None:
        return (render_to_response('users/usersearch.html', request, None, {'error': error, 'extra':extra,  'list': returnList}), False)
        
    if len(users) == 1:
        return (users[0], True)
        
    else:

        users.sort()

        if (request.GET.has_key('listokay') and request.GET['listokay'] == 'true') or \
           (request.GET.has_key('submitform') and request.GET['submitform'] == 'Use Filtered List'):
            Q_Filter = None
            if not hasattr(Q_include, 'old'):
                Q_Filter = Q_include
                if not hasattr(Q_exclude, 'old'):
                    Q_Filter &= ~Q_exclude
            else:
                if not hasattr(Q_exclude, 'old'):
                    Q_Filter = ~Q_exclude
            
            return (Q_Filter, True)
        
        context = {'users': users, 'extra':str(extra), 'list': returnList}

        return (render_to_response('users/userpick.html', request, None, context), False)

    print 'Ran into some kind of problem. %d users' % len(users)
Exemple #5
0
def search_for_user(request, user_type='Any', extra='', returnList=False):
    """ Interface to search for a user. If you need a user, just use this.
        Returns (user or response, user returned?) """

    users = None
    error = False

    usc = UserSearchController()
    if isinstance(user_type, basestring):
        user_query = usc.query_from_criteria(user_type, request.GET)
        QSUsers = ESPUser.objects.filter(user_query).distinct()
    elif isinstance(user_type, QuerySet):
        QSUsers = usc.filter_from_criteria(user_type, request.GET)
    else:
        raise ESPError('Invalid user_type: %s' % type(user_type), log=True)

    #   We need to ask for more user input if no filtering options were selected
    if not usc.updated:
        users = None
    else:
        users = [user for user in QSUsers]

    if users is not None and len(users) == 0:
        error = True
        users = None

    if users is None:
        return (render_to_response('users/usersearch.html', request, {
            'error': error,
            'extra': extra,
            'list': returnList
        }), False)

    if len(users) == 1:
        return (users[0], True)

    else:

        users.sort()

        if request.GET.get('listokay') == 'true' or \
           request.GET.get('submitform') == 'Use Filtered List':
            Q_Filter = Q(id__in=QSUsers.values_list('id', flat=True))
            return (Q_Filter, True)

        context = {'users': users, 'extra': str(extra), 'list': returnList}

        return (render_to_response('users/userpick.html', request,
                                   context), False)
Exemple #6
0
    def paiditems(self, request, tl, one, two, module, extra, prog):

        #   Get a user
        filterObj, found = UserSearchController().create_filter(
            request, self.program)
        if not found:
            return filterObj
        user = filterObj.getList(ESPUser).distinct()[0]

        #   Get the optional purchases for that user
        iac = IndividualAccountingController(prog, user)
        context = {}
        context['student'] = user
        context['requireditems'] = iac.get_transfers(required_only=True)
        context['reserveditems'] = iac.get_transfers(optional_only=True)
        context['amount_requested'] = iac.amount_requested()
        context['amount_finaid'] = iac.amount_finaid()
        context['amount_due'] = iac.amount_due()

        return render_to_response(self.baseDir() + 'paiditems.html', request,
                                  context)
class TestUserSearchController(TestCase):
    controller = UserSearchController()
    program = Program.objects.get(id=88)  #Splash

    def _get_combination_post_data(self, list_a, list_b):
        return {
            'username': '',
            'checkbox_and_confirmed': '',
            'first_name': '',
            'last_name': '',
            'school': '',
            'use_checklist': '0',
            'gradyear_max': '',
            'userid': '',
            'zipcode': '',
            'combo_base_list': '%s:%s' % (list_a, list_b),
            'email': '',
            'states': '',
            'zipdistance': '',
            'grade_min': '',
            'gradyear_min': '',
            'checkbox_and_attended': '',
            'csrfmiddlewaretoken': '3kn9b0NY3t6WNbDRqA7zq7dy6FVOF8iD',
            'grade_max': '',
            'student_sendto_self': '1',
            'zipdistance_exclude': '',
        }

    def test_student_confirmed(self):
        post_data = self._get_combination_post_data('Student', 'confirmed')
        qobject = self.controller.filter_from_postdata(
            self.program, post_data).getList(ESPUser)

        self.assertGreater(qobject.count(), 0)

    def test_teacher_classroom_tables(self):
        post_data = self._get_combination_post_data('Teacher',
                                                    'teacher_res_150_8')
        qobject = self.controller.filter_from_postdata(
            self.program, post_data).getList(ESPUser)
        self.assertGreater(qobject.count(), 0)

    def test_teacher_classroom_tables_query_from_post(self):
        post_data = {
            u'username': u'',
            u'zipdistance_exclude': u'',
            u'first_name': u'',
            u'last_name': u'',
            u'use_checklist': u'0',
            u'gradyear_max': u'',
            u'userid': u'',
            u'school': u'',
            u'combo_base_list': u'Teacher:teacher_res_150_8',
            u'zipcode': u'',
            u'states': u'',
            u'student_sendto_self': u'1',
            u'checkbox_and_teacher_res_152_0': u'',
            u'grade_min': u'',
            u'gradyear_min': u'',
            u'zipdistance': u'',
            u'csrfmiddlewaretoken': u'GKk9biBZE2muppi7jcv2OnqQyIehiCuw',
            u'grade_max': u'',
            u'email': u''
        }

        query = self.controller.query_from_postdata(self.program, post_data)
        # TODO(benkraft): what is going on here?  Should these tests be getting
        # run?
        logger.info(query)  # need to inspect why this is failing
        assert False
        #self.assertGreater(qobject.count(), 0)

    def test_teacher_interview(self):
        post_data = self._get_combination_post_data('Teacher', 'interview')
        qobject = self.controller.filter_from_postdata(
            self.program, post_data).getList(ESPUser)
        self.assertGreater(qobject.count(), 0)