-
Notifications
You must be signed in to change notification settings - Fork 8
Add inspiration tab and integrate into generation #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -9,12 +9,16 @@ | |||||
| from core.api.auth import session_auth, superuser_api_auth | ||||||
| from core.api.schemas import ( | ||||||
| AddCompetitorIn, | ||||||
| AddInspirationIn, | ||||||
| AddInspirationOut, | ||||||
| AddKeywordIn, | ||||||
| AddKeywordOut, | ||||||
| AddPricingPageIn, | ||||||
| BlogPostIn, | ||||||
| BlogPostOut, | ||||||
| CompetitorAnalysisOut, | ||||||
| DeleteInspirationIn, | ||||||
| DeleteInspirationOut, | ||||||
| DeleteProjectKeywordIn, | ||||||
| DeleteProjectKeywordOut, | ||||||
| FixGeneratedBlogPostIn, | ||||||
|
|
@@ -52,6 +56,7 @@ | |||||
| Competitor, | ||||||
| Feedback, | ||||||
| GeneratedBlogPost, | ||||||
| Inspiration, | ||||||
| Keyword, | ||||||
| Project, | ||||||
| ProjectKeyword, | ||||||
|
|
@@ -1056,3 +1061,84 @@ def toggle_project_page_always_use(request: HttpRequest, data: ToggleProjectPage | |||||
| "always_use": False, | ||||||
| "message": f"Failed to toggle always use: {str(error)}", | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| @api.post("/inspirations/add", response=AddInspirationOut, auth=[session_auth]) | ||||||
| def add_inspiration(request: HttpRequest, data: AddInspirationIn): | ||||||
| """Add a new inspiration link to a project.""" | ||||||
| profile = request.auth | ||||||
| project = get_object_or_404(Project, id=data.project_id, profile=profile) | ||||||
|
|
||||||
| url_to_add = data.url.strip() | ||||||
|
|
||||||
| if not url_to_add: | ||||||
| return {"status": "error", "message": "URL cannot be empty"} | ||||||
|
|
||||||
| if not url_to_add.startswith(("http://", "https://")): | ||||||
| return {"status": "error", "message": "URL must start with http:// or https://"} | ||||||
|
|
||||||
| try: | ||||||
| if Inspiration.objects.filter(project=project, url=url_to_add).exists(): | ||||||
| return {"status": "error", "message": "This inspiration already exists for your project"} | ||||||
|
|
||||||
| inspiration = Inspiration.objects.create(project=project, url=url_to_add) | ||||||
|
|
||||||
| inspiration.get_page_content() | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: calling
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: core/api/views.py
Line: 1086:1086
Comment:
**logic:** calling `get_page_content()` in the request-response cycle can cause timeout issues as it makes external HTTP requests. Consider moving this to a background task using django-q2
```suggestion
async_task("core.tasks.fetch_inspiration_content", inspiration.id)
```
How can I resolve this? If you propose a fix, please make it concise. |
||||||
|
|
||||||
| logger.info( | ||||||
| "[Add Inspiration] Successfully added inspiration", | ||||||
| inspiration_id=inspiration.id, | ||||||
| project_id=project.id, | ||||||
| url=url_to_add, | ||||||
| ) | ||||||
|
|
||||||
| return { | ||||||
| "status": "success", | ||||||
| "inspiration_id": inspiration.id, | ||||||
| "title": inspiration.title, | ||||||
| "url": inspiration.url, | ||||||
| "message": "Inspiration added successfully!", | ||||||
| } | ||||||
|
|
||||||
| except Exception as e: | ||||||
| logger.error( | ||||||
| "Failed to add inspiration", | ||||||
| error=str(e), | ||||||
| exc_info=True, | ||||||
| project_id=project.id, | ||||||
| url=url_to_add, | ||||||
| ) | ||||||
| return {"status": "error", "message": f"An unexpected error occurred: {str(e)}"} | ||||||
|
|
||||||
|
|
||||||
| @api.post("/inspirations/delete", response=DeleteInspirationOut, auth=[session_auth]) | ||||||
| def delete_inspiration(request: HttpRequest, data: DeleteInspirationIn): | ||||||
| """Delete an inspiration from a project.""" | ||||||
| profile = request.auth | ||||||
|
|
||||||
| try: | ||||||
| inspiration = get_object_or_404( | ||||||
| Inspiration, id=data.inspiration_id, project__profile=profile | ||||||
| ) | ||||||
|
|
||||||
| inspiration_url = inspiration.url | ||||||
| inspiration.delete() | ||||||
|
|
||||||
| logger.info( | ||||||
| "[Delete Inspiration] Successfully deleted inspiration", | ||||||
| inspiration_id=data.inspiration_id, | ||||||
| url=inspiration_url, | ||||||
| profile_id=profile.id, | ||||||
| ) | ||||||
|
|
||||||
| return {"status": "success", "message": f"Inspiration deleted successfully"} | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
f-string is unnecessary here. This can just be a string. Read more. |
||||||
|
|
||||||
| except Exception as e: | ||||||
| logger.error( | ||||||
| "Failed to delete inspiration", | ||||||
| error=str(e), | ||||||
| exc_info=True, | ||||||
| inspiration_id=data.inspiration_id, | ||||||
| profile_id=profile.id, | ||||||
| ) | ||||||
| return {"status": "error", "message": f"Failed to delete inspiration: {str(e)}"} | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code duplication: Similar function exists in core/models.py.
This
add_inspirationsfunction is nearly identical to the one incore/models.py(lines 634-663), with only minor differences in the prompt text. Both functions:Consider extracting a shared utility function to avoid duplication:
Then update the similar function in
core/models.pyto use the same utility.🤖 Prompt for AI Agents