Esempio n. 1
0
    def compress(self, data_list):
        """
        Compress data from the hidden input fields.

        The input value is usually the result of the client-side DartDM lookup,
        however a user can hit 'submit' with a self-entered name, or change the
        autocompleted name. If this is the case we do another DartDm lookup to
        verify the name.

        `data_list` is of the form `[NAME_WITH_YEAR, NETID, NAME_WITH_AFFIL]`
        """
        logger.info('compress: %r' % data_list)
        if len(data_list) == 0:
            # Empty field
            return None

        if len(data_list) == 1 or not data_list[2] == data_list[0]:
            # User did not wait for the typeahead autocomplete,
            # or changed the autocompleted name after the lookup.
            # Try and lookup the given name.
            results = lookup.lookup_dartdm(data_list[0])
            if len(results) == 0:
                raise ValidationError('User not found')
            elif len(results) == 1:
                return results[0]  # Lookup results are already formatted
            else:
                raise ValidationError("Ambiguous name %r" % data_list[0])

        return {lookup.NAME: data_list[0], lookup.NETID: data_list[1]}
Esempio n. 2
0
    def compress(self, data_list):
        """
        Compress data from the hidden input fields.

        The input value is usually the result of the client-side DartDM lookup,
        however a user can hit 'submit' with a self-entered name, or change the
        autocompleted name. If this is the case we do another DartDm lookup to
        verify the name.

        `data_list` is of the form `[NAME_WITH_YEAR, NETID, NAME_WITH_AFFIL]`
        """
        logger.info('compress: %r' % data_list)
        if len(data_list) == 0:
            # Empty field
            return None

        if len(data_list) == 1 or not data_list[2] == data_list[0]:
            # User did not wait for the typeahead autocomplete,
            # or changed the autocompleted name after the lookup.
            # Try and lookup the given name.
            results = lookup.lookup_dartdm(data_list[0])
            if len(results) == 0:
                raise ValidationError('User not found')
            elif len(results) == 1:
                return results[0]  # Lookup results are already formatted
            else:
                raise ValidationError("Ambiguous name %r" % data_list[0])

        return {lookup.NAME: data_list[0], lookup.NETID: data_list[1]}
Esempio n. 3
0
def get_newest_name(apps, schema_editor):
    User = apps.get_model('users', 'DartmouthUser')
    for localUser in User.objects.all():

        if is_staff_or_current_student(localUser):
            print('Retrieving user with netid', localUser.netid, 'and name', localUser.name)
            dartResponse = lookup_dartdm(localUser.netid)
            dartdmUser = dartResponse[0] if len(dartResponse) != 0 else None

            if dartdmUser is None:
                print('Error, netid', localUser.netid, 'not found')
            elif localUser.name != dartdmUser['name']:
                print('Remote name ', dartdmUser['name'], ' did not match localUser name', localUser.name)
                print('Setting to updated name')
                localUser.name = dartdmUser['name']
                localUser.save()
Esempio n. 4
0
def dartdm_lookup_view(request):
    """
    Dartmouth Name Directory connector.

    The dartdm netid lookup doesn't allow cross-site requests,
    hence no AJAX. This view allows us to do DND lookups by acting as
    an endpoint for typeahead.
    """

    try:
        query = request.GET['term']
    except KeyError:
        results = []
    else:
        results = lookup_dartdm(query)
    # setting safe=False allows us to return the JSON array
    return JsonResponse(results, safe=False)
Esempio n. 5
0
 def test_query_with_comma(self):
     self.assertEqual([], lookup_dartdm('a,'))
Esempio n. 6
0
 def test_too_short_query(self):
     self.assertEqual([], lookup_dartdm('A'))
Esempio n. 7
0
 def test_query_with_comma(self):
     self.assertEqual([], lookup_dartdm('a,'))
Esempio n. 8
0
 def test_too_short_query(self):
     self.assertEqual([], lookup_dartdm('A'))