Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atharva/sprint 5 #126

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def register_blueprints(app):
from app.controllers.admin_controller import admin_bp
from app.controllers.new_requests_controller import upload_new_req_bp
from app.controllers.cases_controller import assign
from app.controllers.my_requests import my_req_bp
from app.controllers.my_cases import my_req_bp
from app.controllers.role_controller import role_bp

app.register_blueprint(user_bp)
Expand Down
93 changes: 93 additions & 0 deletions app/controllers/my_cases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
from datetime import datetime

from flask import jsonify
from flask import request, Blueprint, render_template
from flask_login import current_user
from flask_wtf import FlaskForm
from wtforms import StringField, IntegerField, SubmitField
from wtforms.fields import DateField

from app import db
from app.decorators.login_decorator import requires_login
from app.models import Case, User

my_req_bp = Blueprint('my-cases', __name__)


class RequestForm(FlaskForm):
id = IntegerField('ID')
customer_id = StringField('Customer ID')
first_name = StringField('First Name')
last_name = StringField('Last Name')
num_of_children = IntegerField('Number of Children')
outreach_date = DateField('Outreach Date')
packet_return_status = StringField('Packet Return Status')
packet_received_date = DateField('Packet Received Date')
staff_initials = StringField('Staff Initials')
decision = StringField('Decision')
num_children_enrolled = IntegerField('Number of Children Enrolled')
decision_date = DateField('Decision Date')
not_enrolled_reason = StringField('Not Enrolled Reason')
submit = SubmitField('Save Changes')


@requires_login
@my_req_bp.route('/my_cases', methods=['GET'])
def view_cases():
cases = User.query.get(current_user.id).user_cases
return render_template('my_cases.html', cases=cases, user=current_user)


@requires_login
@my_req_bp.route('/my_cases/edit/', methods=['POST'])
def edit_case():
data = request.json
num_children_enrolled = data.get('numChildrenEnrolled')

print(num_children_enrolled)
decision_date_str = data.get('decisionDate')
packet_received_date_str = data.get('packetReceivedDate')
case_id = data.get('caseId')
case_to_edit = Case.query.filter_by(id=case_id).first()

if not case_to_edit:
return jsonify({"status": "Error", "message": "Case not found"}), 404

outreach_date = case_to_edit.outreach_date
if num_children_enrolled != "":
try:
int(num_children_enrolled)
except:
return jsonify({"status": "Error", "message": "no. of children enrolled must be integer"}), 400
num_children_enrolled = int(
num_children_enrolled) if num_children_enrolled != "" else 0

try:
decision_date = datetime.strptime(
decision_date_str, '%Y-%m-%d') if decision_date_str and decision_date_str.lower() != 'none' else None
packet_received_date = datetime.strptime(
packet_received_date_str,
'%Y-%m-%d') if packet_received_date_str and packet_received_date_str.lower() != 'none' else None
except ValueError as e:
return jsonify({"status": "Error", "message": "Decision/Package dates must be valid dates"}), 400
print(decision_date, packet_received_date)
# Validate that decision and packet_received_date are not before outreach_date
if decision_date and decision_date.date() < outreach_date:
return jsonify({"status": "Error", "message": "Decision date cannot be before outreach date"}), 400

if packet_received_date and packet_received_date.date() < outreach_date:
return jsonify({"status": "Error", "message": "Packet received date cannot be before outreach date"}), 400

# Get the case ID from the data
case_to_edit.packet_return_status = data.get('packetReturnStatus')
case_to_edit.packet_received_date = data.get('packetReceivedDate')
case_to_edit.decision = data.get('decision')
case_to_edit.num_children_enrolled = num_children_enrolled
case_to_edit.decision_date = decision_date
case_to_edit.not_enrolled_reason = data.get('notEnrolledReason')

try:
db.session.commit()
return jsonify({"status": "OK"}), 200
except Exception as e:
return jsonify({"status": "Error", "message": e}), 400
57 changes: 0 additions & 57 deletions app/controllers/my_requests.py

This file was deleted.

2 changes: 1 addition & 1 deletion app/controllers/new_requests_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def populateDatabase(upload_file, file_path):
except Exception as e:
return jsonify({'message': 'Unsupported file format', 'error': str(e)}), 501

df = df.iloc[:, :5]
#df = df.iloc[:, :5]
df.rename(columns={'Outreach_Date': 'outreach_date'}, inplace=True)
valid_data, invalid_data = validateData(df)

Expand Down
27 changes: 27 additions & 0 deletions app/seeds/cases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from app import db
from app.models import Case
import logging


def seed():
my_case_1 = Case(customer_id="1", first_name="Tanmai", last_name="Harish", num_of_children=3,
outreach_date="2023-11-11")
my_case_2 = Case(customer_id="2", first_name="John", last_name="Jonhnson", num_of_children=2,
outreach_date="2023-11-12")
my_case_3 = Case(customer_id="3", first_name="Great", last_name="Khali", num_of_children=1,
outreach_date="2023-11-13")
my_case_4 = Case(customer_id="4", first_name="Daehee", last_name="Han", num_of_children=4,
outreach_date="2023-11-14")
my_case_5 = Case(customer_id="5", first_name="Ravi", last_name="Ashwin", num_of_children=5,
outreach_date="2023-11-15")
my_case_6 = Case(customer_id="6", first_name="Rajesh", last_name="Jadhav", num_of_children=3,
outreach_date="2023-11-16")
db.session.add(my_case_1)
db.session.add(my_case_2)
db.session.add(my_case_3)
db.session.add(my_case_4)
db.session.add(my_case_5)
db.session.add(my_case_6)
db.session.commit()

logging.info("Cases seeded")
21 changes: 21 additions & 0 deletions app/static/css/cases.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.hidden {
display: none;
}
.purple-table {
background-color: #662484;
color: white;
}

.purple-button {
background-color: #662484;
color: white;
border: none;
}

.purple-button:hover {
background-color: #501c68;
}

.hidden-assign-button {
display: none;
}
64 changes: 50 additions & 14 deletions app/static/css/homepage.css
Original file line number Diff line number Diff line change
Expand Up @@ -132,27 +132,29 @@ tr:nth-child(even) {
}
/* for popup in my_cases */
.overlay {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(102, 36, 132, 0.8);
transition: opacity 500ms;
visibility: hidden;
opacity: 0;
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
transition: opacity 500ms;
visibility: hidden;
opacity: 0;
z-index:100;
}

.overlay:target {
visibility: visible;
opacity: 1;
}

.wrapper {
margin: 70px auto;
padding: 20px;
background: #e7e7e7;
border-radius: 5px;
width: 30%;
z-index:101;
margin: 70px auto;
padding: 20px;
background: #e7e7e7;
border-radius: 5px;
width: 30%;
height: 100%;
position: relative;
transition: all 5s ease-in-out;
Expand All @@ -179,8 +181,42 @@ tr:nth-child(even) {
}

.popupContent {
z-index:101;
margin-bottom: 20px;
border-radius: 5px;
background-color: #e7e7e7;
padding: 20px 0;
}

/* for mycases edit button */
.wrapper2 {
z-index:101;
margin: 70px auto;
padding: 20px;
background: #e7e7e7;
border-radius: 5px;
width: 100%;
height: 100%;
position: relative;
transition: all 5s ease-in-out;
}
.wrapper2 h2 {
margin-top: 0;
}
.wrapper2 .close {
position: absolute;
top: 20px;
right: 30px;
transition: all 200ms;
font-size: 30px;
font-weight: bold;
text-decoration: none;
color: #662484;
}
.wrapper2 .close:hover {
color: yellow;
}
.wrapper2 .content {
height: 70%;
overflow-y: scroll;
}
4 changes: 2 additions & 2 deletions app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<script src="https://cdn.datatables.net/1.13.7/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.11.5/js/jquery.dataTables.js"></script>
{% block addhead %}{% endblock %}
{% block addhead %}{% endblock %}
</head>

<body>
Expand All @@ -35,7 +35,7 @@ <h2>{% block header %} {% endblock %}</h2>
</section>
</div>

<!-- Script -->>
<!-- Script -->
{% block script %}{% endblock %}
</body>
</html>
Loading