Example #1
0
def create_argument(type='neut', title="", text="", authors=()):
    arg = Argument(arg_type=type, title=title)
    arg.node_type = 'argument'
    arg.save()
    text_obj = Text(node=arg, text=text)
    text_obj.save()
    for author in authors:
        text_obj.authors.add(author)
    text_obj.save()
    return arg
Example #2
0
 def get_all_arguments(self):
     """
     Gets all arguments and premises belong to it. It stores result in
     arguments variable. After you call this method, you can use arguments
     variable.
     """
     arguments = self.fetch_arguments()
     for argument in arguments.results:
         a = Argument(argument)
         a.user = User(a.user)
         premises = []
         for premise in a.premises:
             prms = Premise(premise)
             prms.user = User(prms.user)
             premises.append(prms)
         a.premises = premises
         self.arguments.append(a)
     if arguments.next:
         self.url = arguments.next
         self.get_all_arguments()
Example #3
0
def create_argument(node, arg_type='n', title="", text="", authors=()):
    arg_type = Argument.short_arg_type(arg_type)
    arg = Argument(arg_type=arg_type, title=title)
    arg.node_type = Node.ARGUMENT
    arg.concerns = node
    arg.save()
    text_obj = Text(node=arg, text=text)
    text_obj.save()
    for author in authors:
        text_obj.authors.add(author)
    text_obj.save()
    return arg
Example #4
0
    def post(self, package_id):
        data = self.request.json
        
        exi_arg_names = set()
        for arg in self.db.query(Argument).filter_by(package_id=package_id):
            name = None
            if arg.component_id is None:
                name = "%s" % arg.name
            else:
                name = "%s.%s" % (arg.component.name, arg.name)
            exi_arg_names.add(name)
        
        new_arg_names = set()
        for arg in data:
            name = None
            if "component" in arg:
                name = "%s.%s" % (arg["component"], arg["name"])
            else:
                name = "%s" % arg["name"]
            new_arg_names.add(name)

        for name in exi_arg_names - new_arg_names:
            (com_name, sep, arg_name) = name.partition(".")
            com_id = self.db.query(Component.id).filter_by(package_id=package_id, name=com_name).scalar()
            arg = self.db.query(Argument).filter_by(package_id=package_id, component_id=com_id, name=arg_name).one()
            self.db.execute("DELETE FROM argument_input WHERE argument_id=:argument_id", {"argument_id":arg.id})
            self.db.delete(arg)
        
        for argdict in data:
            kwargs = {}
            kwargs["package_id"] = package_id
            kwargs["name"] = argdict["name"]
            if "component" in argdict:
                kwargs["component_id"] = self.db.query(Component.id).filter_by(package_id=package_id, name=argdict["component"]).scalar()

            query = self.db.query(Argument).filter_by(**kwargs)
            if query.count() == 0:
                if "value" in argdict:
                    kwargs["value"] = argdict["value"]
                arg = Argument(**kwargs)
                self.db.add( arg )
            else:
                arg = query.one()
                if "value" in argdict:
                    kwargs["value"] = argdict["value"]
                if "reference" in argdict:
                    refdict = argdict["reference"]
                    if "component" in refdict:
                        component_id = self.db.query(Component.id).filter_by(package_id=package_id, name=refdict["component"]).scalar()
                    kwargs["reference_id"] = self.db.query(Argument.id).filter_by(package_id=package_id, component_id=component_id, name=refdict["name"]).scalar()
                else:
                    kwargs["reference_id"] = None
                for key, value in kwargs.iteritems():
                    arg.__setattr__(key, value)

            if "input" in argdict:
                inpdict = argdict["input"]
                if "release" in inpdict:
                    rlsname = inpdict.pop("release")
                    release_id = self.db.query(Release.id).filter_by(package_id=package_id, name=rlsname).scalar()
                    inpdict["release_id"] = release_id
                if "options" in inpdict:
                    options = inpdict.pop("options")
                    self.db.execute("DELETE FROM argument_input_option WHERE argument_id=:argument_id", {"argument_id":arg.id})
                    for option in options:
                        arginpopt = ArgumentInputOption(arg.id, option)
                        self.db.add(arginpopt)
                        
                if arg.input is None:
                    arg.input = ArgumentInput(**inpdict)
                else:
                    for key, value in inpdict.iteritems():
                        arg.input.__setattr__(key, value)
            else:
                self.db.execute("DELETE FROM argument_input WHERE argument_id=:argument_id", {"argument_id":arg.id})
            self.db.commit()