Repository: e-valuation/EvaP

Issue:
"manage.py create_user" crashes (or: can this script be removed?)
the installation instructions told me to `create some users` by running `python manage.py create_user -p`, which i did. i got this:

```
vagrant@ubuntu-server-12042-x64-vbox4210:/vagrant$ python manage.py create_user -p
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 272, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 75, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 40, in import_module
    __import__(name)
  File "/vagrant/evap/evaluation/management/commands/create_user.py", line 7, in <module>
    from django.contrib.auth.management.commands.createsuperuser import RE_VALID_USERNAME, EMAIL_RE
ImportError: cannot import name RE_VALID_USERNAME
```

these strings got removed in https://github.com/django/django/commit/70a0de37d132e5f1514fb939875f69649f103124, but i didn't find any notes in the breaking changes of 1.5 and 1.6.

actually i wonder whether this script can be removed altogether. does someone know what it's use cases were?



Discussion:
I am in favor of keeping it. When working, it gives us the freedom to create users from the commandline, not only from the GUI.
For the stacktrace, I think we should see whats broken and fix it.


Resolving patch:
diff --git a/evap/evaluation/management/commands/create_user.py b/evap/evaluation/management/commands/create_user.py
--- a/evap/evaluation/management/commands/create_user.py
+++ b/evap/evaluation/management/commands/create_user.py
@@ -4,20 +4,18 @@
 
 from django.core import exceptions
 from django.core.management.base import BaseCommand
-from django.contrib.auth.management.commands.createsuperuser import RE_VALID_USERNAME, EMAIL_RE
 from django.utils.translation import ugettext as _
 
-from evap.evaluation.models import User, UserProfile
+from evap.evaluation.models import UserProfile
+from django.contrib.auth.models import User
 
 
 def is_valid_email(value):
-    if not EMAIL_RE.search(value):
-        raise exceptions.ValidationError(_('Enter a valid email address.\n'))
+    User._meta.get_field('email').clean(value, None)
 
 
 def is_valid_username(username):
-    if not RE_VALID_USERNAME.match(username):
-        raise exceptions.ValidationError(_("Error: That username is invalid. Use only letters, digits and underscores.\n"))
+    User._meta.get_field('username').clean(username, None)
 
     try:
         User.objects.get(username__iexact=username)
@@ -38,7 +36,7 @@ def read_value(question, validator_func):
         try:
             validator_func(value)
         except exceptions.ValidationError, e:
-            sys.stderr.write(str(e.messages[0]))
+            sys.stderr.write(str(e.messages[0]) + '\n')
             continue
         else:
             return value


Test patch: