We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Add support to update the user profile.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `settings/common.py`
Content:
```
1 """
2 Django settings for evalai project.
3 
4 Generated by 'django-admin startproject' using Django 1.10.2.
5 
6 For more information on this file, see
7 https://docs.djangoproject.com/en/1.10/topics/settings/
8 
9 For the full list of settings and their values, see
10 https://docs.djangoproject.com/en/1.10/ref/settings/
11 """
12 
13 import datetime
14 import os
15 import sys
16 
17 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
18 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
19 APPS_DIR = os.path.join(BASE_DIR, 'apps')
20 
21 sys.path.append(APPS_DIR)
22 
23 # Quick-start development settings - unsuitable for production
24 # See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/
25 
26 # SECURITY WARNING: keep the secret key used in production secret!
27 SECRET_KEY = os.environ.get('SECRET_KEY', 'random_secret_key')
28 
29 # SECURITY WARNING: don't run with debug turned on in production!
30 DEBUG = True
31 
32 ALLOWED_HOSTS = []
33 
34 
35 # Application definition
36 
37 DEFAULT_APPS = [
38     'django.contrib.admin',
39     'django.contrib.auth',
40     'django.contrib.contenttypes',
41     'django.contrib.sessions',
42     'django.contrib.messages',
43     'django.contrib.staticfiles',
44     'django.contrib.sites',
45 ]
46 
47 OUR_APPS = [
48     'accounts',
49     'analytics',
50     'base',
51     'challenges',
52     'hosts',
53     'jobs',
54     'participants',
55     'web',
56 ]
57 
58 THIRD_PARTY_APPS = [
59     'allauth',
60     'allauth.account',
61     'corsheaders',
62     'import_export',
63     'rest_auth',
64     'rest_auth.registration',
65     'rest_framework.authtoken',
66     'rest_framework',
67     'rest_framework_docs',
68     'rest_framework_expiring_authtoken',
69 ]
70 
71 INSTALLED_APPS = DEFAULT_APPS + OUR_APPS + THIRD_PARTY_APPS
72 
73 MIDDLEWARE = [
74     'corsheaders.middleware.CorsMiddleware',
75     'django.middleware.security.SecurityMiddleware',
76     'django.contrib.sessions.middleware.SessionMiddleware',
77     'django.middleware.common.CommonMiddleware',
78     'django.middleware.csrf.CsrfViewMiddleware',
79     'django.contrib.auth.middleware.AuthenticationMiddleware',
80     'django.contrib.messages.middleware.MessageMiddleware',
81     'django.middleware.clickjacking.XFrameOptionsMiddleware',
82 ]
83 
84 ROOT_URLCONF = 'evalai.urls'
85 
86 
87 TEMPLATES = [
88     {
89         'BACKEND': 'django.template.backends.django.DjangoTemplates',
90         'DIRS': [],
91         'APP_DIRS': True,
92         'OPTIONS': {
93             'context_processors': [
94                 'django.template.context_processors.debug',
95                 'django.template.context_processors.request',
96                 'django.contrib.auth.context_processors.auth',
97                 'django.contrib.messages.context_processors.messages',
98             ],
99         },
100     },
101 ]
102 
103 WSGI_APPLICATION = 'evalai.wsgi.application'
104 
105 
106 # Password validation
107 # https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators
108 
109 AUTH_PASSWORD_VALIDATORS = [
110     {
111         'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',  # noqa
112     },
113     {
114         'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',  # noqa
115     },
116     {
117         'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',  # noqa
118     },
119     {
120         'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',  # noqa
121     },
122 ]
123 
124 
125 # Internationalization
126 # https://docs.djangoproject.com/en/1.10/topics/i18n/
127 
128 LANGUAGE_CODE = 'en-us'
129 
130 TIME_ZONE = 'UTC'
131 
132 USE_I18N = True
133 
134 USE_L10N = True
135 
136 USE_TZ = True
137 
138 # Static files (CSS, JavaScript, Images)
139 # https://docs.djangoproject.com/en/1.10/howto/static-files/
140 
141 STATIC_URL = '/static/'
142 STATIC_ROOT = os.path.join(BASE_DIR, 'static')
143 MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
144 MEDIA_URL = "/media/"
145 
146 SITE_ID = 1
147 
148 REST_FRAMEWORK = {
149     'DEFAULT_PAGINATION_CLASS': (
150         'rest_framework.pagination.LimitOffsetPagination'),
151     'PAGE_SIZE': 10,
152     'DEFAULT_PERMISSION_CLASSES': [
153         'rest_framework.permissions.IsAuthenticatedOrReadOnly'
154     ],
155     'DEFAULT_AUTHENTICATION_CLASSES': [
156         'rest_framework_expiring_authtoken.authentication.ExpiringTokenAuthentication',
157     ],
158     'TEST_REQUEST_DEFAULT_FORMAT': 'json',
159     'DEFAULT_THROTTLE_CLASSES': (
160         'rest_framework.throttling.AnonRateThrottle',
161         'rest_framework.throttling.UserRateThrottle'
162     ),
163     'DEFAULT_THROTTLE_RATES': {
164         'anon': '100/minute',
165         'user': '100/minute'
166     },
167     'DEFAULT_RENDERER_CLASSES': (
168         'rest_framework.renderers.JSONRenderer',
169     )
170 }
171 
172 # ALLAUTH SETTINGS
173 ACCOUNT_EMAIL_REQUIRED = True
174 OLD_PASSWORD_FIELD_ENABLED = True
175 ACCOUNT_CONFIRM_EMAIL_ON_GET = True
176 ACCOUNT_EMAIL_CONFIRMATION_ANONYMOUS_REDIRECT_URL = '/api/auth/email-confirmed/'
177 ACCOUNT_EMAIL_CONFIRMATION_AUTHENTICATED_REDIRECT_URL = '/api/auth/email-confirmed/'
178 
179 AUTHENTICATION_BACKENDS = (
180     # Needed to login by username in Django admin, regardless of `allauth`
181     'django.contrib.auth.backends.ModelBackend',
182     # `allauth` specific authentication methods, such as login by e-mail
183     'allauth.account.auth_backends.AuthenticationBackend',
184 )
185 
186 # CORS Settings
187 CORS_ORIGIN_ALLOW_ALL = True
188 
189 # REST Framework Expiring Tokens Configuration
190 EXPIRING_TOKEN_LIFESPAN = datetime.timedelta(days=7)
191 
192 # Logging
193 LOGGING = {
194     'version': 1,
195     'disable_existing_loggers': False,
196     'root': {
197         'level': 'INFO',
198         'handlers': ['console'],
199     },
200     'filters': {
201         'require_debug_false': {
202             '()': 'django.utils.log.RequireDebugFalse',
203         },
204         'require_debug_true': {
205             '()': 'django.utils.log.RequireDebugTrue',
206         }
207     },
208     'formatters': {
209         'simple': {
210             'format': '[%(asctime)s] %(levelname)s %(message)s',
211             'datefmt': '%Y-%m-%d %H:%M:%S'
212         },
213         'verbose': {
214             'format': '[%(asctime)s] %(levelname)s %(module)s %(message)s',
215             'datefmt': '%Y-%m-%d %H:%M:%S'
216         }
217     },
218     'handlers': {
219         'console': {
220             'level': 'INFO',
221             'filters': ['require_debug_true'],
222             'class': 'logging.StreamHandler',
223             'formatter': 'simple'
224         },
225         'logfile': {
226             'level': 'DEBUG',
227             'class': 'logging.handlers.RotatingFileHandler',
228             'filename': "/tmp/logfile",
229             'maxBytes': 50000,
230             'backupCount': 10,
231             'formatter': 'verbose'
232         },
233         'mail_admins': {
234             'level': 'ERROR',
235             'class': 'django.utils.log.AdminEmailHandler',
236             'filters': ['require_debug_false'],
237         }
238     },
239     'loggers': {
240         'django': {
241             'handlers': ['console'],
242             'propagate': False,
243         },
244         'django.request': {
245             'handlers': ['mail_admins'],
246             'level': 'ERROR',
247             'propagate': False,
248         },
249         'django.security': {
250             'handlers': ['mail_admins'],
251             'level': 'ERROR',
252             'propagate': False,
253         },
254         'django.db.backends': {
255             'handlers': ['mail_admins'],
256             'level': 'ERROR',
257             'propagate': False,
258         }
259     }
260 }
261 
262 CACHES = {
263     'default': {
264         'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
265     }
266 }
267 
268 RABBITMQ_PARAMETERS = {
269     'HOST': os.environ.get("RABBITMQ_HOST", 'localhost'),
270     'EVALAI_EXCHANGE': {
271         'NAME': 'evalai_submissions',
272         'TYPE': 'topic',
273     },
274     'SUBMISSION_QUEUE': 'submission_task_queue',
275 }
276 
277 # To make usermame field read-only, customized serializer is defined.
278 REST_AUTH_SERIALIZERS = {
279     'USER_DETAILS_SERIALIZER': 'accounts.serializers.UserDetailsSerializer',
280 }
281
```

Path: `apps/accounts/serializers.py`
Content:
```
1 from django.contrib.auth import get_user_model
2 
3 from rest_framework import serializers
4 
5 
6 class UserDetailsSerializer(serializers.ModelSerializer):
7     """
8     Make username as a read_only field.
9     """
10     class Meta:
11         model = get_user_model()
12         fields = ('pk', 'email', 'username', 'first_name', 'last_name')
13         read_only_fields = ('email', 'username')
14
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/apps/accounts/serializers.py b/apps/accounts/serializers.py
--- a/apps/accounts/serializers.py
+++ b/apps/accounts/serializers.py
@@ -11,3 +11,26 @@
         model = get_user_model()
         fields = ('pk', 'email', 'username', 'first_name', 'last_name')
         read_only_fields = ('email', 'username')
+
+
+class ProfileSerializer(UserDetailsSerializer):
+    """
+    Serializer to update the user profile.
+    """
+
+    affiliation = serializers.CharField(source="profile.affiliation")
+
+    class Meta(UserDetailsSerializer.Meta):
+        fields = UserDetailsSerializer.Meta.fields + ('affiliation',)
+
+    def update(self, instance, validated_data):
+        profile_data = validated_data.pop('profile', {})
+        affiliation = profile_data.get('affiliation')
+
+        instance = super(ProfileSerializer, self).update(instance, validated_data)
+
+        profile = instance.profile
+        if profile_data and affiliation:
+            profile.affiliation = affiliation
+            profile.save()
+        return instance
diff --git a/settings/common.py b/settings/common.py
--- a/settings/common.py
+++ b/settings/common.py
@@ -276,5 +276,5 @@
 
 # To make usermame field read-only, customized serializer is defined.
 REST_AUTH_SERIALIZERS = {
-    'USER_DETAILS_SERIALIZER': 'accounts.serializers.UserDetailsSerializer',
+    'USER_DETAILS_SERIALIZER': 'accounts.serializers.ProfileSerializer',
 }

{"golden_diff": "diff --git a/apps/accounts/serializers.py b/apps/accounts/serializers.py\n--- a/apps/accounts/serializers.py\n+++ b/apps/accounts/serializers.py\n@@ -11,3 +11,26 @@\n         model = get_user_model()\n         fields = ('pk', 'email', 'username', 'first_name', 'last_name')\n         read_only_fields = ('email', 'username')\n+\n+\n+class ProfileSerializer(UserDetailsSerializer):\n+    \"\"\"\n+    Serializer to update the user profile.\n+    \"\"\"\n+\n+    affiliation = serializers.CharField(source=\"profile.affiliation\")\n+\n+    class Meta(UserDetailsSerializer.Meta):\n+        fields = UserDetailsSerializer.Meta.fields + ('affiliation',)\n+\n+    def update(self, instance, validated_data):\n+        profile_data = validated_data.pop('profile', {})\n+        affiliation = profile_data.get('affiliation')\n+\n+        instance = super(ProfileSerializer, self).update(instance, validated_data)\n+\n+        profile = instance.profile\n+        if profile_data and affiliation:\n+            profile.affiliation = affiliation\n+            profile.save()\n+        return instance\ndiff --git a/settings/common.py b/settings/common.py\n--- a/settings/common.py\n+++ b/settings/common.py\n@@ -276,5 +276,5 @@\n \n # To make usermame field read-only, customized serializer is defined.\n REST_AUTH_SERIALIZERS = {\n-    'USER_DETAILS_SERIALIZER': 'accounts.serializers.UserDetailsSerializer',\n+    'USER_DETAILS_SERIALIZER': 'accounts.serializers.ProfileSerializer',\n }\n", "issue": "Add support to update the user profile.\n\n", "before_files": [{"content": "\"\"\"\nDjango settings for evalai project.\n\nGenerated by 'django-admin startproject' using Django 1.10.2.\n\nFor more information on this file, see\nhttps://docs.djangoproject.com/en/1.10/topics/settings/\n\nFor the full list of settings and their values, see\nhttps://docs.djangoproject.com/en/1.10/ref/settings/\n\"\"\"\n\nimport datetime\nimport os\nimport sys\n\n# Build paths inside the project like this: os.path.join(BASE_DIR, ...)\nBASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))\nAPPS_DIR = os.path.join(BASE_DIR, 'apps')\n\nsys.path.append(APPS_DIR)\n\n# Quick-start development settings - unsuitable for production\n# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/\n\n# SECURITY WARNING: keep the secret key used in production secret!\nSECRET_KEY = os.environ.get('SECRET_KEY', 'random_secret_key')\n\n# SECURITY WARNING: don't run with debug turned on in production!\nDEBUG = True\n\nALLOWED_HOSTS = []\n\n\n# Application definition\n\nDEFAULT_APPS = [\n    'django.contrib.admin',\n    'django.contrib.auth',\n    'django.contrib.contenttypes',\n    'django.contrib.sessions',\n    'django.contrib.messages',\n    'django.contrib.staticfiles',\n    'django.contrib.sites',\n]\n\nOUR_APPS = [\n    'accounts',\n    'analytics',\n    'base',\n    'challenges',\n    'hosts',\n    'jobs',\n    'participants',\n    'web',\n]\n\nTHIRD_PARTY_APPS = [\n    'allauth',\n    'allauth.account',\n    'corsheaders',\n    'import_export',\n    'rest_auth',\n    'rest_auth.registration',\n    'rest_framework.authtoken',\n    'rest_framework',\n    'rest_framework_docs',\n    'rest_framework_expiring_authtoken',\n]\n\nINSTALLED_APPS = DEFAULT_APPS + OUR_APPS + THIRD_PARTY_APPS\n\nMIDDLEWARE = [\n    'corsheaders.middleware.CorsMiddleware',\n    'django.middleware.security.SecurityMiddleware',\n    'django.contrib.sessions.middleware.SessionMiddleware',\n    'django.middleware.common.CommonMiddleware',\n    'django.middleware.csrf.CsrfViewMiddleware',\n    'django.contrib.auth.middleware.AuthenticationMiddleware',\n    'django.contrib.messages.middleware.MessageMiddleware',\n    'django.middleware.clickjacking.XFrameOptionsMiddleware',\n]\n\nROOT_URLCONF = 'evalai.urls'\n\n\nTEMPLATES = [\n    {\n        'BACKEND': 'django.template.backends.django.DjangoTemplates',\n        'DIRS': [],\n        'APP_DIRS': True,\n        'OPTIONS': {\n            'context_processors': [\n                'django.template.context_processors.debug',\n                'django.template.context_processors.request',\n                'django.contrib.auth.context_processors.auth',\n                'django.contrib.messages.context_processors.messages',\n            ],\n        },\n    },\n]\n\nWSGI_APPLICATION = 'evalai.wsgi.application'\n\n\n# Password validation\n# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators\n\nAUTH_PASSWORD_VALIDATORS = [\n    {\n        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',  # noqa\n    },\n    {\n        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',  # noqa\n    },\n    {\n        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',  # noqa\n    },\n    {\n        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',  # noqa\n    },\n]\n\n\n# Internationalization\n# https://docs.djangoproject.com/en/1.10/topics/i18n/\n\nLANGUAGE_CODE = 'en-us'\n\nTIME_ZONE = 'UTC'\n\nUSE_I18N = True\n\nUSE_L10N = True\n\nUSE_TZ = True\n\n# Static files (CSS, JavaScript, Images)\n# https://docs.djangoproject.com/en/1.10/howto/static-files/\n\nSTATIC_URL = '/static/'\nSTATIC_ROOT = os.path.join(BASE_DIR, 'static')\nMEDIA_ROOT = os.path.join(BASE_DIR, 'media')\nMEDIA_URL = \"/media/\"\n\nSITE_ID = 1\n\nREST_FRAMEWORK = {\n    'DEFAULT_PAGINATION_CLASS': (\n        'rest_framework.pagination.LimitOffsetPagination'),\n    'PAGE_SIZE': 10,\n    'DEFAULT_PERMISSION_CLASSES': [\n        'rest_framework.permissions.IsAuthenticatedOrReadOnly'\n    ],\n    'DEFAULT_AUTHENTICATION_CLASSES': [\n        'rest_framework_expiring_authtoken.authentication.ExpiringTokenAuthentication',\n    ],\n    'TEST_REQUEST_DEFAULT_FORMAT': 'json',\n    'DEFAULT_THROTTLE_CLASSES': (\n        'rest_framework.throttling.AnonRateThrottle',\n        'rest_framework.throttling.UserRateThrottle'\n    ),\n    'DEFAULT_THROTTLE_RATES': {\n        'anon': '100/minute',\n        'user': '100/minute'\n    },\n    'DEFAULT_RENDERER_CLASSES': (\n        'rest_framework.renderers.JSONRenderer',\n    )\n}\n\n# ALLAUTH SETTINGS\nACCOUNT_EMAIL_REQUIRED = True\nOLD_PASSWORD_FIELD_ENABLED = True\nACCOUNT_CONFIRM_EMAIL_ON_GET = True\nACCOUNT_EMAIL_CONFIRMATION_ANONYMOUS_REDIRECT_URL = '/api/auth/email-confirmed/'\nACCOUNT_EMAIL_CONFIRMATION_AUTHENTICATED_REDIRECT_URL = '/api/auth/email-confirmed/'\n\nAUTHENTICATION_BACKENDS = (\n    # Needed to login by username in Django admin, regardless of `allauth`\n    'django.contrib.auth.backends.ModelBackend',\n    # `allauth` specific authentication methods, such as login by e-mail\n    'allauth.account.auth_backends.AuthenticationBackend',\n)\n\n# CORS Settings\nCORS_ORIGIN_ALLOW_ALL = True\n\n# REST Framework Expiring Tokens Configuration\nEXPIRING_TOKEN_LIFESPAN = datetime.timedelta(days=7)\n\n# Logging\nLOGGING = {\n    'version': 1,\n    'disable_existing_loggers': False,\n    'root': {\n        'level': 'INFO',\n        'handlers': ['console'],\n    },\n    'filters': {\n        'require_debug_false': {\n            '()': 'django.utils.log.RequireDebugFalse',\n        },\n        'require_debug_true': {\n            '()': 'django.utils.log.RequireDebugTrue',\n        }\n    },\n    'formatters': {\n        'simple': {\n            'format': '[%(asctime)s] %(levelname)s %(message)s',\n            'datefmt': '%Y-%m-%d %H:%M:%S'\n        },\n        'verbose': {\n            'format': '[%(asctime)s] %(levelname)s %(module)s %(message)s',\n            'datefmt': '%Y-%m-%d %H:%M:%S'\n        }\n    },\n    'handlers': {\n        'console': {\n            'level': 'INFO',\n            'filters': ['require_debug_true'],\n            'class': 'logging.StreamHandler',\n            'formatter': 'simple'\n        },\n        'logfile': {\n            'level': 'DEBUG',\n            'class': 'logging.handlers.RotatingFileHandler',\n            'filename': \"/tmp/logfile\",\n            'maxBytes': 50000,\n            'backupCount': 10,\n            'formatter': 'verbose'\n        },\n        'mail_admins': {\n            'level': 'ERROR',\n            'class': 'django.utils.log.AdminEmailHandler',\n            'filters': ['require_debug_false'],\n        }\n    },\n    'loggers': {\n        'django': {\n            'handlers': ['console'],\n            'propagate': False,\n        },\n        'django.request': {\n            'handlers': ['mail_admins'],\n            'level': 'ERROR',\n            'propagate': False,\n        },\n        'django.security': {\n            'handlers': ['mail_admins'],\n            'level': 'ERROR',\n            'propagate': False,\n        },\n        'django.db.backends': {\n            'handlers': ['mail_admins'],\n            'level': 'ERROR',\n            'propagate': False,\n        }\n    }\n}\n\nCACHES = {\n    'default': {\n        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',\n    }\n}\n\nRABBITMQ_PARAMETERS = {\n    'HOST': os.environ.get(\"RABBITMQ_HOST\", 'localhost'),\n    'EVALAI_EXCHANGE': {\n        'NAME': 'evalai_submissions',\n        'TYPE': 'topic',\n    },\n    'SUBMISSION_QUEUE': 'submission_task_queue',\n}\n\n# To make usermame field read-only, customized serializer is defined.\nREST_AUTH_SERIALIZERS = {\n    'USER_DETAILS_SERIALIZER': 'accounts.serializers.UserDetailsSerializer',\n}\n", "path": "settings/common.py"}, {"content": "from django.contrib.auth import get_user_model\n\nfrom rest_framework import serializers\n\n\nclass UserDetailsSerializer(serializers.ModelSerializer):\n    \"\"\"\n    Make username as a read_only field.\n    \"\"\"\n    class Meta:\n        model = get_user_model()\n        fields = ('pk', 'email', 'username', 'first_name', 'last_name')\n        read_only_fields = ('email', 'username')\n", "path": "apps/accounts/serializers.py"}], "after_files": [{"content": "\"\"\"\nDjango settings for evalai project.\n\nGenerated by 'django-admin startproject' using Django 1.10.2.\n\nFor more information on this file, see\nhttps://docs.djangoproject.com/en/1.10/topics/settings/\n\nFor the full list of settings and their values, see\nhttps://docs.djangoproject.com/en/1.10/ref/settings/\n\"\"\"\n\nimport datetime\nimport os\nimport sys\n\n# Build paths inside the project like this: os.path.join(BASE_DIR, ...)\nBASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))\nAPPS_DIR = os.path.join(BASE_DIR, 'apps')\n\nsys.path.append(APPS_DIR)\n\n# Quick-start development settings - unsuitable for production\n# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/\n\n# SECURITY WARNING: keep the secret key used in production secret!\nSECRET_KEY = os.environ.get('SECRET_KEY', 'random_secret_key')\n\n# SECURITY WARNING: don't run with debug turned on in production!\nDEBUG = True\n\nALLOWED_HOSTS = []\n\n\n# Application definition\n\nDEFAULT_APPS = [\n    'django.contrib.admin',\n    'django.contrib.auth',\n    'django.contrib.contenttypes',\n    'django.contrib.sessions',\n    'django.contrib.messages',\n    'django.contrib.staticfiles',\n    'django.contrib.sites',\n]\n\nOUR_APPS = [\n    'accounts',\n    'analytics',\n    'base',\n    'challenges',\n    'hosts',\n    'jobs',\n    'participants',\n    'web',\n]\n\nTHIRD_PARTY_APPS = [\n    'allauth',\n    'allauth.account',\n    'corsheaders',\n    'import_export',\n    'rest_auth',\n    'rest_auth.registration',\n    'rest_framework.authtoken',\n    'rest_framework',\n    'rest_framework_docs',\n    'rest_framework_expiring_authtoken',\n]\n\nINSTALLED_APPS = DEFAULT_APPS + OUR_APPS + THIRD_PARTY_APPS\n\nMIDDLEWARE = [\n    'corsheaders.middleware.CorsMiddleware',\n    'django.middleware.security.SecurityMiddleware',\n    'django.contrib.sessions.middleware.SessionMiddleware',\n    'django.middleware.common.CommonMiddleware',\n    'django.middleware.csrf.CsrfViewMiddleware',\n    'django.contrib.auth.middleware.AuthenticationMiddleware',\n    'django.contrib.messages.middleware.MessageMiddleware',\n    'django.middleware.clickjacking.XFrameOptionsMiddleware',\n]\n\nROOT_URLCONF = 'evalai.urls'\n\n\nTEMPLATES = [\n    {\n        'BACKEND': 'django.template.backends.django.DjangoTemplates',\n        'DIRS': [],\n        'APP_DIRS': True,\n        'OPTIONS': {\n            'context_processors': [\n                'django.template.context_processors.debug',\n                'django.template.context_processors.request',\n                'django.contrib.auth.context_processors.auth',\n                'django.contrib.messages.context_processors.messages',\n            ],\n        },\n    },\n]\n\nWSGI_APPLICATION = 'evalai.wsgi.application'\n\n\n# Password validation\n# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators\n\nAUTH_PASSWORD_VALIDATORS = [\n    {\n        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',  # noqa\n    },\n    {\n        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',  # noqa\n    },\n    {\n        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',  # noqa\n    },\n    {\n        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',  # noqa\n    },\n]\n\n\n# Internationalization\n# https://docs.djangoproject.com/en/1.10/topics/i18n/\n\nLANGUAGE_CODE = 'en-us'\n\nTIME_ZONE = 'UTC'\n\nUSE_I18N = True\n\nUSE_L10N = True\n\nUSE_TZ = True\n\n# Static files (CSS, JavaScript, Images)\n# https://docs.djangoproject.com/en/1.10/howto/static-files/\n\nSTATIC_URL = '/static/'\nSTATIC_ROOT = os.path.join(BASE_DIR, 'static')\nMEDIA_ROOT = os.path.join(BASE_DIR, 'media')\nMEDIA_URL = \"/media/\"\n\nSITE_ID = 1\n\nREST_FRAMEWORK = {\n    'DEFAULT_PAGINATION_CLASS': (\n        'rest_framework.pagination.LimitOffsetPagination'),\n    'PAGE_SIZE': 10,\n    'DEFAULT_PERMISSION_CLASSES': [\n        'rest_framework.permissions.IsAuthenticatedOrReadOnly'\n    ],\n    'DEFAULT_AUTHENTICATION_CLASSES': [\n        'rest_framework_expiring_authtoken.authentication.ExpiringTokenAuthentication',\n    ],\n    'TEST_REQUEST_DEFAULT_FORMAT': 'json',\n    'DEFAULT_THROTTLE_CLASSES': (\n        'rest_framework.throttling.AnonRateThrottle',\n        'rest_framework.throttling.UserRateThrottle'\n    ),\n    'DEFAULT_THROTTLE_RATES': {\n        'anon': '100/minute',\n        'user': '100/minute'\n    },\n    'DEFAULT_RENDERER_CLASSES': (\n        'rest_framework.renderers.JSONRenderer',\n    )\n}\n\n# ALLAUTH SETTINGS\nACCOUNT_EMAIL_REQUIRED = True\nOLD_PASSWORD_FIELD_ENABLED = True\nACCOUNT_CONFIRM_EMAIL_ON_GET = True\nACCOUNT_EMAIL_CONFIRMATION_ANONYMOUS_REDIRECT_URL = '/api/auth/email-confirmed/'\nACCOUNT_EMAIL_CONFIRMATION_AUTHENTICATED_REDIRECT_URL = '/api/auth/email-confirmed/'\n\nAUTHENTICATION_BACKENDS = (\n    # Needed to login by username in Django admin, regardless of `allauth`\n    'django.contrib.auth.backends.ModelBackend',\n    # `allauth` specific authentication methods, such as login by e-mail\n    'allauth.account.auth_backends.AuthenticationBackend',\n)\n\n# CORS Settings\nCORS_ORIGIN_ALLOW_ALL = True\n\n# REST Framework Expiring Tokens Configuration\nEXPIRING_TOKEN_LIFESPAN = datetime.timedelta(days=7)\n\n# Logging\nLOGGING = {\n    'version': 1,\n    'disable_existing_loggers': False,\n    'root': {\n        'level': 'INFO',\n        'handlers': ['console'],\n    },\n    'filters': {\n        'require_debug_false': {\n            '()': 'django.utils.log.RequireDebugFalse',\n        },\n        'require_debug_true': {\n            '()': 'django.utils.log.RequireDebugTrue',\n        }\n    },\n    'formatters': {\n        'simple': {\n            'format': '[%(asctime)s] %(levelname)s %(message)s',\n            'datefmt': '%Y-%m-%d %H:%M:%S'\n        },\n        'verbose': {\n            'format': '[%(asctime)s] %(levelname)s %(module)s %(message)s',\n            'datefmt': '%Y-%m-%d %H:%M:%S'\n        }\n    },\n    'handlers': {\n        'console': {\n            'level': 'INFO',\n            'filters': ['require_debug_true'],\n            'class': 'logging.StreamHandler',\n            'formatter': 'simple'\n        },\n        'logfile': {\n            'level': 'DEBUG',\n            'class': 'logging.handlers.RotatingFileHandler',\n            'filename': \"/tmp/logfile\",\n            'maxBytes': 50000,\n            'backupCount': 10,\n            'formatter': 'verbose'\n        },\n        'mail_admins': {\n            'level': 'ERROR',\n            'class': 'django.utils.log.AdminEmailHandler',\n            'filters': ['require_debug_false'],\n        }\n    },\n    'loggers': {\n        'django': {\n            'handlers': ['console'],\n            'propagate': False,\n        },\n        'django.request': {\n            'handlers': ['mail_admins'],\n            'level': 'ERROR',\n            'propagate': False,\n        },\n        'django.security': {\n            'handlers': ['mail_admins'],\n            'level': 'ERROR',\n            'propagate': False,\n        },\n        'django.db.backends': {\n            'handlers': ['mail_admins'],\n            'level': 'ERROR',\n            'propagate': False,\n        }\n    }\n}\n\nCACHES = {\n    'default': {\n        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',\n    }\n}\n\nRABBITMQ_PARAMETERS = {\n    'HOST': os.environ.get(\"RABBITMQ_HOST\", 'localhost'),\n    'EVALAI_EXCHANGE': {\n        'NAME': 'evalai_submissions',\n        'TYPE': 'topic',\n    },\n    'SUBMISSION_QUEUE': 'submission_task_queue',\n}\n\n# To make usermame field read-only, customized serializer is defined.\nREST_AUTH_SERIALIZERS = {\n    'USER_DETAILS_SERIALIZER': 'accounts.serializers.ProfileSerializer',\n}\n", "path": "settings/common.py"}, {"content": "from django.contrib.auth import get_user_model\n\nfrom rest_framework import serializers\n\n\nclass UserDetailsSerializer(serializers.ModelSerializer):\n    \"\"\"\n    Make username as a read_only field.\n    \"\"\"\n    class Meta:\n        model = get_user_model()\n        fields = ('pk', 'email', 'username', 'first_name', 'last_name')\n        read_only_fields = ('email', 'username')\n\n\nclass ProfileSerializer(UserDetailsSerializer):\n    \"\"\"\n    Serializer to update the user profile.\n    \"\"\"\n\n    affiliation = serializers.CharField(source=\"profile.affiliation\")\n\n    class Meta(UserDetailsSerializer.Meta):\n        fields = UserDetailsSerializer.Meta.fields + ('affiliation',)\n\n    def update(self, instance, validated_data):\n        profile_data = validated_data.pop('profile', {})\n        affiliation = profile_data.get('affiliation')\n\n        instance = super(ProfileSerializer, self).update(instance, validated_data)\n\n        profile = instance.profile\n        if profile_data and affiliation:\n            profile.affiliation = affiliation\n            profile.save()\n        return instance\n", "path": "apps/accounts/serializers.py"}]}