class HelloWorldProcess(Process): text = models.CharField(_('Message'), max_length=50) approved = models.BooleanField(_('Approved'), default=False) class Meta: verbose_name = _("World Request") verbose_name_plural = _('World Requests')
class HelloWorldFlow(Flow): """ Hello world This process demonstrates hello world approval request flow. """ process_class = HelloWorldProcess process_title = _('Hello world') process_description = _( 'This process demonstrates hello world approval request flow.') lock_impl = lock.select_for_update_lock summary_template = _("'{{ process.text }}' message to the world") start = (flow.Start(flow_views.CreateProcessView, fields=['text'], task_title=_('New message')).Permission( auto_create=True).Next(this.approve)) approve = (flow.View( flow_views.UpdateProcessView, fields=['approved'], task_title=_('Approve'), task_description=_("{{ process.text }} approvement required"), task_result_summary=_( "Messsage was {{ process.approved|yesno:'Approved,Rejected' }}")). Permission(auto_create=True).Next(this.check_approve)) check_approve = (flow.If( cond=lambda act: act.process.approved, task_title=_('Approvement check'), ).Then(this.send).Else(this.end)) send = (flow.Handler( this.send_hello_world_request, task_title=_('Send message'), ).Next(this.end)) end = flow.End(task_title=_('End'), ) def send_hello_world_request(self, activation): with open(os.devnull, "w") as world: world.write(activation.process.text)
class ResearchFlow(Flow): process_class = ResearchProcess process_title = _("Research Assistant Process") process_description = _( "This process helps researchers to find and analyze papers") lock_impl = lock.select_for_update_lock summary_template = ("Research: '{{ process.research.name }}'") start = (flow.Start(views.StartView).Permission(auto_create=True).Next( this.select_bases)) select_bases = (flow.View( views.BasesView).Permission(auto_create=True).Next(this.search_params)) search_params = (flow.View( views.SearchParams).Permission(auto_create=True).Next(this.approve)) approve = (flow.View( flow_views.UpdateProcessView, fields=['approved'], task_title=('Approve'), task_description=("Research {{ process.text }} approvement required"), task_result_summary=( "Messsage was {{ process.approved }}")).Permission( auto_create=True).Next(this.check_approve)) check_approve = (flow.If(cond=lambda act: act.process.approved, task_title=_('Approvement check')).Then( this.get_metadata).Else(this.end)) get_metadata = (flow.Handler(this.get_papers_metadata, task_title="Getting papers metadata").Next( this.paper_review)) paper_review = (flow.View(views.paper_review).Permission( auto_create=True).Next(this.check_papers_for_review)) check_papers_for_review = (flow.If( cond=lambda act: len(act.process.research.papers.all()) == act.process. research.papers_metadata_analized, task_title=_('Approvement check'), ).Then(this.end).Else(this.paper_review)) end = flow.End(task_title=_('End')) def get_papers_metadata(self, activation): #import ipdb; ipdb.set_trace() logger.info("Starting get metadata function") research = activation.process.research search_params = { 'search_string': research.search_params_string, 'date': research.search_params_date } papers = {} try: os.environ["SD_TOKEN"] except KeyError: print( "Please set the environment variable SD_TOKEN as token for ScienceDirect API" ) sys.exit(1) token = os.environ["SD_TOKEN"] search_bases = research.search_bases.iterator() for base in search_bases: if base.name == "ACM Digital Library": logging.info("Getting ACM papers metadata") acm_search = acm.Acm() papers.update(acm_search.search(search_params)) elif base.name == "ScienceDirect": logging.info("Getting ScienceDirect papers metadata") sd_search = science_direct.ScienceDirect(token) papers.update(sd_search.search(search_params)) for doi in papers.keys(): paper = papers[doi] paper.save() logging.info("Adding paper {}".format(paper.title)) research.papers.add(paper)
class Meta: verbose_name = _("World Request") verbose_name_plural = _('World Requests')
class Meta: proxy = True verbose_name = _("World Request") verbose_name_plural = _('World Requests')