home » zplus/freepost.git
Author zPlus <zplus@peers.community> 2018-07-18 22:20:45
Committer zPlus <zplus@peers.community> 2018-07-18 22:20:45
Commit f67dca1 (patch)
Tree a390ece
Parent(s)

Add some comments to controllers. modified: freepost/__init__.py


commits diff: 975f0d9..f67dca1
1 file changed, 95 insertions, 0 deletionsdownload


Diffstat
-rwxr-xr-x freepost/__init__.py 95

Diff options
View
Side
Whitespace
Context lines
Inter-hunk lines
+95/-0 M   freepost/__init__.py
index 60a9b36..783bd10
old size: 23K - new size: 24K
@@ -103,6 +103,10 @@ def requires_logout (controller):
103 103
104 104 @get ('/', name='homepage')
105 105 def homepage ():
106 + """
107 + Display homepage with posts sorted by 'hot'.
108 + """
109 +
106 110 # Page number
107 111 page = int (request.query.page or 0)
108 112
@@ -120,6 +124,10 @@ def homepage ():
120 124
121 125 @get ('/new', name='new')
122 126 def new ():
127 + """
128 + Display homepage with posts sorted by 'new'.
129 + """
130 +
123 131 # Page number
124 132 page = int (request.query.page or 0)
125 133
@@ -137,16 +145,28 @@ def new ():
137 145
138 146 @get ('/about', name='about')
139 147 def about ():
148 + """
149 + Display "About" page.
150 + """
151 +
140 152 return template ('about.html')
141 153
142 154 @get ('/login', name='login')
143 155 @requires_logout
144 156 def login ():
157 + """
158 + The login page.
159 + """
160 +
145 161 return template ('login.html')
146 162
147 163 @post ('/login')
148 164 @requires_logout
149 165 def login_check ():
166 + """
167 + Check login form.
168 + """
169 +
150 170 username = request.forms.get ('username')
151 171 password = request.forms.get ('password')
152 172 remember = 'remember' in request.forms
@@ -177,11 +197,19 @@ def login_check ():
177 197 @get ('/register', name='register')
178 198 @requires_logout
179 199 def register ():
200 + """
201 + Register new account.
202 + """
203 +
180 204 return template ('register.html')
181 205
182 206 @post ('/register')
183 207 @requires_logout
184 208 def register_new_account ():
209 + """
210 + Check form for creating new account.
211 + """
212 +
185 213 username = request.forms.get ('username')
186 214 password = request.forms.get ('password')
187 215
@@ -220,6 +248,10 @@ def register_new_account ():
220 248 @get ('/logout', name='logout')
221 249 @requires_login
222 250 def logout ():
251 + """
252 + Logout user and return to homepage.
253 + """
254 +
223 255 session.close ()
224 256
225 257 redirect (application.get_url ('homepage'))
@@ -227,11 +259,20 @@ def logout ():
227 259 @get ('/password_reset', name='password_reset')
228 260 @requires_logout
229 261 def password_reset ():
262 + """
263 + Display form to reset users password.
264 + """
265 +
230 266 return template ('login_reset.html')
231 267
232 268 @post ('/password_reset', name='password_reset_send_code')
233 269 @requires_logout
234 270 def password_reset_send_code ():
271 + """
272 + Validate form for resetting password, and if valid send secret
273 + code via email.
274 + """
275 +
235 276 username = request.forms.get ('username')
236 277 email = request.forms.get ('email')
237 278
@@ -276,11 +317,21 @@ def password_reset_send_code ():
276 317 @get ('/change_password', name='change_password')
277 318 @requires_logout
278 319 def change_password ():
320 + """
321 + After the secret code was sent via email, display this form where
322 + the user can insert the secret code + new password.
323 + """
324 +
279 325 return template ('login_change_password.html')
280 326
281 327 @post ('/change_password', name='validate_new_password')
282 328 @requires_logout
283 329 def validate_new_password ():
330 + """
331 + Validate the new password, check the secret code, and if everything
332 + is OK change the user password.
333 + """
334 +
284 335 username = request.forms.get ('username')
285 336 email = request.forms.get ('email')
286 337 password = request.forms.get ('password')
@@ -322,11 +373,19 @@ def validate_new_password ():
322 373 @get ('/user', name='user')
323 374 @requires_login
324 375 def user_private_homepage ():
376 + """
377 + A user's personal page.
378 + """
379 +
325 380 return template ('user_private_homepage.html')
326 381
327 382 @post ('/user')
328 383 @requires_login
329 384 def update_user ():
385 + """
386 + Update user info (about, email, ...).
387 + """
388 +
330 389 user = session.user ()
331 390
332 391 about = request.forms.get ('about')
@@ -367,6 +426,10 @@ def user_replies ():
367 426
368 427 @get ('/user/<username>', name='user_public')
369 428 def user_public_homepage (username):
429 + """
430 + Display a publicly accessible page with public info about the user.
431 + """
432 +
370 433 account = database.get_user_by_username (username)
371 434
372 435 if account is None:
@@ -376,6 +439,10 @@ def user_public_homepage (username):
376 439
377 440 @get ('/post/<hash_id>', name='post')
378 441 def post_thread (hash_id):
442 + """
443 + Display a single post with all its comments.
444 + """
445 +
379 446 user = session.user ()
380 447 post = database.get_post (hash_id, user['id'] if user else None)
381 448 comments = database.get_post_comments (post['id'], user['id'] if user else None)
@@ -511,11 +578,19 @@ def edit_comment_check (hash_id):
511 578 @get ('/submit')
512 579 @requires_login
513 580 def submit ():
581 + """
582 + Submit a new post.
583 + """
584 +
514 585 return template ('submit.html')
515 586
516 587 @post ('/submit')
517 588 @requires_login
518 589 def submit_check ():
590 + """
591 + Check submission of new post.
592 + """
593 +
519 594 # Somebody sent a <form> without a title???
520 595 if not request.forms.get ('title'):
521 596 abort ()
@@ -597,6 +672,10 @@ def reply_check (hash_id):
597 672 @requires_login
598 673 @post ('/vote', name='vote')
599 674 def vote ():
675 + """
676 + Handle upvotes and downvotes.
677 + """
678 +
600 679 user = session.user ()
601 680
602 681 # Vote a post
@@ -677,6 +756,10 @@ def vote ():
677 756
678 757 @get ('/search')
679 758 def search ():
759 + """
760 + Search content on this instance, and display the results.
761 + """
762 +
680 763 # Get the search query
681 764 query = request.query.get ('q')
682 765
@@ -694,11 +777,19 @@ def search ():
694 777
695 778 @get ('/rss')
696 779 def rss_default ():
780 + """
781 + Redirect base RSS URL to default "hot" feed.
782 + """
783 +
697 784 return redirect (application.get_url ('rss', sorting='hot'))
698 785
699 786 # TODO check if <description> is correctly displayed in RSS aggregators
700 787 @get ('/rss/<sorting>', name='rss')
701 788 def rss (sorting):
789 + """
790 + Output an RSS feed of posts.
791 + """
792 +
702 793 posts = []
703 794
704 795 # Retrieve the hostname from the HTTP request.
@@ -718,6 +809,10 @@ def rss (sorting):
718 809
719 810 @get ('/<filename:path>', name='static')
720 811 def static (filename):
812 + """
813 + Serve static files.
814 + """
815 +
721 816 return static_file (filename, root='freepost/static/')
722 817
723 818