Exemplo n.º 1
0
def projects():
    if session:

        username = session['username']
        uid = session['id']
        # Fetch all records in projects
        projects = ProjectsModel.fetch_records(uid)
        # workers = ProjectsModel.
        print(type(projects))

        # Fetching all inputs from projects

        if request.method == 'POST':
            projectTitle = request.form['projectTitle']
            description = request.form['description']
            cost = request.form['cost']
            timeframe = request.form['timeframe']
            workers = request.form['workers']

            project = ProjectsModel(projectTitle=projectTitle,
                                    description=description,
                                    cost=cost,
                                    timeframe=timeframe,
                                    workers=workers,
                                    user_id=uid)

            project.create_task()
            return redirect(url_for('projects'))

        return render_template('projects.html', projects=projects)
    else:
        flash('Unauthorized Access', 'danger')
        return redirect(url_for('login'))
Exemplo n.º 2
0
    def post(self):
        """save the project details"""
        project_details = PROJECT_PARSER.parse_args()
        if ProjectsModel.fetch_project_by_code(
                project_details['project_code']):
            response_obj = {
                'status':
                'failed',
                'message':
                'Project {} already registered'.format(
                    project_details['project_code'])
            }

            return make_response(jsonify(response_obj))

        new_project = ProjectsModel(project_details['project_code'],
                                    project_details['trimesters'],
                                    project_details['degree'],
                                    project_details['diploma'])

        new_project.save_project()
        response_obj = {
            'status':
            'success',
            'message':
            'Project {} has been registered'.format(
                project_details['project_code'])
        }

        return make_response(jsonify(response_obj))
Exemplo n.º 3
0
    def post(self):
        """
        save allocations to database
        """
        # get the allocation details from request
        allocation_details = ALLOCATIONS_PARSER.parse_args()
        # get associated student data
        student_db_details = StudentsModel.find_student_by_adm(
            allocation_details['student_adm'])

        # get associated project data
        project_db_details = ProjectsModel.fetch_project_by_code(
            student_db_details.project_code)
        no_of_trimesters = int(project_db_details.trimesters)
        curr_month = int(helpers.date_today_month())
        due_date = helpers.find_due_date(no_of_trimesters, curr_month)
        full_date_registered = helpers.date_today()

        new_allocation = AllocationsModel(allocation_details['allocation_id'],
                                          allocation_details['supervisor_id'],
                                          allocation_details['student_adm'],
                                          project_db_details.project_code,
                                          full_date_registered, due_date)
        new_allocation.save_allocation()

        # allocation successfully saved, update student's allocated status to True
        student_db_details.allocated = True
        student_db_details.update_student()

        response_obj = {
            'status': 'success',
            'message': 'Allocation has been successfully made'
        }
        return make_response(jsonify(response_obj), 200)
Exemplo n.º 4
0
def home():
    if session:

        username = session['username']
        uid = session['id']
        # print(uid)

        projects = ProjectsModel.fetch_records(uid)
        users = UserModel.fetch_records()

        status = [x.status for x in projects]
        print(status)
        pie_chart = pygal.Pie()
        pie_chart.title = 'Incomplete projects vs Complete projects'
        pie_chart.add('ProjectModel', status.count('Complete'))
        pie_chart.add('ProjectModel', status.count('Incomplete'))
        graph = pie_chart.render_data_uri()

        return render_template('index.html',
                               proj=len(projects),
                               user=len(users),
                               graph=graph)
    else:
        flash("Unauthorised Access", "danger")
        return redirect(url_for('login'))
Exemplo n.º 5
0
def update_projects(id):
    if request.method == 'POST':
        newProjectTitle = request.form['newProjectTitle']
        newDescription = request.form['newDescription']
        newDateCreated = request.form['newDateCreated']
        newCost = request.form['newCost']
        newTimeframe = request.form['newTimeframe']
        newStatus = request.form['newStatus']
        newWorkers = request.form['newWorkers']

        update_project = ProjectsModel.update_by_id(
            id=id,
            newProjectTitle=newProjectTitle,
            newDescription=newDescription,
            newDateCreated=newDateCreated,
            newCost=newCost,
            newTimeframe=newTimeframe,
            newStatus=newStatus,
            newWorkers=newWorkers)

        if update_project:
            print('record successfully updated')
            return redirect(url_for('projects'))
        else:
            print('update unsuccessfull')
            return redirect(url_for('projects'))
Exemplo n.º 6
0
    def put(self):
        project_details = PROJECT_PARSER.parse_args()
        project_db_details = ProjectsModel.fetch_project_by_code(
            project_details['old_project_code'])
        if project_db_details:
            project_db_details.project_code = project_details[
                'new_project_code']
            project_db_details.trimesters = project_details['trimesters']
            project_db_details.degree = project_details['degree']
            project_db_details.diploma = project_details['diploma']
            project_db_details.update_project()
            response_obj = {
                'status':
                'success',
                'message':
                "{}  details updated".format(
                    project_details['new_project_code'])
            }

            return make_response(jsonify(response_obj), 200)

        response_obj = {  # student was not found, respond with an error message
            'status': 'failed',
            'message': 'The project was not found'
        }

        return make_response(jsonify(response_obj), 404)
Exemplo n.º 7
0
def delete_project(id):
    deleted = ProjectsModel.delete_by_id(id=id)
    if deleted:
        print('successfully deleted')
        return redirect(url_for('projects'))
    else:
        print('record not found')
        return redirect(url_for('projects'))
Exemplo n.º 8
0
    def get(self):
        """get all projects from the database"""
        projects_db_details = ProjectsModel.fetch_all_projects()
        if projects_db_details:
            return make_response(jsonify(projects=projects_db_details), 200)

        response_obj = {  # lecturer was not found
            'status': 'failed',
            'message': 'an error occurred'
        }

        return make_response(jsonify(response_obj), 404)