def Overall_Summary(): email = session['email'] user = User.get_by_email(email) if email is not None: if request.method == 'GET': return render_template('between_dates_overall.html', user=user) else: start_date = request.form['startdate'] end_date = request.form['enddate'] return render_template('overall_summary_sheet.html', user=user, start_date=start_date, end_date=end_date) else: return render_template('login_fail.html', user=user)
def login_user(): email = request.form['email'] password = request.form['password'] valid = User.valid_login(email, password) User.login(email) user = User.get_by_email(email) if valid: if user.designation == 'HQ Staff': return render_template('profile_HQ.html', user=user) else: return render_template('profile_blocks.html', user=user) else: return render_template('login_fail.html')
def deletework(work_id): email = session['email'] user = User.get_by_email(email) Work.deletefrom_mongo(work_id=work_id) return render_template('deleted.html', user=user)
def preview_image(_id): URI = os.environ['MONGODB_URI'] client = pymongo.MongoClient(Database.URI) DATABASE = client['heroku_thg5d5x0'] email = session['email'] user = User.get_by_email(email) # URI = "mongodb://127.0.0.1:27017" # client = pymongo.MongoClient(URI) # DATABASE = client['Dindugul'] fid = "" fs = gridfs.GridFS(DATABASE) print(DATABASE['road_images'].find({'fileid': _id})) for output_data1 in DATABASE['road_images'].find({'stageid': _id}): fid = output_data1["fileid"] output_data = fs.get(fid).read() base64_data = codecs.encode(output_data, 'base64') image = base64_data.decode('utf-8') if user.designation == 'HQ Staff': return render_template('road_image_display.html', images=image, user=user) else: return render_template('road_image_display_blocks.html', images=image, user=user)
def register_user(): email = request.form['email'] password = request.form['password'] username = request.form['username'] designation = request.form['designation'] block = request.form['block'] User.register(email, password, username, designation, block, department=None) user = User.get_by_email(email) if user.designation == 'HQ Staff': return render_template('profile_HQ.html', user=user) else: return render_template('profile_blocks.html', user=user)
def user_blogs(user_id): if user_id is not None: user = User.get_by_id(user_id) else: user = User.get_by_email(session['email']) blogs = user.get_blogs() return render_template("user_blogs.html", blogs=blogs)
def log_out(): email = session['email'] user = User.get_by_email(email) if email is not None: user.logout() return render_template('logged_out.html', user=user.username) else: return render_template('login_fail.html')
def create_new_post(blog_id): if request.method == 'GET': return render_template('new_post.html', blog_id=blog_id) else: title = request.form['title'] content = request.form['content'] user = User.get_by_email(session['email']) new_post = Post(blog_id, title, content, user.email) new_post.save_to_mongo() return make_response(blog_posts(blog_id))
def create_new_blog(): if request.method == 'GET': return render_template('new_blog.html') else: title = request.form['title'] description = request.form['description'] user = User.get_by_email(session['email']) new_blog = Blog(user.email, title, description, user._id) new_blog.save_to_mongo() return make_response(user_blogs(user._id))
def view_work_by_blocks(): email = session['email'] user = User.get_by_email(email) if email is not None: return render_template('view_work_by_blocks.html', user=user) else: return render_template('login_fail.html', user=user)
def Deadline_violation_stages(): email = session['email'] user = User.get_by_email(email) if email is not None: return render_template('deadline_violation_stages_sheet.html', user=user) else: return render_template('login_fail.html', user=user)
def update_scheme(_id): email = session['email'] if email is not None: if request.method == 'GET': user = User.get_by_email(email) return render_template('update_scheme_form.html', user=user, _id=_id) else: user = User.get_by_email(email) scheme_group_name = request.form['schemegroupname'] scheme_name = request.form['schemename'] work_group_name = request.form['workgroupname'] work_type = request.form['worktype'] Scheme.update_scheme(scheme_group_name=scheme_group_name, scheme_name=scheme_name, work_group_name=work_group_name, work_type=work_type, _id=_id) return render_template('application_added.html', user=user) else: return render_template('login_fail.html')
def Block_Summary(): email = session['email'] user = User.get_by_email(email) if email is not None: if request.method == 'GET': if user.designation == 'HQ Staff': return render_template('between_dates_blockwise.html', user=user) else: return render_template('between_dates_blockwise_blocks.html', user=user) else: start_date = request.form['startdate'] end_date = request.form['enddate'] if user.designation == 'HQ Staff': block = request.form['block'] return render_template('blockwise_summary_sheet.html', user=user, start_date=start_date, end_date=end_date, block=block) else: block = user.block return render_template('blockwise_summary_sheet_blocks.html', user=user, start_date=start_date, end_date=end_date, block=block) else: return render_template('login_fail.html', user=user)
def profile(): email = session['email'] user = User.get_by_email(email) if email: if user.designation == 'HQ Staff': return render_template('profile_HQ.html', user=user) else: return render_template('profile_blocks.html', user=user) else: return render_template('login_fail.html')
def view_stage(work_id): email = session['email'] user = User.get_by_email(email) if email is not None: if user.designation == 'HQ Staff': return render_template('view_stage.html', user=user, work_id=work_id) else: return render_template('view_stage_blocks.html', user=user, work_id=work_id) else: return render_template('login_fail.html', user=user)
def Deadline_violation_work(): email = session['email'] user = User.get_by_email(email) if email is not None: if user.designation == 'HQ Staff': return render_template('deadline_violation_work.html', user=user) else: block = user.block return render_template('deadline_violation_work_blocks.html', user=user, block=block) else: return render_template('login_fail.html', user=user)
def Scheme_Summary(): email = session['email'] user = User.get_by_email(email) if email is not None: if request.method == 'GET': return render_template('between_dates_departmentwise.html', user=user) else: start_date = request.form['startdate'] end_date = request.form['enddate'] scheme_group_name = request.form['schemegroupname'] scheme_name = request.form['schemename'] work_group_name = request.form['workgroupname'] work_type = request.form['worktype'] return render_template('departmentwise_summary_sheet.html', user=user, start_date=start_date, end_date=end_date, scheme_group_name=scheme_group_name, scheme_name=scheme_name, work_group_name=work_group_name, work_type=work_type) else: return render_template('login_fail.html', user=user)
def delete_scheme(_id): email = session['email'] user = User.get_by_email(email) Scheme.delete_from_mongo(_id=_id) return render_template('deleted.html', user=user)
def update_work(work_id): email = session['email'] if email is not None: if request.method == 'GET': user = User.get_by_email(email) if user.designation == 'HQ Staff': return render_template('update_work_form.html', user=user, work_id=work_id) else: return render_template('update_work_form_blocks.html', user=user, work_id=work_id) else: user = User.get_by_email(email) amount = request.form['amount'] block = request.form['Blocks'] work_status = request.form['workstatus'] total_stages = request.form['totalstages'] panchayat = request.form['panchayat'] habitation = request.form['habitation'] start_date = request.form['startdate'] end_date = request.form['enddate'] work_name = request.form['workname'] amount_spent = request.form['amountspent'] scheme_group_name = request.form['schemegroupname'] scheme_name = request.form['schemename'] work_group_name = request.form['workgroupname'] work_type = request.form['worktype'] user_id = user._id user_name = user.username start_date = datetime.combine( datetime.strptime(start_date, '%Y-%m-%d').date(), datetime.now().time()) end_date = datetime.combine( datetime.strptime(end_date, '%Y-%m-%d').date(), datetime.now().time()) Work.update_work(amount=amount, block=block, amount_spent=amount_spent, scheme_group_name=scheme_group_name, scheme_name=scheme_name, panchayat=panchayat, habitation=habitation, work_group_name=work_group_name, work_type=work_type, total_stages=total_stages, start_date=start_date, user_id=user_id, user_name=user_name, work_id=work_id, work_status=work_status, work_name=work_name, end_date=end_date) Stage.update_work_name(work_id=work_id, work_name=work_name) if user.designation == 'HQ Staff': return render_template('application_added.html', user=user) else: return render_template('application_added_blocks.html', user=user) else: return render_template('login_fail.html')
def add_stage(work_id): email = session['email'] if email is not None: if request.method == 'GET': user = User.get_by_email(email) if user.designation == 'HQ Staff': return render_template('add_stage.html', user=user, work_id=work_id) else: return render_template('add_stage_blocks.html', user=user, work_id=work_id) else: user = User.get_by_email(email) stage_name = request.form['stagename'] start_date = request.form['startdate'] end_date = request.form['enddate'] amount = request.form['amount'] total_stages = request.form['totalstages'] stage_order_id = request.form['stageorderid'] user_id = user._id user_name = user.username work_id = work_id application = Stage(stage_name=stage_name, start_date=start_date, end_date=end_date, amount=amount, total_stages=total_stages, stage_status="Open", user_name=user_name, user_id=user_id, stage_order_id=stage_order_id, work_id=work_id) application.save_to_mongo() if user.designation == 'HQ Staff': return render_template('application_added.html', application=application, user=user) else: return render_template('application_added_blocks.html', application=application, user=user) else: return render_template('login_fail.html')
def update_stage(_id): email = session['email'] if email is not None: if request.method == 'GET': user = User.get_by_email(email) if user.designation == 'HQ Staff': return render_template('update_stage_form.html', user=user, _id=_id) else: return render_template('update_stage_from_blocks.html', user=user, _id=_id) else: user = User.get_by_email(email) amount = request.form['amount'] stage_name = request.form['stagename'] stage_order_id = request.form['stageorderid'] total_stages = request.form['totalstages'] stage_status = request.form['stagestatus'] start_date = request.form['startdate'] end_date = request.form['enddate'] user_id = user._id user_name = user.username start_date = datetime.combine( datetime.strptime(start_date, '%Y-%m-%d').date(), datetime.now().time()) end_date = datetime.combine( datetime.strptime(end_date, '%Y-%m-%d').date(), datetime.now().time()) application = Database.find("stages", {"_id": _id}) work_id = None for result_object in application[0:1]: work_id = result_object['work_id'] application = Database.find("stages", {"_id": _id}) stage_status_old = None for result_object in application[0:1]: stage_status_old = result_object['stage_status'] if stage_status_old != stage_status and stage_status == 'Close': var = int(stage_order_id) + 1 print(work_id, var) app = Database.find("stages", { "$and": [{ "work_id": work_id }, { "stage_order_id": str(var) }] }) stage_second_name = None for result_object in app[0:1]: stage_second_name = result_object['stage_name'] Work.update_current_stage(work_id=work_id, stage_name=stage_second_name, stage_order_id=stage_order_id) else: var = int(stage_order_id) app = Database.find("stages", { "$and": [{ "work_id": work_id }, { "stage_order_id": str(var) }] }) stage_second_name = None for result_object in app[0:1]: stage_second_name = result_object['stage_name'] var = int(stage_order_id) - 1 Work.update_current_stage(work_id=work_id, stage_name=stage_second_name, stage_order_id=str(var)) print(request.files["Image_upload"]) for file in request.files.getlist("Image_upload"): filename = file.filename URI = os.environ['MONGODB_URI'] client = pymongo.MongoClient(Database.URI) DATABASE = client['heroku_thg5d5x0'] # URI = "mongodb://127.0.0.1:27017" # client = pymongo.MongoClient(URI) # DATABASE = client['Dindugul'] fs = gridfs.GridFS(DATABASE) # print(file) fileid = fs.put(file, filename=filename) # fileid = fs.put(request.files['Image_upload'].read(), filename=filename) DATABASE['road_images'].insert_one({ "Image_upload": filename, "fileid": fileid, "stageid": _id }) Stage.update_stage(amount=amount, stage_name=stage_name, stage_order_id=stage_order_id, total_stages=total_stages, start_date=start_date, user_id=user_id, user_name=user_name, _id=_id, work_id=work_id, stage_status=stage_status, end_date=end_date) if user.designation == 'HQ Staff': return render_template('application_added.html', user=user) else: return render_template('application_added_blocks.html', user=user) else: return render_template('login_fail.html')