mirror of
https://github.com/Hopiu/django-fobi.git
synced 2026-05-10 22:03:09 +00:00
mailchimp importer pep8
This commit is contained in:
parent
bd17bdb2bd
commit
546b02cd07
5 changed files with 55 additions and 48 deletions
|
|
@ -4,6 +4,7 @@ __copyright__ = '2014-2016 Artur Barseghyan'
|
|||
__license__ = 'GPL 2.0/LGPL 2.1'
|
||||
__all__ = ('default_app_config', 'UID',)
|
||||
|
||||
default_app_config = 'fobi.contrib.plugins.form_importers.mailchimp_importer.apps.Config'
|
||||
default_app_config = 'fobi.contrib.plugins.form_importers.' \
|
||||
'mailchimp_importer.apps.Config'
|
||||
|
||||
UID = 'mailchimp'
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ try:
|
|||
from django.apps import AppConfig
|
||||
|
||||
class Config(AppConfig):
|
||||
"""Config."""
|
||||
|
||||
name = 'fobi.contrib.plugins.form_importers.mailchimp_importer'
|
||||
label = 'fobi_contrib_plugins_form_importers_mailchimp_importer'
|
||||
|
||||
|
|
|
|||
|
|
@ -1,20 +1,21 @@
|
|||
__title__ = 'fobi.contrib.plugins.form_importers.mailchimp_importer.fobi_form_importers'
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from fobi.contrib.plugins.form_elements import fields
|
||||
from fobi.form_importers import BaseFormImporter, form_importer_plugin_registry
|
||||
|
||||
from .views import MailchimpImporterWizardView
|
||||
|
||||
__title__ = 'fobi.contrib.plugins.form_importers.mailchimp_importer.' \
|
||||
'fobi_form_importers'
|
||||
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
|
||||
__copyright__ = '2014-2016 Artur Barseghyan'
|
||||
__license__ = 'GPL 2.0/LGPL 2.1'
|
||||
__all__ = ('MailChimpImporter',)
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from fobi.form_importers import BaseFormImporter, form_importer_plugin_registry
|
||||
from fobi.contrib.plugins.form_elements import fields
|
||||
|
||||
from .views import MailchimpImporterWizardView
|
||||
|
||||
class MailChimpImporter(BaseFormImporter):
|
||||
"""
|
||||
MailChimp data importer.
|
||||
"""
|
||||
"""MailChimp data importer."""
|
||||
|
||||
uid = 'mailchimp'
|
||||
name = _("MailChimp")
|
||||
wizard = MailchimpImporterWizardView
|
||||
|
|
@ -40,10 +41,10 @@ class MailChimpImporter(BaseFormImporter):
|
|||
'phone': fields.text.UID,
|
||||
|
||||
# Unsure of what to do
|
||||
#'imageurl': '???',
|
||||
# 'imageurl': '???',
|
||||
|
||||
# Not implemented yet
|
||||
#'birthday': '???',
|
||||
# 'birthday': '???',
|
||||
}
|
||||
|
||||
# Django standard: remote
|
||||
|
|
@ -60,7 +61,8 @@ class MailChimpImporter(BaseFormImporter):
|
|||
position_prop_name = 'order'
|
||||
|
||||
def extract_field_properties(self, field_data):
|
||||
"""
|
||||
"""Extract field properties.
|
||||
|
||||
Handle choices differently as we know what the mailchimp
|
||||
format is.
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -1,15 +1,17 @@
|
|||
import mailchimp
|
||||
|
||||
from django import forms
|
||||
|
||||
__title__ = 'fobi.contrib.plugins.form_importers.mailchimp_importer.forms'
|
||||
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
|
||||
__copyright__ = '2014-2016 Artur Barseghyan'
|
||||
__license__ = 'GPL 2.0/LGPL 2.1'
|
||||
__all__ = ('MailchimpAPIKeyForm', 'MailchimpListIDForm',)
|
||||
|
||||
import mailchimp
|
||||
|
||||
from django import forms
|
||||
|
||||
class MailchimpAPIKeyForm(forms.Form):
|
||||
"""
|
||||
"""MailchimpAPIKeyForm.
|
||||
|
||||
First form the the wizard. Here users are supposed to provide the
|
||||
API key of their Mailchimp account.
|
||||
"""
|
||||
|
|
@ -17,15 +19,15 @@ class MailchimpAPIKeyForm(forms.Form):
|
|||
|
||||
|
||||
class MailchimpListIDForm(forms.Form):
|
||||
"""
|
||||
"""MailchimpListIDForm.
|
||||
|
||||
Second form of the wizard. Here users are supposed to choose the form
|
||||
they want to import.
|
||||
"""
|
||||
list_id = forms.ChoiceField(required=True, choices=[])
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""
|
||||
"""
|
||||
"""Constructor."""
|
||||
self._api_key = None
|
||||
|
||||
if 'api_key' in kwargs:
|
||||
|
|
@ -38,5 +40,5 @@ class MailchimpListIDForm(forms.Form):
|
|||
lists = client.lists.list()
|
||||
choices = [(l['id'], l['name']) for l in lists['data']]
|
||||
self.fields['list_id'].choices = choices
|
||||
#else:
|
||||
# self.fields['list_id'] = forms.CharField(required=True)
|
||||
# else:
|
||||
# self.fields['list_id'] = forms.CharField(required=True)
|
||||
|
|
|
|||
|
|
@ -1,39 +1,39 @@
|
|||
import logging
|
||||
|
||||
import mailchimp
|
||||
|
||||
from django.contrib import messages
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.shortcuts import redirect
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from nine.versions import DJANGO_GTE_1_8
|
||||
|
||||
from .forms import MailchimpAPIKeyForm, MailchimpListIDForm
|
||||
|
||||
if DJANGO_GTE_1_8:
|
||||
from formtools.wizard.views import SessionWizardView # , CookieWizardView
|
||||
else:
|
||||
from django.contrib.formtools.wizard.views import SessionWizardView
|
||||
|
||||
__title__ = 'fobi.contrib.plugins.form_importers.mailchimp_importer.views'
|
||||
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
|
||||
__copyright__ = '2014-2016 Artur Barseghyan'
|
||||
__license__ = 'GPL 2.0/LGPL 2.1'
|
||||
__all__ = ('MailchimpImporterWizardView',)
|
||||
|
||||
import logging
|
||||
|
||||
import mailchimp
|
||||
|
||||
from django.shortcuts import redirect
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.contrib import messages
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from nine.versions import DJANGO_GTE_1_8
|
||||
|
||||
if DJANGO_GTE_1_8:
|
||||
from formtools.wizard.views import SessionWizardView#, CookieWizardView
|
||||
else:
|
||||
from django.contrib.formtools.wizard.views import SessionWizardView
|
||||
|
||||
from .forms import MailchimpAPIKeyForm, MailchimpListIDForm
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class MailchimpImporterWizardView(SessionWizardView):
|
||||
"""
|
||||
"""
|
||||
"""MailchimpImporterWizardView."""
|
||||
|
||||
form_list = [MailchimpAPIKeyForm, MailchimpListIDForm]
|
||||
|
||||
def get_form_kwargs(self, step):
|
||||
"""
|
||||
"""
|
||||
#logger.debug('step: ' + step)
|
||||
#logger.debug(self.request.session.__dict__)
|
||||
"""Get form kwargs."""
|
||||
# logger.debug('step: ' + step)
|
||||
# logger.debug(self.request.session.__dict__)
|
||||
if '1' == step:
|
||||
data = self.get_cleaned_data_for_step('0') or {}
|
||||
api_key = data.get('api_key', None)
|
||||
|
|
@ -45,7 +45,7 @@ class MailchimpImporterWizardView(SessionWizardView):
|
|||
cleaned_data = {}
|
||||
for form in form_list:
|
||||
cleaned_data.update(form.cleaned_data)
|
||||
#cleaned_data = self.get_all_cleaned_data()
|
||||
# cleaned_data = self.get_all_cleaned_data()
|
||||
|
||||
# Connecting to mailchimp
|
||||
client = mailchimp.Mailchimp(cleaned_data['api_key'])
|
||||
|
|
|
|||
Loading…
Reference in a new issue