OLD | NEW |
(Empty) | |
| 1 # Copyright 2014 Google Inc. |
| 2 |
| 3 """Classes that handle internal and external API requests. |
| 4 |
| 5 Each FooCollection class implements methods to create and search entities, and |
| 6 each Foo class implements operations on individual entities. All handlers take |
| 7 all inputs in keyword arguments and return a python dict that will become a JSON |
| 8 response to the browser, or by used by a UI servlet. |
| 9 """ |
| 10 |
| 11 from v2 import servlet |
| 12 |
| 13 |
| 14 class IssueCollectionJSON(servlet.EchoJSON): |
| 15 """Placeholder until we implement real JSON request handlers.""" |
| 16 |
| 17 # Map each HTTP method to a more meaningful name. |
| 18 def get(self, **kwargs): return self.search_issues(**kwargs) |
| 19 def post(self, **kwargs): return self.create_issue(**kwargs) |
| 20 |
| 21 def search_issues(self, **kwargs): |
| 22 return self.echo(**kwargs) |
| 23 |
| 24 def parse_request(self, request, **kwargs): |
| 25 typed_kwargs = super(self, IssueCollectionJSON).parse_request( |
| 26 request, **kwargs) |
| 27 typed_kwargs.update( |
| 28 subject=request.POST.get('subject'), |
| 29 ) |
| 30 return typed_kwargs |
| 31 |
| 32 def create_issue( |
| 33 self, subject=None, description=None, owner=None, cc=None, |
| 34 reviewers=None, private=False, **unused_kwargs): |
| 35 """Create an Issue entity, store it, and return it in JSON.""" |
| 36 issue = models.Issue( |
| 37 subject=subject, description=description, owner=owner, cc=cc, |
| 38 private=private, n_comments=0) |
| 39 issue.put() |
| 40 return issue.to_dict() |
| 41 |
| 42 |
| 43 class IssueJSON(servlet.EchoJSON): |
| 44 """Placeholder until we implement real JSON request handlers.""" |
| 45 |
| 46 # Map each HTTP method to a more meaningful name. |
| 47 def get(self, **kwargs): return self.get_issue(**kwargs) |
| 48 def put(self, **kwargs): return self.update_issue(**kwargs) |
| 49 def delete(self, **kwargs): return self.delete_issue(**kwargs) |
| 50 |
| 51 def get_issue(self, issue=None, **kwargs): |
| 52 if not issue: self.abort(404) |
| 53 return issue.to_dict() |
| 54 |
| 55 def update_issue( |
| 56 self, subject=None, description=None, owner=None, cc=None, |
| 57 private=None, **unused_kwargs): |
| 58 if not issue: self.abort(404) |
| 59 if not issue.edit_allowed: self.abort(403) |
| 60 |
| 61 if subject is not None: |
| 62 issue.subject = subject |
| 63 if description is not None: |
| 64 issue.description = description |
| 65 if owner is not None: |
| 66 issue.owner = owner |
| 67 if cc is not None: |
| 68 issue.cc = cc |
| 69 if private is not None: |
| 70 issue.private = private |
| 71 return issue.to_dict() |
| 72 |
| 73 def delete_issue(self, **kwargs): |
| 74 return self.echo(**kwargs) |
| 75 |
| 76 |
| 77 class PatchsetCollectionJSON(servlet.EchoJSON): |
| 78 """Placeholder until we implement real JSON request handlers.""" |
| 79 |
| 80 # Map each HTTP method to a more meaningful name. |
| 81 def get(self, **kwargs): return self.get_issue_patchsets(**kwargs) |
| 82 def post(self, **kwargs): return self.create_patchset(**kwargs) |
| 83 |
| 84 def get_issue_patchsets(self, **kwargs): |
| 85 return self.echo(**kwargs) |
| 86 |
| 87 def create_patchset(self, **kwargs): |
| 88 return self.echo(**kwargs) |
| 89 |
| 90 |
| 91 class PatchsetJSON(servlet.EchoJSON): |
| 92 """Placeholder until we implement real JSON request handlers.""" |
| 93 |
| 94 # Map each HTTP method to a more meaningful name. |
| 95 def get(self, **kwargs): return self.get_patchset(**kwargs) |
| 96 def delete(self, **kwargs): return self.delete_patchset(**kwargs) |
| 97 |
| 98 def get_patchset(self, **kwargs): |
| 99 return self.echo(**kwargs) |
| 100 |
| 101 def delete_patchset(self, **kwargs): |
| 102 return self.echo(**kwargs) |
| 103 |
| 104 |
| 105 class PatchCollectionJSON(servlet.EchoJSON): |
| 106 """Placeholder until we implement real JSON request handlers.""" |
| 107 |
| 108 # Map each HTTP method to a more meaningful name. |
| 109 def get(self, **kwargs): return self.get_patchset_patches(**kwargs) |
| 110 def post(self, **kwargs): return self.create_patch(**kwargs) |
| 111 |
| 112 def get_patchset_patches(self, **kwargs): |
| 113 return self.echo(**kwargs) |
| 114 |
| 115 def create_patch(self, **kwargs): |
| 116 return self.echo(**kwargs) |
| 117 |
| 118 |
| 119 class PatchJSON(servlet.EchoJSON): |
| 120 """Placeholder until we implement real JSON request handlers.""" |
| 121 |
| 122 # Map each HTTP method to a more meaningful name. |
| 123 def get(self, **kwargs): return self.get_patch(**kwargs) |
| 124 |
| 125 def get_patch(self, **kwargs): |
| 126 return self.echo(**kwargs) |
| 127 |
| 128 |
| 129 class MessageCollectionJSON(servlet.EchoJSON): |
| 130 """Placeholder until we implement real JSON request handlers.""" |
| 131 |
| 132 # Map each HTTP method to a more meaningful name. |
| 133 def get(self, **kwargs): return self.get_issue_patchsets(**kwargs) |
| 134 def post(self, **kwargs): return self.create_patchset(**kwargs) |
| 135 |
| 136 def get_issue_messages(self, **kwargs): |
| 137 return self.echo(**kwargs) |
| 138 |
| 139 def create_message(self, **kwargs): |
| 140 return self.echo(**kwargs) |
| 141 |
| 142 |
| 143 class MessageJSON(servlet.EchoJSON): |
| 144 """Placeholder until we implement real JSON request handlers.""" |
| 145 |
| 146 # Map each HTTP method to a more meaningful name. |
| 147 def get(self, **kwargs): return self.get_message(**kwargs) |
| 148 def delete(self, **kwargs): return self.delete_message(**kwargs) |
| 149 |
| 150 def get_message(self, **kwargs): |
| 151 return self.echo(**kwargs) |
| 152 |
| 153 def delete_message(self, **kwargs): |
| 154 return self.echo(**kwargs) |
| 155 |
| 156 |
| 157 class CommentCollectionJSON(servlet.EchoJSON): |
| 158 """Placeholder until we implement real JSON request handlers.""" |
| 159 |
| 160 # Map each HTTP method to a more meaningful name. |
| 161 def get(self, **kwargs): return self.get_issue_comments(**kwargs) |
| 162 def post(self, **kwargs): return self.create_comment(**kwargs) |
| 163 |
| 164 def get_issue_comments(self, **kwargs): |
| 165 return self.echo(**kwargs) |
| 166 |
| 167 def create_comment(self, **kwargs): |
| 168 return self.echo(**kwargs) |
| 169 |
| 170 |
| 171 class CommentJSON(servlet.EchoJSON): |
| 172 """Placeholder until we implement real JSON request handlers.""" |
| 173 |
| 174 # Map each HTTP method to a more meaningful name. |
| 175 def get(self, **kwargs): return self.get_comment(**kwargs) |
| 176 def put(self, **kwargs): return self.update_comment(**kwargs) |
| 177 def delete(self, **kwargs): return self.delete_comment(**kwargs) |
| 178 |
| 179 def get_comment(self, **kwargs): |
| 180 return self.echo(**kwargs) |
| 181 |
| 182 def get_comment(self, **kwargs): |
| 183 return self.echo(**kwargs) |
| 184 |
| 185 def delete_delete(self, **kwargs): |
| 186 return self.echo(**kwargs) |
OLD | NEW |