コード例 #1
0
 def handle(self, *args, **options):
     for user in User.objects.all():
         realname = u"%s %s" % (user.first_name.strip(), user.last_name.strip())
         realname = realname.strip()
         realname = realname[:75]
         if realname and user.username != realname:
             realname = generate_unique_username(realname, 75)
             if user.username != realname:
                 print "%s -> %s" % (user.username, realname)
                 user.username = realname
                 user.save()
コード例 #2
0
    def handle(self, *args, **options):
        users = User.objects.filter(username='')
        if not args:
            print "Args is required as target mail"
            return None
        else:
            mails = args

        if len(users) == 1:
            user = users[0]

            msg = ("""Forum Link: %(forum_link)s\r\n"""
                   """User with empty username has been detected.\r\n"""
                   """email: %(email)s\r\n"""
                   """id: %(id)s\r\n"""
                   """firt_name: %(first_name)s\r\n"""
                   """last_name: %(last_name)s\r\n""" % dict(email=user.email,
                                                           id=user.id,
                                                           first_name=user.first_name,
                                                           last_name=user.last_name,
                                                           forum_link=settings.FULL_ASKBOT_URL
                                                      )
                   )

            if hasattr(settings, "DEFAULT_FROM_EMAIL") and settings.DEFAULT_FROM_EMAIL:
                from_email = settings.DEFAULT_FROM_EMAIL
            else:
                from_email = "*****@*****.**"


            send_mail("""Username empty detected in a askbot forum""",
                      msg, from_email, mails)


            candidate = u"%s %s" % (user.first_name.strip(), user.last_name.strip())
            candidate = candidate.strip()
            candidate = candidate[:75]
            if candidate and user.username != candidate:
                candidate = generate_unique_username(candidate, 75)
                if user.username != candidate:
                    print "%s -> %s" % (user.username, candidate)
                    user.username = candidate
                    user.save()
コード例 #3
0
ファイル: models.py プロジェクト: OpenMOOC/askbot-openmooc
def change_username(user, candidate):
    if User.objects.filter(username=candidate).count() > 0:
        candidate = generate_unique_username(candidate, 75)
    user.username = candidate