Repository: dotkom/onlineweb4

Issue:
RegisterForm and OnlineUser model uses different maxlength for address
RegisterForm has a maxlength of 50 and OnlineUser 30. This causes problems since the form accepts >30 length addresses, but the database does not. 

I think we should consider increasing the max length too, since apparantly someone just tried to register with a >30 length address.



Discussion:
Yeah, just increase the OnlineUser's field for it.

There seems to be a few errors of this kind coming to the surface now. What is the thought of having should low fields anyways? Especially on the model which translate directly to the database. There should be extra room for flexibility on this level imo. There are next to no performance gains using PostgreSQL by limiting chars this way.


Resolving patch:
diff --git a/apps/authentication/forms.py b/apps/authentication/forms.py
--- a/apps/authentication/forms.py
+++ b/apps/authentication/forms.py
@@ -46,7 +46,7 @@ class RegisterForm(forms.Form):
     email = forms.EmailField(label=_("Epost"), max_length=50)
     password = forms.CharField(widget=forms.PasswordInput(render_value=False), label=_("Passord"))
     repeat_password = forms.CharField(widget=forms.PasswordInput(render_value=False), label=_("Gjenta passord"))
-    address = forms.CharField(label=_("Adresse"), max_length=50, required=False)
+    address = forms.CharField(label=_("Adresse"), max_length=100, required=False)
     zip_code = forms.CharField(label=_("Postnummer"), max_length=4, required=False)
     phone = forms.CharField(label=_("Telefon"), max_length=20, required=False)
     
diff --git a/apps/authentication/migrations/0022_auto__chg_field_onlineuser_address.py b/apps/authentication/migrations/0022_auto__chg_field_onlineuser_address.py
new file mode 100644
--- /dev/null
+++ b/apps/authentication/migrations/0022_auto__chg_field_onlineuser_address.py
@@ -0,0 +1,106 @@
+# -*- coding: utf-8 -*-
+from south.utils import datetime_utils as datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+
+        # Changing field 'OnlineUser.address'
+        db.alter_column(u'authentication_onlineuser', 'address', self.gf('django.db.models.fields.CharField')(max_length=100, null=True))
+
+    def backwards(self, orm):
+
+        # Changing field 'OnlineUser.address'
+        db.alter_column(u'authentication_onlineuser', 'address', self.gf('django.db.models.fields.CharField')(max_length=30, null=True))
+
+    models = {
+        u'auth.group': {
+            'Meta': {'object_name': 'Group'},
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+            'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+        },
+        u'auth.permission': {
+            'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'},
+            'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+        },
+        u'authentication.allowedusername': {
+            'Meta': {'ordering': "(u'username',)", 'object_name': 'AllowedUsername'},
+            'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+            'expiration_date': ('django.db.models.fields.DateField', [], {}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'note': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'registered': ('django.db.models.fields.DateField', [], {}),
+            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '10'})
+        },
+        u'authentication.email': {
+            'Meta': {'object_name': 'Email'},
+            'email': ('django.db.models.fields.EmailField', [], {'unique': 'True', 'max_length': '75'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'primary': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'email_user'", 'to': u"orm['authentication.OnlineUser']"}),
+            'verified': ('django.db.models.fields.BooleanField', [], {'default': 'False'})
+        },
+        u'authentication.onlineuser': {
+            'Meta': {'ordering': "['first_name', 'last_name']", 'object_name': 'OnlineUser'},
+            'address': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
+            'allergies': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+            'compiled': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+            'field_of_study': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}),
+            'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'gender': ('django.db.models.fields.CharField', [], {'default': "'male'", 'max_length': '10'}),
+            'groups': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "u'user_set'", 'blank': 'True', 'to': u"orm['auth.Group']"}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'infomail': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'mark_rules': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'nickname': ('django.db.models.fields.CharField', [], {'max_length': '50', 'null': 'True', 'blank': 'True'}),
+            'ntnu_username': ('django.db.models.fields.CharField', [], {'max_length': '10', 'unique': 'True', 'null': 'True', 'blank': 'True'}),
+            'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+            'phone_number': ('django.db.models.fields.CharField', [], {'max_length': '20', 'null': 'True', 'blank': 'True'}),
+            'rfid': ('django.db.models.fields.CharField', [], {'max_length': '50', 'null': 'True', 'blank': 'True'}),
+            'started_date': ('django.db.models.fields.DateField', [], {'default': 'datetime.datetime(2014, 2, 3, 0, 0)'}),
+            'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "u'user_set'", 'blank': 'True', 'to': u"orm['auth.Permission']"}),
+            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}),
+            'website': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
+            'zip_code': ('django.db.models.fields.CharField', [], {'max_length': '4', 'null': 'True', 'blank': 'True'})
+        },
+        u'authentication.position': {
+            'Meta': {'ordering': "(u'user', u'period')", 'object_name': 'Position'},
+            'committee': ('django.db.models.fields.CharField', [], {'default': "'hs'", 'max_length': '10'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'period': ('django.db.models.fields.CharField', [], {'default': "'2013-2014'", 'max_length': '9'}),
+            'position': ('django.db.models.fields.CharField', [], {'default': "'medlem'", 'max_length': '10'}),
+            'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'positions'", 'to': u"orm['authentication.OnlineUser']"})
+        },
+        u'authentication.registertoken': {
+            'Meta': {'object_name': 'RegisterToken'},
+            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'email': ('django.db.models.fields.EmailField', [], {'max_length': '254'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'token': ('django.db.models.fields.CharField', [], {'max_length': '32'}),
+            'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'register_user'", 'to': u"orm['authentication.OnlineUser']"})
+        },
+        u'contenttypes.contenttype': {
+            'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+            'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+        }
+    }
+
+    complete_apps = ['authentication']
\ No newline at end of file
diff --git a/apps/authentication/models.py b/apps/authentication/models.py
--- a/apps/authentication/models.py
+++ b/apps/authentication/models.py
@@ -75,7 +75,7 @@ class OnlineUser(AbstractUser):
 
     # Address
     phone_number = models.CharField(_(u"telefonnummer"), max_length=20, blank=True, null=True)
-    address = models.CharField(_(u"adresse"), max_length=30, blank=True, null=True)
+    address = models.CharField(_(u"adresse"), max_length=100, blank=True, null=True)
     zip_code = models.CharField(_(u"postnummer"), max_length=4, blank=True, null=True)
 
     # Other


Test patch: