SomethingGeneric / flaskpress

Wordpress but it's actually Python + Flask
GNU General Public License v3.0
0 stars 0 forks source link

Sweep: Implement saving a post as markdown #6

Closed SomethingGeneric closed 1 year ago

SomethingGeneric commented 1 year ago

Details

In line 47 of main.py, handle an incoming post request with a markdown text attribute, and save to an appropriate file name under the (presumed) pages/ directory, so that the /pages endpoint can then load it. Ideally, return a redirect to the appropriate /pages/ endpoint.

Checklist - [X] `main.py` > • Modify the `post()` function to extract the markdown text from the incoming POST request. You can access the markdown text using `request.form.get('markdown')`. > • In the `post()` function, generate a unique filename for the new post. One way to do this is to use the current timestamp, like so: `filename = f"{time.time()}.md"`. > • Still in the `post()` function, check if the `pages/` directory exists. If it does not, create it using `os.makedirs('pages')`. > • Next, in the `post()` function, open a new file in the `pages/` directory with the generated filename and write the markdown text to it. > • Finally, modify the `post()` function to return a redirect to the new post's page. You can do this with `return redirect(url_for('page', filename=filename))`.
sweep-ai[bot] commented 1 year ago

Here's the PR! https://github.com/SomethingGeneric/flaskpress/pull/7.

⚡ Sweep Free Trial: I used GPT-3.5 to create this ticket. You have 3 GPT-4 tickets left for the month and 0 for the day. For more GPT-4 tickets, visit our payment portal. To retrigger Sweep, edit the issue.


Step 1: 🔍 Code Search

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I looked at (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/SomethingGeneric/flaskpress/blob/8b4314d1c19c16751ead02badd06ee2e8240f90f/tests/test_main.py#L1-L26 https://github.com/SomethingGeneric/flaskpress/blob/8b4314d1c19c16751ead02badd06ee2e8240f90f/main.py#L1-L64 https://github.com/SomethingGeneric/flaskpress/blob/8b4314d1c19c16751ead02badd06ee2e8240f90f/README.md#L1-L1 https://github.com/SomethingGeneric/flaskpress/blob/8b4314d1c19c16751ead02badd06ee2e8240f90f/sweep.yaml#L1-L13 https://github.com/SomethingGeneric/flaskpress/blob/8b4314d1c19c16751ead02badd06ee2e8240f90f/LICENSE#L1-L48

Step 2: 🧐 Snippet Analysis

From looking through the relevant snippets, I decided to make the following modifications:

File Path Proposed Changes
main.py Modify main.py with contents:
• Modify the post() function to extract the markdown text from the incoming POST request. You can access the markdown text using request.form.get('markdown').
• In the post() function, generate a unique filename for the new post. One way to do this is to use the current timestamp, like so: filename = f"{time.time()}.md".
• Still in the post() function, check if the pages/ directory exists. If it does not, create it using os.makedirs('pages').
• Next, in the post() function, open a new file in the pages/ directory with the generated filename and write the markdown text to it.
• Finally, modify the post() function to return a redirect to the new post's page. You can do this with return redirect(url_for('page', filename=filename)).

Step 3: 📝 Planning

I have created a plan for writing the pull request. I am now working my plan and coding the required changes to address this issue. Here is the planned pull request:

Implement saving a post as markdown sweep/save-post-as-markdown

Description

This PR implements the functionality to save a post as a markdown file in the Flaskpress application. It modifies the post() function in main.py to handle incoming POST requests with a markdown text attribute. The markdown text is extracted from the request, and a unique filename is generated for the new post. The markdown file is then saved in the pages/ directory. If the pages/ directory does not exist, it is created. After saving the markdown file, the post() function returns a redirect to the new post's page.

Summary of Changes

  • Modified the post() function in main.py to handle incoming POST requests with a markdown text attribute.
  • Extracted the markdown text from the request using request.form.get('markdown').
  • Generated a unique filename for the new post using the current timestamp.
  • Checked if the pages/ directory exists and created it if it does not.
  • Opened a new file in the pages/ directory with the generated filename and wrote the markdown text to it.
  • Modified the post() function to return a redirect to the new post's page using return redirect(url_for('page', filename=filename)).

Step 4: ⌨️ Coding

File Instructions Progress Error logs
main.py Modify main.py with contents:
• Modify the post() function to extract the markdown text from the incoming POST request. You can access the markdown text using request.form.get('markdown').
• In the post() function, generate a unique filename for the new post. One way to do this is to use the current timestamp, like so: filename = f"{time.time()}.md".
• Still in the post() function, check if the pages/ directory exists. If it does not, create it using os.makedirs('pages').
• Next, in the post() function, open a new file in the pages/ directory with the generated filename and write the markdown text to it.
• Finally, modify the post() function to return a redirect to the new post's page. You can do this with return redirect(url_for('page', filename=filename)).
✅ Commit 2dd49d5 No errors. I have finished coding the issue. I am now reviewing it for completeness.

Step 5: 🔁 Code Review

Here are my self-reviews of my changes at sweep/save-post-as-markdown.

Here is the 1st review

No changes required. The implemented functionality correctly handles the saving of a post as a markdown file in the 'pages' directory and redirects to the 'page' endpoint with the filename as a parameter. Good job!

I finished incorporating these changes.


🎉 Latest improvements to Sweep:


💡 To recreate the pull request edit the issue title or description. Join Our Discord