Example #1
0
def add_item():
    form = ItemForm()
    if form.validate_on_submit():
        item = Items(name=form.name.data,
                     quantity=form.quantity.data,
                     description=form.description.data,
                     date_added=datetime.datetime.now())
        db_session.add(item)
        db_session.commit()
        return redirect(url_for('success'))
    return render_template('index.html', form=form)
Example #2
0
def add_item():
    #raise
    form = ItemForm()
    if request.method == 'POST': 
        if form.validate_on_submit():
            item = Items(name=form.name.data, quantity=form.quantity.data, description=form.description.data, date_added=datetime.datetime.now())
            db_session.add(item)
            db_session.commit()
            logging.warn(" after committ...")
            #return redirect(url_for('success'))
            return redirect('/success')
    return render_template('index.html', form=form)
Example #3
0
def add_item():
    form = ItemForm()
    if form.validate_on_submit():
        item = Items(
            name=form.name.data,
            quantity=form.quantity.data,
            description=form.description.data,
            date_added=str(datetime.datetime.now()),
        )
        db_session.add(item)
        db_session.commit()
        return redirect(url_for("success", _external=True))
    return render_template("index.html", form=form)
Example #4
0
def order(request):
    # 这里添加验证 不能全是0 网页上也要验证
    orderTemp = Order(employee=Employee.objects.get(name=request.session['username']))
    orderTemp.save()
    for stationery in Stationery.objects.all():
        if request.POST.get(str(stationery.id)) != '0':
            item = Items(stationery=stationery, amount=request.POST[str(stationery.id)], order=orderTemp)
            item.save()

            # print request.POST.get(str(stationery.id))
    ItemList = Items.objects.filter(order=orderTemp)

    return render(request, 'wenjuApp/result.html', {'ItemList': ItemList})
Example #5
0
def item():
    print "reached in item view"
    if request.method == 'GET':
        form = ItemForm(request.form)
        return render_template('forms/item.html', form=form)
    if request.method == 'POST':
        print "hii"
        itemlist = Items(request.form['itemname'], request.form['price'],
                         request.form['description'])
        print itemlist
        db.session.add(itemlist)
        db.session.commit()
        return redirect(url_for('how'))
Example #6
0
def add_item():
    if request.method == 'GET':
        if (login_session['username'] is not None):
            categories = db.query(Category).all()
            return render_template('add_item.html',
                                   login_session=login_session,
                                   categories=categories)
        else:
            return render_template('login.html',
                                   error="You must be logged in to do that!")
    elif request.method == 'POST':
        if login_session['username'] is not None:
            categories = db.query(Category).all()
            item_name = request.form.get('item_name')
            price = request.form.get('price')
            description = request.form.get('description')
            category = request.form.get('category')
            new_category = request.form.get('new_category')

            if item_name is not None and item_name != '':
                item = Items(name=item_name)
                if price is not None and item.price != '':
                    item.price = price
                if description is not None and description != '':
                    item.description = description
                item.author = getUserInfo(login_session['user_id'])
            else:
                flash("You need to give an item!")
                return redirect(url_for('add_item'))

            if category is not None and category != '':
                c = db.query(Category).filter_by(name=category).first()
                item.category = c
            elif new_category is not None and new_category != '':
                c = db.query(Category).filter_by(name=new_category).first()
                if (c):
                    flash("You cannot add a category that already exists!")
                    return redirect(url_for('add_item'))
                new_category = Category(name=new_category)
                item.category = new_category
                db.add(new_category)
            else:
                flash("You need to provide a category!")
                return redirect(url_for('add_item'))

            db.add(item)
            db.commit()
            return redirect(url_for('index'))
        else:
            flash("Please log in to add items")
            return redirect(url_for('index'))
Example #7
0
def newCategoryItem():
    """add new items"""
    categories = session.query(Categories).all()
    if request.method == 'POST':
        newItem = Items(name=request.form['name'],
                        description=request.form['description'],
                        date=datetime.datetime.now(),
                        category_id=request.form['category'],
                        user_id=login_session['user_id'])
        session.add(newItem)
        session.commit()
        flash("New Item added: %s " % newItem.name)
        return redirect(url_for('showCatalog'))
    return render_template('addItem.html', categories=categories)
Example #8
0
def addItem():
    catalog = session.query(Category).all()
    if request.method == 'POST':
        newItemToAdd = Items(name=request.form['name'],
                             description=request.form['description'],
                             category=session.query(Category).filter_by(
                                 name=request.form['category']).one(),
                             user_id=login_session['user_id'])
        session.add(newItemToAdd)
        session.commit()
        flash("Successfully Added New Item")
        return redirect(url_for('showCatalog'))
    else:
        return render_template('private_AddItem.html', catalog=catalog)
def add_todo(name, item):

    os.system('clear')

    todo_title()

    s = select([Category])
    result = s.execute()
    for r in result:
        if r[1] == name:
            data = Items(category_id=r[0], items=item)
            session.add(data)
            session.commit()
            open_todo(name)
Example #10
0
def addCatalogItem():
    if not login_session.get('access_token'):
        return redirect('/')
    else:
        logged_in = True
    ownerId = login_session["user_id"]
    # Query all of the categories
    categories = session.query(Categories).order_by("categoryName").all()
    # POST methods actions
    if request.method == 'POST':
        # Set the name of the new restaurant into the dictionary
        new_item = Items(itemName=request.form['item_name'],
                         itemDescription=request.form['item_description'],
                         owner=ownerId,
                         added=currentDateTime,
                         modified=currentDateTime,
                         status='A')
        # Add it to the session
        session.add(new_item)
        # Commit the addition to the database
        session.commit()
        addedItem = session.query(Items).order_by(Items.itemId.desc()).first()
        """Flash message that the item was successfully added. Add BOOTSTRAP
        css classes as the message category."""
        flash('New item was successfully added! (%s)' % addedItem.itemName,
              'badge badge-success')
        new_cat = request.form['item_category']
        new_count = request.form['item_inventory']
        new_price = request.form['item_price']
        new_item_category = ItemCategories(categoryId=new_cat,
                                           itemId=addedItem.itemId)
        new_item_inventory = Inventory(itemId=addedItem.itemId,
                                       inventoryCount=new_count,
                                       itemPrice=new_price,
                                       lastUpdated=currentDateTime)
        session.add(new_item_category)
        session.add(new_item_inventory)
        session.commit()
        # Item Tags - Outside of scope of this project - Do later
        # Item Photo - Outside of scope of this project - Do later
        # Redirect the user back to the main Restaurants page
        return redirect(url_for('showMyItems'))
    # GET method actions
    else:
        # Display the Add New Restaurant form page
        return render_template('addItem_LoggedIn.html',
                               categories=categories,
                               email=login_session['email'],
                               logged_in=logged_in)
Example #11
0
def add_item():
    form = ItemForm()
    # Only when posting
    if form.validate_on_submit():
        # Populate item for insertion
        item = Items(name=form.name.data, quantity=form.quantity.data,
                     description=form.description.data, date_added=datetime.datetime.now())
        try:
            db_session.add(item)
            db_session.commit()
            return redirect(url_for('success'))
        except:
            #When failed, pressing the back key will keep the input boxes filled
            return "Go back and check if quantity is a number or not."
    return render_template('index.html', form=form)
Example #12
0
def add_item():
    form = ItemForm(request.form)
    if request.method=="POST" and form.validate_on_submit():
        try:
            item = Items(
                name=form.name.data,
                quantity=form.quantity.data,
                description=form.description.data,
                date_added=datetime.datetime.now())
            db_session.add(item)
            db_session.commit()
            return redirect(url_for('success'))
        except:
            return 'There was a problem adding an item'
    return render_template('index.html', form=form)
Example #13
0
def add_item():
    form = ItemForm()
    if form.validate_on_submit():
        item = Items(id=random.randint(1, 5000),
                     name=form.name.data,
                     quantity=form.quantity.data,
                     description=form.description.data,
                     date_added=datetime.datetime.now())
        db_session.add(item)
        db_session.commit()
        flash('Thank you for entering your item')
        return redirect(url_for('success'))
    # else: add some sort of error catching here

    return render_template('index.html', form=form)
Example #14
0
def addItem():
    categories = session.query(Category).all()
    if request.method == 'GET':
        return render_template('addItem.html', categories=categories)
    else:
        item_cat_name = request.form.get('category_select')
        print(item_cat_name)
        item_cat_id = getCatagoryId(item_cat_name)
        print(item_cat_id)
        newitem = Items()
        newitem.item_name = request.form['item_name']
        newitem.item_description = request.form['item_description']
        newitem.cat_item_id = item_cat_id
        newitem.item_cat_name = item_cat_name
        session.add(newitem)
        session.commit()
        return redirect(url_for('getAllCategories'))
    def create(self, data):
        customers_id = data['customers_id']
        items = data['items']
        self.buy_at_most_ten_diferrent_books(items)
        price = self.apply_discount(items, customers_id)
        total = price.total
        discount = price.discount

        sales = Sales(customers_id, total, discount)
        db.session.add(sales)

        for item in items:
            new_items = Items(sales.id, item['books_id'], item['quantity'])
            sales.items.append(new_items)
            db.session.add(new_items)
        db.session.commit()

        return create_sales(sales)
Example #16
0
def createItem(category):

    if request.method == 'POST':
        find_category = session.query(Categories).filter_by(
            category=category).first()
        item = Items(category_id=find_category.id,
                     item=request.form['item'],
                     description=request.form['description'],
                     user_id=login_session['id'])
        session.add(item)
        session.commit()
        flash('%s has been succesfully added' % request.form['item'])
        return redirect(
            url_for('itemDetail', category=category,
                    item=request.form['item']))

    # GET request
    return render_template('newItem.html', category=category)
Example #17
0
def newItem(category_id):
    session = DBSession()
    if 'username' not in login_session:
        return redirect('/login')
    category = session.query(Category).filter_by(id=category_id).one()
    if login_session['user_id'] != category.user_id:
        return """<script>function myFunction() {alert('You are not authorized
         to add items items to this catalog. Please create your own catalog
         in order to add items.');}</script><body onload='myFunction()'>"""
    if request.method == 'POST':
        newItem = Items(name=request.form['name'],
                        description=request.form['description'],
                        category_id=category.id,
                        user_id=category.user_id)
        session.add(newItem)
        session.commit()
        flash('New %s Item Successfully Created' % (newItem.name))
        return redirect(url_for('showItems', category_id=category_id))
    else:
        return render_template('newitem.html', category_id=category_id)
Example #18
0
def newItem():
    if 'username' not in login_session:
        return 'Unauthorized Access!'
    else:
        categories = session.query(Categories).all()
        if request.method == 'POST':
            getuser = session.query(User).filter_by(
                username=login_session['username']).first()
            getuser_id = getuser.id
            new_item = Items(user_id=getuser_id,
                             title=request.form.get('title', False),
                             description=request.form.get(
                                 'description', False),
                             cat_id=request.form.get('id', False))
            session.add(new_item)
            session.commit()
            flash('New item created!')
            return redirect(url_for('pcatalog'))
        else:
            return render_template('newItem.html', categories=categories)
Example #19
0
def add_item():
    form = ItemForm()
    if form.validate_on_submit():
        item = Items(name=form.name.data, quantity=form.quantity.data, description=form.description.data, date_added=datetime.datetime.now())
        db_session.add(item)
        db_session.commit()
        print("item: {}".format(item))
        print("form.name.data: {}".format(form.name.data))
        print("form.quantity.data: {}".format(form.quantity.data))
        print("form.description.data: {}".format(form.description.data))
        print("datetime.datetime.now(): {}".format(datetime.datetime.now()))

        print("\n--\n")

        print("success url: {}".format(url_for('success')))
        print("xsuccess url: {}".format(url_for('success', _external=True)))
        print("redirect url: {}".format(str(redirect(url_for('success')))))
        return redirect(url_for('success'))

    print("rendering template index.html...")
    return render_template('index.html', form=form)
Example #20
0
def Additem():
    # Check if user logged in give him adding permission
    if 'username' in login_session:
        Cat = session.query(Category).all()
        if request.method == 'GET':
            # Render template used to specify new item components
            return render_template('add-item.html', CatAll=Cat)
        # Add the new item with specified components
        else:
            Newitem = Items(name=request.form['name'],
                            description=request.form['des'],
                            category_id=request.form['Category'],
                            user_id=login_session['user_id'])
            session.add(Newitem)
            session.commit()
            flash('New item added succesfully')
            return redirect(url_for('showMaster'))

    else:
        flash('Your aren' 't have permissions to this link')
        return redirect(url_for('showMaster'))
    def get_firebase(self):
        name = click.prompt(
            click.style('Please enter username?', fg='cyan', bold=True))
        jsonData = firebase.get('/todo-cli', name)
        for k in jsonData:
            #inserting category to database
            category = Category(category=k)
            session.add(category)
            session.commit()

            for i in jsonData[k]:
                s = select([Category])
                result = s.execute()
                for r in result:
                    if r[1] == k:
                        data = Items(category_id=r[0], items=i)
                        session.add(data)
                        session.commit()
                        session.close()

        click.secho('Done', fg='yellow', bold=True)
Example #22
0
def add_item():
    if request.method == 'POST':
        item_name = request.form.get('name')
        item_category = request.form.get('category')
        item_description = request.form.get('description')
        item_nutrition = request.form.get('nutrition')
        item_ingredients = request.form.get('ingredients')
        item_price = request.form.get('price')
        item_location = request.form.get('location')

        newItem = Items(name=item_name,
                        category=item_category,
                        description=item_description,
                        nutrition=item_nutrition,
                        ingredients=item_ingredients,
                        price=item_price,
                        location=item_location)

        session.add(newItem)
        session.commit()
        return jsonify({'response': success[0]})
def addItem():
    if request.method == 'GET':
        # Make sure only logged in users can access this page
        if ('username' in login_session):
            return render_template('addItem.html',
                                    login_session=login_session)
        else:
            flash('Please login in order to add key/value pairs')
            return redirect(url_for('login'))
    elif request.method == 'POST':
        # Make sure only logged in users are adding key/value pairs
        if ('username' in login_session):
            key = request.form.get('key')
            value = request.form.get('value')

            item = db.query(Items).filter_by(key=key).first()

            # Make sure key is unique/not already added
            if item:
                flash('"%s" has already been added' % item.key)
                return redirect(url_for('addItem'))

            if key is not None and key != '':
                item = Items(key=key)
                if value is not None and value != '':
                    item.value = value
                item.author = getUserInfo(login_session['user_id'])
            else:
                flash('You need to provide a proper Key/Value pair')
                return redirect(url_for('addItem'))

            db.add(item)
            db.commit()
            flash('Item Added!')
            return redirect(url_for('index'))
        else:
            flash('Please login in order to add key/value pairs')
            return redirect(url_for('login'))
    else:
        return redirect(url_for('index'))
Example #24
0
def save():
  category_id = request.form['category']
  user_id = session.get('user_id')
  title = request.form['title']
  description = request.form['description']

  #validation
  error = None
  if title is None:
    error = 'Title is required'
  elif description is None:
    error = 'Description is required'
  
  if error is None:
    itm = Items(category_id=category_id, user_id=user_id, title=title, description=description)
    db_session.add(itm)
    db_session.commit()
    return redirect(url_for('index'))

  flash(error)
  
  return redirect(url_for('item.new'))
Example #25
0
def newItem():
    if 'username' not in login_session:
        print('you are not login')
        return redirect(url_for('showTop'))
    if request.method == 'POST':
        print(
            "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
        print(request.form['item_name'])
        print(type(request.form['item_name']))
        if request.form['item_name'] == '':
            flash('no item name is entered')
            return redirect(url_for('newItem'))
        if request.form['description'] == '':
            flash('no description is written')
            return redirect(url_for('newItem'))
        category_name = request.form['category']
        item_name = request.form['item_name']
        description = request.form['description']
        user = session.query(User).filter(
            User.username == login_session['username']).first()
        category = session.query(Category.id).filter(
            Category.category_name == category_name).first()
        newItem = Items(item_name=item_name,
                        registered_at=str(datetime.now()),
                        category_id=category.id,
                        description=description,
                        registered_user_id=user.id)
        print(newItem)
        session.add(newItem)
        flash('New Item {} Successfully Created'.format(newItem.item_name))
        session.commit()
        return redirect(url_for('showTop'))
    else:
        category_names = session.query(Category.category_name).order_by(
            asc(Category.category_name)).all()
        if category_names == []:
            category_names = str("No category is registered yet.")
            print(category_names)
        return render_template('reg_item.html', category_names=category_names)
Example #26
0
def add_item():

    form = form_add_item()
    items_py = []
    for items_iter in Items.query.all():
        items_py.append(
            (str(items_iter.id), str(items_iter.Naming),
             str(items_iter.Description), str(items_iter.Cat.name)))
    categs = []
    for categs_iter in Cat.query.all():
        categs.append((str(categs_iter.id), str(categs_iter.name)))
    form.item_categ.choices = categs

    if form.validate_on_submit():
        item_name = str(form.item_name.data)
        item_desc = str(form.item_desc.data)
        item_categ = str(form.item_categ.data)

        for categ in Cat.query.all():
            if int(categ.id) == int(item_categ):
                categ_is = categ
                break
        i1 = Items(item_name, item_desc, categ_is)
        db.session.add(i1)
        db.session.commit()
        # print ('New Category Added = {}').format(new_categ)
        message = "Item Added:" + i1.Naming
        flash(message)
        return render_template('item_added.html',
                               title='Item_added',
                               Items=items_py,
                               categs=categs)

    return render_template('add_item.html',
                           title='Add Item',
                           form=form,
                           Items=items_py,
                           categs=categs)
Example #27
0
def items(category):
    if request.method == 'POST':
        newItem = Items(item_name=request.form['name'],
                        registered_at=str(datetime.now()))
        session.add(newItem)
        flash('New Item {} Successfully Created'.format(newItem.item_name))
        session.commit()
        return redirect(url_for('showTop'))
    else:
        category_list = session.query(Category.category_name).order_by(
            asc(Category.category_name)).all()
        category = session.query(Category.id, Category.category_name).filter(
            Category.category_name == category).first()
        itemsJoin = session.query(Items, Category.category_name).join(
            Items, Items.category_id == Category.id).filter(
                Items.category_id == category.id).all()
        print(itemsJoin)
        print(type(itemsJoin))
        num_items = session.query(
            Items.item_name).filter(Items.category_id == category.id).count()
        items = session.query(Items).filter(
            Items.category_id == category.id).all()
        if 'username' not in login_session:
            print('you are not login')
            return render_template('items_in_category.html',
                                   items=items,
                                   category_list=category_list,
                                   category=category.category_name,
                                   num_items=num_items)
        else:
            print('you are login')
            return render_template('items_in_categoryLogin.html',
                                   items=items,
                                   category_list=category_list,
                                   category=category.category_name,
                                   num_items=num_items)
category4 = Categories(name='news')
category5 = Categories(name='stories')
category6 = Categories(name='movies')
session.add(category1)
session.add(category2)
session.add(category3)
session.add(category4)
session.add(category5)
session.add(category6)
session.commit()

print 'Categories Added!'

categories = session.query(Categories).all()
id_c = ''
for c in categories:
    if c.name == 'sports':
        id_c = c.id
new_item = Items(title='Swimming',
                 description='''Swimming is a great workout because you need to
                 move your whole body against the resistance of the water.
                 Swimming is a good all-round activity because it:
                 keeps your heart rate up but takes some of the impact stress
                 off your body builds endurance, muscle strength and cardiovascular
                 fitness helps maintain a healthy weight, healthy heart and lungs
                 tones muscles and builds strength provides an all-over body
                 workout, as nearly all of your muscles are used during swimming.''',
                 cat_id=id_c)
session.add(new_item)
session.commit()
Example #29
0
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from models import Category, Base, Items

engine = create_engine('sqlite:///catalog.db')
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)

session = DBSession()

# Adds items to the Items class/ table in the Models
item1 = Items(item_name='Ball',
              item_description='Ball Ball Ball BallBall',
              cat_item_id='1',
              item_cat_name='Soccer')
session.add(item1)
session.commit()

item2 = Items(item_name='Ball Basket',
              item_description='Ball Ball Ball Basket Ball',
              cat_item_id='2',
              item_cat_name='Basketball')
session.add(item2)
session.commit()

item3 = Items(item_name='Bat',
              item_description='Bat Bat Bat Bat',
              cat_item_id='3',
              item_cat_name='Baseball')
session.add(item3)
Example #30
0
cat7=Category(name='Foosball')
cat8=Category(name='Skating')
cat9=Category(name='Hockey')

session.add(cat1)
session.add(cat2)
session.add(cat3)
session.add(cat4)
session.add(cat5)
session.add(cat6)
session.add(cat7)
session.add(cat8)
session.add(cat9)


item1=Items(name='jersey',category=cat1,description='dsfdsfdsfdsfdsfdsfdsfsdfdsf')
item2=Items(name='short',category=cat1)
item3=Items(name='footwear',category=cat1)


item4=Items(name='goggles',category=cat2)
item5=Items(name='basketball ',category=cat2)
item6=Items(name='socks',category=cat2)

item7=Items(name='glove',category=cat3)
item8=Items(name='baseball cleats ',category=cat3)


item9=Items(name='disc golf',category=cat4)
item10=Items(name='flying discs',category=cat4)