Exemplo n.º 1
0
def newListItem(category_id):
    """Creates an item for a specific category."""

    if 'username' not in login_session:
        return redirect('/login')

    category = session.query(Category).filter_by(id=category_id).one()

    if category.user_id != login_session['user_id']:
        flash('You are not the creator of %s category, and cannot modify it' %
              category.name)
        return redirect(url_for('showItems', category_id=category.id))
    if request.method == 'POST':
        if "btn_new" in request.form:
            newItem = ListItem(name=request.form['name'],
                               description=request.form['description'],
                               category_id=category_id,
                               user_id=login_session['user_id'])
            session.add(newItem)
            session.commit()
            flash('New Catalog Item: %s Successfully Created' % (newItem.name))
            return redirect(url_for('showItems', category_id=category_id))
        else:
            return redirect(url_for('showItems', category_id=category_id))
    else:
        return render_template('newitem.html',
                               category_id=category_id,
                               user=getUserInfo(login_session['user_id']))
Exemplo n.º 2
0
def newListItem(category_id):
    if 'user_id' 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 to this category. Please create your own category in order to add items.');}</script><body onload='myFunction()''>"
    if request.method == 'POST':
        print "0"
        print category_id
        print category.user_id
        print request
        print request.form['title']
        print request.form['description']
        newItem = ListItem(title=request.form['title'],
                           description=request.form['description'],
                           category_id=category_id,
                           user_id=category.user_id)
        print "0.1"
        session.add(newItem)
        print "1"
        session.commit()
        print "2"
        flash('New Item %s Item Successfully Created' % (newItem.title))
        return redirect(url_for('showList', category_id=category_id))
    else:
        return render_template('newListItem.html', category_id=category_id)
Exemplo n.º 3
0
def newListItem(list_id):
    """ Create a new list item """
    if not login_session.get('logged_in'):
        return redirect(url_for('home'))

    try:
        topTenList = session.query(List).filter_by(id=list_id).one()
    except NoResultFound:
        abort(404)

    # check if the user created the list they're about to edit
    if login_session.get('user_id') != topTenList.user_account_id:
        return redirect(
            url_for('showCategory', category_url=topTenList.category.url))

    listItems = session.query(ListItem).filter_by(list_id=list_id).order_by(
        asc(ListItem.position)).all()
    newItemPosition = -1
    if (len(listItems) < 10):
        newItemPosition = len(listItems) + 1
    else:
        return render_template(
            'list_form.html',
            listItems=listItems,
            list=topTenList,
            canAddMoreItems=False,
            error="Can't create more than 10 items in your list",
            logged_in=login_session.get('logged_in'))

    if request.method == 'GET':
        return render_template('listItem_form.html',
                               list=topTenList,
                               id="",
                               position=newItemPosition,
                               editing=False,
                               title="",
                               description="",
                               error="",
                               logged_in=login_session.get('logged_in'))
    else:
        if request.form['title']:
            newItem = ListItem(list_id=list_id,
                               position=newItemPosition,
                               title=request.form['title'],
                               description=request.form['description'])
            session.add(newItem)
            session.commit()
            return redirect(url_for('editTopTenList', list_id=list_id))
        else:
            error = "Please include a title."
            return render_template('listItem_form.html',
                                   list=topTenList,
                                   id="",
                                   position=newItemPosition,
                                   editing=False,
                                   title=request.form['title'],
                                   description=request.form['description'],
                                   error=error,
                                   logged_in=login_session.get('logged_in'))
Exemplo n.º 4
0
def newListItem(category_id):
    category = session.query(Category).filter_by(id=category_id).one()
    if request.method == 'POST':
        newItem = ListItem(name=request.form['name'],
                           description=request.form['description'],
                           category_id=category_id,
                           user_id=category.user_id)
        session.add(newItem)
        session.commit()
        flash('New List %s Item Successfully Created' % (newItem.name))
        return redirect(url_for('showList', category_id=category_id))
    else:
        return render_template('newlistitem.html', category_id=category_id)
Exemplo n.º 5
0
def createLists(titleList, category_id, list_id):
    for i in range(2, 11):
        # create list
        session.add(List(user_account_id=i,
                         category_id=category_id,
                         id=list_id))
        visited = [False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False]
        for j in range(1, 11):
            # create list items
            t = getTitle(titleList, visited)
            d = descriptions[randint(0, 8)]
            session.add(ListItem(list_id=list_id,
                                 position=j,
                                 title=t,
                                 description=d,
                                 img_url="http://placehold.it/50x75"))
        list_id = list_id + 1
        session.commit()

    return list_id
Exemplo n.º 6
0
def newListItem(catalog_id):
    if 'username' not in login_session:
        return redirect('/login')
    catalog = session.query(Catalog).filter_by(id=catalog_id).one()
    print(login_session['user_id'], catalog.user_id)
    if login_session['user_id'] != catalog.user_id:
        return '''<script>function myFunction() {alert('You are not authorized
        to add list items to this catalog. Please create your own catalog in
        order to add items.');}</script><body onload='myFunction()''>
        '''
    if request.method == 'POST':
        newItem = ListItem(name=request.form['name'],
                           description=request.form['description'],
                           price=request.form[
                               'price'], catalog_id=catalog_id,
                           user_id=catalog.user_id)
        session.add(newItem)
        session.commit()
        flash('New List %s Item Successfully Created' % (newItem.name))
        return redirect(url_for('showList', catalog_id=catalog_id))
    else:
        return render_template('newlistitem.html', catalog_id=catalog_id)
Exemplo n.º 7
0
session = DBSession()


# Create dummy user
User1 = User(name="Alan Peke", email="*****@*****.**",
             picture='https://lh3.googleusercontent.com/a-/AAuE7mB1D0ZkxLRJmYQAnDsKfSdtfi_phHCapEjDX74x=s60')
session.add(User1)
session.commit()

# Category "Sports"
category1 = Category(user_id=1, name="Sports")

session.add(category1)
session.commit()

listItem1 = ListItem(user_id=1, name="Soccer", description="A Sport were two opposing teams with 11 players on the field each, try to score goals in the other team's goalie using their bodys, except their hands",
                    category=category1)

session.add(listItem1)
session.commit()


listItem2 = ListItem(user_id=1, name="Hockey", description="A sport in which two teams play against each other by trying to manoeuvre a ball or a puck into the opponent's goal using hockey sticks.",
                    category=category1)

session.add(listItem2)
session.commit()


listItem3 = ListItem(user_id=1, name="Baseball", description="A bat-and-ball game played between two opposing teams who take turns batting and fielding",
                     category=category1)
Exemplo n.º 8
0
    email="*****@*****.**",
    picture=
    'https://pbs.twimg.com/profile_images/2671170543/18debd694829ed78203a5a36dd364160_400x400.png'
)
session.add(User1)
session.commit()

# List for UrbanBurger
catalog1 = Catalog(user_id=1, name="Urban Burger")

session.add(catalog1)
session.commit()

listItem2 = ListItem(
    user_id=1,
    name="Veggie Burger",
    description="Juicy grilled veggie patty with tomato mayo and lettuce",
    price="$7.50",
    catalog=catalog1)

session.add(listItem2)
session.commit()

listItem1 = ListItem(user_id=1,
                     name="French Fries",
                     description="with garlic and parmesan",
                     price="$2.99",
                     catalog=catalog1)

session.add(listItem1)
session.commit()
Exemplo n.º 9
0
#session.commit()
#-----user local permission


#now added Analysis categories:

#1. Menu for AlphaDiversity
#category1 = Category(user_id=1, name = "Alpha diversity")
category1 = Category(name = "Alpha diversity")

session.add(category1)
session.commit()


#listItem1 = ListItem(user_id=1, name = "ace richness index", description = "Here we calculate richness index of ace", category = category1)
listItem1 = ListItem(name = "ace richness index", description = "Here we calculate richness index of ace", category = category1)

session.add(listItem1)
session.commit()

#listItem2 = ListItem(user_id=1, name = "chao richness index", description = "Here we calculate richness index of chao", category = category1)
listItem2 = ListItem(name = "chao richness index", description = "Here we calculate richness index of chao", category = category1)

session.add(listItem2)
session.commit()

#listItem3 = ListItem(user_id=1, name = "shannon diversity index", description = "Here we calculate diversity index of shannon", category = category1)
listItem3 = ListItem(name = "shannon diversity index", description = "Here we calculate diversity index of shannon", category = category1)

session.add(listItem3)
session.commit()