Esempio n. 1
0
def job_edit(id):
    form = AddJobForm()
    if request.method == "GET":
        session = db_session.create_session()
        jobs = session.query(Jobs).filter(
            Jobs.id == id, (Jobs.whose_salary == current_user.id) |
            (current_user.id == 1)).first()
        if jobs:
            form.job.data = jobs.job
            form.whose_salary.data = jobs.whose_salary
            form.work_size.data = jobs.work_size
            # form.category.data = jobs.category
            # form.is_finished.data = jobs.is_finished
        else:
            abort(404)
    if form.validate_on_submit():
        session = db_session.create_session()
        jobs = session.query(Jobs).filter(
            Jobs.id == id, (Jobs.whose_salary == current_user.id) |
            (current_user.id == 1)).first()
        if jobs:
            jobs.job = form.job.data
            jobs.whose_salary = form.whose_salary.data
            jobs.work_size = form.work_size.data
            # jobs.category = form.category.data
            # jobs.is_finished = form.is_finished.data
            session.commit()
            return redirect('/')
        else:
            abort(404)
    return render_template('addjob.html',
                           title='Редактирование записи дохода',
                           form=form)
Esempio n. 2
0
def edit_job(id):
    form = AddJobForm()
    if request.method == "GET":
        session = db_session.create_session()
        j = session.query(Jobs).filter(Jobs.id == id).first()
        if j:
            form.team_leader.data = j.team_leader
            job = form.job.data = j.job
            form.work_size.data = j.work_size
            form.collaborators.data = j.collaborators
            form.start_date.data = j.start_date
            form.end_date.data = j.end_date
            form.is_finished.data = j.is_finished
        # else:
        #     abort(404)
    if form.validate_on_submit():
        session = db_session.create_session()
        j = session.query(Jobs).filter(Jobs.id == id).first()
        if j:
            j.team_leader = int(form.team_leader.data)
            j.job = form.job.data
            j.work_size = int(form.work_size.data)
            j.collaborators = form.collaborators.data
            j.start_date = form.start_date.data
            j.end_date = form.end_date.data
            j.is_finished = form.is_finished.data
            session.commit()
            return redirect(url_for('jobs_table'))
        # else:
        #     abort(404)
    return render_template('addjob.html', title='Редактирование задания', form=form)
Esempio n. 3
0
def basket():
    form = AddJobForm()
    db_sess = db_session.create_session()
    basket = current_user.basket
    tovars_user_col = 0
    if basket is not None:
        basket = basket.split()
        tovars_user_col = len(basket)
    baskets = []
    all_cost = 0
    for i in basket:
        t = db_sess.query(Tovar).filter(Tovar.id == i).first()
        all_cost += int(t.cost)
        baskets.append(t)
    if form.validate_on_submit():
        user = db_sess.query(User).filter(User.id == current_user.id).first()
        user.basket = ''
        db_sess.commit()
        db_sess = db_session.create_session()
        payments = Payment(sum_cost=all_cost,
                           quantity=tovars_user_col,
                           status=2,
                           user_id=current_user.id)
        db_sess.add(payments)
        db_sess.commit()

        msg = MIMEMultipart()

        message = f"Спасибо за заказ. \nСумма заказа: {all_cost}\nСтатус заказа: отправлено"

        # setup the parameters of the message
        password = "******"
        msg['From'] = "*****@*****.**"
        msg['To'] = current_user.email
        msg['Subject'] = "Subscription"

        # add in the message body
        msg.attach(MIMEText(message, 'plain'))

        # create server
        server = smtplib.SMTP('smtp.gmail.com: 587')

        server.starttls()

        # Login Credentials for sending the mail
        server.login(msg['From'], password)

        # send the message via the server.
        server.sendmail(msg['From'], msg['To'], msg.as_string())

        server.quit()
        return redirect('/profile')
    print(baskets)
    return render_template("basket.html",
                           basket=baskets,
                           tovars_user_col=tovars_user_col,
                           user=current_user,
                           title='Корзина',
                           form=form,
                           all_cost=all_cost)
Esempio n. 4
0
 def job_edit(id):
     form = AddJobForm()
     if request.method == "GET":
         session = db_session.create_session()
         jobs = session.query(Jobs).filter(Jobs.id == id,
                                           (Jobs.team_leader == current_user.id) | (current_user.id == 1)).first()
         if jobs:
             form.job.data = jobs.job
             form.team_leader.data = jobs.team_leader
             form.work_size.data = jobs.work_size
             form.collaborators.data = jobs.collaborators
             form.is_finished.data = jobs.is_finished
         else:
             abort(404)
     if form.validate_on_submit():
         session = db_session.create_session()
         jobs = session.query(Jobs).filter(Jobs.id == id,
                                           (Jobs.team_leader == current_user.id) | (current_user.id == 1)).first()
         if jobs:
             jobs.job = form.job.data
             jobs.team_leader = form.team_leader.data
             jobs.work_size = form.work_size.data
             jobs.collaborators = form.collaborators.data
             jobs.is_finished = form.is_finished.data
             session.commit()
             return redirect('/')
         else:
             abort(404)
     return render_template('addjob.html', title='Job Edit', form=form)
Esempio n. 5
0
def edit_job(id):
    css = url_for('static', filename='css/base.css')
    form = AddJobForm()
    if request.method == "GET":
        db_sess = db_session.create_session()
        jobs = db_sess.query(Jobs).filter(Jobs.id == id,
                                         ((Jobs.team_lead == current_user) | (current_user.id == 1))).first()
        if jobs:
            form.job.data = jobs.job
            form.team_leader.data = jobs.team_leader
            form.work_size.data = jobs.work_size
            form.collaborators.data = jobs.collaborators
            form.is_finished.data = jobs.is_finished
        else:
            abort(404)
    if form.validate_on_submit():
        db_sess = db_session.create_session()
        job = db_sess.query(Jobs).filter(Jobs.id == id,
                                         ((Jobs.team_lead == current_user) | (current_user.id == 1))).first()
        if job:
            job.job = form.job.data
            job.team_leader = form.team_leader.data
            job.collaborators = form.collaborators.data
            job.work_size = form.work_size.data
            job.is_finished = form.is_finished.data
            db_sess.add(job)
            db_sess.commit()
            return redirect('/')
        else:
            abort(404)
    return render_template('addjob.html', form=form, css=css, title='Изменение работы')
Esempio n. 6
0
def addjob():
    add_form = AddJobForm()
    if add_form.validate_on_submit():
        db_sess = db_session.create_session()
        tovars = Tovar(name=add_form.job.data,
                       cost=add_form.team_leader.data,
                       user_id_create=add_form.work_size.data)
        db_sess.add(tovars)
        db_sess.commit()
        return redirect('/')
    return render_template('addjob.html', title='Adding a job', form=add_form)
Esempio n. 7
0
def addjob():
    add_form = AddJobForm()
    if add_form.validate_on_submit():
        db_sess = db_session.create_session()
        jobs = Jobs(job=add_form.job.data,
                    team_leader=add_form.team_leader.data,
                    work_size=add_form.work_size.data,
                    collaborators=add_form.collaborators.data,
                    is_finished=add_form.is_finished.data)
        db_sess.add(jobs)
        db_sess.commit()
        return redirect('/')
    return render_template('addjob.html', title='Adding a job', form=add_form)
Esempio n. 8
0
def add_job():
    css = url_for('static', filename='css/base.css')
    form = AddJobForm()
    if form.validate_on_submit():
        db_sess = db_session.create_session()
        job = Jobs()
        job.job = form.job.data
        job.team_leader = form.team_leader.data
        job.work_size = form.work_size.data
        job.collaborators = form.collaborators.data
        job.is_finished = form.is_finished.data
        db_sess.add(job)
        db_sess.commit()
        return redirect('/log')
    return render_template('addjob.html', form=form, css=css)
Esempio n. 9
0
def addjob():
    add_form = AddJobForm()
    if add_form.validate_on_submit():
        session = db_session.create_session()
        jobs = Jobs(
            job=add_form.job.data,
            whose_salary=add_form.whose_salary.data,
            work_size=add_form.work_size.data,
            # collaborators=add_form.collaborators.data,
            # is_finished=add_form.is_finished.data
        )
        session.add(jobs)
        session.commit()
        return redirect('/')
    return render_template('addjob.html', title='Adding a job', form=add_form)
Esempio n. 10
0
def addjob():
    if current_user.is_authenticated:
        add_form = AddJobForm()
        if add_form.validate_on_submit():
            print(1)
            db_sess = db_session.create_session()
            jobs = Jobs(job=add_form.job.data,
                        team_leader=current_user.id,
                        work_size=add_form.work_size.data,
                        collaborators=add_form.collaborators.data,
                        is_finished=add_form.is_finished.data)
            db_sess.add(jobs)
            db_sess.commit()
            return redirect('/')
        return render_template('addjob.html',
                               title='Добавить вакансию',
                               form=add_form)
    return redirect('/')
Esempio n. 11
0
def info(id):
    form = AddJobForm()
    db_sess = db_session.create_session()
    infos = db_sess.query(Tovar).filter(Tovar.id == id).first()

    if form.validate_on_submit():
        user = db_sess.query(User).filter(User.id == current_user.id).first()
        user.basket = str(current_user.basket) + ' ' + str(id)
        db_sess.commit()
        return redirect('/')

    tovars_user_col = 0
    if current_user.is_authenticated:
        basket = current_user.basket
        if basket is not None:
            basket = basket.split()
            tovars_user_col = len(basket)
    geocoder_request = f"http://geocode-maps.yandex.ru/1.x/?apikey=40d1649f-0493-4b70-98ba-98533de7710b&geocode={infos.adress}&format=json"
    print(geocoder_request)
    response = requests.get(geocoder_request)
    if response:
        json_response = response.json()
        toponym = json_response["response"]["GeoObjectCollection"][
            "featureMember"][0]["GeoObject"]
        toponym_coodrinates = toponym["Point"]["pos"]
        print(toponym_coodrinates)
    else:
        print("Ошибка выполнения запроса:")
        print(geocoder_request)
        print("Http статус:", response.status_code, "(", response.reason, ")")
    coodrinates = toponym_coodrinates.split()
    x = coodrinates[0]
    y = coodrinates[1]
    print(x, y)
    print(type(55.887422))
    x = float(x)
    print(type(x))
    return render_template('info.html',
                           info=infos,
                           tovars_user_col=tovars_user_col,
                           title='Информация о товаре',
                           form=form,
                           x=x,
                           y=y)
Esempio n. 12
0
def editjob(id):
    if current_user.is_authenticated:
        db_sess = db_session.create_session()
        jobs = db_sess.query(Jobs).filter(Jobs.id == id).first()
        if current_user.id == jobs.team_leader or current_user.id == 1:
            add_form = AddJobForm()
            if add_form.validate_on_submit():
                jobs.job = add_form.job.data
                jobs.team_leader = current_user.id
                jobs.work_size = add_form.work_size.data
                jobs.collaborators = add_form.collaborators.data
                jobs.is_finished = add_form.is_finished.data
                db_sess.commit()
                return redirect('/')
            return render_template('addjob.html',
                                   title='Редактировать вакансию',
                                   form=add_form)
        return redirect('/')
    return redirect('/')
Esempio n. 13
0
def addjob():
    form = AddJobForm()
    if form.validate_on_submit():
        session = db_session.create_session()

        job = Jobs(team_leader=int(form.team_leader.data),
                   job=form.job.data,
                   work_size=int(form.work_size.data),
                   collaborators=form.collaborators.data,
                   start_date=form.start_date.data,
                   end_date=form.end_date.data,
                   is_finished=form.is_finished.data)

        session.add(job)
        session.commit()
        return redirect(url_for('jobs_table'))  # redirect('/jobstable')
    return render_template('addjob.html',
                           title='Добавление нового задания',
                           form=form)