Skip to content

Commit

Permalink
Prepare notion calls
Browse files Browse the repository at this point in the history
  • Loading branch information
fabienheureux committed Jan 15, 2025
1 parent 33330b7 commit edde69e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ STIMULUS_DEBUG=false
POSTHOG_DEBUG=false
ASSISTANT_MATOMO_ID=82
ASSISTANT_POSTHOG_KEY=phc_fSfhoWDOUxZdKWty16Z3XfRiAoWd1qdJK0N0z9kQHJr # [DEV] project
NOTION_TOKEN=
NOTION_CONTACT_FORM_DATABASE_ID=17c6523d57d78140b87f000cd3ecef4b # Correspond à https://www.notion.so/accelerateur-transition-ecologique-ademe/17c6523d57d7808b8cc5f5ccae264f7c?v=17c6523d57d78140b87f000cd3ecef4b&pvs=4
34 changes: 34 additions & 0 deletions core/notion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import requests
from django.conf import settings

# Replace these with your details
NOTION_TOKEN = settings.NOTION_TOKEN


def fill_database(database_id):
headers = {
"Authorization": f"Bearer {NOTION_TOKEN}",
"Content-Type": "application/json",
"Notion-Version": "2022-06-28", # Use the correct version of the API
}

# Payload to create a new row
payload = {
"parent": {"database_id": database_id},
"properties": {
"Name": {"title": [{"text": {"content": "Sample Row"}}]},
"Status": {"select": {"name": "In Progress"}},
"Date": {"date": {"start": "2025-01-15"}},
},
}

# Make the API request
response = requests.post(
"https://api.notion.com/v1/pages", headers=headers, json=payload
)

# Check response
if response.status_code == 200:
print("Row added successfully!")
else:
print("Failed to add row:", response.status_code, response.text)
5 changes: 5 additions & 0 deletions core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,3 +388,8 @@ def context_processors():
cast=str,
),
}

NOTION = {
"TOKEN": decouple.config("NOTION_TOKEN", default=""),
"CONTACT_FORM_DATABASE_ID": decouple.config("NOTION_CONTACT_FORM_DATABASE_ID"),
}
5 changes: 4 additions & 1 deletion qfdmd/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.urls import reverse_lazy
from django.views.generic import DetailView, FormView, ListView

from core.notion import create_new_row_in
from qfdmd.forms import ContactForm, SearchForm
from qfdmd.models import CMSPage, Suggestion, Synonyme

Expand Down Expand Up @@ -46,7 +47,9 @@ class ContactFormView(FormView):
success_url = reverse_lazy("qfdmd:nous-contacter-confirmation")

def form_valid(self, form):
logger.error(f"{form=}")
create_new_row_in(
settings.NOTION.get("CONTACT_FORM_DATABASE_ID"), form.cleaned_data
)
return super().form_valid(form)


Expand Down

0 comments on commit edde69e

Please sign in to comment.