From a2e076ee09f9b6ebd4a500600a1cf49bc8cc374a Mon Sep 17 00:00:00 2001 From: melwil Date: Wed, 15 Jan 2014 21:02:56 +0100 Subject: [PATCH 1/3] Some progress. --- apps/authentication/models.py | 3 +++ apps/authentication/templatetags/gravatar_url_resolver.py | 8 +------- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/apps/authentication/models.py b/apps/authentication/models.py index cb4ded701..165fab99f 100644 --- a/apps/authentication/models.py +++ b/apps/authentication/models.py @@ -149,6 +149,9 @@ def save(self, *args, **kwargs): elif primary_email.email != self.email: self.primary = False self.email = self.email.lower() + if self.primary: + self.user.email = self.email + self.user.save() super(Email, self).save(*args, **kwargs) def __unicode__(self): diff --git a/apps/authentication/templatetags/gravatar_url_resolver.py b/apps/authentication/templatetags/gravatar_url_resolver.py index ff86e6935..6443be2f2 100644 --- a/apps/authentication/templatetags/gravatar_url_resolver.py +++ b/apps/authentication/templatetags/gravatar_url_resolver.py @@ -6,17 +6,11 @@ @register.assignment_tag(takes_context=True) def gravatar_url(context, user, size): - email = user.get_email() - if email: - email = email.email - else: - email = "empty" - prefix = "https://" if context['request'].is_secure() else "http://" default = "%s%s%s_%s.png" % (prefix, context['request'].META['HTTP_HOST'], settings.DEFAULT_PROFILE_PICTURE_PREFIX, user.gender) - gravatar_url = "https://www.gravatar.com/avatar/" + hashlib.md5(email).hexdigest() + "?" + gravatar_url = "https://www.gravatar.com/avatar/" + hashlib.md5(user.email).hexdigest() + "?" gravatar_url += urllib.urlencode({'d': default, 's':str(size)}) return gravatar_url From 3834127f54fa5fc466755a30891e11abfb06750a Mon Sep 17 00:00:00 2001 From: melwil Date: Wed, 15 Jan 2014 21:05:45 +0100 Subject: [PATCH 2/3] Fixing primary mails for existing users. --- .../migrations/0017_set_primary_emails.py | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 apps/authentication/migrations/0017_set_primary_emails.py diff --git a/apps/authentication/migrations/0017_set_primary_emails.py b/apps/authentication/migrations/0017_set_primary_emails.py new file mode 100644 index 000000000..d67f00185 --- /dev/null +++ b/apps/authentication/migrations/0017_set_primary_emails.py @@ -0,0 +1,98 @@ +# -*- coding: utf-8 -*- +import datetime +from south.db import db +from south.v2 import DataMigration +from django.db import models + +class Migration(DataMigration): + + def forwards(self, orm): + emails = orm.Email.objects.all() + + for email in emails: + email.save() + + def backwards(self, orm): + raise RuntimeError("Cannot reverse this migration.") + + 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': '30', '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', [], {'to': u"orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'image': ('django.db.models.fields.files.ImageField', [], {'max_length': '200', 'null': 'True', 'blank': '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(2013, 11, 22, 0, 0)'}), + 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), + '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.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'] + symmetrical = True From 2062db2e0109f096260b956af3611bd0cf052c91 Mon Sep 17 00:00:00 2001 From: melwil Date: Thu, 23 Jan 2014 21:38:12 +0100 Subject: [PATCH 3/3] Fixed references to user.get_email() that should be user.email --- apps/feedback/mommy.py | 2 +- apps/feedback/tests.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/feedback/mommy.py b/apps/feedback/mommy.py index 16531cac8..40b845a4b 100644 --- a/apps/feedback/mommy.py +++ b/apps/feedback/mommy.py @@ -132,7 +132,7 @@ def get_users(feedback): @staticmethod def get_user_mails(not_responded): - return [str(user.get_email()) for user in not_responded] + return [user.email for user in not_responded] @staticmethod def get_link(feedback): diff --git a/apps/feedback/tests.py b/apps/feedback/tests.py index 66af26192..4c995962b 100644 --- a/apps/feedback/tests.py +++ b/apps/feedback/tests.py @@ -45,7 +45,7 @@ def setUp(self): def test_attendees(self): feedback_relation = FeedbackRelation.objects.get(pk=1) message = FeedbackMail.generate_message(feedback_relation) - user_mails = [str(user.get_email()) for user in User.objects.all()] + user_mails = [user.email for user in User.objects.all()] self.assertEqual(set(message.attended_mails), set(user_mails)) @@ -53,7 +53,7 @@ def test_attendees(self): feedback_relation.answered = [user1] message = FeedbackMail.generate_message(feedback_relation) - user_mails = [str(user.get_email()) for user in [User.objects.get(pk=2)]] + user_mails = [user.email for user in [User.objects.get(pk=2)]] self.assertEqual(set(message.attended_mails), set(user_mails)) feedback_relation = FeedbackRelation.objects.get(pk=2)