{"action":"created","issue":{"url":"https://api.github.com/repos/pennersr/django-allauth/issues/1496","repository_url":"https://api.github.com/repos/pennersr/django-allauth","labels_url":"https://api.github.com/repos/pennersr/django-allauth/issues/1496/labels{/name}","comments_url":"https://api.github.com/repos/pennersr/django-allauth/issues/1496/comments","events_url":"https://api.github.com/repos/pennersr/django-allauth/issues/1496/events","html_url":"https://github.com/pennersr/django-allauth/issues/1496","id":178027464,"number":1496,"title":"Limit the number of related email addresses","user":{"login":"arogachev","id":8326201,"avatar_url":"https://avatars.githubusercontent.com/u/8326201?v=3","gravatar_id":"","url":"https://api.github.com/users/arogachev","html_url":"https://github.com/arogachev","followers_url":"https://api.github.com/users/arogachev/followers","following_url":"https://api.github.com/users/arogachev/following{/other_user}","gists_url":"https://api.github.com/users/arogachev/gists{/gist_id}","starred_url":"https://api.github.com/users/arogachev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arogachev/subscriptions","organizations_url":"https://api.github.com/users/arogachev/orgs","repos_url":"https://api.github.com/users/arogachev/repos","events_url":"https://api.github.com/users/arogachev/events{/privacy}","received_events_url":"https://api.github.com/users/arogachev/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-09-20T10:50:35Z","updated_at":"2016-09-21T06:10:34Z","closed_at":null,"body":"Currently there is no limitation of related email addresses number (added with `/account/email/` link). I think it would be useful too have an option for setting max count of related emails.\r\n\r\nMy current workaround:\r\n\r\n**1)** Subclass `AddEmailForm ` and add according validation:\r\n\r\n```python\r\nfrom allauth.account.forms import AddEmailForm\r\nfrom django.core.exceptions import ValidationError\r\n\r\n\r\nclass MyAddEmailForm(AddEmailForm):\r\n    EMAILS_MAX_COUNT = 2\r\n\r\n    def clean_email(self):\r\n        email = super(MyAddEmailForm, self).clean_email()\r\n        if self.user.emailaddress_set.count() >= self.EMAILS_MAX_COUNT:\r\n            raise ValidationError('Max number of related emails - %d.' % self.EMAILS_MAX_COUNT)\r\n        return email\r\n```\r\n\r\n2) Subclass `EmailView` and change it to use our custom form:\r\n\r\n```python\r\nfrom allauth.account.views import EmailView\r\nfrom django.contrib.auth.decorators import login_required\r\nfrom .forms import MyAddEmailForm\r\n\r\nclass MyEmailView(EmailView):\r\n    form_class = MyAddEmailForm\r\n```\r\n\r\n**3)** Override `account_email` like that:\r\n\r\n```pyrhon\r\nurl(r\"^accounts/email/$\", views.email, name='account_email'),\r\n```\r\n\r\nand place it above allauth urls:\r\n\r\n```python\r\nurl(r'^accounts/', include('allauth.urls')),\r\n```\r\n\r\nRelated - #1109, but this is different because related emails functionality stays enabled, just new option added."},"comment":{"url":"https://api.github.com/repos/pennersr/django-allauth/issues/comments/248520661","html_url":"https://github.com/pennersr/django-allauth/issues/1496#issuecomment-248520661","issue_url":"https://api.github.com/repos/pennersr/django-allauth/issues/1496","id":248520661,"user":{"login":"pennersr","id":201022,"avatar_url":"https://avatars.githubusercontent.com/u/201022?v=3","gravatar_id":"","url":"https://api.github.com/users/pennersr","html_url":"https://github.com/pennersr","followers_url":"https://api.github.com/users/pennersr/followers","following_url":"https://api.github.com/users/pennersr/following{/other_user}","gists_url":"https://api.github.com/users/pennersr/gists{/gist_id}","starred_url":"https://api.github.com/users/pennersr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pennersr/subscriptions","organizations_url":"https://api.github.com/users/pennersr/orgs","repos_url":"https://api.github.com/users/pennersr/repos","events_url":"https://api.github.com/users/pennersr/events{/privacy}","received_events_url":"https://api.github.com/users/pennersr/received_events","type":"User","site_admin":false},"created_at":"2016-09-21T06:10:34Z","updated_at":"2016-09-21T06:10:34Z","body":"Instead of setting up an arbitratry hard limit, I think the strategy described here makes more sense:\r\n\r\nhttps://github.com/pennersr/django-allauth/issues/650#issuecomment-48118827\r\n\r\n"}}
{"actor":{"display_login":"pennersr"}}