Exemplo n.º 1
0
def editItem(category_id=None, item_id=None):
    if not is_logged_in():
        flash("You must be logged in to perform that action.")
        return redirect(url_for('getCatalog'))

    item = get_item(item_id)
    if not is_authorized(item.user_id):
        flash("You may only edit items you have created.")
        return redirect(url_for('getCategory', category_id=category_id))

    if request.method == 'POST':
        item.update_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)
        if item:
            return render_template(
                'edit.html',
                categories=categories,
                item=item,
            )
Exemplo n.º 2
0
def deleteItem(category_id=None, item_id=None):
    if not is_logged_in():
        flash("You must be logged in to perform that action.")
        return redirect(url_for('getCatalog'))

    item = get_item(item_id)
    if not is_authorized(item.user_id):
        flash("You may only delete items you have created.")
        return redirect(url_for('getCategory', category_id=category_id))

    if request.method == 'POST' and item_id:
        delete_item(item_id)
        return redirect(url_for('getCategory', category_id=category_id))
    else:
        item = get_item(item_id)
        return render_template('delete.html',
                               category_id=item.category_id,
                               item=item)
Exemplo n.º 3
0
 def post( self, item_id, title ):
     user = users.get_current_user()
     
     old_item = models.get_item( long(item_id) )
     if( old_item ):
         if old_item.update( user,
                             self.request.get( "title" ),
                             self.request.get( "comment" ),
                             self.request.get( "tags" ),
                             self.request.get( "problem" ) ):                            
             self.redirect( self.get_item_url( old_item ) )
             return
     
     template_values = {}
     path = os.path.join( os.path.dirname( __file__ ), 'templates/error.htm' )
     self.response.out.write( template.render( path, template_values ) )
Exemplo n.º 4
0
 def get( self, item_id, title ):
     user = users.get_current_user()
     greeting = self.GenerateGreeting()
     my_item = models.get_item( long(item_id) )
     
     parent_url = self.get_user_item_url( my_item.owner )
     
     # Initialize whether this item can be edited by the current user
     user_can_edit = None;
     username = None;
     if( user ):
         user_can_edit = ( my_item.owner == user.user_id() )
     
     # Get the username for the user who owns this item
     muser = _get_user_by_id( my_item.owner )
             
     # Output
     template_values = { 'item':my_item, 'greeting':greeting, 'user_can_edit':user_can_edit, 'parent_url':parent_url, 'username':muser.username }
     path = os.path.join( os.path.dirname( __file__ ), 'templates/view_item.htm' )
     self.response.out.write( template.render( path, template_values ) )