From c5cb234278fede7d1eeb97e35de52d25d746b583 Mon Sep 17 00:00:00 2001 From: Philip Semanchuk Date: Thu, 6 Jul 2017 16:55:48 -0400 Subject: [PATCH] Replaced 3rd party library django-hstore with native Django functionality (hstore has been native since django 1.8) Removing this library removes an impediment to upgrading to Django 1.10. django-hstore isn't compatible with Django 1.10. The author is aware of this but has no more time to maintain the module and is looking for a new maintainer. https://github.com/djangonauts/django-hstore/issues/154 https://github.com/djangonauts/django-hstore/issues/161 Also fixed all flake8 complaints in the file I touched (partners/models.py). --- EquiTrack/EquiTrack/settings/base.py | 1 - EquiTrack/partners/migrations/0001_initial.py | 4 +-- EquiTrack/partners/models.py | 32 +++++++++++-------- EquiTrack/requirements/base.txt | 1 - 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/EquiTrack/EquiTrack/settings/base.py b/EquiTrack/EquiTrack/settings/base.py index f57a40d3cd..87ead7b429 100644 --- a/EquiTrack/EquiTrack/settings/base.py +++ b/EquiTrack/EquiTrack/settings/base.py @@ -398,7 +398,6 @@ 'analytical', 'mptt', 'easy_pdf', - 'django_hstore', 'vision', 'management', diff --git a/EquiTrack/partners/migrations/0001_initial.py b/EquiTrack/partners/migrations/0001_initial.py index ddc9e4439e..42531bbb53 100644 --- a/EquiTrack/partners/migrations/0001_initial.py +++ b/EquiTrack/partners/migrations/0001_initial.py @@ -5,10 +5,10 @@ import EquiTrack.mixins from django.conf import settings import django.contrib.postgres.fields.jsonb +from django.contrib.postgres.fields import HStoreField from django.db import migrations, models import django.db.models.deletion import django.utils.timezone -import django_hstore.fields import model_utils.fields import partners.models import smart_selects.db_fields @@ -187,7 +187,7 @@ class Migration(migrations.Migration): ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('year', models.CharField(max_length=4)), ('planned_amount', models.IntegerField(default=0, verbose_name=b'Planned Cash Transfers')), - ('activities', django_hstore.fields.DictionaryField(blank=True, null=True)), + ('activities', HStoreField(blank=True, null=True)), ('planned_visits', models.IntegerField(default=0)), ('activities_list', models.ManyToManyField(blank=True, related_name='activities_list', to='reports.Result')), ('intervention', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='results', to='partners.GovernmentIntervention')), diff --git a/EquiTrack/partners/models.py b/EquiTrack/partners/models.py index 485d8d9b5f..831d50f13f 100644 --- a/EquiTrack/partners/models.py +++ b/EquiTrack/partners/models.py @@ -2,11 +2,10 @@ import logging import datetime import json -from dateutil.relativedelta import relativedelta from django.conf import settings from django.contrib.auth.models import Group -from django.contrib.postgres.fields import JSONField, ArrayField +from django.contrib.postgres.fields import JSONField, ArrayField, HStoreField from django.db import models, connection, transaction from django.db.models import Q, Sum, F from django.db.models.signals import post_save, pre_delete @@ -14,17 +13,16 @@ from django.utils.functional import cached_property from django_fsm import FSMField, transition -from django_hstore import hstore from smart_selects.db_fields import ChainedForeignKey from model_utils.models import ( TimeFramedModel, TimeStampedModel, ) from model_utils import Choices, FieldTracker +from dateutil.relativedelta import relativedelta from EquiTrack.utils import get_changeform_link, get_current_site from EquiTrack.mixins import AdminURLMixin - from funds.models import Grant from reports.models import ( ResultStructure, @@ -460,7 +458,6 @@ def audit_needed(cls, partner, assesment=None): hact = json.loads(partner.hact_values) if isinstance(partner.hact_values, str) else partner.hact_values if partner.total_ct_cp > 500000.00: audits = 1 - current_cycle = CountryProgramme.current() last_audit = partner.latest_assessment(u'Scheduled Audit report') if assesment: if last_audit: @@ -1011,7 +1008,8 @@ def reference_number(self): # status__in=[self.ACTIVE, self.SUSPENDED, # self.TERMINATED, self.ENDED], created__year=self.created.year, - # agreement_type=self.agreement_type #removing type: in case agreement saved and agreement_type changed after + # removing type: in case agreement saved and agreement_type changed after + # agreement_type=self.agreement_type ).count() sequence = '{0:02d}'.format(agreements_count + 1) number = u'{code}/{type}{year}{seq}'.format( @@ -1057,7 +1055,8 @@ def update_related_interventions(self, oldself, **kwargs): document_type__in=[Intervention.PD, Intervention.SHPD] ) for item in interventions: - if item.status not in [Intervention.DRAFT, Intervention.CANCELLED, Intervention.IMPLEMENTED] and item.status != self.status: + if item.status not in [Intervention.DRAFT, Intervention.CANCELLED, Intervention.IMPLEMENTED] and \ + item.status != self.status: item.status = self.status item.save() @@ -1402,7 +1401,8 @@ def days_from_review_to_signed(self): @property def sector_names(self): - return u', '.join(Sector.objects.filter(intervention_locations__intervention=self).values_list('name', flat=True)) + return u', '.join(Sector.objects.filter(intervention_locations__intervention=self).values_list('name', + flat=True)) @cached_property def total_partner_contribution(self): @@ -1449,7 +1449,8 @@ def total_unicef_cash_local(self): def total_budget_local(self): # TODO: test this if self.planned_budget.exists(): - return self.planned_budget.aggregate(mysum=Sum('in_kind_amount_local'))['mysum'] + self.total_unicef_cash_local + self.total_partner_contribution_local + return self.planned_budget.aggregate(mysum=Sum('in_kind_amount_local'))['mysum'] + \ + self.total_unicef_cash_local + self.total_partner_contribution_local return 0 @property @@ -1795,7 +1796,9 @@ class InterventionSectorLocationLink(models.Model): class GovernmentInterventionManager(models.Manager): def get_queryset(self): - return super(GovernmentInterventionManager, self).get_queryset().prefetch_related('results', 'results__sectors', 'results__unicef_managers') + return super(GovernmentInterventionManager, self).get_queryset().prefetch_related('results', + 'results__sectors', + 'results__unicef_managers') # TODO: check this for sanity @@ -1891,7 +1894,7 @@ class GovernmentInterventionResult(models.Model): default=0, verbose_name='Planned Cash Transfers' ) - activities = hstore.DictionaryField( + activities = HStoreField( blank=True, null=True ) activity = JSONField(blank=True, null=True, default=activity_default) @@ -1908,7 +1911,6 @@ class GovernmentInterventionResult(models.Model): planned_visits = models.IntegerField(default=0) tracker = FieldTracker() - objects = hstore.HStoreManager() @transaction.atomic def save(self, **kwargs): @@ -2365,7 +2367,8 @@ def total_budget(self): if self.budget_log.exists(): return sum([b['unicef_cash'] + b['in_kind_amount'] + b['partner_contribution'] for b in - self.budget_log.values('created', 'year', 'unicef_cash', 'in_kind_amount', 'partner_contribution'). + self.budget_log.values('created', 'year', 'unicef_cash', 'in_kind_amount', + 'partner_contribution'). order_by('year', '-created').distinct('year').all()]) return 0 @@ -2394,7 +2397,8 @@ def total_budget_local(self): if self.budget_log.exists(): return sum([b['unicef_cash_local'] + b['in_kind_amount_local'] + b['partner_contribution_local'] for b in - self.budget_log.values('created', 'year', 'unicef_cash_local', 'in_kind_amount_local', 'partner_contribution_local'). + self.budget_log.values('created', 'year', 'unicef_cash_local', 'in_kind_amount_local', + 'partner_contribution_local'). order_by('year', '-created').distinct('year').all()]) return 0 diff --git a/EquiTrack/requirements/base.txt b/EquiTrack/requirements/base.txt index 410d4463c2..f5ef3475bc 100644 --- a/EquiTrack/requirements/base.txt +++ b/EquiTrack/requirements/base.txt @@ -9,7 +9,6 @@ django-logentry-admin==1.0.2 djrill==2.1.0 django-autocomplete-light==3.2.1 django-smart-selects==1.3.1 -django-hstore==1.4.2 django-redis-cache==1.7.1 django-datetime-widget==0.9.3 django-leaflet==0.19.0