コード例 #1
0
 def set_up(self, mysql_x, user=None, passwd=None):
     """Setup the test cases"""
     self.mygarage = self.begin(mysql_x, "Workbenches", user, passwd)
     self.workbenches = Workbenches(self.mygarage)
     self.vendors = Vendors(self.mygarage)
     self.vendor_id = self.vendors.read()[0].get('_id', None)
コード例 #2
0
 def set_up(self, mysql_x, user=None, passwd=None):
     """Setup the test cases"""
     self.mygarage = self.begin(mysql_x, "Locations", user, passwd)
     self.locations = Locations(self.mygarage)
     self.vendors = Vendors(self.mygarage)
     self.vendor_id = self.vendors.read()[0].get('_id', None)
コード例 #3
0
 def set_up(self, mysql_x, user=None, passwd=None):
     """Setup the test cases"""
     self.mygarage = self.begin(mysql_x, "Vendors", user, passwd)
     self.vendors = Vendors(self.mygarage)
コード例 #4
0
 def set_up(self, mysql_x, user=None, passwd=None):
     """Setup the test cases"""
     self.mygarage = self.begin(mysql_x, "ShelvingUnits", user, passwd)
     self.shelving_units = ShelvingUnits(self.mygarage)
     self.vendors = Vendors(self.mygarage)
     self.vendor_id = self.vendors.read()[0].get('_id', None)
コード例 #5
0
def tool(tool_id=None):
    """Manage tool CRUD operations."""
    collection = Tools(mygarage)
    form = ToolForm()
    # Get data from the form if present
    form_toolid = form.toolid.data
    # Tool type choices
    vendor_data = Vendors(mygarage)
    vendors = vendor_data.read()
    vendor_list = []
    for item in vendors:
        vendor_list.append((item["_id"], item["name"]))
    form.vendor.choices = vendor_list
    form.location.choices = mygarage.get_locations()
    form_vendor = form.vendor.data
    form_desc = form.description.data
    form_location = form.location.data
    form_category = form.category.data
    form_toolsize = form.toolsize.data
    form_tooltype = form.tooltype.data
    # If the route with the variable is called, change the create button to update
    # then populate the form with the data from the row in the table. Otherwise,
    # remove the delete button because this will be a new data item.
    if tool_id:
        form.create_button.label.text = "Update"
        # Here, we get the data and populate the form
        data = collection.read(tool_id)
        if data == []:
            flash("Tool not found!")
        data_dict = dict(data[0])
        form.toolid.data = data_dict.get("_id", None)
        form.vendorid.data = data_dict.get("vendorid", None)
        form.vendor.process_data(data_dict.get("vendorid", None))
        form.description.data = data_dict.get("description", None)
        form.location.choices = mygarage.get_locations()
        form.location.process_data(data_dict.get("location", None))
        form.category.process_data(data_dict.get("category", None))
        form.toolsize.data = data_dict.get("size", None)
        form.tooltype.process_data(data_dict.get("type", None))
    else:
        del form.del_button
    if request.method == 'POST':
        # First, determine if we must create, update, or delete when form posts.
        operation = "Create"
        if form.close_button.data:
            return redirect('/list/tools')
        if form.create_button.data:
            if form.create_button.label.text == "Update":
                operation = "Update"
        if form.del_button and form.del_button.data:
            operation = "Delete"
        if form.validate_on_submit():
            # Get the data from the form here
            if operation == "Create":
                try:
                    tool_data = {
                        "vendorid": form_vendor,
                        "description": form_desc,
                        "type": form_tooltype,
                        "size": form_toolsize,
                        "location": form_location,
                        "category": form_category,
                    }
                    collection.create(tool_data)
                    flash("Added.")
                    return redirect('/list/tools')
                except Exception as err:
                    flash(err)
            elif operation == "Update":
                try:
                    tool_data = {
                        "_id": tool_id,
                        "vendorid": form_vendor,
                        "description": form_desc,
                        "type": form_tooltype,
                        "size": form_toolsize,
                        "location": form_location,
                        "category": form_category,
                    }
                    collection.update(tool_data)
                    flash("Updated.")
                    return redirect('/list/tools')
                except Exception as err:
                    flash(err)
            else:
                try:
                    mygarage.get_session().start_transaction()
                    locations = Locations(mygarage)
                    locations.remove_tool(form_toolid)
                    organizers = Organizers(mygarage)
                    organizers.remove_tool(form_toolid)
                    collection.delete(form_toolid)
                    mygarage.get_session().commit()
                    flash("Deleted.")
                    return redirect('/list/tools')
                except Exception as err:
                    flash(err)
        else:
            flash_errors(form)
    return render_template("tool.html", form=form)
コード例 #6
0
def storage_places(kind=None, storage_place_id=None):
    """Manage storage place CRUD operations."""
    if kind == 'cabinets':
        collection = Cabinets(mygarage)
        collection_str = 'Cabinet'
    elif kind == 'shelving_units':
        collection = ShelvingUnits(mygarage)
        collection_str = 'Shelving Unit'
    elif kind == 'toolchests':
        collection = Toolchests(mygarage)
        collection_str = 'Toolchest'
    elif kind == 'workbenches':
        collection = Workbenches(mygarage)
        collection_str = 'Workbench'
    elif kind == 'tools':
        # Redirect!
        flash("Must redirect to tools.")
    elif kind == 'organizers':
        # Redirect!
        flash("Must redirect to organizers.")
    else:
        flash("Something is wrong. Wrong 'kind' specified for the detail.")
    form = StoragePlaceForm()
    # Get data from the form if present
    form_storageid = form.storageid.data
    vendor_data = Vendors(mygarage)
    vendors = vendor_data.read()
    vendor_list = []
    for item in vendors:
        vendor_list.append((item["_id"], item["name"]))
    form.vendor.choices = vendor_list
    form_vendor = form.vendor.data
    form_desc = form.description.data
    # Only cabinets have doors
    if kind == 'cabinets':
        form_ndoors = form.numdoors.data
    else:
        del form.numdoors
    form_width = form.width.data
    form_depth = form.depth.data
    form_height = form.height.data
    form_location = form.location.data
    tool_locations = None
    # If the route with the variable is called, change the create button to update
    # then populate the form with the data from the row in the table. Otherwise,
    # remove the delete button because this will be a new data item.
    if storage_place_id:
        if kind == 'cabinets':
            form.caption.label = "Cabinet"
        elif kind == 'shelving_units':
            form.caption.label = "Shelving Unit"
        elif kind == 'toolchests':
            form.caption.label = "Toolchest"
        elif kind == 'workbenches':
            form.caption.label = "Workbench"
        form.create_button.label.text = "Update"
        # Here, we get the data and populate the form
        data = collection.read(storage_place_id)
        if data == []:
            flash("The {0} was not found!".format(collection_str))
        data_dict = dict(data[0])
        form.vendorid.data = data_dict.get("vendorid", None)
        form.vendor.process_data(data_dict.get("vendorid", None))
        form.storageid.data = data_dict.get("_id", None)
        form.description.data = data_dict.get("description", None)
        if kind == 'cabinets':
            form.numdoors.data = data_dict.get("numdoors", None)
        form.width.data = data_dict.get("width", None)
        form.depth.data = data_dict.get("depth", None)
        form.height.data = data_dict.get("height", None)
        form.location.data = data_dict.get("location", None)
        places = data_dict.get("tool_locations")
        tool_locations = mygarage.build_storage_contents(places)
    else:
        del form.del_button
        del form.manage_tool_locations_button
    if request.method == 'POST':
        # First, determine if we must create, update, or delete when form posts.
        operation = "Create"
        if form.close_button.data:
            return redirect('/list/{0}'.format(kind))
        if form.create_button.data:
            if form.create_button.label.text == "Update":
                operation = "Update"
        if form.del_button and form.del_button.data:
            operation = "Delete"
        if form.manage_tool_locations_button and form.manage_tool_locations_button.data:
            return redirect('/list/tool_locations/{0}/{1}'.format(
                kind, form.storageid.data))
        if form.validate_on_submit():
            # Get the data from the form here
            if operation == "Create":
                try:
                    storage_place_data = {
                        "vendorid": form_vendor,
                        "description": form_desc,
                        "width": form_width,
                        "depth": form_depth,
                        "height": form_height,
                        "location": form_location,
                    }
                    if kind == 'cabinets':
                        storage_place_data.update({"numdoors": form_ndoors})
                    collection.create(storage_place_data)
                    flash("Added.")
                    return redirect('/list/{0}'.format(kind))
                except Exception as err:
                    flash(err)
            elif operation == "Update":
                try:
                    storage_place_data = {
                        "_id": storage_place_id,
                        "vendorid": form_vendor,
                        "description": form_desc,
                        "width": form_width,
                        "depth": form_depth,
                        "height": form_height,
                        "location": form_location,
                    }
                    if kind == 'cabinets':
                        storage_place_data.update({"numdoors": form_ndoors})
                    collection.update(storage_place_data)
                    flash("Updated.")
                    return redirect('/list/{0}'.format(kind))
                except Exception as err:
                    flash(err)
            else:
                try:
                    mygarage.get_session().start_transaction()
                    locations = Locations(mygarage)
                    if places:
                        for loc_id in places:
                            locations.delete(loc_id)
                    collection.delete(form_storageid)
                    mygarage.get_session().commit()
                    flash("Deleted.")
                    return redirect('/list/{0}'.format(kind))
                except Exception as err:
                    flash(err)
        else:
            flash_errors(form)
    return render_template("storage_place.html",
                           form=form,
                           tool_locations=tool_locations,
                           tool_locations_columns=TOOL_LOCATIONS_COLUMNS)
コード例 #7
0
def simple_list(kind=None, storage_type=None, docid=None):
    """Display the simple list and landing page"""
    form = ListForm()
    if kind == 'cabinets':
        form.form_name.label = 'Cabinets'
        if request.method == 'POST':
            return redirect('storage_places/cabinets')
        columns = (
            '<td style="width:500px"><b>Description</b></td>',
            '<td style="width:300px"><b>Location</b></td>',
        )
        kind = 'cabinets'
        cabinet_data = Cabinets(mygarage)
        rows = make_list(cabinet_data.read(),
                         ['_id', 'description', 'location'])
        del form.back_button
        return render_template("list.html",
                               form=form,
                               rows=rows,
                               columns=columns,
                               kind=kind,
                               redirect='storage_places')
    elif kind == 'organizers':
        form.form_name.label = 'Organizers'
        if request.method == 'POST':
            return redirect('organizers')
        columns = (
            '<td style="width:100px"><b>Type</b></td>',
            '<td style="width:300px"><b>Description</b></td>',
            '<td style="width:400px"><b>Location</b></td>',
        )
        kind = 'organizers'
        organizer_data = Organizers(mygarage)
        rows = make_list(organizer_data.read(),
                         ['_id', 'type', 'description', 'location'])
        del form.back_button
        return render_template("list.html",
                               form=form,
                               rows=rows,
                               columns=columns,
                               kind=kind,
                               redirect='storage_places')
    elif kind == 'shelving_units':
        form.form_name.label = 'Shelving_units'
        if request.method == 'POST':
            return redirect('storage_places/shelving_units')
        columns = (
            '<td style="width:300px"><b>Description</b></td>',
            '<td style="width:400px"><b>Location</b></td>',
        )
        kind = 'shelving_units'
        workbench_data = ShelvingUnits(mygarage)
        rows = make_list(workbench_data.read(),
                         ['_id', 'description', 'location'])
        del form.back_button
        return render_template("list.html",
                               form=form,
                               rows=rows,
                               columns=columns,
                               kind=kind,
                               redirect='storage_places')
    elif kind == 'toolchests' or not kind:
        form.form_name.label = 'Toolchests'
        if request.method == 'POST':
            return redirect('storage_places/toolchests')
        columns = (
            '<td style="width:300px"><b>Description</b></td>',
            '<td style="width:400px"><b>Location</b></td>',
        )
        kind = 'toolchests'
        toolchest_data = Toolchests(mygarage)
        rows = make_list(toolchest_data.read(),
                         ['_id', 'description', 'location'])
        del form.back_button
        return render_template("list.html",
                               form=form,
                               rows=rows,
                               columns=columns,
                               kind=kind,
                               redirect='storage_places')
    elif kind == 'tools':
        form.form_name.label = 'Tools'
        if request.method == 'POST':
            return redirect('tools')
        columns = TOOL_COLUMNS
        kind = 'tools'
        workbench_data = Tools(mygarage)
        rows = make_list(
            workbench_data.read(),
            ['_id', 'category', 'type', 'size', 'description', 'location'])
        del form.back_button
        return render_template("list.html",
                               form=form,
                               rows=rows,
                               columns=columns,
                               kind=kind,
                               redirect=None)
    elif kind == 'vendors':
        form.form_name.label = 'Vendors'
        if request.method == 'POST':
            return redirect('vendors')
        columns = (
            '<td style="width:200px"><b>Name</b></td>',
            '<td style="width:400px"><b>URL</b></td>',
            '<td style="width:200px"><b>Sources</b></td>',
        )
        kind = 'vendors'
        vendor_data = Vendors(mygarage)
        rows = make_list(vendor_data.read(), ['_id', 'name', 'url', 'sources'])
        del form.back_button
        return render_template("list.html",
                               form=form,
                               rows=rows,
                               columns=columns,
                               kind=kind,
                               redirect=None)
    elif kind == 'workbenches':
        form.form_name.label = 'Workbenches'
        if request.method == 'POST':
            return redirect('storage_places/workbenches')
        columns = (
            '<td style="width:300px"><b>Description</b></td>',
            '<td style="width:400px"><b>Location</b></td>',
        )
        kind = 'workbenches'
        workbench_data = Workbenches(mygarage)
        rows = make_list(workbench_data.read(),
                         ['_id', 'description', 'location'])
        del form.back_button
        return render_template("list.html",
                               form=form,
                               rows=rows,
                               columns=columns,
                               kind=kind,
                               redirect='storage_places')
    elif kind == 'tool_locations':
        label_str = storage_type.rstrip('s').replace('_', ' ')
        form.form_name.label = 'Tool locations for {0}'.format(label_str)
        if request.method == 'POST':
            if form.submit.data:
                return redirect('/tool_locations/{0}/{1}'.format(
                    storage_type, docid))
            return redirect('/storage_places/{0}/{1}'.format(
                storage_type, docid))
        columns = (
            '<td style="width:100px"><b>Type</b></td>',
            '<td style="width:300px"><b>Description</b></td>',
            '<td style="width:100px"><b>Height</b></td>',
            '<td style="width:100px"><b>Width</b></td>',
            '<td style="width:100px"><b>Depth</b></td>',
        )
        if storage_type == 'cabinets':
            collection = Cabinets(mygarage)
        elif storage_type == 'shelving_units':
            collection = ShelvingUnits(mygarage)
        elif storage_type == 'toolchests':
            collection = Toolchests(mygarage)
        else:
            collection = Workbenches(mygarage)
        locations = collection.get_tool_locations(docid)
        rows = []
        for item in locations:
            loc_dict = dict(item)
            rows.append((loc_dict.get("_id"), loc_dict.get("type", None),
                         loc_dict.get("description",
                                      None), loc_dict.get("height", None),
                         loc_dict.get("width",
                                      None), loc_dict.get("depth", None)))
        return render_template("list.html",
                               form=form,
                               rows=rows,
                               columns=columns,
                               kind='tool_location/{0}/{1}'.format(
                                   storage_type, docid),
                               redirect=None)
    else:
        flash("Something is wrong. No 'kind' specified for list. "
              "Got this: {0}".format(kind))
    return None
コード例 #8
0
def vendor(vendor_id=None):
    """Manage vendor CRUD operations."""
    vendor_collection = Vendors(mygarage)
    form = VendorForm()
    # Get data from the form if present
    form_vendorid = form.vendorid.data
    form_name = form.name.data
    form_url = form.url.data
    form_sources = form.sources.data
    # If the route with the variable is called, change the create button to update
    # then populate the form with the data from the row in the table. Otherwise,
    # remove the delete button because this will be a new data item.
    if vendor_id:
        form.create_button.label.text = "Update"
        # Here, we get the data and populate the form
        data = vendor_collection.read(vendor_id)
        if data == []:
            flash("Vendor not found!")
        data_dict = dict(data[0])
        form.vendorid.data = data_dict.get("_id", None)
        form.name.data = data_dict.get("name", None)
        form.url.data = data_dict.get("url", None)
        form.sources.data = data_dict.get("sources", None)
    else:
        del form.del_button
    if request.method == 'POST':
        # First, determine if we must create, update, or delete when form posts.
        operation = "Create"
        if form.close_button.data:
            return redirect('/list/vendors')
        if form.create_button.data:
            if form.create_button.label.text == "Update":
                operation = "Update"
        if form.del_button and form.del_button.data:
            operation = "Delete"
        if form.validate_on_submit():
            # Get the data from the form here
            if operation == "Create":
                try:
                    vendor_data = {
                        "name": form_name,
                        "url": form_url,
                        "sources": form_sources,
                    }
                    res = vendor_collection.create(vendor_data)
                    if res[0]:
                        flash("Added.")
                    else:
                        flash("Cannot add vendor: {0}".format(res[1]))
                    return redirect('/list/vendors')
                except Exception as err:
                    flash(err)
            elif operation == "Update":
                try:
                    vendor_data = {
                        "_id": form.vendorid.data,
                        "name": form_name,
                        "url": form_url,
                        "sources": form_sources,
                    }
                    res = vendor_collection.update(vendor_data)
                    if res[0]:
                        flash("Updated.")
                    else:
                        flash("Cannot update vendor: {0}".format(res[1]))
                    return redirect('/list/vendors')
                except Exception as err:
                    flash(err)
            else:
                try:
                    if not mygarage.vendor_in_use(form_vendorid):
                        res = vendor_collection.delete(form_vendorid)
                        if res[0]:
                            flash("Deleted.")
                        else:
                            flash("Cannot delete vendor: {0}".format(res[1]))
                    else:
                        flash("Vendor {0} in use. Cannot delete.".format(
                            form_name))
                    return redirect('/list/vendors')
                except Exception as err:
                    flash(err)
        else:
            flash_errors(form)
    return render_template("vendor.html", form=form)