def repair_item(modeladmin, request, queryset): for obj in queryset: # t = Transition.objects.get(name = "") s = State.objects.get(name = "Item Being Repaired") # u = request.user u = User.objects.get(username = "******") # do_transition(obj, t, u) set_state(obj, s)
def pull_item(modeladmin, request, queryset): for obj in queryset: t = Transition.objects.get(name = "Pull Item") s = State.objects.get(name = "Item Pulled") # u = request.user u = User.objects.get(username = "******") # do_transition(obj, t, u) set_state(obj, s)
def approve_order_request(modeladmin, request, queryset): for obj in queryset: # t = Transition.objects.get(name = "") s = State.objects.get(name = "Digitization Request Approved") # u = request.user u = User.objects.get(username = "******") # do_transition(obj, t, u) set_state(obj, s)
def outsource_item_digitization(modeladmin, request, queryset): for obj in queryset: # t = Transition.objects.get(name = "") s = State.objects.get(name = "Item Outsourced") # u = request.user u = User.objects.get(username = "******") # do_transition(obj, t, u) set_state(obj, s)
def withdraw_item(modeladmin, request, queryset): for obj in queryset: # t = Transition.objects.get(name = "") s = State.objects.get(name = "Item Being Withdrawn (Deaccessioned)") # u = request.user u = User.objects.get(username = "******") # do_transition(obj, t, u) set_state(obj, s)
def set_state_for_draft(draft, state, estimated_date=None): workflow = get_workflow_for_draft(draft) if state in workflow.get_states(): set_state(draft, state) relation = StateObjectRelation.objects.get( content_type=ContentType.objects.get_for_model(draft), content_id=draft.pk) metadata = StateObjectRelationMetadata.objects.get_or_create(relation=relation)[0] metadata.from_date = datetime.date.today() metadata.to_date = estimated_date metadata.save() return state return False
def perm(request): workflow = Workflow.objects.get(name="Standard") private = State.objects.get(name="Private", workflow= workflow) public = State.objects.get(name="Public", workflow= workflow) # Add a role from permissions.utils import register_role owner = Role.objects.get(name='Owner') # Create a user from django.contrib.auth.models import User user = User.objects.get(username="******") # Assign user to role owner.add_principal(user) # Create example content type page_1 = Project.objects.get(name="abc") # Register permissions from permissions.utils import register_permission view = register_permission("View", "view") edit = register_permission("Edit", "edit") # Add all permissions which are managed by the workflow from workflows.models import WorkflowPermissionRelation WorkflowPermissionRelation.objects.create(workflow=workflow, permission=view) WorkflowPermissionRelation.objects.create(workflow=workflow, permission=edit) # Add permissions for the single states from workflows.models import StatePermissionRelation StatePermissionRelation.objects.create(state=public, permission=view, role=owner) StatePermissionRelation.objects.create(state=private, permission=view, role=owner) StatePermissionRelation.objects.create(state=private, permission=edit, role=owner) # Assign the workflow to the content object from workflows.utils import set_workflow set_workflow(page_1, workflow) # Now self.page_1 has the intial workflow state. from permissions.utils import has_permission print has_permission(page_1, user, "edit") # Now we change the workflow state set_state(page_1, public) print has_permission(page_1, user, "edit")
def change_state(self, transition, actor): """ Set new state for the instance of the workflow managed model :param transition: a transition object :type transition: `workflows.models.Transition <http://packages.python.org/django-workflows/api.html#workflows.models.Transition>`_ :param actor: a user object :type actor: `django.contrib.auth.User <https://docs.djangoproject.com/en/1.4/topics/auth/#users>`_ This method send a signal to the application to notify a managed instance is changing state. The signal provides several arguments as the previous state, the executed transition and the actor. """ actual_state = self.state set_state(self, transition.destination) changed_state.send_robust(sender=self, transition=transition, actor=actor, previous_state=actual_state)
def request_for_sharing(request): """ send a request for sharing to resource owner """ resource = Resource.objects.get(id=request.GET.get('id')) relatedResources = request.GET.getlist('relatedResources', []) resource_request, created = ResourceRequest.objects.get_or_create(resource=resource, requestor=request.user) resource_request.message = request.GET.get('message', None) resource_request.save() set_workflow(resource_request, ResourceRequestWorkflow) set_state(resource_request, request_pending) # alert owner by email try: alert_user_by_email( mail_from='VPH-Share Webmaster <*****@*****.**>', mail_to='%s %s <%s>' % (resource.owner.first_name, resource.owner.last_name, resource.owner.email), subject='[VPH-Share] You have receive a request for sharing', mail_template='incoming_request_for_sharing', dictionary={ 'message': request.GET.get('message', None), 'resource': resource, 'requestor': request.user, 'BASE_URL': settings.BASE_URL } ) # alert requestor by email alert_user_by_email( mail_from='VPH-Share Webmaster <*****@*****.**>', mail_to='%s %s <%s>' % (request.user.first_name, request.user.last_name, request.user.email), mail_template='request_for_sharing_sent', subject='[VPH-Share] Your request for sharing has been delivered to resource owner', dictionary={ 'requestor': request.user } ) except Exception, e: pass
def create_institution(request): """ submit a request to create an institution """ if request.method == 'POST': if request.user.id not in request.POST.getlist('managers'): request.POST.appendlist('managers', unicode(request.user.id)) # filter post field "name" request.POST['name'] = ''.join( c for c in request.POST['name'] if c.isalnum() ) form = InstitutionForm(request.POST, request.FILES) if form.is_valid(): group = form.save(commit=False) group.save() set_workflow(group, GroupRequestWorkflow) set_state(group, group_pending) return redirect('/groups') else: return render_to_response( 'scs_groups/createinstitution.html', {'form': form}, RequestContext(request) ) else: form = InstitutionForm(initial={'managers': [request.user]}) return render_to_response( 'scs_groups/createinstitution.html', {'form': form}, RequestContext(request) )
def subscribe(request, idGroup=None, idStudy=None, iduser=None): """ create a subscription_pending subscription to an institution """ if request.method == 'POST': if idStudy is not None: group, gtype = get_group_by_id(idStudy) else: group, gtype = get_group_by_id(idGroup) if iduser is None: subscription = SubscriptionRequest(user=request.user, group=group) subscription.save() set_workflow(subscription, SubscriptionRequestWorkflow) set_state(subscription, subscription_pending) elif request.user in group.managers.all(): user = User.objects.get(pk=iduser) subscription = SubscriptionRequest.objects.get(user=user, group=group) if request.POST['operation'] == 'accept': if do_transition(subscription, subscription_accept_subscription, request.user): group.user_set.add(user) subscription.delete() else: do_transition(subscription, subscription_refuse_subscription, request.user) subscription.delete() if gtype == 1: return redirect('/groups/%s/%s/' % (idGroup, idStudy)) else: return redirect('/groups/%s/' % idGroup) return redirect('/groups')
def __set__(self, instance, value): utils.set_state(instance, value)
def template_digital_item(modeladmin, request, queryset): for obj in queryset: s = State.objects.get(name = "Templated (Batch Edited)") u = User.objects.get(username = "******") set_state(obj, s)
def archive_hathi_trust_digital_item(modeladmin, request, queryset): for obj in queryset: s = State.objects.get(name = "Archived (Hathi Trust)") u = User.objects.get(username = "******") set_state(obj, s)
def ocr_digital_item(modeladmin, request, queryset): for obj in queryset: s = State.objects.get(name = "OCR'd") u = User.objects.get(username = "******") set_state(obj, s)
def archive_emory_digital_item(modeladmin, request, queryset): for obj in queryset: s = State.objects.get(name = "Archived (Fedora)") u = User.objects.get(username = "******") set_state(obj, s)
subject='[VPH-Share] Your request for sharing has been delivered to resource owner', dictionary={ 'requestor': request.user } ) except Exception, e: pass for related in relatedResources: resource = Resource.objects.get(global_id=related) resource_request, created = ResourceRequest.objects.get_or_create(resource=resource, requestor=request.user) resource_request.message = request.GET.get('message', None) resource_request.save() set_workflow(resource_request, ResourceRequestWorkflow) set_state(resource_request, request_pending) # alert owner by email try: alert_user_by_email( mail_from='VPH-Share Webmaster <*****@*****.**>', mail_to='%s %s <%s>' % (resource.owner.first_name, resource.owner.last_name, resource.owner.email), subject='[VPH-Share] You have receive a request for sharing', mail_template='incoming_request_for_sharing', dictionary={ 'message': request.GET.get('message', None), 'resource': resource, 'requestor': request.user, 'BASE_URL': settings.BASE_URL } )
def complete_digital_item(modeladmin, request, queryset): for obj in queryset: s = State.objects.get(name = "Digitization Completed") u = User.objects.get(username = "******") set_state(obj, s)
def describe_digital_item(modeladmin, request, queryset): for obj in queryset: s = State.objects.get(name = "Described (Fast Track)") u = User.objects.get(username = "******") set_state(obj, s)
def qc_digital_item(modeladmin, request, queryset): for obj in queryset: s = State.objects.get(name = "Quality Checked") u = User.objects.get(username = "******") set_state(obj, s)