Skip to content

Commit

Permalink
Replaced 3rd party library django-hstore with native Django functiona…
Browse files Browse the repository at this point in the history
…lity

(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.
djangonauts/django-hstore#154
djangonauts/django-hstore#161

Also fixed all flake8 complaints in the file I touched (partners/models.py).
  • Loading branch information
caktus-philip committed Jul 6, 2017
1 parent b8ec769 commit c5cb234
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
1 change: 0 additions & 1 deletion EquiTrack/EquiTrack/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,6 @@
'analytical',
'mptt',
'easy_pdf',
'django_hstore',

'vision',
'management',
Expand Down
4 changes: 2 additions & 2 deletions EquiTrack/partners/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')),
Expand Down
32 changes: 18 additions & 14 deletions EquiTrack/partners/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,27 @@
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
from django.utils.translation import ugettext as _
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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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):
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion EquiTrack/requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c5cb234

Please sign in to comment.