Exemplo n.º 1
0
def test_add_entry(app):
    app.session.login(user_name="admin", password="******")
    app.entry.create(Entry(firstname="Test",
                           nickname="NS",
                           middlename="FOS",
                           email="*****@*****.**"))
    app.session.logout()
Exemplo n.º 2
0
def update():

    result = {}

    page = int(request.form.get("page", 1))
    category = request.form.get("category", None)

    next = page + 1

    offset = (next - 1) * const.PAGE_SIZE
    entries = Entry().query(None, offset, const.PAGE_SIZE)

    data = []
    for entry in entries:
        d = dict(entry)
        data.append({
            "_id": d["_id"],
            "title": d["title"],
            "thumb": d["thumb"],
            "width": d["width"],
            "height": d["height"]
        })

    result["data"] = data
    result["page"] = next
    result["cat"] = ""

    return json.dumps(result)
Exemplo n.º 3
0
def index():

    entries = Entry().query(None, 0, const.PAGE_SIZE * 2)
    categories = Category().query(None, 0, const.MAX_CATEGORY_SIZE)

    return render_template("index.html",
                           entries=entries,
                           categories=categories,
                           page=2,
                           cat="")
Exemplo n.º 4
0
def upload():
    categories = Category().query(None, 0, const.MAX_CATEGORY_SIZE)
    if request.method == 'POST':
        file_storage = request.files['upload_img']
        file_name = file_storage.filename

        if file_name:
            ext = file_name.rsplit('.', 1)[1]
            date_dir = get_date_dir()
            uuid = get_uuid()
            name = '%s_source.%s' % (uuid, ext)
            source = uploads.save(file_storage, folder=date_dir, name=name)

            thumb_name = '%s_thumb.%s' % (uuid, ext)
            thumb = os.path.join(date_dir, thumb_name).replace('\\', '/')
            thumb_path = os.path.join(app.config["UPLOADS_DEFAULT_DEST"],
                                      "uploads/" + thumb)

            source_path = os.path.join(app.config["UPLOADS_DEFAULT_DEST"],
                                       "uploads/" + source)
            ret = resizeImg(source_path, thumb_path, ext)

            if ret["status"]:
                height = ret.get("height", 0)
                width = ret.get("width", 0)

            entry = Entry()
            document = entry.document()
            document.update({
                "title": request.form['title'],
                "link": request.form['link'],
                "categories": request.form['categories'],
                "tags": request.form['tags'],
                "description": request.form['description'],
                "source": source,
                "thumb": thumb,
                "width": width,
                "height": height
            })

            entry.insert(document)

            flash(u"恭喜你,上传图片成功了")
            return redirect(url_for("upload"))
        else:
            flash(ret["msg"])
    else:
        flash(u"亲,必须选择一张图片的哦")

    return render_template("upload.html", categories=categories)
Exemplo n.º 5
0
                  'opkdato > "2015-08-07 10:33:29" '
                  'ORDER BY opkdato ASC')

print(my_cursor.statement)

result = my_cursor.fetchall()

array = []
for res in result:
    date = res[0]
    values = dict()
    i = 1
    for column in columns:
        values[column] = parse_value(column, res[i])
        i = i + 1
    array.append(Entry(date, values))

# acc = 0
# for i in range(0, len(array)):
#     if i + 1 >= len(array):
#         break
#     diff = array[i+1].date - array[i].date
#     # print("Message", array[i].values['id'], "received on", array[i].date, "seconds to next opkald2 entry:", diff.seconds)
#     acc = acc + diff.seconds

# print("Average number of seconds inbetween messages:", acc / len(array))

my_cursor.execute(
    'SELECT dato, haendelse, effekt FROM anlaegshaendelser WHERE anlaeg_id = '
    + str(machineID) + ' ORDER BY dato ASC')