-
Notifications
You must be signed in to change notification settings - Fork 4
Scheduler #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Scheduler #4
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # -*- coding: utf-8 -*- | ||
| """ | ||
|
|
||
| Action Behaviors | ||
| ================ | ||
|
|
||
| Implementations for the various behaviors action objects may have. | ||
|
|
||
|
|
||
| """ | ||
|
|
||
| from workflow import models | ||
|
|
||
|
|
||
| def request_data(case, action): | ||
| """Requests a piece of data by creating a message | ||
| that is displayed by the submission form.""" | ||
| request_message = models.Message( | ||
| message_type='Request', | ||
| view=action.output.view, | ||
| case=case, | ||
| response=action.output, | ||
| content='The data is requested', | ||
| section='upload' | ||
| ) | ||
| request_message.save() | ||
| request_message.origin.add(action), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,54 +1,203 @@ | ||
| from django.contrib import admin | ||
| from workflow import models | ||
| from django.contrib.admin import register | ||
| from django.contrib.admin import ModelAdmin | ||
| from django.contrib.admin import SimpleListFilter | ||
|
|
||
| from django.core.exceptions import FieldError | ||
|
|
||
| from django.contrib.auth.models import User, Group | ||
|
|
||
| from workflow.models import Workflow | ||
| from workflow.models import Case | ||
| from workflow.models import Action | ||
| from workflow.models import Parameter | ||
| from workflow.models import Condition | ||
| from workflow.models import Message | ||
| from workflow.models import Value | ||
|
|
||
|
|
||
| class WorkflowListFilter(SimpleListFilter): | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This filter is new |
||
| """Filter an object list by workflow""" | ||
|
|
||
| title = 'Workflow' | ||
| parameter_name = 'workflow' | ||
| default_value = None | ||
|
|
||
| def lookups(self, request, model_admin): | ||
| """Returns a list of tuples. The first element in each | ||
| tuple is the coded value for the option that will | ||
| appear in the URL query. The second element is the | ||
| human-readable name for the option that will appear | ||
| in the right sidebar.""" | ||
|
|
||
| return sorted([(str(workflow.id), workflow.name) | ||
| for workflow in Workflow.objects.all()]) | ||
|
|
||
| def queryset(self, request, queryset): | ||
| """Returns the filtered queryset based on the value | ||
| provided in the query string and retrievable via | ||
| `self.value()`.""" | ||
|
|
||
| if self.value(): | ||
| try: | ||
| return queryset.filter(workflow_id=self.value()) | ||
| except FieldError: | ||
| return queryset.filter(workflows=self.value()) | ||
| return queryset | ||
|
|
||
|
|
||
| class CaseListFilter(SimpleListFilter): | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This filter is new |
||
| """Filter an object list by workflow""" | ||
|
|
||
| title = 'Case' | ||
| parameter_name = 'case' | ||
| default_value = None | ||
|
|
||
| def lookups(self, request, model_admin): | ||
| """Returns a list of tuples. The first element in each | ||
| tuple is the coded value for the option that will | ||
| appear in the URL query. The second element is the | ||
| human-readable name for the option that will appear | ||
| in the right sidebar.""" | ||
|
|
||
| return sorted([(str(case.id), case.id) | ||
| for case in Case.objects.all()]) | ||
|
|
||
| @admin.register(models.Net) | ||
| class Net(admin.ModelAdmin): | ||
| list_display = ( | ||
| def queryset(self, request, queryset): | ||
| """Returns the filtered queryset based on the value | ||
| provided in the query string and retrievable via | ||
| `self.value()`.""" | ||
|
|
||
| if self.value(): | ||
| try: | ||
| return queryset.filter(case_id=self.value()) | ||
| except FieldError: | ||
| return queryset.filter(case=self.value()) | ||
| return queryset | ||
|
|
||
|
|
||
| @register(Workflow) | ||
| class WorkflowAdmin(ModelAdmin): | ||
|
|
||
| list_display = [ | ||
| 'name', | ||
| 'description' | ||
| ) | ||
| ] | ||
|
|
||
| @admin.register(models.Transition) | ||
| class Transition(admin.ModelAdmin): | ||
| list_display = ( | ||
| "name", | ||
| "transition_class", | ||
| ) | ||
|
|
||
| @admin.register(models.Token) | ||
| class Token(admin.ModelAdmin): | ||
| list_display = ( | ||
| 'id', | ||
| @register(Case) | ||
| class CaseAdmin(ModelAdmin): | ||
|
|
||
| def get_workflow_name(self, object): | ||
| return object.workflow.name | ||
|
|
||
| get_workflow_name.admin_order_field = 'name' # Allows column order sorting | ||
| get_workflow_name.short_description = 'Workflow Name' # Renames column head | ||
|
|
||
| list_display = [ | ||
| "id", | ||
| "get_workflow_name" | ||
| ] | ||
|
|
||
| list_filter = [ | ||
| WorkflowListFilter | ||
| ] | ||
|
|
||
|
|
||
| @register(Action) | ||
| class ActionAdmin(ModelAdmin): | ||
|
|
||
| list_display = [ | ||
| 'name', | ||
| 'color', | ||
| 'location' | ||
| ) | ||
| 'description', | ||
| 'action_function' | ||
| ] | ||
|
|
||
| list_filter = [ | ||
| WorkflowListFilter | ||
| ] | ||
|
|
||
|
|
||
| @register(Parameter) | ||
| class ParameterAdmin(ModelAdmin): | ||
|
|
||
| @admin.register(models.Location) | ||
| class Location(admin.ModelAdmin): | ||
| list_display = ( | ||
| list_display = [ | ||
| "name", | ||
| "description" | ||
| ) | ||
|
|
||
| @admin.register(models.Arc) | ||
| class Arc(admin.ModelAdmin): | ||
| list_display = ( | ||
| "type", | ||
| "transition", | ||
| "location" | ||
| ) | ||
|
|
||
| @admin.register(models.Case) | ||
| class Case(admin.ModelAdmin): | ||
| list_display = ( | ||
| "id", | ||
| "net", | ||
| #"messages" | ||
| ) | ||
| "view" | ||
| ] | ||
|
|
||
| list_filter = [ | ||
| WorkflowListFilter | ||
| ] | ||
|
|
||
|
|
||
| @register(Value) | ||
| class ValueAdmin(ModelAdmin): | ||
|
|
||
| list_display = [ | ||
| 'case', | ||
| 'parameter', | ||
| 'value', | ||
| 'state' | ||
| ] | ||
|
|
||
| list_filter = [ | ||
| WorkflowListFilter, | ||
| CaseListFilter | ||
| ] | ||
|
|
||
|
|
||
| @register(Condition) | ||
| class ConditionAdmin(ModelAdmin): | ||
|
|
||
| def get_action_name(self, object): | ||
| return object.action.name | ||
|
|
||
| def get_data_name(self, object): | ||
| return object.data.name | ||
|
|
||
| def get_workflow_name(self, object): | ||
| return object.workflow.name | ||
|
|
||
| get_action_name.admin_order_field = 'name' | ||
| get_data_name.admin_order_field = 'name' | ||
| get_workflow_name.admin_order_field = 'name' | ||
|
|
||
| get_action_name.short_descripition = 'Action' | ||
| get_data_name.short_description = 'Data' | ||
| get_workflow_name.short_description = 'Workflow Name' | ||
|
|
||
| list_display = [ | ||
| 'get_data_name', | ||
| 'state', | ||
| 'type', | ||
| 'get_action_name', | ||
| 'get_workflow_name' | ||
| ] | ||
|
|
||
| list_filter = [ | ||
| WorkflowListFilter | ||
| ] | ||
|
|
||
|
|
||
| @register(Message) | ||
| class MessageAdmin(ModelAdmin): | ||
|
|
||
| def get_case_id(self, object): | ||
| return object.case.id | ||
|
|
||
| get_case_id.admin_order_field = 'id' | ||
| get_case_id.short_description = 'case' | ||
|
|
||
| list_display = [ | ||
| 'id', | ||
| 'case', | ||
| 'timestamp' | ||
| ] | ||
|
|
||
| list_filter = [ | ||
| WorkflowListFilter, | ||
| CaseListFilter | ||
| ] | ||
|
|
||
|
|
||
| @admin.register(models.Message) | ||
| class Message(admin.ModelAdmin): | ||
| list_display = ("id", ) | ||
| # | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All the admin classes got updated to reflect model changes |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are the actual functions that implement the behavior of action objects
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved from operations.py; still more to come.