Commit 72c3ee12 authored by okhin's avatar okhin

Fixing the TEMPLATES dict in settings.py

parent 51ddf02e
# encoding: utf-8
#import os
from datetime import datetime
import json
from os.path import exists, join
import urllib
from django.core.management.base import BaseCommand
from django.db import transaction
from picampaign.contact.models import Contact
JSON_DUMP_LOCALIZATION = join('/tmp', 'latest_meps.json')
class Command(BaseCommand):
help = 'Update the eurodeputies data by pulling it from compotista'
def handle(self, *args, **options):
if not exists(JSON_DUMP_LOCALIZATION):
print("download lastest data dump of meps from compotista")
urllib.urlretrieve('http://compotista.mm.staz.be/latest/', JSON_DUMP_LOCALIZATION)
print("load json")
meps = json.load(open(JSON_DUMP_LOCALIZATION, "r"))
# This should not be used, since old contacts should stay in database
print("cleaning Contacts")
Contact.objects.all().delete()
print("adding Contacts")
added = 0
for mep in meps:
insert_mep = False
for mandate in mep['mandates']:
if datetime.strptime(mandate['begin_date'], '%Y-%m-%d') < datetime.today() < datetime.strptime(mandate['end_date'], '%Y-%m-%d'):
insert_mep = True
if insert_mep:
first_name = mep['personal']['first_name']
last_name = mep['personal']['last_name']
if mep['contact']['phones']!=[]:
phone = mep['contact']['phones'][0]['phone']
else:
phone = ''
if mep['contact']['emails']!=[]:
mail = mep['contact']['emails'][0]['email']
else:
mail = ''
if mep['contact']['websites']!=[]:
for website in mep['contact']['websites']:
if 'twitter' in website['website']:
twitter = ''.join(('@', website['website'].split('/')[-1]))
break
else:
twitter = ''
if phone!='':
contact = Contact.objects.create(
first_name=first_name,
last_name=last_name,
phone=phone,
mail=mail,
twitter=twitter
)
added += 1
print('%d - %s %s' % (added, first_name, last_name))
if added>=50:
return
......@@ -8,7 +8,7 @@ from django.utils.translation import ugettext_lazy as _
from picampaign.contact.models import Contact, Phone
from picampaign.campaign.models import Campaign, CampaignContact
from picampaign.organization.models import Group, GroupType, Organization
from picampaign.organization.models import Group, GroupType
class Importer(models.Model):
"""Importer model. Used to populate campaign with contacts"""
......@@ -19,7 +19,6 @@ class Importer(models.Model):
file = models.FileField(upload_to='imports/', blank=True, null=True)
url = models.URLField(blank=True, null=True)
campaign = models.ForeignKey(Campaign, on_delete=models.SET_NULL, null=True)
organization = models.ForeignKey(Organization, on_delete=models.CASCADE)
last_count = models.IntegerField(null=True, blank=True)
last_imported = models.IntegerField(null=True, blank=True)
......@@ -64,7 +63,7 @@ class Importer(models.Model):
# This mandate has ended
continue
# We want to only use the groups own by the organisation
for groupType in GroupType.objects.filter(organization = self.organization,
for groupType in GroupType.objects.filter(organization = self.campaign.organization,
name = mandate['group']['kind']):
if 'abbreviation' in mandate['group']:
group, added = Group.objects.get_or_create(name = mandate['group']['abbreviation'],
......
......@@ -23,8 +23,6 @@ SECRET_KEY = 'select a secret key'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
TEMPLATE_DEBUG = False
ALLOWED_HOSTS = []
......@@ -106,5 +104,10 @@ TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'APP_DIRS': True,
'TEMPLATE_DEBUG': False
},
{
'BACKEND': 'django.contrib.auth.context_processors.auth',
'TEMPLATE_DEBUG': False
},
]
#!/bin/bash
${VIRTUAL_ENV}/bin/coverage run --source='.' manage.py test
${VIRTUAL_ENV}/bin/coverage report --skip-covered --omit="${VIRTUAL_ENV}/*",'*__init__.py'
${VIRTUAL_ENV}/bin/coverage report -m --skip-covered --omit="${VIRTUAL_ENV}/*",'*__init__.py'
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment