-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ajout du formulaire de contact dans l'assistant (#1190)
* Ajout du formulaire de contact dans l'assistant * Update template * Prepare ntion calls * Fix Notion payload on form submission * Format * Update core/notion.py Co-authored-by: Nicolas Oudard <[email protected]> --------- Co-authored-by: Nicolas Oudard <[email protected]>
- Loading branch information
1 parent
b7ee1ec
commit 856efc2
Showing
8 changed files
with
147 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import logging | ||
|
||
import requests | ||
from django.conf import settings | ||
from django.utils import timezone | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def create_new_row_in_notion_table(database_id, data): | ||
notion_token = settings.NOTION.get("TOKEN") | ||
if not notion_token: | ||
logging.error("The notion token is not set in local environment") | ||
return | ||
|
||
headers = { | ||
"Authorization": f"Bearer {notion_token}", | ||
"Content-Type": "application/json", | ||
"Notion-Version": "2022-06-28", | ||
} | ||
|
||
payload = { | ||
"parent": {"database_id": database_id}, | ||
"properties": { | ||
"Nom": {"title": [{"text": {"content": data.get("name")}}]}, | ||
"Email": {"email": data.get("email")}, | ||
"Objet": {"rich_text": [{"text": {"content": data.get("subject")}}]}, | ||
"Message": {"rich_text": [{"text": {"content": data.get("message")}}]}, | ||
"Date": {"date": {"start": timezone.now().isoformat()}}, | ||
}, | ||
} | ||
|
||
response = requests.post( | ||
"https://api.notion.com/v1/pages", headers=headers, json=payload | ||
) | ||
|
||
if response.status_code == 200: | ||
logger.info("New contact form submission") | ||
else: | ||
logger.error(f"Failed to add row:{response.status_code=}, {response.text=}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<turbo-frame id='contact-form'> | ||
<form | ||
method="post" | ||
action="{% url 'qfdmd:nous-contacter' %}" | ||
> | ||
{% csrf_token %} | ||
{% if request.resolver_match.url_name == 'nous-contacter' %} | ||
{{ form }} | ||
<button class="fr-btn" type="submit"> | ||
Envoyer mon message | ||
</button> | ||
{% else %} | ||
<div class="qf-flex qf-flex-row qf-gap-1w qf-items-center"> | ||
<span class="fr-icon--lg fr-icon fr-icon-success-fill" aria-hidden="true"></span> | ||
|
||
<span> | ||
Votre message a bien été envoyé | ||
</span> | ||
</div> | ||
{% endif %} | ||
</form> | ||
</turbo-frame> |