Beispiel #1
0
def populate_items():
    """Create minimum sample data for the item table."""

    user_id = get_user_id(ADMIN_EMAIL)
    categories = get_category(category_id=None)
    items = [{
        'name': '1name',
        'description': '1description',
        'url': '1url',
        'category_id': categories[0].id,
        'user_id': user_id
    }, {
        'name': '1name1',
        'description': '1description1',
        'url': '1url1',
        'category_id': categories[0].id,
        'user_id': user_id
    }, {
        'name': '2name',
        'description': '2description',
        'url': '2url',
        'category_id': categories[1].id,
        'user_id': user_id
    }, {
        'name': '2name1',
        'description': '2description1',
        'url': '2url1',
        'category_id': categories[1].id,
        'user_id': user_id
    }, {
        'name': '3name',
        'description': '3description',
        'url': '3url',
        'category_id': categories[2].id,
        'user_id': user_id
    }, {
        'name': '3name1',
        'description': '3description1',
        'url': '3url1',
        'category_id': categories[2].id,
        'user_id': user_id
    }, {
        'name': '4name',
        'description': '4description',
        'url': '4url',
        'category_id': categories[3].id,
        'user_id': user_id
    }, {
        'name': '4name1',
        'description': '4description1',
        'url': '4url1',
        'category_id': categories[3].id,
        'user_id': user_id
    }]
    for item in items:
        add_item(name=item['name'],
                 description=item['description'],
                 url=item['url'],
                 category_id=item['category_id'],
                 user_id=item['user_id'])
Beispiel #2
0
 def post( self ):
     models.add_item( 
         users.get_current_user().user_id(), 
         self.request.get( 'title' ),
         self.request.get( "comment" ),
         self.request.get( "tags" ),
         self.request.get( "problem" ) )
     self.redirect( '/items' )
Beispiel #3
0
def handle_post(request):
    data = request.json

    if not data:
        return {'status': 'JSON only buddy'}

    if not data.get('auth', None) == config.AUTH_KEY:
        return {'status': 'unauthorized'}

    try:
        owner = Owner.query.filter_by(name=data['owner']).first()
        if owner is None:
            add_item(Owner(data['owner']))

        city = City.query.filter_by(name=data['city']).first()
        if city is None:
            add_item(City(data['city']))

        event = Event(address=data['address'],
                      title=data['title'],
                      start_date=data['start_date'],
                      end_date=data['end_date'],
                      owner=owner,
                      city=city,
                      desc=data.get('desc'),
                      link=data.get('link'),
                      featured=data.get('featured'),
                      paid=data.get('paid'))
        error = add_item(event)

        if error is not None:
            return {'status': 'IntegrityError', 'error': error}

    except KeyError as e:
        return {'status': 'KeyError failure', 'error': repr(e)}
    except Exception as e:
        return {'status': 'Unknown failure', 'error': repr(e)}

    return {'status': 'saved', 'event': convert_to_dict(event)}
Beispiel #4
0
def addItem():
    if not is_logged_in():
        flash("You must be logged in to perform that action.")
        return redirect(url_for('getCatalog'))

    if request.method == 'POST':
        item = add_item(name=request.form['name'],
                        description=request.form['description'],
                        url=request.form['url'],
                        category_id=request.form['category_id'])
        return redirect(
            url_for('getCategoryItem',
                    category_id=item.category_id,
                    item_id=item.id))
    else:
        categories = get_category(category_id=None)
        return render_template(
            'add.html',
            categories=categories,
        )