<commit_before>Release notes
=============

Version 0.2.4
-------------

This fixes a bug with handling of dates. If you want to fix historic data in
your IPN tables, you need to apply a migration like the following::

    # -*- coding: utf-8 -*-
    from __future__ import unicode_literals

    import pytz
    from datetime import datetime
    from django.db import migrations
    from django.utils import timezone


    PAYPAL_DATE_FORMATS = [
        "%H:%M:%S %b. %d, %Y PST",
        "%H:%M:%S %b. %d, %Y PDT",
        "%H:%M:%S %b %d, %Y PST",
        "%H:%M:%S %b %d, %Y PDT",
    ]


    def parse_date(datestring):
        for format in PAYPAL_DATE_FORMATS:
            try:
                return datetime.strptime(datestring, format)
            except (ValueError, TypeError):
                continue


    def fix_ipn_dates(apps, schema_editor):
        PayPalIPN = apps.get_model("ipn", "PayPalIPN")

        for ipn in PayPalIPN.objects.all():
            # Need to recreate PayPalIPN.posted_data_dict
            posted_data_dict = None
            if ipn.query:
                from django.http import QueryDict
                roughdecode = dict(item.split('=', 1) for item in ipn.query.split('&'))
                encoding = roughdecode.get('charset', None)
                if encoding is not None:
                    query = ipn.query.encode('ascii')
                    data = QueryDict(query, encoding=encoding)
                    posted_data_dict = data.dict()
            if posted_data_dict is None:
                continue

            for field in ['time_created', 'payment_date', 'next_payment_date', 'subscr_date', 'subscr_effective']:
                if field in posted_data_dict:
                    raw = posted_data_dict[field]
                    naive = parse_date(raw)
                    if naive is not None:
                        aware = timezone.make_aware(naive, pytz.timezone('US/Pacific'))
                        setattr(ipn, field, aware)
            ipn.save()


    class Migration(migrations.Migration):

        dependencies = [
            ('ipn', '0003_auto_20141117_1647'),
        ]

        operations = [
            migrations.RunPython(fix_ipn_dates,
                                 lambda apps, schema_editor: None)  # allowing reverse migration is harmless)
        ]


Version 0.2
-----------<commit_msg>Updated docs about migration for additional DateTimeField fields<commit_after>Release notes
=============

Version 0.2.4/0.2.5
-------------------

This fixes a bug with handling of dates. If you want to fix historic data in
your IPN tables, you need to apply a migration like the following::

    # -*- coding: utf-8 -*-
    from __future__ import unicode_literals

    import pytz
    from datetime import datetime
    from django.db import migrations
    from django.utils import timezone


    PAYPAL_DATE_FORMATS = [
        "%H:%M:%S %b. %d, %Y PST",
        "%H:%M:%S %b. %d, %Y PDT",
        "%H:%M:%S %b %d, %Y PST",
        "%H:%M:%S %b %d, %Y PDT",
    ]


    def parse_date(datestring):
        for format in PAYPAL_DATE_FORMATS:
            try:
                return datetime.strptime(datestring, format)
            except (ValueError, TypeError):
                continue


    def fix_ipn_dates(apps, schema_editor):
        PayPalIPN = apps.get_model("ipn", "PayPalIPN")

        for ipn in PayPalIPN.objects.all():
            # Need to recreate PayPalIPN.posted_data_dict
            posted_data_dict = None
            if ipn.query:
                from django.http import QueryDict
                roughdecode = dict(item.split('=', 1) for item in ipn.query.split('&'))
                encoding = roughdecode.get('charset', None)
                if encoding is not None:
                    query = ipn.query.encode('ascii')
                    data = QueryDict(query, encoding=encoding)
                    posted_data_dict = data.dict()
            if posted_data_dict is None:
                continue

            for field in ['time_created', 'payment_date', 'next_payment_date', 'subscr_date', 'subscr_effective',
                          'retry_at', 'case_creation_date', 'auction_closing_date']:
                if field in posted_data_dict:
                    raw = posted_data_dict[field]
                    naive = parse_date(raw)
                    if naive is not None:
                        aware = timezone.make_aware(naive, pytz.timezone('US/Pacific'))
                        setattr(ipn, field, aware)
            ipn.save()


    class Migration(migrations.Migration):

        dependencies = [
            ('ipn', '0003_auto_20141117_1647'),
        ]

        operations = [
            migrations.RunPython(fix_ipn_dates,
                                 lambda apps, schema_editor: None)  # allowing reverse migration is harmless)
        ]


Version 0.2
-----------
{'fraction_non_alphanumeric': 0.1095890410958904, 'fraction_numerical': 0.01001840114496013, 'mean_word_length': 1.7545045045045045, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7211127', 'n_tokens_mistral': 1469, 'n_tokens_neox': 1353, 'n_words': 374}