def render_admin_hub(uri):
    if session['email'] is None:
        return redirect("https://kcbootcampers-api-heroku.herokuapp.com/login")
    cookie_uri = request.cookies.get('login_id')
    if cookie_uri == uri:
        users = Admin.get_all()
        posts = Post.get_all()
        posts.reverse()
        assignments = Assignment.get_all()
        assignments.reverse()
        others = Other.get_all()
        others.reverse()
        videos = Video.get_all()
        videos.reverse()
        books = Book.get_all()
        books.reverse()
        return render_template(
            "admin_hub.html",
            href="https://kcbootcampers-api-heroku.herokuapp.com/admin/hub/" +
            cookie_uri,
            acc=session['email'],
            posts=posts,
            users=users,
            assignments=assignments,
            others=others,
            videos=videos,
            books=books,
            uri=uri,
            display='all')
    else:
        return render_template(
            "expired.html",
            acc="Account" if session['email'] is None else session['email'])
Example #2
0
def get_assignment_by_id():

    assignment_id = request.get_json()
    assignment = Assignment.get_assignment_by_id(assignment_id)
    assignment_in_json = json.dumps(assignment.__dict__, ensure_ascii=False)

    return assignment_in_json
Example #3
0
def edit_assignment():

    assignment_content = request.get_json()
    assignment_title = assignment_content["assignment_title"]
    content = assignment_content["content"]
    due_date = assignment_content["due_date"]
    max_points = assignment_content["max_points"]
    is_team = assignment_content["is_team"]
    assignment_id = assignment_content["id"]

    Assignment.get_assignment_by_id(assignment_id).edit_assignment(
        assignment_title, is_team, content, due_date, max_points)
    edited_assignment = Assignment.get_assignment_by_id(assignment_id)
    edited_assignment_in_json = json.dumps(edited_assignment.__dict__,
                                           ensure_ascii=False)
    return edited_assignment_in_json
Example #4
0
def assignment_new():
    if request.method == "POST":
        assignment_title = request.form['assignment_title']
        if 'is_team' in request.form:
            is_team = 1
        else:
            is_team = 0
        content = request.form['content']
        due_date = request.form['due_date']
        max_points = request.form['max_points']
        Assignment.add_assignment(assignment_title, is_team, content, due_date,
                                  max_points)
        return redirect(url_for('assignments_ctrl.assignments'))
    return render_template("add_edit_assignment.html",
                           title="Add an assignment",
                           mainmenu=mainmenu)
def render_assigment(uri, assignment_id):
    assignment = Assignment.get_by_id(assignment_id)
    if request.method == 'GET':
        return render_template("admin_assignments.html",
                               assignment=assignment,
                               acc=session['email'])
    else:
        title = request.form['title']
        content = request.form['content']
        assignment = Assignment.get_by_id(assignment_id)
        assignment.update("title", title)
        assignment.update("content", content)
        assignment = Assignment.get_by_id(assignment_id)
        return render_template("admin_assignments.html",
                               assignment=assignment,
                               acc=session['email'])
def render_hub(uri=None):
    if session['email'] is None:
        return redirect("https://kcbootcampers-api-heroku.herokuapp.com/login")
    posts = Post.get_all()
    posts.reverse()
    others = Other.get_all()
    others.reverse()
    books = Book.get_all()
    books.reverse()
    videos = Video.get_all()
    videos.reverse()
    assignments = Assignment.get_all()
    assignments.reverse()
    user = User.get_by_email(session['email'])
    password = "******" * randint(5, 12)
    cellphone = user.cellphone
    fname = user.fname
    lname = user.lname
    if user.status == "*":
        display = "all"
    else:
        display = "none"
    return render_template("hub.html",
                           acc=session['email'],
                           posts=posts,
                           others=others,
                           videos=videos,
                           books=books,
                           assignments=assignments,
                           fname=fname,
                           lname=lname,
                           password=password,
                           cellphone=cellphone,
                           display=display)
def list_assignment_submissions(assignment_id, methods=['GET', 'POST']):
    """ Shows list of submissions stored in the database.
    """
    assignment = Assignment.get_assignment_by_id(assignment_id)
    return render_template('submissions.html', assignment=assignment,
                           list_assignment_submissions=Submission.get_submission_list_by_assignment_id(assignment_id),
                           mainmenu=mainmenu)
def set_assignment_cookie(assignment_id):
    assignment = Assignment.get_by_id(assignment_id)
    resp = make_response("Success")
    resp.set_cookie("assignment",
                    assignment.title,
                    expires=datetime.datetime.now() +
                    datetime.timedelta(days=1))
    return resp
def page_not_found(e):
    if session['user_role'] == 'Student':
        assignment_list = Assignment.get_assignment_list()
    else:
        assignment_list = []
    return render_template('user_details.html',
                           user=User.get_user_by_id(session['user_id']),
                           assignment_list=assignment_list)
def index():
    if session['user_role'] == 'Student':
        assignment_list = Assignment.get_assignment_list()
    else:
        assignment_list = []
    return render_template('user_details.html',
                           user=User.get_user_by_id(session['user_id']),
                           assignment_list=assignment_list,
                           mainmenu=mainmenu,
                           dashboard=True)
Example #11
0
def user_details(user_id):
    if not user_id.isnumeric():
        flash("Site not found")
        return redirect('/')
    assignment_list = Assignment.get_assignment_list()
    return render_template('user_details.html',
                           assignment_list=assignment_list,
                           user=User.get_user_by_id(user_id),
                           mainmenu=mainmenu,
                           dashboard=False)
Example #12
0
def new_assignment():

    assignment_content = request.get_json()
    assignment_title = assignment_content["assignment_title"]
    content = assignment_content["content"]
    due_date = assignment_content["due_date"]
    max_points = assignment_content["max_points"]
    is_team = assignment_content["is_team"]
    new_assignment = Assignment.add_assignment(assignment_title, is_team,
                                               content, due_date, max_points)
    new_assignment_in_json = json.dumps(new_assignment.__dict__,
                                        ensure_ascii=False)

    return new_assignment_in_json
def send_assignment_obj():
    assignments = []
    dict_assignments = {}
    if request.method == 'POST':
        data = request.form.get('data')
        if data is not None:
            assignments = Assignment.search(qs=data)
            for assignment in assignments:
                assignment.date_created = assignment.date_created.isoformat()
                assignment.date_due = assignment.date_due.isoformat()
        try:
            for i in range(len(assignments)):
                dict_assignments[i] = assignments[i].__dict__
            return dumps(dict_assignments)
        except IndexError:
            return ""
    else:
        return ""
def render_assignments(assignment_id):
    assignment = Assignment.get_by_id(assignment_id)
    return render_template("assignment.html",
                           assignment=assignment,
                           acc=session['email'])
Example #15
0
def assignments():
    return render_template("assignments.html",
                           assignment_list=Assignment.get_assignment_list(),
                           mainmenu=mainmenu)
Example #16
0
def assignment_details(assignment_id):
    return render_template(
        "assignment_details.html",
        assignment=Assignment.get_assignment_by_id(assignment_id),
        mainmenu=mainmenu)
def get_assigment_images(assignment_id):
    assignment = Assignment.get_by_id(assignment_id)
    if assignment.imgs is not None:
        return dumps(assignment.imgs)
    else:
        return dumps({'imgs': {}})
Example #18
0
 def team_assignments_list(self):
     return Assignment.get_team_assignment_list()
def redner_create(uri):
    file_dict = {}
    if request.method == 'GET':
        return render_template("create_assignment.html", acc=session['email'])
    else:
        title = request.form['title']
        content = request.form['content']
        if 'file' not in request.files:
            title = request.form['title']
            content = request.form['content']
            date_due = request.form['days-until']
            format_due = date_due.split('-')
            due_date = datetime.datetime.utcfromtimestamp(
                datetime.datetime(year=int(format_due[0]),
                                  month=int(format_due[1]),
                                  day=int(format_due[2])).timestamp())
            assignment = Assignment(author=session['email'],
                                    content=content,
                                    title=title,
                                    date_due=due_date)
            assignment.save_to_mongo()
            return redirect(
                'https://kcbootcampers-api-heroku.herokuapp.com/admin/hub/' +
                uri)
        files = request.files.getlist("file")
        #if user does not select file, browser also
        #submit an empty part without filename
        for file in files:
            if file.filename == '':
                title = request.form['title']
                content = request.form['content']
                date_due = request.form['days-until']
                format_due = date_due.split('-')
                due_date = datetime.datetime.utcfromtimestamp(
                    datetime.datetime(year=int(format_due[0]),
                                      month=int(format_due[1]),
                                      day=int(format_due[2])).timestamp())
                assignment = Assignment(author=session['email'],
                                        content=content,
                                        title=title,
                                        date_due=due_date)
                assignment.save_to_mongo()
                return redirect(
                    'https://kcbootcampers-api-heroku.herokuapp.com/admin/hub/'
                    + uri)
            if file and allowed_file(file.filename):
                filename = secure_filename(file.filename)
                file_dict[filename.split('.')[0]] = os.path.join(
                    "/uploads/images/", filename)
                try:
                    os.mkdir(app.config['ADMIN_UPLOAD_FOLDER'])
                except FileExistsError:
                    pass
                file.save(
                    os.path.join(app.config['ADMIN_UPLOAD_FOLDER'], filename))
                title = request.form['title']
                content = request.form['content']
                date_due = request.form['days-until']
                format_due = date_due.split('-')
                due_date = datetime.datetime.utcfromtimestamp(
                    datetime.datetime(year=int(format_due[0]),
                                      month=int(format_due[1]),
                                      day=int(format_due[2])).timestamp())
                name_of_file = filename
            else:
                return render_template("create_assignment.html",
                                       acc=session['email'])

        assignment = Assignment(author=session['email'],
                                content=content,
                                title=title,
                                date_created=None,
                                date_due=due_date,
                                _id=None,
                                **file_dict)
        assignment.save_to_mongo()
        return redirect(
            'https://kcbootcampers-api-heroku.herokuapp.com/admin/hub/' + uri)
def remove_assignment(assignment_id):
    Assignment.remove_fr_mongo(assignment_id)
    return "True"
def remove_post(post_id):
    Post.remove_fr_mongo(post_id)
    Assignment.remove_fr_mongo(post_id)
    return "True"