'''
Created on Jul 22, 2016

@author: Dayo
'''
from import_export import resources, fields
from .models import Contact
from core.models import KITUser
from import_export.widgets import ForeignKeyWidget

import phonenumbers
from phonenumbers.phonenumberutil import NumberParseException


class ContactResource(resources.ModelResource):
    #first_name = fields.Field(column_name='firstname')
    #last_name = fields.Field(column_name='lastname')
    #kit_user = fields.Field(widget=ForeignKeyWidget(KITUser,'id'))
    
    #def __init__(self, *args, **kwargs):
    #    self.kuid = kwargs.pop('kuserid')
    #    super(ContactResource, self).__init__(*args, **kwargs)
    #    self.kit_user = fields.Field(default=self.kuid, widget=ForeignKeyWidget(KITUser,'id'))
    
    class Meta:
        model = Contact
        skip_unchanged = True
        report_skipped = True
        import_id_fields = ('email','phone','kit_user')
        exclude = ('slug','last_modified', 'created','active')
    
    def for_delete(self, row, instance):
        # ignore rows without both phone and email
        if not (self.fields['phone'].clean(row) or self.fields['email'].clean(row)):
            return True
        # ignore rows without firstname
        if not self.fields['first_name'].clean(row):
            return True
        try:
            # if there is a phone number
            if self.fields['phone'].clean(row):
                # if when trying to parse a number, an exception occurs, ignore.            
                phonenumbers.parse(self.fields['phone'].clean(row), 'NG')
        except NumberParseException:
            return True
        
    
        
17d1a56bf394520000a98381c3f12d68d70aa8f9
<mask token>

<mask token>


class ContactResource(resources.ModelResource):


    class Meta:
        model = Contact
        skip_unchanged = True
        report_skipped = True
        import_id_fields = 'email', 'phone', 'kit_user'
        exclude = 'slug', 'last_modified', 'created', 'active'
    <mask token>

<mask token>


class ContactResource(resources.ModelResource):


    class Meta:
        model = Contact
        skip_unchanged = True
        report_skipped = True
        import_id_fields = 'email', 'phone', 'kit_user'
        exclude = 'slug', 'last_modified', 'created', 'active'

    def for_delete(self, row, instance):
        if not (self.fields['phone'].clean(row) or self.fields['email'].
            clean(row)):
            return True
        if not self.fields['first_name'].clean(row):
            return True
        try:
            if self.fields['phone'].clean(row):
                phonenumbers.parse(self.fields['phone'].clean(row), 'NG')
        except NumberParseException:
            return True

<mask token>
from import_export import resources, fields
from .models import Contact
from core.models import KITUser
from import_export.widgets import ForeignKeyWidget
import phonenumbers
from phonenumbers.phonenumberutil import NumberParseException


class ContactResource(resources.ModelResource):


    class Meta:
        model = Contact
        skip_unchanged = True
        report_skipped = True
        import_id_fields = 'email', 'phone', 'kit_user'
        exclude = 'slug', 'last_modified', 'created', 'active'

    def for_delete(self, row, instance):
        if not (self.fields['phone'].clean(row) or self.fields['email'].
            clean(row)):
            return True
        if not self.fields['first_name'].clean(row):
            return True
        try:
            if self.fields['phone'].clean(row):
                phonenumbers.parse(self.fields['phone'].clean(row), 'NG')
        except NumberParseException:
            return True

'''
Created on Jul 22, 2016

@author: Dayo
'''
from import_export import resources, fields
from .models import Contact
from core.models import KITUser
from import_export.widgets import ForeignKeyWidget

import phonenumbers
from phonenumbers.phonenumberutil import NumberParseException


class ContactResource(resources.ModelResource):
    #first_name = fields.Field(column_name='firstname')
    #last_name = fields.Field(column_name='lastname')
    #kit_user = fields.Field(widget=ForeignKeyWidget(KITUser,'id'))
    
    #def __init__(self, *args, **kwargs):
    #    self.kuid = kwargs.pop('kuserid')
    #    super(ContactResource, self).__init__(*args, **kwargs)
    #    self.kit_user = fields.Field(default=self.kuid, widget=ForeignKeyWidget(KITUser,'id'))
    
    class Meta:
        model = Contact
        skip_unchanged = True
        report_skipped = True
        import_id_fields = ('email','phone','kit_user')
        exclude = ('slug','last_modified', 'created','active')
    
    def for_delete(self, row, instance):
        # ignore rows without both phone and email
        if not (self.fields['phone'].clean(row) or self.fields['email'].clean(row)):
            return True
        # ignore rows without firstname
        if not self.fields['first_name'].clean(row):
            return True
        try:
            # if there is a phone number
            if self.fields['phone'].clean(row):
                # if when trying to parse a number, an exception occurs, ignore.            
                phonenumbers.parse(self.fields['phone'].clean(row), 'NG')
        except NumberParseException:
            return True
        
    
        