Esempio n. 1
0
def upload_csv(f):
    result = check_csv(f)
    if not isinstance(f, FileStorage):
        f = open(f)
    if result != "OK":
        return result
    ctr = 0
    lines = f.readlines()
    lines = [l.decode('utf-8') for l in lines]
    print(lines)
    for line in lines:
        line = line.strip()
        if line == "":
            pass

        data = line.split(";")

        if data[0].strip() not in users:
            ctr += 1
            users[data[0]] = ctr
            user = User(data[0])
            session.add(user)
        try:
            ts = datetime.strptime(data[3] + " " + data[4], "%d/%m/%Y %H:%M:%S")
            print("Timestamp is :", ts)
        except ValueError:
            continue
        user_id = users[data[0]]
        location = Location(data[1], data[2], ts, user_id)
        print(location)
        session.add(location)
        session.flush()

    f.close()
    return "OK"
Esempio n. 2
0
def fill_db():
    form = LocationForm()
    print(form.user_id.data)

    if form.validate_on_submit():
        location = Location(lat=form.lat.data,
                            lan=form.lan.data,
                            timestamp=form.timestamp.data,
                            user_id=form.user_id.data)
        session.add(location)
        session.flush()
        return redirect("/")
    # if request.method == 'POST':
    #     lat = request.form['lat']
    #     lan = request.form['lan']
    #     timestamp = request.form['timestamp']
    #     user_id = request.form['user_id']
    #     print(timestamp)
    #     ts = datetime.strptime(timestamp, "%Y-%m-%d")
    #     location = Location(lat, lan, ts, user_id)
    #     session.add(location)
    #     session.flush()
    #     return redirect("/")
    else:
        users = session.query(User).all()
        return render_template('add_location.html', users=users, form=form)
Esempio n. 3
0
    def _save_instance(model, data):
        data_to_db = model(**data)
        session.add(data_to_db)
        session.flush()
        session.commit()

        return data_to_db
Esempio n. 4
0
def apostile_create_post():
    count = session.query(Apostile).filter(Apostile.number == int(request.form['number'])).count()
    if count:
        return render_template('message.html', title='Помилка',
                               msg=f'Апостиль з номером {request.form["number"]} уже існує', **user_config())

    doc = Document(
        country=request.form['country'],
        date=request.form['doc_date'],
        author_name=request.form['person_name'],
        author_info=request.form['person_position'],
        stamp_info=request.form['stamp_info'] if request.form['stamp_info'] else '-/-/-'
    )
    session.add(doc)
    session.flush()

    tr_id, tr_type = find_trusted_by_str(request.form['ap_author'])
    ap = Apostile(
        number=int(request.form['number']),
        date=request.form['ap_date'],
        is_archived=False,
        trusted_id=tr_id, trusted_type=tr_type,
        document_id=doc.id
    )
    session.add(ap)
    session.flush()
    session.commit()

    return redirect(f'/apostile/{ap.id}')
def add_user():
    if request.method == 'POST':
        username = request.form['username']
        user = User(username)
        session.add(user)
        session.flush()
        return redirect("/")
    else:
        return render_template("add_user.html")
def fill_db():
    form = LocationForm()
    print(form.user_id.data)

    if form.validate_on_submit():
        location = Location(lat=form.lat.data, lan=form.lan.data, timestamp=form.timestamp.data, user_id=form.user_id.data)
        session.add(location)
        session.flush()
        return redirect("/")
    else:
        users = session.query(User).all()
        return render_template("add_location.html", users=users, form=form)
Esempio n. 7
0
    def add_new_message(self, message) -> 'User':
        """
        Создает сообщение и добавляет привязку к текущему пользователю

        :param message:
        :return:
        """

        message = Message(message)
        session.add(message)
        session.flush()
        self.messages.append(message)
        session.commit()

        return self
Esempio n. 8
0
def add_ad_info(name, price, description=None, main_url=None, url2=None, url3=None):
    if name is not None and price is not None:
        ad = Ads(
            name=name,
            price=price,
            description=description,
            main_url=main_url,
            url2=url2,
            url3=url3
        )
        session.add(ad)
        session.flush()
        return get_ad_info(name=name)
    else:
        raise IncorrectInputException
Esempio n. 9
0
    def post(self):
        data = request.json

        try:
            show = Show(data["name"], data["show_type"], data["description"],
                        data["time"], data["place"])
            session.add(show)
            session.flush()
            session.commit()
            return Response(response=json.dumps({"message": "Show added"}),
                            status=200,
                            mimetype="application/json")
        except:
            return Response(response=json.dumps({"message": "Invalid input"}),
                            status=405,
                            mimetype="application/json")
Esempio n. 10
0
    def post(self, sid):

        data = request.json
        try:
            ticket = Ticket(1, data["clas"], sid, None)

            session.add(ticket)
            session.flush()
            session.commit()

            return Response(response=json.dumps({"message": "Success"}),
                            status=200,
                            mimetype="application/json")
        except:
            return Response(response=json.dumps({"message": "Invalid input"}),
                            status=405,
                            mimetype="application/json")
Esempio n. 11
0
 def create_upload():
     """Create a new Upload record and upload it appropriately"""
     fileStorage = request.files['file']
     uploader = Uploader(AppConfig.BASE_UPLOAD_PATH)
     newUpload = Upload(source_filename=fileStorage.filename)
     uploadFile = UploadFile(newUpload, fileStorage)
     if uploader.can_upload(uploadFile):
         session.add(newUpload)
         session.flush()  #Give uploader access to id/ts
         uploader.upload(uploadFile)
         session.commit()
         return jsonify({})
     else:
         return jsonify({
             'error':
             'Failed to upload, please ensure the file is uploadable'
         }), 500
Esempio n. 12
0
 def post(self):
     data = request.json
     try:
         user = User(data["username"], data["first_name"],
                     data["last_name"], data["email"], data["password"])
         session.add(user)
         session.flush()
         if "groups" in data:
             for group in data["groups"]:
                 invited = Invited(user.id, group)
                 session.add(invited)
         session.commit()
         return Response(response=json.dumps({"message": "Success"}),
                         status=200,
                         mimetype="application/json")
     except:
         return Response(response=json.dumps({"message": "Invalid input"}),
                         status=405,
                         mimetype="application/json")
Esempio n. 13
0
 def post(self):
     data = request.json
     try:
         user = User(data["name"], data["password"], data["phone"],
                     data["mail"])
         checkuser = session.query(User).filter(
             User.mail == user.mail).all()
         if checkuser:
             return Response(response=json.dumps(
                 {"message": "user with such email already exist"}),
                             status=405,
                             mimetype="application/json")
         user.password = generate_password_hash(data["password"])
         session.add(user)
         session.flush()
         session.commit()
         return Response(response=json.dumps({"message":
                                              "User registered"}),
                         status=200,
                         mimetype="application/json")
     except:
         return Response(response=json.dumps({"message": "invalid input"}),
                         status=405,
                         mimetype="application/json")
Esempio n. 14
0
def del_ad(id):
    ad = session.query(Ads).filter_by(id=id).one()
    session.delete(ad)
    session.flush()
    return f'ok', 200