# -*- coding: utf-8 -*-
# Generated by Django 1.11.7 on 2017-12-19 08:44
from __future__ import unicode_literals

from django.db import migrations
from django.utils.encoding import force_text

import user_agents


def update_user_agent(apps, schema_editor):
    AuditLog = apps.get_model('accounts', 'AuditLog')
    for log in AuditLog.objects.exclude(user_agent=''):
        uaobj = user_agents.parse(log.user_agent)
        log.user_agent = force_text(uaobj)
        log.save(update_fields=['user_agent'])


class Migration(migrations.Migration):

    dependencies = [
        ('accounts', '0034_auto_20171129_1438'),
    ]

    operations = [
        migrations.RunPython(update_user_agent),
    ]
