Skip to content

Commit 5805544

Browse files
committed
refactor: code format with ruff #138
1 parent 7a19f4d commit 5805544

26 files changed

+333
-220
lines changed

app.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,13 @@
117117
) # Importing CSRF protection for Flask forms
118118

119119
# Importing database related utilities
120-
from utils.dbChecker import dbFolder, usersTable, postsTable, commentsTable, analyticsTable
120+
from utils.dbChecker import (
121+
dbFolder,
122+
usersTable,
123+
postsTable,
124+
commentsTable,
125+
analyticsTable,
126+
)
121127

122128
# Importing various configuration variables from the modules
123129
from modules import (
@@ -198,7 +204,7 @@
198204
browserLanguage, # A function that sets the app language based on the browser's preferred language
199205
injectTranslations, # A function that injects translations into the context of the application
200206
returnUserProfilePicture, # A function that returns the user's profile picture
201-
returnPostUrlID # A function that returns the post's URL id
207+
returnPostUrlID, # A function that returns the post's URL id
202208
)
203209

204210
# Create a Flask app object with the app name, root path, static folder and template folder
@@ -234,7 +240,7 @@
234240
) # A context processor that adds the getProfilePicture variable to the template context
235241
app.context_processor(
236242
returnPostUrlID
237-
) # A context processor that adds the getPostUrlIdFromPost variable to template context
243+
) # A context processor that adds the getPostUrlIdFromPost variable to template context
238244
app.context_processor(
239245
injectTranslations
240246
) # A context processor that adds the translations variable to the template context
@@ -315,9 +321,9 @@
315321
Log.app(f"reCAPTCHA badge: {RECAPTCHA_BADGE}")
316322
# Log the recaptcha settings for different actions
317323
Log.app(f"reCAPTCHA login: {RECAPTCHA_LOGIN}")
318-
Log.app(f"reCAPTCHA sign up: {RECAPTCHA_SIGN_UP }")
324+
Log.app(f"reCAPTCHA sign up: {RECAPTCHA_SIGN_UP}")
319325
Log.app(f"reCAPTCHA post create: {RECAPTCHA_POST_CREATE}")
320-
Log.app(f"reCAPTCHA post edit: {RECAPTCHA_POST_EDIT }")
326+
Log.app(f"reCAPTCHA post edit: {RECAPTCHA_POST_EDIT}")
321327
Log.app(f"reCAPTCHA post delete: {RECAPTCHA_POST_DELETE}")
322328
Log.app(f"reCAPTCHA comment: {RECAPTCHA_COMMENT}")
323329
Log.app(f"reCAPTCHA comment delete: {RECAPTCHA_COMMENT_DELETE}")
@@ -464,10 +470,10 @@ def afterRequest(response):
464470
) # Registering the blueprint for the change profile picture route
465471
app.register_blueprint(
466472
analyticsBlueprint
467-
) # Registering the blueprint for the analytics page route
473+
) # Registering the blueprint for the analytics page route
468474
app.register_blueprint(
469475
returnPostAnalyticsDataBlueprint
470-
) # Registering the blueprint for the postAnalyticsData endpoint route
476+
) # Registering the blueprint for the postAnalyticsData endpoint route
471477

472478
# Check if the name of the module is the main module
473479
match __name__:

constants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
LANGUAGES = ["en", "tr", "es", "de", "zh", "fr", "uk", "ru", "pt", "ja", "pl"] # (list)
4444

4545
# Enable or Disable analytics feature for posts
46-
ANALYTICS = True # (bool)
46+
ANALYTICS = True # (bool)
4747

4848
### LOGGER SETTINGS ###
4949
# Toggle custom logging feature
@@ -84,7 +84,7 @@
8484
DB_COMMENTS_ROOT = DB_FOLDER_ROOT + "comments.db" # (str)
8585

8686
# Root path of the analytics database
87-
DB_ANALYTICS_ROOT = DB_FOLDER_ROOT + "analytics.db" # (str)
87+
DB_ANALYTICS_ROOT = DB_FOLDER_ROOT + "analytics.db" # (str)
8888

8989

9090
### SMTP MAIL SETTINGS ###

modules.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
from json import load # Importing load function from json module
2222
import uuid # UUID (Universally Unique Identifier) generation
2323
from re import sub # Importing sub function from re module
24-
import requests # Importing requests module for http requests
25-
from user_agents import parse # Importing parse function to parsing user agent string
26-
import geoip2 # Importing geoip2.databse
27-
from geoip2 import database # Importing geoip2.databse
24+
import requests # Importing requests module for http requests
25+
from user_agents import parse # Importing parse function to parsing user agent string
26+
import geoip2 # Importing geoip2.databse
27+
from geoip2 import database # Importing geoip2.databse
2828

2929
# Importing constants
3030
from constants import *
@@ -68,7 +68,7 @@
6868
send_file, # Sends a file to the client
6969
render_template, # Renders HTML templates
7070
send_from_directory, # Sends a file from a directory to the client
71-
make_response, # Sends a response to client
71+
make_response, # Sends a response to client
7272
)
7373

7474
# Importing the 'flashMessage' function from the 'utils.flashMessage' module for displaying flash messages.
@@ -114,7 +114,7 @@
114114
from utils.contextProcessor.returnUserProfilePicture import returnUserProfilePicture
115115

116116
# importing the 'returnPostUrlID' context processor from the 'utils.contextProcessor.returnPostUrlID' module
117-
from utils.contextProcessor.returnPostUrlID import returnPostUrlID
117+
from utils.contextProcessor.returnPostUrlID import returnPostUrlID
118118

119119
# Importing the 'Delete' class from the 'utils.delete' module for handling delete operations.
120120
from utils.delete import Delete
@@ -129,4 +129,8 @@
129129
from utils.getDataFromUserIP import getDataFromUserIP
130130

131131
# Importing the getAnalyticsPageCountryGraphData, getAnalyticsPageOSGraphData, getAnalyticsPageTrafficGraphData for analytics
132-
from utils.getAnalyticsPageData import getAnalyticsPageCountryGraphData, getAnalyticsPageOSGraphData, getAnalyticsPageTrafficGraphData
132+
from utils.getAnalyticsPageData import (
133+
getAnalyticsPageCountryGraphData,
134+
getAnalyticsPageOSGraphData,
135+
getAnalyticsPageTrafficGraphData,
136+
)

routes/accountSettings.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ def accountSettings():
5555
url=f"{RECAPTCHA_VERIFY_URL}?secret={RECAPTCHA_SECRET_KEY}&response={secretResponse}"
5656
).json()
5757
# Check if the reCAPTCHA verification is successful or has a high score
58-
match verifyResponse["success"] == True or verifyResponse[
59-
"score"
60-
] > 0.5:
58+
match (
59+
verifyResponse["success"] == True
60+
or verifyResponse["score"] > 0.5
61+
):
6162
case True:
6263
# Log the reCAPTCHA verification result
6364
Log.success(

routes/adminPanel.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ def adminPanel():
3737
# Check if the user role is admin
3838
match role == "admin":
3939
case True:
40-
4140
# Log info message that the admin reached to the admin panel
42-
Log.info(f'Admin: {session["userName"]} reached to the admin panel')
41+
Log.info(f"Admin: {session['userName']} reached to the admin panel")
4342
# Log a message that admin panel loaded
4443
Log.info(f"Rendering adminPanel.html.jinja: params: None")
4544
# Render the admin panel template

routes/changePassword.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ def changePassword():
8888
language=session["language"],
8989
) # Display a flash message
9090
# Check if old password is different from new password and passwords match
91-
match oldPassword != password and password == passwordConfirm:
91+
match (
92+
oldPassword != password and password == passwordConfirm
93+
):
9294
case True:
9395
# Hash the new password
9496
newPassword = encryption.hash(password)
@@ -112,9 +114,10 @@ def changePassword():
112114
url=f"{RECAPTCHA_VERIFY_URL}?secret={RECAPTCHA_SECRET_KEY}&response={secretResponse}"
113115
).json()
114116
# Check if reCAPTCHA verification is successful
115-
match verifyResponse[
116-
"success"
117-
] == True or verifyResponse["score"] > 0.5:
117+
match (
118+
verifyResponse["success"] == True
119+
or verifyResponse["score"] > 0.5
120+
):
118121
case True:
119122
# Log reCAPTCHA verification
120123
Log.success(

routes/changeProfilePicture.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ def changeProfilePicture():
6060
url=f"{RECAPTCHA_VERIFY_URL}?secret={RECAPTCHA_SECRET_KEY}&response={secretResponse}"
6161
).json()
6262
# Check if the reCAPTCHA verification is successful or has a high score
63-
match verifyResponse["success"] == True or verifyResponse[
64-
"score"
65-
] > 0.5:
63+
match (
64+
verifyResponse["success"] == True
65+
or verifyResponse["score"] > 0.5
66+
):
6667
case True:
6768
# Log the reCAPTCHA verification result
6869
Log.success(

routes/changeUserName.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ def changeUserName():
9191
match userNameCheck == None:
9292
case True:
9393
# Check Recaptcha if enabled
94-
match RECAPTCHA and RECAPTCHA_USERNAME_CHANGE:
94+
match (
95+
RECAPTCHA and RECAPTCHA_USERNAME_CHANGE
96+
):
9597
case True:
9698
# Verify Recaptcha response
9799
secretResponse = request.form[
@@ -101,11 +103,11 @@ def changeUserName():
101103
url=f"{RECAPTCHA_VERIFY_URL}?secret={RECAPTCHA_SECRET_KEY}&response={secretResponse}"
102104
).json()
103105
# Check Recaptcha verification result
104-
match verifyResponse[
105-
"success"
106-
] == True or verifyResponse[
107-
"score"
108-
] > 0.5:
106+
match (
107+
verifyResponse["success"]
108+
== True
109+
or verifyResponse["score"] > 0.5
110+
):
109111
case True:
110112
# Log the reCAPTCHA verification result
111113
Log.success(

routes/createPost.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,10 @@ def createPost():
7979
url=f"{RECAPTCHA_VERIFY_URL}?secret={RECAPTCHA_SECRET_KEY}&response={secretResponse}"
8080
).json()
8181
# Check Recaptcha verification result
82-
match verifyResponse[
83-
"success"
84-
] == True or verifyResponse["score"] > 0.5:
82+
match (
83+
verifyResponse["success"] == True
84+
or verifyResponse["score"] > 0.5
85+
):
8586
case True:
8687
# Log the reCAPTCHA verification result
8788
Log.success(

routes/dashboard.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def dashboard(userName):
121121
f'User: "{session["userName"]}" tried to login to another users dashboard',
122122
)
123123
# Redirect to the dashboard of the session user name
124-
return redirect(f'/dashboard/{session["userName"].lower()}')
124+
return redirect(f"/dashboard/{session['userName'].lower()}")
125125
case False:
126126
# Log a message that the dashboard cannot be accessed without user login
127127
Log.danger(

0 commit comments

Comments
 (0)