def edit_item(catalog_id, item_id):
  active_catalog = session.query(Catalog).filter_by(id = catalog_id).all()
   
  if 'username' not in login_session:
    return redirect(url_for('showLogin'))
  
  if active_catalog[0].user_id != login_session['user_id']:
    return "<script>function myFunction() {alert('You are not authorized to edit this item. Please create your own catalog in order to add.');}</script><body onload='myFunction()'>"

  editedItem = session.query(CatalogItems).filter_by(catalog_id=catalog_id, id = item_id).one()
  
  form = AddItemForm(request.values, item_id = item_id, name = editedItem.name, description = editedItem.description)
  #if request.method == 'GET':
  #  form.item_id.data = item_id
   # form.name.data = editedItem.name
  #  form.description.data = editedItem.description

  if form.validate_on_submit():

    try:
      session.query(CatalogItems).filter(CatalogItems.id == form.item_id.data).update({'name': form.name.data, 'description':form.description.data})
      session.commit()
      flash('Item Successfully Edited')
    except:
      session.rollback
      flash('Item edit Aborted')
    
    return redirect(url_for('catalog_select', catalog_id = catalog_id))
  else:
    return render_template('additem.html', form = form, active_catalog = active_catalog)
def add_item(catalog_id):
   # catalogs = session.query(Catalog).filter_by(id = catalog_id).one()
  active_catalog = session.query(Catalog).filter_by(id = catalog_id).all()
   
  if 'username' not in login_session:
    return redirect(url_for('showLogin'))

  if active_catalog[0].user_id != login_session['user_id']:
    return "<script>function myFunction() {alert('You are not authorized to add item to this catalog. Please create your own catalog in order to add.');}</script><body onload='myFunction()'>"

  
  form = AddItemForm()

  if form.validate_on_submit():
      #print "form ok"
      #print form.name.data
      #print form.description.data
#      temp = CatalogItems(name = form.name, description = form.description,
 #        catalog_id = catalog_id)
    temp = CatalogItems(name = form.name.data, description = form.description.data,catalog_id = catalog_id)
    session.add(temp)
    session.commit()

      # print "item saved"
    return redirect(url_for('catalog_select', catalog_id = catalog_id))
      #return render_template('additemsuccess.html')
  else:
      #print "first time form render"
    return render_template('additem.html', form = form, active_catalog = active_catalog)
   
      #session.close()

  catalogs = session.query(Catalog).all()
  items = session.query(CatalogItems).filter_by(catalog_id=catalog_id).all()
  return render_template('main.html', catalogs=catalogs,items=items,catalog_id = catalog_id, active_catalog=active_catalog)
예제 #3
0
파일: app.py 프로젝트: blturley/demilich
def process_new_item_form(char_id):
    """Add new item to database."""

    form = AddItemForm()
    if form.validate_on_submit():
        new_item = Item(name=form.name.data,
                        image_url=form.image_url.data,
                        description=form.description.data,
                        weight=form.weight.data,
                        is_wearable=form.is_wearable.data,
                        armor_class=form.armor_class.data,
                        condition=form.condition.data,
                        rarity=form.rarity.data,
                        quantity=form.quantity.data,
                        notes=form.notes.data,
                        is_equipped=form.is_equipped.data,
                        character_id=char_id)

        if new_item.is_wearable == False:
            new_item.is_equipped = False

        db.session.add(new_item)

        db.session.commit()

        serial_item = new_item.serialize()

        return (jsonify(serial_item), 200)

    errors = {"errors": form.errors}
    return jsonify(errors)
예제 #4
0
파일: views.py 프로젝트: g13013/dzlibs
    def post(self):

        form = AddItemForm()
        item = Item()

        if form.validate_on_submit():
            ar_title = Titles()
            fr_title = Titles()
            en_title = Titles()

            ar_title.title = form.ar_title.data.strip()
            ar_title.lang = 'ar'

            fr_title.title = form.fr_title.data.strip()
            fr_title.lang = 'fr'

            en_title.title = form.en_title.data.strip()
            en_title.lang = 'en'

            item.titles.append(ar_title)
            item.titles.append(fr_title)
            item.titles.append(en_title)

            item.description = form.description.data

            item.submitter = User.objects.get(id=current_user.id)

        else:
            flash('upload unsuccessful', 'error')
            return render_template('items/add_item.html', form=form)

        uploaded_files = request.files.getlist("files")
        thumbnail = request.files['thumbnail']

        thumbnail_name = secure_filename(thumbnail.filename)

        if thumbnail and allowed_thumbnails(thumbnail_name):
            ext = thumbnail.mimetype.split('/')[-1]
            # use the 'thumbnail' name for all thumbnails
            filename = '.'.join(["thumbnail", ext])
            item.thumbnail.put(thumbnail.stream,
                               content_type=thumbnail.mimetype,
                               filename=filename)

        for file in uploaded_files:
            # Make the filename safe, remove unsupported chars
            filename = secure_filename(file.filename)
            # Check if the file is one of the allowed types/extensions
            if file and allowed_file(filename):
                # put the file in the ListField.
                # see https://gist.github.com/tfausak/1299339
                file_ = GridFSProxy()
                file_.put(file.stream,
                          content_type=file.mimetype,
                          filename=filename)
                item.files.append(file_)
        # Save the thing
        item.save()
        flash('upload successful')
        return render_template('items/add_item.html', form=form)
예제 #5
0
파일: views.py 프로젝트: mohamed-io/dzlibs
    def get(self):
        form = AddItemForm()

        categories = Category.objects.all()
        licenses = License.objects.all()
        form.set_categories(categories, g.lang)
        form.set_licenses(licenses)
        return render_template('items/add_item.html', form=form)
def add_item(request):
    context = {}
    if request.method == 'GET':
        form = AddItemForm()
        context = {
            'AddItemForm': form,
        }
        return render(request, 'funfly/add_item.html', context)
    elif request.method == 'POST':
        form = AddItemForm(request.POST, request.FILES)
        item_option = form.data['item_type']
        if item_option == 'Ninegag':
            form.fields.pop('text_area')
            if form.data['source_url'] == '':
                form.fields.pop('source_url')
        elif item_option == 'Video':
            form.fields.pop('media_file')
            form.fields.pop('text_area')
        elif item_option == 'Joke':
            form.fields.pop('title')
            form.fields.pop('media_file')
        if form.is_valid():
            if item_option == 'Ninegag':
                title = form.cleaned_data['title']
                url = ''
                if 'source_url' in form.cleaned_data.keys():
                    url = form.cleaned_data['source_url']
                imagevideo = request.FILES['media_file']
                path = save_file(imagevideo, 'imagesandvideos/imageorvideos/')
                file_path, file_extension = os.path.splitext(path)
                if file_extension == '.png' or file_extension == '.jpg':
                    is_video = False
                else:
                    is_video = True
                if url:
                    ninegag = Ninegag.objects.create(title=title,
                                                     source_url=url,
                                                     imagevideo_path=path,
                                                     is_video=is_video)
                else:
                    ninegag = Ninegag.objects.create(title=title,
                                                     imagevideo_path=path,
                                                     is_video=is_video)

            elif item_option == 'Video':
                title = form.cleaned_data['title']
                source_url = form.cleaned_data['source_url']
                youtube = Youtube.objects.create(title=title,
                                                 url=source_url,
                                                 date_added=datetime.today())
            else:
                text = form.cleaned_data['text_area']
                joke = Joke.objects.create(text=text)
            return redirect('add_item')
        else:
            context = {'AddItemForm': form}
            return render(request, 'funfly/add_item.html', context)
예제 #7
0
def add_item():
    form = AddItemForm()
    if form.validate_on_submit():
        item_entry = Items(form.item.data, form.item_description.data,
                           form.category.data)
        db.session.add(item_entry)
        db.session.commit()
        return redirect(url_for("index"))
    return render_template("edit_add_item.html", form=form)
예제 #8
0
def add_item():
    form = AddItemForm()
    sku = len(db.session.query(relations.Item).all()) + 1
    if form.validate_on_submit():
        print(form.quantity.data)
        new_item = relations.Item(sku=sku, title=form.title.data, description=form.description.data,
                                  price=form.price.data, category=form.category.data, quantity=form.quantity.data,
                                  rating=0, seller=current_user.id, image=form.image.data)
        db.session.add(new_item)

        db.session.commit()
        x = db.session.query(relations.Item.quantity).filter_by(sku=sku).first()
        print(x)
        flash('Item added to inventory.')
        return redirect(url_for('main'))
    return render_template('additem.html', form=form)
예제 #9
0
def save_modify():
    error = None
    form = AddItemForm(request.form)
    if request.method == 'POST':
        print form.item_id.data
        if form.validate_on_submit():
            db.session.query(Item).filter_by(item_id=form.item_id.data).update({
                "name":form.name.data, 
                "item_details":form.item_details.data
                })
            db.session.commit()
            flash('Item was updated')
            return redirect(url_for('items'))
        else:
            return render_template('items.html', form=form, error=error)
    else:
        return redirect(url_for('items'))
예제 #10
0
def add_item():
    import datetime
    error = None
    form = AddItemForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            new_item = Item(
                form.name.data,
                form.item_details.data,
                datetime.datetime.utcnow(),
            )
            db.session.add(new_item)
            db.session.commit()
            flash('New entry was successfully posted. Thanks.')
            return redirect(url_for('items'))
        else:
            return render_template('items.html', form=form, error=error)
    else:
        return redirect(url_for('items'))
예제 #11
0
파일: views.py 프로젝트: weichuanjun/pocket
def add():
    form = AddItemForm()
    if form.validate_on_submit():
        item = Item(link=form.link.data)
        # todo add error handler.
        # item.parse_html()
        if form.tags.data:
            tags = form.tags.data.split(',')
            for tag in tags:
                if Tag.query.filter_by(name=tag).first():
                    item.tags.append(Tag.query.filter_by(name=tag).first())
                else:
                    item.tags.append(Tag(name=tag))
        current_user.items.append(item)
        db.session.add(current_user)
        db.session.commit()
        parse_html(item.id)
        flash(u'已添加新条目:「{} 」。'.format(form.link.data), 'success')
        return redirect(url_for('.index'))
    return render_template('add.html', form=form)
예제 #12
0
def newItem():

    categories = session.query(Category).all()

    # Add a dynamically assigned list to the form's SelectField
    choices = [(category.id, category.name) for category in categories]
    form = AddItemForm()
    form.category.choices = choices

    if form.validate_on_submit():
        new_item = Item(name=form.name.data,
                        description=form.description.data,
                        category_id=form.category.data,
                        user_id=get_logged_in_ID())
        session.add(new_item)
        session.commit()

        flash('New item created.')
        return redirect(
            url_for('showCategory', category_id=new_item.category_id))

    return render_template('newitem.html', form=form)
예제 #13
0
    def get(self):
        form = AddItemForm()

        categories = Category.objects.all()
        licenses = License.objects.all()
        form.set_categories(categories, g.lang)
        form.set_licenses(licenses)
        return render_template('items/add_item.html', form=form)
예제 #14
0
파일: app.py 프로젝트: blturley/demilich
def home_page():
    """Render main page."""

    if not g.user:
        return redirect("/login")

    characters = g.user.characters

    form1 = AddCharacterForm()
    form2 = AddAbilityForm()
    form3 = AddWeaponForm()
    form4 = AddItemForm()

    weapons = requests.get(
        'https://www.dnd5eapi.co/api/equipment-categories/weapon')
    armor = requests.get(
        'https://www.dnd5eapi.co/api/equipment-categories/armor')
    gear = requests.get(
        'https://www.dnd5eapi.co/api/equipment-categories/standard-gear')
    symbols = requests.get(
        'https://www.dnd5eapi.co/api/equipment-categories/holy-symbols')
    tools = requests.get(
        'https://www.dnd5eapi.co/api/equipment-categories/tools')
    spells = requests.get('https://www.dnd5eapi.co/api/spells')
    skills = requests.get('https://www.dnd5eapi.co/api/skills')

    weapons_json = weapons.json()
    armor_json = armor.json()
    gear_json = gear.json()
    symbols_json = symbols.json()
    tools_json = tools.json()
    spells_json = spells.json()
    skills_json = skills.json()

    randnum = random.randint(1, 5000)

    return render_template("home.html",
                           form1=form1,
                           form2=form2,
                           form3=form3,
                           form4=form4,
                           characters=characters,
                           weapons=weapons_json,
                           armor=armor_json,
                           gear=gear_json,
                           symbols=symbols_json,
                           tools=tools_json,
                           spells=spells_json,
                           skills=skills_json,
                           randnum=randnum)
예제 #15
0
def additem():

    items = Items.query.filter(Items.status == 0).all()
    form = AddItemForm()

    # if request.method == 'POST' and form.validate():
    image_file = None

    # if form.validate_on_submit():
    if request.method == 'POST':
        name = form.name.data
        description = form.description.data
        price = form.price.data
        # thumbnail = form.thumbnail.data

        f = request.files['file1']

        if f.filename != '':

            f.save(
                os.path.join(app.config['UPLOAD_FOLDER'],
                             secure_filename(f.filename)))
            # photos.save(request.files.get('image_file'))

            image_file = os.path.join(app.config['UPLOAD_FOLDER'],
                                      secure_filename(f.filename))
            # print(thumbnail)
            print(image_file)

        else:
            image_file = None

        entry = Items(name=name,
                      description=description,
                      price=price,
                      status=0,
                      image_file=image_file)
        db.session.add(entry)
        db.session.commit()
        flash(f'New Item "{form.name.data}" Added succesfully!', 'success')
        return redirect('/additem')

    return render_template('additem.html',
                           title='AddItem',
                           form=form,
                           items=items,
                           image_file=image_file)
예제 #16
0
def grocery_list(request):
    if request.method == "POST":
        if request.POST.get("delete"):
            response = delete_item_ajax(request)
            return HttpResponse(json.dumps(response),
                                content_type="application/json")
        else:
            response = add_item_ajax(request)
            return HttpResponse(json.dumps(response),
                                content_type="application/json")
    else:
        # normal page load
        items_list = Item.objects.order_by('date_added')
        form = AddItemForm()

        context = {
            "items_list": items_list,
            "form": form,
        }

        return render(request, "personal_website/grocery_list.html", context)
예제 #17
0
파일: views.py 프로젝트: zendyani/dzlibs
    def post(self):

        form = AddItemForm()
        item = Item()

        if form.validate_on_submit():
            ar_meta = Meta()
            fr_meta = Meta()
            en_meta = Meta()

            ar_meta.title = form.ar_title.data.strip()
            ar_meta.short_description = form.ar_short_description.data
            ar_meta.lang = 'ar'

            fr_meta.title = form.fr_title.data.strip()
            fr_meta.short_description = form.fr_short_description.data
            fr_meta.lang = 'fr'

            en_meta.title = form.en_title.data.strip()
            en_meta.short_description = form.en_short_description.data
            en_meta.lang = 'en'

            item.meta_info.append(ar_meta)
            item.meta_info.append(fr_meta)
            item.meta_info.append(en_meta)

            item.description = form.description.data

            item.submitter = User.objects.get(id=current_user.id)

        else:
            flash('upload unsuccesful', 'error')
            return render_template('items/add_item.html', form=form)

        uploaded_files = request.files.getlist("files")
        thumbnail = request.files['thumbnail']
        thumbnail_name = secure_filename(thumbnail.filename)

        path = os.path.join(app.config['UPLOAD_FOLDER'], str(item.item_id))
        make_dir(path)

        if thumbnail and allowed_file(thumbnail.filename):
            thumbnail.save(os.path.join(path, thumbnail_name))

        filenames = []
        for file in uploaded_files:
            # Check if the file is one of the allowed types/extensions
            if file and allowed_file(file.filename):
                # Make the filename safe, remove unsupported chars
                filename = secure_filename(file.filename)
                # Move the file form the temporal folder to the upload
                # folder we setup
                file.save(os.path.join(path, filename))
                # Save the filename into a list, we'll use it later
                # filenames.append(filename)
                item.item_data.append(filename)
                # Redirect the user to the uploaded_file route, which
                # will basicaly show on the browser the uploaded file
        # Load an html page with a link to each uploaded file
        # item.item_data.append(filenames)
        item.save()
        flash('upload succesful')
        return render_template('items/add_item.html', form=form)
예제 #18
0
파일: views.py 프로젝트: mohamed-io/dzlibs
    def post(self):

        form = AddItemForm()
        item = Item()

        categories = Category.objects.all()
        licenses = License.objects.all()
        form.set_categories(categories, g.lang)
        form.set_licenses(licenses)

        if form.validate_on_submit():
            # first, the user has to share something !
            if not form.github.data and not form.files.data:
                flash('Neither a repo URL nor files has been shared, come on!',
                      category='alert')
                return render_template('items/add_item.html', form=form)

            # give that something at least one title
            if not form.ar_title.data and not form.fr_title.data and \
               not form.en_title.data:

                flash('You need to give this item at least one title, \
                       just pick one language and name it!',
                      category='alert')
                return render_template('items/add_item.html', form=form)

            # now we can proceed
            ar_title = Title()
            fr_title = Title()
            en_title = Title()

            ar_title.title = form.ar_title.data.strip()
            ar_title.lang = 'ar'

            fr_title.title = form.fr_title.data.strip()
            fr_title.lang = 'fr'

            en_title.title = form.en_title.data.strip()
            en_title.lang = 'en'

            item.titles.append(ar_title)
            item.titles.append(fr_title)
            item.titles.append(en_title)

            item.description = form.description.data
            item.tags = form.tags.data.strip().split(',')
            item.category = Category.objects.get(category_id=
                                                 int(form.category.data))

            item.submitter = User.objects.get(id=current_user.id)

            thumbnail = request.files['thumbnail']
            thumbnail_name = secure_filename(thumbnail.filename)

            if thumbnail and allowed_thumbnails(thumbnail_name):
                ext = thumbnail.mimetype.split('/')[-1]
                # use the 'thumbnail' name for all thumbnails
                filename = '.'.join(["thumbnail", ext])
                item.thumbnail.put(thumbnail.stream,
                                   content_type=thumbnail.mimetype,
                                   filename=filename)

            if form.github.data:
                item.github = form.github.data
                item.save()
                # no need to process any uploaded files
                flash('Item submitted successfully', category='success')
                return redirect(url_for('items.detail', item_id=item.item_id))
            else:
                item.license = License.objects.get(license_id=
                                                   int(form.license.data))

        else:
            flash('upload unsuccessful', category='error')
            return render_template('items/add_item.html', form=form)

        uploaded_files = request.files.getlist("files")
        for file in uploaded_files:
            # Make the filename safe, remove unsupported chars
            filename = secure_filename(file.filename)
            # Check if the file is one of the allowed types/extensions
            if file and allowed_file(filename):
                # put the file in the ListField.
                # see https://gist.github.com/tfausak/1299339
                file_ = GridFSProxy()
                file_.put(file.stream,
                          content_type=file.mimetype,
                          filename=filename)
                item.files.append(file_)
        # Save the thing
        item.save()
        flash('Item uploaded successfully', category='success')
        return redirect(url_for('items.detail', item_id=item.item_id))
예제 #19
0
    def post(self):

        form = AddItemForm()
        item = Item()

        categories = Category.objects.all()
        licenses = License.objects.all()
        form.set_categories(categories, g.lang)
        form.set_licenses(licenses)

        if form.validate_on_submit():
            # first, the user has to share something !
            if not form.github.data and not form.files.data:
                flash('Neither a repo URL nor files has been shared, come on!',
                      category='alert')
                return render_template('items/add_item.html', form=form)

            # give that something at least one title
            if not form.ar_title.data and not form.fr_title.data and \
               not form.en_title.data:

                flash('You need to give this item at least one title, \
                       just pick one language and name it!',
                      category='alert')
                return render_template('items/add_item.html', form=form)

            # now we can proceed
            ar_title = Title()
            fr_title = Title()
            en_title = Title()

            ar_title.title = form.ar_title.data.strip()
            ar_title.lang = 'ar'

            fr_title.title = form.fr_title.data.strip()
            fr_title.lang = 'fr'

            en_title.title = form.en_title.data.strip()
            en_title.lang = 'en'

            item.titles.append(ar_title)
            item.titles.append(fr_title)
            item.titles.append(en_title)

            item.description = form.description.data
            item.tags = form.tags.data.strip().split(',')
            item.category = Category.objects.get(
                category_id=int(form.category.data))

            item.submitter = User.objects.get(id=current_user.id)

            thumbnail = request.files['thumbnail']
            thumbnail_name = secure_filename(thumbnail.filename)

            if thumbnail and allowed_thumbnails(thumbnail_name):
                ext = thumbnail.mimetype.split('/')[-1]
                # use the 'thumbnail' name for all thumbnails
                filename = '.'.join(["thumbnail", ext])
                item.thumbnail.put(thumbnail.stream,
                                   content_type=thumbnail.mimetype,
                                   filename=filename)

            if form.github.data:
                item.github = form.github.data
                item.save()
                # no need to process any uploaded files
                flash('Item submitted successfully', category='success')
                return redirect(url_for('items.detail', item_id=item.item_id))
            else:
                item.license = License.objects.get(
                    license_id=int(form.license.data))

        else:
            flash('upload unsuccessful', category='error')
            return render_template('items/add_item.html', form=form)

        uploaded_files = request.files.getlist("files")
        for file in uploaded_files:
            # Make the filename safe, remove unsupported chars
            filename = secure_filename(file.filename)
            # Check if the file is one of the allowed types/extensions
            if file and allowed_file(filename):
                # put the file in the ListField.
                # see https://gist.github.com/tfausak/1299339
                file_ = GridFSProxy()
                file_.put(file.stream,
                          content_type=file.mimetype,
                          filename=filename)
                item.files.append(file_)
        # Save the thing
        item.save()
        flash('Item uploaded successfully', category='success')
        return redirect(url_for('items.detail', item_id=item.item_id))