Skip to content

Commit 0a54fa0

Browse files
Refactor app.py and __init__.py for code consistency
1 parent 9d47184 commit 0a54fa0

File tree

5 files changed

+11
-21
lines changed

5 files changed

+11
-21
lines changed

app.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
if __name__ == "__main__":
77
port = int(
88
os.environ.get("PORT", 5000)
9-
) # Get the PORT environment variable, default to 5000 if not set
9+
)
1010
app.run(
1111
host="0.0.0.0", port=port, debug=True
1212
)

app/__init__.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ def create_app():
4848

4949
@login_manager.user_loader
5050
def load_user(user_id):
51-
role = session.get('role') # Get the user's role from the session
51+
role = session.get('role')
5252

5353
if role == 'customer':
54-
return Customer.query.get(int(user_id)) # Load customer by ID
54+
return Customer.query.get(int(user_id))
5555
elif role == 'professional':
56-
return Professional.query.get(int(user_id)) # Load professional by ID
56+
return Professional.query.get(int(user_id))
5757
elif role == 'admin':
58-
return Admin.query.get(int(user_id)) # Load admin by ID
58+
return Admin.query.get(int(user_id))
5959
else:
60-
return None # If no valid role is found, return None
60+
return None
6161

6262
return app

app/admin.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
@login_required
1313
@role_required('admin')
1414
def admin_dashboard():
15-
# Fetch all customers, professionals, and services for admin view
1615
customers = Customer.query.all()
1716
professionals = Professional.query.all()
1817
services = Service.query.all()
@@ -27,7 +26,7 @@ def approve_professional(professional_id):
2726
try:
2827
professional = Professional.query.get(professional_id)
2928
if professional:
30-
professional.is_verified = True # Assuming a field 'is_verified' exists in the Professional model
29+
professional.is_verified = True
3130
db.session.commit()
3231
flash("Professional verified successfully.", "success")
3332
else:
@@ -50,7 +49,7 @@ def block_user(user_id, user_type):
5049
user = Professional.query.get(user_id)
5150

5251
if user:
53-
user.is_blocked = not user.is_blocked # Assuming a 'is_blocked' field in both models
52+
user.is_blocked = not user.is_blocked
5453
db.session.commit()
5554
status = "unblocked" if not user.is_blocked else "blocked"
5655
flash(f"User successfully {status}.", "success")
@@ -72,8 +71,8 @@ def create_service():
7271
price = request.form.get('price')
7372
time_required = request.form.get('time_required')
7473
description = request.form.get('description')
75-
banner = request.form.get('banner') # Assuming banner is an image URL or path
76-
provider_id = request.form.get('provider') # Select from available professionals
74+
banner = request.form.get('banner')
75+
provider_id = request.form.get('provider')
7776

7877
if not name or not price or not time_required or not description or not provider_id:
7978
flash("All fields are required.", "warning")
@@ -86,7 +85,7 @@ def create_service():
8685
time_required_in_hours=time_required,
8786
description=description,
8887
banner=banner,
89-
provider=provider_id # Foreign key to Professional
88+
provider=provider_id
9089
)
9190
db.session.add(service)
9291
db.session.commit()

app/customer.py

-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ def services():
7070
pincode = request.args.get('pincode', '')
7171

7272
if query and pincode:
73-
# Querying the database for services matching the query and pincode
7473
services = Service.query.filter(
7574
or_(
7675
Service.name.ilike(f'%{query}%'),

dockerfile

-8
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,16 @@
1-
# Step 1: Use the official Python image as the base image
21
FROM python:3.10-slim
32

4-
# Step 2: Set the working directory inside the container
53
WORKDIR /app
64

7-
# Step 3: Copy the Python app requirements
85
COPY requirements.txt .
96

10-
# Step 4: Install Python dependencies
117
RUN pip install -r requirements.txt
128

13-
# Step 5: Copy the entire project to the container
149
COPY . .
1510

16-
# Step 6: Expose the port Flask will run on
1711
EXPOSE 5000
1812

19-
# Step 7: Set environment variables
2013
ENV FLASK_APP=app.py
2114
ENV FLASK_ENV=production
2215

23-
# Step 8: Run the Flask app
2416
CMD ["flask", "run", "--host=0.0.0.0"]

0 commit comments

Comments
 (0)