Пример #1
0
    def construct_Single_Project(self):
        """
        This method constucts a Project with one of each
        of the objects from the hierarchy and returns it.
        """ 
        project = Project("PojectTestName", "ProjectTestDescription")
        groupone = BudgetGroup("BGTestName", "BGTestDescription")
        itemone = BudgetItem("BITestName", "BITestDescription", 2, 5)

        groupone.add(itemone)              
        project.add(groupone)

        return project
Пример #2
0
    def construct_Multiple_Project(self):
        """
        This method constucts a Project with two of each
        of the objects from the hierarchy and returns it.
        """ 
        project = Project("PojectTestName", "ProjectTestDescription")
        groupone = BudgetGroup("BGTestName", "BGTestDescription")
        grouptwo = BudgetGroup("BGTestNameTwo", "BG Test Description Two")
        itemone = BudgetItem("BITestName", "BITestDescription", 2, 5)
        itemtwo = BudgetItem("BITestNameTwo", "BI Test Description Two", 10, 3)
        itemthree = BudgetItem("BITestNameThree", "BI Test Description Three", 5, 4)
        itemfour = BudgetItem("BITestNameFour", "BI Test Description Four", 2, 5)
                        
        groupone.add(itemone)
        groupone.add(itemtwo)
        grouptwo.add(itemthree)
        grouptwo.add(itemfour)
                        
        project.add(groupone)
        project.add(grouptwo)

        return project
Пример #3
0
def add_projects():
    """Explains what projects are and shows form to add new projects. POST adds new project"""

    form = ProjectAddForm()
    form.plots.choices = [(
        plot.id,
        plot.name,
    ) for plot in g.user.plots]
    form.plantlists.choices = [(
        plantlist.id,
        plantlist.name,
    ) for plantlist in g.user.plantlists]
    if form.validate_on_submit():
        try:
            project = Project.add(
                name=form.name.data,
                description=form.description.data,
                # is_public=form.is_public.data,
            )
            db.session.commit()
            g.user.projects.append(project)

            # Append selected plots to the project
            for plot in form.plots.data:
                plot = Plot.query.get(plot)
                project.plots.append(plot)
            # Append selected plant list to the project
            for plantlist in form.plantlists.data:
                plantlist = PlantList.query.get(plantlist)
                project.plantlists.append(plantlist)

            db.session.commit()

        except IntegrityError:
            flash("Failed to create Project.", "danger")
            return render_template("projects/add.html", form=form)

        flash("Successfully created project!", "success")
        return redirect(url_for("show_project", project_id=project.id))

    return render_template("projects/add.html", form=form)
Пример #4
0
def addData():
    # Enter data for constructing the objects.
    name = raw_input("\nEnter Project Name:\n")
    desc = raw_input("\nEnter Project Description:\n")

    # Instantiate a Project
    project = Project(name, desc)

    # Loop while adding groups and items
    while True:
        # The user has to enter "0" to stop the loop
        if "0" == raw_input ("\nEnter 0 to stop adding BudgetGroups: "):
                break
        
        name = raw_input("\nEnter BudgetGroup Name:\n")
        desc = raw_input("\nEnter BudgetGroup Description:\n")

        # Instantiate a BudgetGroup object
        group = BudgetGroup(name, desc)

        # Loop and add multiple Items
        while True:
            # The user has to enter "0" to stop the loop
            if "0" == raw_input ("\nEnter 0 to stop adding BudgetItems: "):
                break
            
            name = raw_input("\nEnter BudgetItem Name:\n")
            desc = raw_input("\nEnter BudgetItem Description:\n")
            
            # Ensure quantities are not negative or letters.
            # If the input is letters catch the error and set quantity to
            # -1 so it goes into the loop.
            try:
                quan = int(raw_input("\nEnter BudgetItem Quantity:\n") )
            except ValueError:
                quan = -1             
            while quan < 0:
                try:
                    quan = int(raw_input("\nQuantity can't be negative or letters. "+
                                     "Enter BudgetItem Quantity:\n"))
                except ValueError:
                    quan = -1
                    
            # Ensure rates are not negative.
            # If the input is letters catch the error and set rate to
            # -1 so it goes into the loop.
            try:
                rate = int(raw_input("\nEnter BudgetItem Rate:\n"))
            except ValueError:
                rate = -1
            while rate < 0:
                try:
                    rate = int(raw_input("\nRate can't be negative or letters. "+
                                     "Enter BudgetItem Rate:\n"))
                except ValueError:
                    rate = -1

            # Instantiate a BudgetItem.
            item = BudgetItem (name, desc, quan, rate)
            group.add(item)
            
        project.add(group)
        

    # Return the Project will all the objects in it
    return project