Esempio n. 1
0
def process_signup():
    id = request.form['id']
    firstname = request.form['firstname']
    lastname = request.form['lastname']
    date_of_birth = request.form['date_of_birth']
    nationality = request.form['nationality']
    job_title = request.form['job_title']
    mode_of_employment = request.form['mode_of_employment']

    try:
        employee = models.Employee(id=id,
                                   firstname=firstname,
                                   lastname=lastname,
                                   date_of_birth=date_of_birth,
                                   nationality=nationality,
                                   job_title=job_title,
                                   mode_of_employment=mode_of_employment)
        db.session.add(employee)
        db.session.commit()

    except Exception as e:
        information = 'Login Unsuccessful. {}.'.format(e.__cause__)
        return render_template('newemployee.html',
                               title="Welcome",
                               information=information)

    information = 'Employee, {} {} successfully added.'.format(
        firstname, lastname)
    return render_template('newemployee.html',
                           title="New Staff",
                           information=information)
Esempio n. 2
0
def create_employee():
    if not request.json or not 'first_name' in request.json or not 'second_name' in request.json or not 'email' in request.json:
        print "abort 400"
        abort(400)
    try:
        employee = models.Employee(first_name=request.json['first_name'],
                                   second_name=request.json['second_name'],
                                   email=request.json['email'])
        db.session.add(employee)
        db.session.commit()
    except Exception as e:
        abort(409)
    return json.dumps({'added': employee.dict()}), 201
Esempio n. 3
0
File: views.py Progetto: kaireg/liu
def add(requset):
    #判断表单是否有数据传入
    if requset.method == "POST":

        #获取表单中传入的数据
        title = requset.POST.get('title', None)
        content = requset.POST.get('content', None)

        #将数据写入数据库
        new = models.Employee(title=title, content=content)
        new.save()

        #跳转
        return HttpResponseRedirect('/list')

    return render_to_response('add.html', {'mod_str': requset.method})
Esempio n. 4
0
session.flush()

pos_objs = []
for pos in position_titles:
    pos_objs.append(models.Position(title=pos))

session.add_all(pos_objs)
session.flush()
session.commit()

org_dep_ids = [org_dep.id for org_dep in org_dep_objs]
positions = session.query(models.Position).all()
position_ids = [pos.id for pos in positions]
emp_objs = []
for emp in employee_names:
    emp_objs.append(
        models.Employee(surname=emp.split()[0],
                        name=emp.split()[1],
                        patronymic=emp.split()[2],
                        phone_number=random.randint(100, 300),
                        org_dep_id=org_dep_ids[random.randint(
                            0,
                            len(org_dep_ids) - 1)],
                        position_id=position_ids[random.randint(
                            0,
                            len(position_titles) - 1)]))

session.add_all(emp_objs)
session.flush()

session.commit()
Esempio n. 5
0
from sqlalchemy.engine import create_engine
from sqlalchemy.orm import sessionmaker
import models
from datetime import datetime

engine = create_engine('sqlite:///:memory:', echo=True)
Session = sessionmaker(engine)

session = Session()

models.Base.metadata.create_all(engine)

manager = models.Employee(name_last='Supervisor', name_first='Mark')

me = models.Employee(name_last='Rubin',
                     name_first='Benjamin',
                     email='*****@*****.**',
                     manager=manager)
jas = models.Employee(name_last='Doe',
                      name_first='Jane',
                      email='*****@*****.**',
                      manager=manager)
session.add(manager)
session.commit()
session.add_all((me, jas))
session.commit()

req = models.Request(start_date=datetime.now(),
                     end_date=datetime.now(),
                     employee_id=me.id)
Esempio n. 6
0
def index_page():

    #Display organigram:

    #finds the CEO of the company as being the person to report to the BOARD:
    for instance in db.session.query(models.Employee).filter(models.Employee.reporting_manager == "BOARD"):
        ceo = instance

    organization = [] #our list to be populated

    #populating the organization list with all positions including indentations
    print_direct_employees(ceo, organization)

    #Add to Organigram

    current_employees = []
    for current_employee in db.session.query(models.Employee):
        current_employees.append(current_employee)

    if request.method == 'POST' and request.form.get('add') == "add":  #looks at the button name and value at the end of the form
        new_name = request.form['new_name']
        new_position = request.form['new_position']
        new_reporting_manager = request.form['new_reporting_manager']

        if new_name and new_position and new_reporting_manager:
            new_employee = models.Employee(name=new_name, position=new_position, reporting_manager=new_reporting_manager)
            db.session.add(new_employee)
            db.session.commit()
        return redirect(url_for('index_page'))

    #Update Organigram

    if request.method == 'POST' and request.form.get('update') == "update":

        ID_update = request.form["ID_update"]
        update_this = models.Employee.query.filter_by(id = ID_update).first()

        update_name = request.form['update_name']
        update_position = request.form['update_position']
        update_reporting_manager = request.form['update_reporting_manager']

        if update_name:
            update_this.name = update_name
        if update_position:
            update_this.position = update_position
        if update_reporting_manager:
            update_this.reporting_manager = update_reporting_manager

        db.session.commit()
        return redirect(url_for('index_page'))

    #Delete from Organigram

    if request.method == 'POST' and request.form.get('delete') == "delete":

        ID_delete = request.form["ID_delete"]
        if ID_delete:
            delete_this = models.Employee.query.filter_by(id = ID_delete).first()

        if delete_this.position == "Manager" or delete_this.position == "VP":
            for employee in current_employees:
                if employee.reporting_manager == delete_this.name:
                    employee.reporting_manager = delete_this.reporting_manager

        db.session.delete(delete_this)
        db.session.commit()
        return redirect(url_for('index_page'))

    return render_template("index.html", organization=organization, ceo=ceo, current_employees=current_employees)
Esempio n. 7
0
for pos in position_titles:
    pos_objs.append(models.Position(title=pos))

session.add_all(pos_objs)
session.flush()
session.commit()

org_dep_ids = [org_dep.id for org_dep in org_dep_objs]
positions = session.query(models.Position).all()
position_ids = [pos.id for pos in positions]
emp_objs = []
for emp in employee_names:
    internal_phone_number = str(random.randint(100, 300))
    phone_number = "+7 (351) " + str(random.randint(2000000, 7999999))
    emp_objs.append(models.Employee(surname=emp.split()[0],
                                    name=emp.split()[1],
                                    patronymic=emp.split()[2],
                                    phone_number=phone_number,
                                    internal_phone_number=internal_phone_number,
                                    email="*****@*****.**",
                                    org_dep_id=org_dep_ids[random.randint(0, len(org_dep_ids) - 1)],
                                    position_id=position_ids[random.randint(0, len(position_titles) - 1)]))

session.add_all(emp_objs)
session.flush()
session.commit()

user = models.User(username="******", password="******")
session.add(user)
session.flush()
session.commit()
Esempio n. 8
0
username = "******"
passphrase = "very insecure passphrase - never use it"

db = zerodb.DB(("localhost", 8001), username=username, password=passphrase)

# Everything we record should be within a transaction manager
# or be ended with transaction.commit()
with transaction.manager:
    for i in range(400):
        if (i % 100) == 0:
            # Random text generation is slow, so we report
            # about progress here
            print(i)
        e = models.Employee(name=names.get_first_name(),
                            surname=names.get_last_name(),
                            salary=random.randrange(200000),
                            description=loremipsum.get_paragraph(),
                            extra=loremipsum.get_sentence())
        db.add(e)  # Don't forget to add created object to the db

    # One special record
    desc = """A theoretical physicist, cosmologist,
author and Director of Research at the Centre for
Theoretical Cosmology within the University of Cambridge,
Stephen William Hawking resides in the United Kingdom."""
    e = models.Employee(name="Stephen",
                        surname="Hawking",
                        salary=400000,
                        description=desc)
    db.add(e)  # Don't forget to add created object to the db