"""Custom querysets for organization app"""

# Django
from django.db import models, transaction

# Standard Library
from datetime import datetime


class OrganizationQuerySet(models.QuerySet):
    """Object manager for profiles"""

    @transaction.atomic
    def squarelet_update_or_create(self, uuid, data):
        """Update or create records based on data from squarelet"""
        required_fields = {'name', 'slug', 'date_update'}
        missing = required_fields - (required_fields & set(data.keys()))
        if missing:
            raise ValueError('Missing required fields: {}'.format(missing))
        # convert date_update from string to date
        # XXX error handle
        if data['date_update'] is not None:
            data['date_update'] = datetime.strptime(
                data['date_update'], '%Y-%m-%d'
            ).date()

        organization, created = self.model.objects.get_or_create(uuid=uuid)
        organization.update_data(data)

        return organization, created

@@ -415,27 +415,25 @@
 slug', '
-date_
 update
+_on
 '%7D%0A     
@@ -690,27 +690,25 @@
 f data%5B'
-date_
 update
+_on
 '%5D is no
@@ -790,27 +790,25 @@
   data%5B'
-date_
 update
+_on
 '%5D, '%25Y-

rename date_update in squarelet api