We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
DateTimeTzFields are serialized with incorrect times
Example saved this time in a `ChannelMetaDataCache` object (at around 14:00 local time)

`2017-06-06 14:44:12.582879(America/Los_Angeles)`

But it gets serialized as

`2017-06-06T07:44:12.582-07:00`

Expected is

`2017-06-06T14:44:12.582-07:00`


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `kolibri/core/serializers.py`
Content:
```
1 from django.utils import timezone
2 from rest_framework.serializers import DateTimeField, ModelSerializer
3 from .fields import DateTimeTzField as DjangoDateTimeTzField
4 
5 class DateTimeTzField(DateTimeField):
6 
7     def to_internal_value(self, data):
8         data = super(DateTimeTzField, self).to_internal_value(data)
9         tz = timezone.get_current_timezone()
10         return data.astimezone(tz)
11 
12 
13 serializer_field_mapping = {
14     DjangoDateTimeTzField: DateTimeTzField,
15 }
16 
17 serializer_field_mapping.update(ModelSerializer.serializer_field_mapping)
18 
19 class KolibriModelSerializer(ModelSerializer):
20 
21     serializer_field_mapping = serializer_field_mapping
22
```

Path: `kolibri/core/fields.py`
Content:
```
1 import datetime
2 import re
3 
4 import pytz
5 from django.db.models.fields import Field
6 from django.utils import timezone
7 
8 date_time_format = "%Y-%m-%d %H:%M:%S.%f"
9 tz_format = "({tz})"
10 tz_regex = re.compile("\(([^\)]+)\)")
11 db_storage_string = "{date_time_string}{tz_string}"
12 
13 def parse_timezonestamp(value):
14     if tz_regex.search(value):
15         tz = pytz.timezone(tz_regex.search(value).groups()[0])
16     else:
17         tz = timezone.get_current_timezone()
18     utc_value = tz_regex.sub('', value)
19     value = datetime.datetime.strptime(utc_value, date_time_format)
20     value = timezone.make_aware(value, pytz.utc)
21     return value.astimezone(tz)
22 
23 def create_timezonestamp(value):
24     if value.tzinfo:
25         tz = value.tzinfo.zone
26     else:
27         tz = timezone.get_current_timezone().zone
28     date_time_string = value.strftime(date_time_format)
29     tz_string = tz_format.format(tz=tz)
30     value = db_storage_string.format(date_time_string=date_time_string, tz_string=tz_string)
31     return value
32 
33 class DateTimeTzField(Field):
34     """
35     A field that stores datetime information as a char in this format:
36 
37     %Y-%m-%d %H:%M:%S.%f(<tzinfo>)
38 
39     It reads a timezone aware datetime object, and extracts the timezone zone information
40     then parses the datetime into the format above with the timezone information appended.
41 
42     As this is ISO formatted, alphabetic sorting should still allow for proper queries
43     against this in the database. Mostly engineered for SQLite usage.
44     """
45 
46     def db_type(self, connection):
47         return "varchar"
48 
49     def from_db_value(self, value, expression, connection, context):
50         if value is None:
51             return value
52         return parse_timezonestamp(value)
53 
54     def to_python(self, value):
55         if isinstance(value, datetime.datetime):
56             return value
57 
58         if value is None:
59             return value
60 
61         return parse_timezonestamp(value)
62 
63     def get_prep_value(self, value):
64         # Casts datetimes into the format expected by the backend
65         if value is None:
66             return value
67         return create_timezonestamp(value)
68 
69     def get_db_prep_value(self, value, connection, prepared=False):
70         if not prepared:
71             value = self.get_prep_value(value)
72         return value
73
```
--- 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/kolibri/core/fields.py b/kolibri/core/fields.py
--- a/kolibri/core/fields.py
+++ b/kolibri/core/fields.py
@@ -25,7 +25,8 @@
         tz = value.tzinfo.zone
     else:
         tz = timezone.get_current_timezone().zone
-    date_time_string = value.strftime(date_time_format)
+        value = timezone.make_aware(value, timezone.get_current_timezone())
+    date_time_string = value.astimezone(pytz.utc).strftime(date_time_format)
     tz_string = tz_format.format(tz=tz)
     value = db_storage_string.format(date_time_string=date_time_string, tz_string=tz_string)
     return value
diff --git a/kolibri/core/serializers.py b/kolibri/core/serializers.py
--- a/kolibri/core/serializers.py
+++ b/kolibri/core/serializers.py
@@ -1,3 +1,5 @@
+import pytz
+
 from django.utils import timezone
 from rest_framework.serializers import DateTimeField, ModelSerializer
 from .fields import DateTimeTzField as DjangoDateTimeTzField
@@ -7,6 +9,8 @@
     def to_internal_value(self, data):
         data = super(DateTimeTzField, self).to_internal_value(data)
         tz = timezone.get_current_timezone()
+        if not data.tzinfo:
+            data = timezone.make_aware(data, pytz.utc)
         return data.astimezone(tz)

{"golden_diff": "diff --git a/kolibri/core/fields.py b/kolibri/core/fields.py\n--- a/kolibri/core/fields.py\n+++ b/kolibri/core/fields.py\n@@ -25,7 +25,8 @@\n         tz = value.tzinfo.zone\n     else:\n         tz = timezone.get_current_timezone().zone\n-    date_time_string = value.strftime(date_time_format)\n+        value = timezone.make_aware(value, timezone.get_current_timezone())\n+    date_time_string = value.astimezone(pytz.utc).strftime(date_time_format)\n     tz_string = tz_format.format(tz=tz)\n     value = db_storage_string.format(date_time_string=date_time_string, tz_string=tz_string)\n     return value\ndiff --git a/kolibri/core/serializers.py b/kolibri/core/serializers.py\n--- a/kolibri/core/serializers.py\n+++ b/kolibri/core/serializers.py\n@@ -1,3 +1,5 @@\n+import pytz\n+\n from django.utils import timezone\n from rest_framework.serializers import DateTimeField, ModelSerializer\n from .fields import DateTimeTzField as DjangoDateTimeTzField\n@@ -7,6 +9,8 @@\n     def to_internal_value(self, data):\n         data = super(DateTimeTzField, self).to_internal_value(data)\n         tz = timezone.get_current_timezone()\n+        if not data.tzinfo:\n+            data = timezone.make_aware(data, pytz.utc)\n         return data.astimezone(tz)\n", "issue": "DateTimeTzFields are serialized with incorrect times\nExample saved this time in a `ChannelMetaDataCache` object (at around 14:00 local time)\r\n\r\n`2017-06-06 14:44:12.582879(America/Los_Angeles)`\r\n\r\nBut it gets serialized as\r\n\r\n`2017-06-06T07:44:12.582-07:00`\r\n\r\nExpected is\r\n\r\n`2017-06-06T14:44:12.582-07:00`\r\n\n", "before_files": [{"content": "from django.utils import timezone\nfrom rest_framework.serializers import DateTimeField, ModelSerializer\nfrom .fields import DateTimeTzField as DjangoDateTimeTzField\n\nclass DateTimeTzField(DateTimeField):\n\n    def to_internal_value(self, data):\n        data = super(DateTimeTzField, self).to_internal_value(data)\n        tz = timezone.get_current_timezone()\n        return data.astimezone(tz)\n\n\nserializer_field_mapping = {\n    DjangoDateTimeTzField: DateTimeTzField,\n}\n\nserializer_field_mapping.update(ModelSerializer.serializer_field_mapping)\n\nclass KolibriModelSerializer(ModelSerializer):\n\n    serializer_field_mapping = serializer_field_mapping\n", "path": "kolibri/core/serializers.py"}, {"content": "import datetime\nimport re\n\nimport pytz\nfrom django.db.models.fields import Field\nfrom django.utils import timezone\n\ndate_time_format = \"%Y-%m-%d %H:%M:%S.%f\"\ntz_format = \"({tz})\"\ntz_regex = re.compile(\"\\(([^\\)]+)\\)\")\ndb_storage_string = \"{date_time_string}{tz_string}\"\n\ndef parse_timezonestamp(value):\n    if tz_regex.search(value):\n        tz = pytz.timezone(tz_regex.search(value).groups()[0])\n    else:\n        tz = timezone.get_current_timezone()\n    utc_value = tz_regex.sub('', value)\n    value = datetime.datetime.strptime(utc_value, date_time_format)\n    value = timezone.make_aware(value, pytz.utc)\n    return value.astimezone(tz)\n\ndef create_timezonestamp(value):\n    if value.tzinfo:\n        tz = value.tzinfo.zone\n    else:\n        tz = timezone.get_current_timezone().zone\n    date_time_string = value.strftime(date_time_format)\n    tz_string = tz_format.format(tz=tz)\n    value = db_storage_string.format(date_time_string=date_time_string, tz_string=tz_string)\n    return value\n\nclass DateTimeTzField(Field):\n    \"\"\"\n    A field that stores datetime information as a char in this format:\n\n    %Y-%m-%d %H:%M:%S.%f(<tzinfo>)\n\n    It reads a timezone aware datetime object, and extracts the timezone zone information\n    then parses the datetime into the format above with the timezone information appended.\n\n    As this is ISO formatted, alphabetic sorting should still allow for proper queries\n    against this in the database. Mostly engineered for SQLite usage.\n    \"\"\"\n\n    def db_type(self, connection):\n        return \"varchar\"\n\n    def from_db_value(self, value, expression, connection, context):\n        if value is None:\n            return value\n        return parse_timezonestamp(value)\n\n    def to_python(self, value):\n        if isinstance(value, datetime.datetime):\n            return value\n\n        if value is None:\n            return value\n\n        return parse_timezonestamp(value)\n\n    def get_prep_value(self, value):\n        # Casts datetimes into the format expected by the backend\n        if value is None:\n            return value\n        return create_timezonestamp(value)\n\n    def get_db_prep_value(self, value, connection, prepared=False):\n        if not prepared:\n            value = self.get_prep_value(value)\n        return value\n", "path": "kolibri/core/fields.py"}], "after_files": [{"content": "import pytz\n\nfrom django.utils import timezone\nfrom rest_framework.serializers import DateTimeField, ModelSerializer\nfrom .fields import DateTimeTzField as DjangoDateTimeTzField\n\nclass DateTimeTzField(DateTimeField):\n\n    def to_internal_value(self, data):\n        data = super(DateTimeTzField, self).to_internal_value(data)\n        tz = timezone.get_current_timezone()\n        if not data.tzinfo:\n            data = timezone.make_aware(data, pytz.utc)\n        return data.astimezone(tz)\n\n\nserializer_field_mapping = {\n    DjangoDateTimeTzField: DateTimeTzField,\n}\n\nserializer_field_mapping.update(ModelSerializer.serializer_field_mapping)\n\nclass KolibriModelSerializer(ModelSerializer):\n\n    serializer_field_mapping = serializer_field_mapping\n", "path": "kolibri/core/serializers.py"}, {"content": "import datetime\nimport re\n\nimport pytz\nfrom django.db.models.fields import Field\nfrom django.utils import timezone\n\ndate_time_format = \"%Y-%m-%d %H:%M:%S.%f\"\ntz_format = \"({tz})\"\ntz_regex = re.compile(\"\\(([^\\)]+)\\)\")\ndb_storage_string = \"{date_time_string}{tz_string}\"\n\ndef parse_timezonestamp(value):\n    if tz_regex.search(value):\n        tz = pytz.timezone(tz_regex.search(value).groups()[0])\n    else:\n        tz = timezone.get_current_timezone()\n    utc_value = tz_regex.sub('', value)\n    value = datetime.datetime.strptime(utc_value, date_time_format)\n    value = timezone.make_aware(value, pytz.utc)\n    return value.astimezone(tz)\n\ndef create_timezonestamp(value):\n    if value.tzinfo:\n        tz = value.tzinfo.zone\n    else:\n        tz = timezone.get_current_timezone().zone\n        value = timezone.make_aware(value, timezone.get_current_timezone())\n    date_time_string = value.astimezone(pytz.utc).strftime(date_time_format)\n    tz_string = tz_format.format(tz=tz)\n    value = db_storage_string.format(date_time_string=date_time_string, tz_string=tz_string)\n    return value\n\nclass DateTimeTzField(Field):\n    \"\"\"\n    A field that stores datetime information as a char in this format:\n\n    %Y-%m-%d %H:%M:%S.%f(<tzinfo>)\n\n    It reads a timezone aware datetime object, and extracts the timezone zone information\n    then parses the datetime into the format above with the timezone information appended.\n\n    As this is ISO formatted, alphabetic sorting should still allow for proper queries\n    against this in the database. Mostly engineered for SQLite usage.\n    \"\"\"\n\n    def db_type(self, connection):\n        return \"varchar\"\n\n    def from_db_value(self, value, expression, connection, context):\n        if value is None:\n            return value\n        return parse_timezonestamp(value)\n\n    def to_python(self, value):\n        if isinstance(value, datetime.datetime):\n            return value\n\n        if value is None:\n            return value\n\n        return parse_timezonestamp(value)\n\n    def get_prep_value(self, value):\n        # Casts datetimes into the format expected by the backend\n        if value is None:\n            return value\n        return create_timezonestamp(value)\n\n    def get_db_prep_value(self, value, connection, prepared=False):\n        if not prepared:\n            value = self.get_prep_value(value)\n        return value\n", "path": "kolibri/core/fields.py"}]}