mirror of
				https://github.com/zulip/zulip.git
				synced 2025-10-30 19:43:47 +00:00 
			
		
		
		
	The main reason why this is needed is because this seems to be convention and because we can't easily test event creation without doing this. Signed-off-by: Hemanth V. Alluri <hdrive1999@gmail.com>
		
			
				
	
	
		
			55 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			55 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| from typing import Any, Dict, List
 | |
| 
 | |
| from django.http import HttpRequest, HttpResponse
 | |
| 
 | |
| from zerver.lib.drafts import (
 | |
|     do_create_drafts,
 | |
|     do_delete_draft,
 | |
|     do_edit_draft,
 | |
|     draft_dict_validator,
 | |
|     draft_endpoint,
 | |
| )
 | |
| from zerver.lib.request import REQ, has_request_variables
 | |
| from zerver.lib.response import json_success
 | |
| from zerver.lib.validator import check_list
 | |
| from zerver.models import Draft, UserProfile
 | |
| 
 | |
| 
 | |
| @draft_endpoint
 | |
| def fetch_drafts(request: HttpRequest, user_profile: UserProfile) -> HttpResponse:
 | |
|     user_drafts = Draft.objects.filter(user_profile=user_profile).order_by("last_edit_time")
 | |
|     draft_dicts = [draft.to_dict() for draft in user_drafts]
 | |
|     return json_success({"count": user_drafts.count(), "drafts": draft_dicts})
 | |
| 
 | |
| 
 | |
| @draft_endpoint
 | |
| @has_request_variables
 | |
| def create_drafts(
 | |
|     request: HttpRequest,
 | |
|     user_profile: UserProfile,
 | |
|     draft_dicts: List[Dict[str, Any]] = REQ(
 | |
|         "drafts", json_validator=check_list(draft_dict_validator)
 | |
|     ),
 | |
| ) -> HttpResponse:
 | |
|     created_draft_objects = do_create_drafts(draft_dicts, user_profile)
 | |
|     draft_ids = [draft_object.id for draft_object in created_draft_objects]
 | |
|     return json_success({"ids": draft_ids})
 | |
| 
 | |
| 
 | |
| @draft_endpoint
 | |
| @has_request_variables
 | |
| def edit_draft(
 | |
|     request: HttpRequest,
 | |
|     user_profile: UserProfile,
 | |
|     draft_id: int,
 | |
|     draft_dict: Dict[str, Any] = REQ("draft", json_validator=draft_dict_validator),
 | |
| ) -> HttpResponse:
 | |
|     do_edit_draft(draft_id, draft_dict, user_profile)
 | |
|     return json_success()
 | |
| 
 | |
| 
 | |
| @draft_endpoint
 | |
| def delete_draft(request: HttpRequest, user_profile: UserProfile, draft_id: int) -> HttpResponse:
 | |
|     do_delete_draft(draft_id, user_profile)
 | |
|     return json_success()
 |