Beispiel #1
0
Datei: views.py Projekt: nvi0/dac
def admin_create_user(request):
    """
    Handle ajax post.
    """
    if is_student(request.user.username):
        return
    if not is_admin(request.user.username):
        return
    if request.method != 'POST':
        return
    
    new_username = request.POST['username']
    if new_username == '':
        return
    
    position = request.POST.get('position','')
    if position not in ('f','s'):
        return

    print(request.POST)
    
    if DacUser.objects.filter(user__username=new_username):
        return HttpResponse(json.dumps({'success':False, 'reason':'existed'}), content_type="application/json")
    
    user_info = ldap_getter.get_user_info(new_username)
    if user_info == None:
        return HttpResponse(json.dumps({'success':False, 'reason':'no_ldap_record'}), content_type="application/json")

    handle_new_user(new_username, user_info, request.POST['position'])
    return HttpResponse(json.dumps({'success':True}), content_type="application/json")
    
Beispiel #2
0
 def populate(self, new_username, user_info=None, position=None):
     """
     Populate new user. Default position: Student
     """
     if user_info == None:
         user_info = get_user_info(new_username)
     if not user_info:
         return False
             
     users = User.objects.filter(username=new_username)
     self.user = User.objects.create_user(new_username, user_info['mail'], 'anything') if len(users) == 0 else users[0]
     self.user.first_name = user_info['first_name']
     self.user.last_name = user_info['last_name']
     self.user.save()
     self.position = position if position != None else 'u'
     self.save()
     return True