Skip to content
Permalink
Browse files

Merge pull request #237 from EE/develop

Master
  • Loading branch information...
SupraSummus committed Sep 4, 2019
2 parents bb6f052 + 656b263 commit 52315295caa6bc96b9c302fdbeb32203d7ad09c2
@@ -130,4 +130,4 @@ Setup instructions:
1. Set `SALESFORCE_CLIENT_SECRET` for application you are using (determined by `SALESFORCE_CLIENT_ID`).
2. Perform authentication of application instance: `./manage.py salesforce_auth`.
3. Store obtained session id in env variable `SALESFORCE_SESSION_ID`.
3. Store obtained refresh token in env variable `SALESFORCE_REFRESH_TOKEN`.
@@ -120,7 +120,7 @@ def process_offer(self):
settings.DEFAULT_FROM_EMAIL,
[settings.CONTACT_EMAIL],
reply_to=[self.cleaned_data['reply_to']],
).send()
).send(fail_silently=False)

lead = {
'email': self.cleaned_data['reply_to'],
@@ -151,7 +151,7 @@ def process_recruitment(self):
if attachment:
email.attach(attachment.name, attachment.read(), attachment.content_type)

email.send()
email.send(fail_silently=False)

def process_other(self):
EmailMessage(
@@ -160,7 +160,7 @@ def process_other(self):
settings.DEFAULT_FROM_EMAIL,
[settings.CONTACT_EMAIL],
reply_to=[self.cleaned_data['reply_to']],
).send()
).send(fail_silently=False)

def process(self):
handlers = {
@@ -54,7 +54,7 @@ def handle(self, *args, **options):
print('authorized!')
print('server response is:')
pprint(response_data)
print(f"access token is: {response_data['access_token']}")
print(f"refresh token is: {response_data['refresh_token']}")
print("(you need to add it to env variables)")
return
else:
@@ -2,6 +2,7 @@

from django.conf import settings
from simple_salesforce import Salesforce
import requests


logger = logging.getLogger(__name__)
@@ -17,14 +18,37 @@ def __init__(self, name):


class SalesforceDummy:
def __init__(self, name):
def __init__(self, name='salesforce'):
self.Lead = DummyObjectHandler(f'{name}.Lead')


if settings.SALESFORCE_INSTANCE is None:
salesforce = SalesforceDummy('salesforce')
else:
salesforce = Salesforce(
def get_salesforce_integration():
if settings.SALESFORCE_INSTANCE is None:
return SalesforceDummy()

# request new session id (aka. access token)
r = requests.post(
f'https://{settings.SALESFORCE_DOMAIN}.salesforce.com/services/oauth2/token',
data={
'grant_type': 'refresh_token',
'refresh_token': settings.SALESFORCE_REFRESH_TOKEN,
'client_id': settings.SALESFORCE_CLIENT_ID,
'client_secret': settings.SALESFORCE_CLIENT_SECRET,
},
)

# check for authentication failure
try:
r.raise_for_status()
except requests.exceptions.HTTPError as e:
logger.exception('failed to obtain salesforce session id', extra={'response': e.response.text})
return SalesforceDummy()

session_id = r.json()['access_token']
return Salesforce(
instance=settings.SALESFORCE_INSTANCE,
session_id=settings.SALESFORCE_ACCESS_TOKEN,
session_id=session_id,
)


salesforce = get_salesforce_integration()
@@ -253,6 +253,6 @@ def register_extra_features(features):
SALESFORCE_DOMAIN = 'login'
SALESFORCE_INSTANCE = 'laboratoriumee.my.salesforce.com'

SALESFORCE_CLIENT_ID = '3MVG9I5UQ_0k_hTmaSws_TCivIuKUH8XiFhTOBY9TAlIbOu8zhRfYxujafSKRGXISgxS4jyIz1A6LIHePNrnZ'
SALESFORCE_CLIENT_ID = '3MVG9I5UQ_0k_hTmaSws_TCivIpexLZoEP.S63TsK3Sj.3MFQRMclngn44zah.u1dVKpcvH3Bq6d8ejRArxJE'
SALESFORCE_CLIENT_SECRET = env.str('SALESFORCE_CLIENT_SECRET', default=None)
SALESFORCE_ACCESS_TOKEN = env.str('SALESFORCE_ACCESS_TOKEN', default=None)
SALESFORCE_REFRESH_TOKEN = env.str('SALESFORCE_REFRESH_TOKEN', default=None)
@@ -36,9 +36,10 @@ <h1 class="title">{% trans 'Co możemy razem zrobić?' %}</h1>
{% include 'main/partials/form/errors.html' with errors=form.message.errors %}
</div>
<div class="mdl-textfield mdl-js-textfield mdl-textfield--file ee-contact-form__textfield ee-formfield ee-contact-form__attachment">
<input class="mdl-textfield__input" placeholder="{% trans 'załącz plik' %}" type="text" id="{{ form.attachment.id_for_label }}" name="attachment" readonly/>
<input class="mdl-textfield__input" placeholder="{% trans 'załącz plik' %}" type="text" readonly/>
<div class="mdl-button mdl-button--primary mdl-button--icon mdl-button--file">
<i class="material-icons">attach_file</i><input type="file">
<i class="material-icons">attach_file</i>
<input type="file" id="{{ form.attachment.id_for_label }}" name="{{ form.attachment.html_name }}">
</div>
{% include 'main/partials/form/errors.html' with errors=form.attachment.errors %}
</div>

0 comments on commit 5231529

Please sign in to comment.
You can’t perform that action at this time.