Skip to content
Permalink
Browse files

Merge pull request #227 from EE/develop

Master
  • Loading branch information...
SupraSummus committed Aug 12, 2019
2 parents 335a24f + 88a91df commit 1e9c7449aae49e8a1bbdd7237745a26c82dd5b11
@@ -20,6 +20,7 @@ boto3 = "*"
django-bulma = "*"
django-recaptcha = "*"
django-inline-svg = "*"
simple-salesforce = "*"

[dev-packages]
"flake8" = "*"

Some generated files are not rendered by default. Learn more.

@@ -189,8 +189,18 @@ class LevelBlock(blocks.StructBlock):
('icon', ImageChooserBlock(required=False)),
('value', blocks.CharBlock()),
('property_name', blocks.CharBlock(required=False)),
('page', blocks.PageChooserBlock(required=False)),
]))

def get_context(self, value, *args, **kwargs):
context = super().get_context(value, *args, **kwargs)

# Calculating if we have any icon in the level. Later this is used to decide wether tiles need space for icons.
# (CSS-based approach propably will be better...)
context['has_icons'] = any(tile.get('icon') for tile in value.get('tiles', []))

return context

class Meta:
template = 'main/blocks/level.html'

@@ -247,6 +257,7 @@ class TileGridBlock(blocks.StructBlock):
('image', ImageChooserBlock()),
('title', blocks.CharBlock(required=False)),
('body', blocks.RichTextBlock(features=settings.RICHTEXT_INLINE_FEATURES)),
('page', blocks.PageChooserBlock(required=False)),
]))

class Meta:
@@ -1,10 +1,20 @@
import logging

from captcha.fields import ReCaptchaField
from captcha.widgets import ReCaptchaV2Checkbox
from django import forms
from django.conf import settings
from django.core.mail import EmailMessage
from django.core.validators import validate_email, ValidationError
from django.utils.translation import gettext as _

from simple_salesforce.exceptions import SalesforceError

from .salesforce import salesforce


logger = logging.getLogger(__name__)


RECRUITMENT_TYPE_DEFAULT = 'default'
RECRUITMENT_TYPE_LONGTERM = 'longterm'
@@ -113,6 +123,24 @@ def process_offer(self):
reply_to=[self.cleaned_data['reply_to']],
).send()

lead = {
'company': self.cleaned_data['organization_name'],
'status': 'new',
'lastname': '-',
}

# reply_to may be either email or phone number
try:
validate_email(self.cleaned_data['reply_to'])
lead['email'] = self.cleaned_data['reply_to']
except ValidationError:
lead['phone'] = self.cleaned_data['reply_to']

try:
salesforce.Lead.create(lead)
except SalesforceError:
logger.exception("failed to create salesforce lead object", extra={'lead': lead})

def process_recruitment(self):
recruitment_type = self.cleaned_data['recruitment_type']
if not recruitment_type:
No changes.
No changes.
@@ -0,0 +1,63 @@
from pprint import pprint
import requests

from django.conf import settings
from django.core.management.base import BaseCommand


class Command(BaseCommand):
help = 'authenticate salesforce oauth2 device'

def handle(self, *args, **options):
if settings.SALESFORCE_DOMAIN is None:
print("authentication cannot be done for dummy integration (SALESFORCE_DOMAIN setting is None)")
return

auth_endpoint = f'https://{settings.SALESFORCE_DOMAIN}.salesforce.com/services/oauth2/token'
client_id = settings.SALESFORCE_CLIENT_ID
client_secret = settings.SALESFORCE_CLIENT_SECRET

with requests.Session() as session:

# request app authorization by a user
r = session.post(
auth_endpoint,
data={
'response_type': 'device_code',
'client_id': client_id,
},
)
r.raise_for_status()

verification_uri = r.json()['verification_uri']
user_code = r.json()['user_code']
device_code = r.json()['device_code']

# wait for authorization
while True:
input(
f"visit {verification_uri} in your browser and enter the code {user_code} "
"(and then hit enter here)"
)
response = session.post(
auth_endpoint,
params={
'grant_type': 'device',
'code': device_code,
'client_id': client_id,
'client_secret': client_secret,
},
)
response_data = response.json()

if response.status_code == 200:
print('authorized!')
print('server response is:')
pprint(response_data)
print(f"access token is: {response_data['access_token']}")
print("(you need to add it to env variables)")
return
else:
print('authorization failed')
print('server response is:')
pprint(response_data)

0 comments on commit 1e9c744

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