def arar_post_save(sender, instance, created, **kwargs): """Post-save hook to request updates from relevant projects if necessary. A new ARAR requests updates from relevant projects. An existing ARAR will not request updates. """ if created: snitch("ARARReport saved as new calls request_progress_reports.") request_progress_reports(instance)
def migrate_documents_to_html(debug=False): """Convert selected fields from markdown to storing HTML. * Converts project names. See also `migrate_html_tables_to_arrays` for migration of tables. """ from pythia.documents import models as m from pythia.utils import extract_md_tables, text2html for d in m.Document.objects.all(): if d._meta.model_name == 'conceptplan': if debug: print("Converting {0}".format(d)) d.summary = text2html(d.summary) d.outcome = text2html(d.outcome) d.collaborations = text2html(d.collaborations) d.strategic = text2html(d.strategic) d.budget = extract_md_tables(d.budget) d.staff = extract_md_tables(d.staff) d.save() action = 'Converted' elif d._meta.model_name == 'projectplan': d.backgorund = text2html(d.background) d.aims = text2html(d.aims) d.outcome = text2html(d.outcome) d.knowledge_transfer = text2html(d.knowledge_transfer) d.project_tasks = text2html(d.project_tasks) d.references = text2html(d.references) d.methodology = text2html(d.methodology) d.no_specimens = text2html(d.no_specimens) d.data_management = text2html(d.data_management) # d.operating_budget = extract_md_tables(d.operating_budget) d.save() action = 'Converted' elif d._meta.model_name == 'progressreport': d.context = text2html(d.context) d.aims = text2html(d.aims) d.progress = text2html(d.progress) d.implications = text2html(d.implications) d.future = text2html(d.future) d.save() action = 'Converted' elif d._meta.model_name == 'studentreport': d.progress_report = text2html(d.progress_report) d.save() action = 'Converted' else: action = "Skipping" # Common actions snitch("{0} {1}".format(action, d))
def call_update(proj, rep, final=False): """Request a (final) update from a project for a report. HACK: project status is set and saved, although the transition should do. """ from pythia.projects.models import Project if final: proj.request_final_update(rep) proj.status = Project.STATUS_FINAL_UPDATE else: proj.request_update(rep) proj.status = Project.STATUS_UPDATE proj.save() snitch("{0} processed request for progress report".format(proj.debugname))
def grant_special_role_permissions(): """Give special roles permission to change project plans. This is required so these roles can edit the endorsement fields. """ from django.contrib.auth.models import Group p = Permission.objects.get(codename="change_projectplan") # special roles bm, created = Group.objects.get_or_create(name='BM') hc, created = Group.objects.get_or_create(name='HC') ae, created = Group.objects.get_or_create(name='AE') dm, created = Group.objects.get_or_create(name='DM') # special roles can "change" all projectplans bm.permissions.add(p) hc.permissions.add(p) ae.permissions.add(p) dm.permissions.add(p) snitch("Granted {0} to special roles".format(p))
def request_progress_reports(instance): """Call Project.request_update() for each active or closing project.""" snitch("Function request_progress_reports() called.") from pythia.projects.models import ( Project, ScienceProject, CoreFunctionProject, StudentProject) snitch("{0} requesting progress reports".format(instance.fullname)) [call_update(Project.objects.get(pk=p), instance) for p in ScienceProject.objects.filter(status=Project.STATUS_ACTIVE ).values_list('pk', flat=True)] [call_update(Project.objects.get(pk=p), instance, final=True) for p in ScienceProject.objects.filter(status=Project.STATUS_CLOSING ).values_list('pk', flat=True)] [call_update(Project.objects.get(pk=p), instance) for p in CoreFunctionProject.objects.filter(status=Project.STATUS_ACTIVE ).values_list('pk', flat=True)] [call_update(Project.objects.get(pk=p), instance, final=True) for p in CoreFunctionProject.objects.filter(status=Project.STATUS_CLOSING ).values_list('pk', flat=True)] [call_update(Project.objects.get(pk=p), instance) for p in StudentProject.objects.filter(status=Project.STATUS_ACTIVE ).values_list('pk', flat=True)] snitch("{0} finished requesting progressreports".format(instance.fullname))
def update_document_permissions(document): """ Assign document permissions. document.project.members can submit_* and change_* (per object) group SMT can review_* (per class) group SCD can approve_* (per class) """ # Avoid cyclic dependency by importing inside method from guardian.shortcuts import assign_perm # from guardian import models as gm # TODO: handle removing permissions too. opts = document._meta snitch("Post-save: Updating permissions for document {0}".format( document.__str__())) for action in ["submit", "change"]: perm = "{0}.{1}_{2}".format(opts.app_label, action, opts.model_name) for user in document.project.members.all(): snitch("Giving {0} permission {1}".format(user.username, perm)) assign_perm(perm, user, document)