Exemple #1
0
def syllabi(page_name, db):
    """Render a page such as the syllabus, help, etc."""
    path = f"content/{course_name}/syllabi/{page_name}.tmd"
    if not osp.exists(path):
        not_found(db)
    title = ""
    with open(path, "rt") as fp:
        top = fp.readline()
        if top.startswith("# "):
            title = title + top[2:].strip()
    content = renderTemplate(path)
    content = renderMarkdown(content)
    return {"base": content, "title": title}
Exemple #2
0
 def test_not_found(self):
     msg = 'test_not_found'
     code = 'âsav'
     res = not_found(msg, code)
     self.assertEqual(msg, res.json['message'])
     self.assertEqual(code, res.json['error'])
     self.assertEqual(404, res.status_code)
Exemple #3
0
def syllabi(page_name, db):
    """Render a page such as the syllabus, help, etc."""
    user = get_user()
    if user_is_admin(user) and request.query.user:
        original_user = user
        user = request.query.user
    else:
        original_user = ''
    if not user_in_roll(user, db):
        log(f"syllabi: {user} not enrolled in COMP523.")

    path = f"views/COMP523/{page_name}.html"
    if not osp.exists(path):
        not_found(db)

    title = ""
    with open(path, "rt") as fp:
        top = fp.readline()
        if top.startswith("# "):
            title = title + top[2:].strip()

    content = renderTemplate(path, user=user, title=title)
    content = renderMarkdown(content)
    if original_user == '':
        db.execute(
            """
         insert into fetched (time, onyen, key, ip, pages, url) values (%s, %s, %s, %s, %s, %s)""",
            [
                datetime.now(), user, page_name, request.remote_addr, [],
                request.url
            ],
        )
    return {
        "base": content,
        "title": title,
        "user": user,
        "admin": user_is_admin(user),
        "agenda_type": 'student'
    }
Exemple #4
0
def add_medicine():
    _json = request.json
    _name = _json['medicine name']
    _group = _json['medicine group']
    _company_name = _json['company name']

    if _name and _group and _company_name and request.method == "POST":
        mongo.db.medicine.insert({'medicine name': _name, 'medicine group': _group, 'company name': _company_name})

        resp = jsonify("Medicine added successfully")

        resp.status_code = 200
        return resp
    else:
        return not_found()
Exemple #5
0
def update_medicine(id):
    _id = id
    _json = request.json
    _name = _json['medicine name']
    _group = _json['medicine group']
    _company_name = _json['company name']

    if _name and _group and _company_name and request.method == "PUT":

        mongo.db.medicine.update_one({'_id': ObjectId(_id['$oid']) if '$oid' in _id else ObjectId(_id)} ,{'$set' : {'medicine name' : _name, 'medicine group': _group, 'company name': _company_name}})
        resp = jsonify("Medicine updated sucessfully")

        return resp

    else:
        return not_found()
Exemple #6
0
def add_doctor():
    _json = request.json
    _name = _json['name']
    _hospital_name = _json['hospital name']
    _speciality = _json['speciality']

    if _name and _hospital_name and _speciality and request.method == 'POST':
        mongo.db.doctor.insert({
            'name': _name,
            'hospital name': _hospital_name,
            'speciality': _speciality
        })

        resp = jsonify("Doctor added successfully")

        resp.status_code = 200
        return resp
    else:
        return not_found()
Exemple #7
0
def update_doctor(id):
    _id = id
    _json = request.json
    _name = _json['name']
    _hospital_name = _json['hospital name']
    _speciality = _json['speciality']

    if _name and _hospital_name and _speciality and request.method == 'PUT':
        mongo.db.doctor.update_one(
            {'_id': ObjectId(_id['$oid']) if '$oid' in _id else ObjectId(_id)},
            {
                '$set': {
                    'name': _name,
                    'hospital name': _hospital_name,
                    'speciality': _speciality
                }
            })
        resp = jsonify("Doctor updated successfully")
        return resp
    else:
        return not_found()
Exemple #8
0
def get_questions(key, db):  # pylint:  disable=too-many-statements
    """
   Allow rendering a set of questions from a template stored in
   the questions folder.
   """
    user = get_user()
    if 'userid' in request.query:
        raise bottle.HTTPError(401, "Invalid parameter userid")
    if 'onyen' in request.query:
        raise bottle.HTTPError(401, "Invalid parameter onyen")
    if user_is_admin(user) and request.query.user:
        original_user = user
        user = request.query.user
    else:
        original_user = ''
    if not user_in_roll(user, db):
        not_allowed()

    path = f"content/{course_name}/{request.path}.tmd"
    now = datetime.now()
    if not osp.exists(path):
        log(f"mypoll{request.path}: path {path} not found")
        not_found(db)
    ip = request.remote_addr

    inp = inputs(key)

    db.execute(
        """
      select extended, section, rid, zwsp
      from roll 
      where onyen = %s """, [user])
    row = db.fetchone()
    section = row and row.section
    extended = row and row.extended
    zwsp = row and row.zwsp  # pylint: disable=possibly-unused-variable
    rid = row and row.rid

    # get the answers as a json formatted string
    db.execute(
        """
        select info, questions from rubrics
        where key = %s""",
        [key],
    )
    row = db.fetchone()
    if row is None:
        rubrics = {}
        pages = []
        info = {}
        print("no rubrics")
    else:
        rubrics = editRubrics(row.questions)
        info = row.info
        pages = info.get('pages', [])

    pages = get_activePages(db, key, user, section, pages)
    if (('pages' in info) and (pages is not None) and (len(pages) == 0)):
        log(f"mypoll/{request.path}: pages=({pages}) so no page shown")
        not_found(db)
    base = renderTemplate(path,
                          user=user,
                          key=key,
                          pages=pages,
                          rid=rid,
                          section=section,
                          constant_e=math.e,
                          constant_pi=math.pi,
                          log=math.log,
                          **inp.env())
    if base.startswith("\n<pre>"):
        # renderTemplate raised an exception
        return base
    base = renderMarkdown(base)

    # Collect up info variables for psform
    # pylint: disable=possibly-unused-variable
    exam = inp.info.get("exam")
    autosave = ((request.path.find("/exams/") == 0)
                or (request.path.find("/quizzes/") == 0)
                or (request.path.find("/worksheets/") == 0))
    includeTimer = extended and exam
    due = inp.info.get("due")
    result = renderTemplate("psform", **locals())
    # hold the lock for as little time as possible
    if original_user == '':
        db.execute(
            """
         insert into fetched (time, onyen, key, ip, pages, url) values (%s, %s, %s, %s, %s, %s)""",
            [now, user, key, ip, pages, request.url],
        )
    return result