def report_task(self, task, edit_description=None): """Generate one feed entry for a new task or an edited task. :param task: the task that was created or edited :param edit_description: The dictionary containing data about what was edited in the task. Its keys correspond to the fields of `~samples.utils.views.EditDescriptionForm`. ``None`` if the task was newly created. :type task: `models.Task` :type edit_description: dict mapping str to ``object`` or ``None`` """ process_class = task.process_class self.interested_users = set( permissions.get_all_adders(task.process_class.model_class())) if edit_description is None: entry = models.FeedNewTask.objects.create( originator=self.originator, task=task) else: self.interested_users.add(task.customer) important = edit_description["important"] entry = models.FeedEditedTask.objects.create( originator=self.originator, task=task, description=edit_description["description"], important=important) self.__connect_with_users(entry)
def __init__(self, user, data=None, **kwargs): self.task = kwargs.get("instance") self.user = user self.fixed_fields = set() if self.task: eligible_operators = set(permissions.get_all_adders(self.task.process_class.model_class())) if self.task.operator: eligible_operators.add(self.task.operator) self.fixed_fields.add("process_class") if self.task.status == "1 new": self.fixed_fields.add("finished_process") if self.user not in eligible_operators: self.fixed_fields.update(["operator", "status"]) elif self.task.status in ["2 accepted", "3 in progress"]: if self.user != self.task.operator: self.fixed_fields.update(["status", "priority", "finished_process", "operator"]) if self.user != self.task.customer: self.fixed_fields.add("comments") else: self.fixed_fields.update(["priority", "finished_process", "operator"]) if self.user != self.task.operator: self.fixed_fields.add("status") if self.user != self.task.customer: self.fixed_fields.add("comments") else: self.fixed_fields.update(["status", "finished_process", "operator"]) if data is not None: data = data.copy() if self.task: data.update(forms.model_to_dict(self.task, self.fixed_fields)) else: initial = kwargs.get("initial", {}) initial.update({"status": "1 new"}) data.update(initial) super(TaskForm, self).__init__(data, **kwargs) self.fields["customer"].required = False self.fields["operator"].choices = [("", "---------")] if self.task: self.fields["operator"].choices.extend((user.pk, common_utils.get_really_full_name(user)) for user in common_utils.sorted_users_by_first_name(eligible_operators)) self.fields["process_class"].choices = utils.choices_of_content_types( permissions.get_all_addable_physical_process_models()) self.fields["finished_process"].choices = [("", "---------")] if self.task: old_finished_process_id = self.task.finished_process.id if self.task.finished_process else None if self.user == self.task.operator: self.fields["finished_process"].choices.extend( [(process.id, process.actual_instance) for process in Process.objects.filter( Q(operator=self.user, content_type=self.task.process_class) | Q(id=old_finished_process_id)).filter(finished=True).order_by("-timestamp")[:10]]) elif old_finished_process_id: self.fields["finished_process"].choices.append((old_finished_process_id, self.task.finished_process)) self.fields["comments"].widget.attrs["cols"] = 30 self.fields["comments"].widget.attrs["rows"] = 5 for field_name in self.fixed_fields: self.fields[field_name].widget.attrs["disabled"] = "disabled" self.fields[field_name].required = False
def __init__(self, addable_model_class): """ :param addable_model_class: the addable model class to which this instance belongs :type addable_model_class: ``class`` (derived from ``django.db.models.Model``) """ self.name = addable_model_class._meta.verbose_name_plural self.codename = addable_model_class.__name__.lower() content_type = ContentType.objects.get_for_model(addable_model_class) try: self.edit_permissions_permission = Permission.objects.get( codename="edit_permissions_for_{}".format(self.codename), content_type=content_type) except Permission.DoesNotExist: self.edit_permissions_permission = None try: self.add_permission = Permission.objects.get( codename="add_{}".format(self.codename), content_type=content_type) except Permission.DoesNotExist: self.add_permission = None try: self.view_all_permission = Permission.objects.get( codename="view_every_{}".format(self.codename), content_type=content_type) except Permission.DoesNotExist: self.view_all_permission = None try: self.edit_all_permission = Permission.objects.get( codename="change_{}".format(self.codename), content_type=content_type) except Permission.DoesNotExist: self.edit_all_permission = None base_query = User.objects.filter(is_active=True, is_superuser=False) permission_editors = base_query.filter(Q(groups__permissions=self.edit_permissions_permission) | Q(user_permissions=self.edit_permissions_permission)).distinct() \ if self.edit_permissions_permission else [] adders = permissions.get_all_adders(addable_model_class) full_viewers = base_query.filter(Q(groups__permissions=self.view_all_permission) | Q(user_permissions=self.view_all_permission)).distinct() \ if self.view_all_permission else [] full_editors = base_query.filter(Q(groups__permissions=self.edit_all_permission) | Q(user_permissions=self.edit_all_permission)).distinct() \ if self.edit_all_permission else [] self.permission_editors = sorted_users(permission_editors) self.adders = sorted_users(adders) self.full_viewers = sorted_users(full_viewers) self.full_editors = sorted_users(full_editors) self.all_users = sorted_users(set(adders) | set(permission_editors))
def report_removed_task(self, task): """Generate one feed for a removed task. It is called immediately before the task is actually deleted. :param task: the to-be-deleted task :type task: `models.Task` """ self.interested_users = set(permissions.get_all_adders(task.process_class.model_class())) self.interested_users.add(task.customer) entry = models.FeedRemovedTask.objects.create(old_id=task.id, originator=self.originator, process_class=task.process_class) entry.samples = task.samples.all() self.__connect_with_users(entry)
def __init__(self, addable_model_class): """ :param addable_model_class: the addable model class to which this instance belongs :type addable_model_class: ``class`` (derived from ``django.db.models.Model``) """ self.name = addable_model_class._meta.verbose_name_plural self.codename = addable_model_class.__name__.lower() content_type = ContentType.objects.get_for_model(addable_model_class) try: self.edit_permissions_permission = Permission.objects.get(codename="edit_permissions_for_{}".format(self.codename), content_type=content_type) except Permission.DoesNotExist: self.edit_permissions_permission = None try: self.add_permission = Permission.objects.get(codename="add_{}".format(self.codename), content_type=content_type) except Permission.DoesNotExist: self.add_permission = None try: self.view_all_permission = Permission.objects.get(codename="view_every_{}".format(self.codename), content_type=content_type) except Permission.DoesNotExist: self.view_all_permission = None try: self.edit_all_permission = Permission.objects.get(codename="change_{}".format(self.codename), content_type=content_type) except Permission.DoesNotExist: self.edit_all_permission = None base_query = User.objects.filter(is_active=True, is_superuser=False) permission_editors = base_query.filter(Q(groups__permissions=self.edit_permissions_permission) | Q(user_permissions=self.edit_permissions_permission)).distinct() \ if self.edit_permissions_permission else [] adders = permissions.get_all_adders(addable_model_class) full_viewers = base_query.filter(Q(groups__permissions=self.view_all_permission) | Q(user_permissions=self.view_all_permission)).distinct() \ if self.view_all_permission else [] full_editors = base_query.filter(Q(groups__permissions=self.edit_all_permission) | Q(user_permissions=self.edit_all_permission)).distinct() \ if self.edit_all_permission else [] self.permission_editors = sorted_users(permission_editors) self.adders = sorted_users(adders) self.full_viewers = sorted_users(full_viewers) self.full_editors = sorted_users(full_editors) self.all_users = sorted_users(set(adders) | set(permission_editors))
def report_task(self, task, edit_description=None): """Generate one feed entry for a new task or an edited task. :param task: the task that was created or edited :param edit_description: The dictionary containing data about what was edited in the task. Its keys correspond to the fields of `~samples.utils.views.EditDescriptionForm`. ``None`` if the task was newly created. :type task: `models.Task` :type edit_description: dict mapping str to ``object`` or ``None`` """ process_class = task.process_class self.interested_users = set(permissions.get_all_adders(task.process_class.model_class())) if edit_description is None: entry = models.FeedNewTask.objects.create(originator=self.originator, task=task) else: self.interested_users.add(task.customer) important = edit_description["important"] entry = models.FeedEditedTask.objects.create(originator=self.originator, task=task, description=edit_description["description"], important=important) self.__connect_with_users(entry)
def __init__(self, user, data=None, **kwargs): self.task = kwargs.get("instance") self.user = user self.fixed_fields = set() if self.task: eligible_operators = set( permissions.get_all_adders( self.task.process_class.model_class())) if self.task.operator: eligible_operators.add(self.task.operator) self.fixed_fields.add("process_class") if self.task.status == "1 new": self.fixed_fields.add("finished_process") if self.user not in eligible_operators: self.fixed_fields.update(["operator", "status"]) elif self.task.status in ["2 accepted", "3 in progress"]: if self.user != self.task.operator: self.fixed_fields.update( ["status", "priority", "finished_process", "operator"]) if self.user != self.task.customer: self.fixed_fields.add("comments") else: self.fixed_fields.update( ["priority", "finished_process", "operator"]) if self.user != self.task.operator: self.fixed_fields.add("status") if self.user != self.task.customer: self.fixed_fields.add("comments") else: self.fixed_fields.update( ["status", "finished_process", "operator"]) if data is not None: data = data.copy() if self.task: data.update(forms.model_to_dict(self.task, self.fixed_fields)) else: initial = kwargs.get("initial", {}) initial.update({"status": "1 new"}) data.update(initial) super(TaskForm, self).__init__(data, **kwargs) self.fields["customer"].required = False self.fields["operator"].choices = [("", "---------")] if self.task: self.fields["operator"].choices.extend( (user.pk, common_utils.get_really_full_name(user)) for user in common_utils.sorted_users_by_first_name( eligible_operators)) self.fields["process_class"].choices = utils.choices_of_content_types( permissions.get_all_addable_physical_process_models()) self.fields["finished_process"].choices = [("", "---------")] if self.task: old_finished_process_id = self.task.finished_process.id if self.task.finished_process else None if self.user == self.task.operator: self.fields["finished_process"].choices.extend([( process.id, process.actual_instance ) for process in Process.objects.filter( Q(operator=self.user, content_type=self.task.process_class) | Q(id=old_finished_process_id)).filter( finished=True).order_by("-timestamp")[:10]]) elif old_finished_process_id: self.fields["finished_process"].choices.append( (old_finished_process_id, self.task.finished_process)) self.fields["comments"].widget.attrs["cols"] = 30 self.fields["comments"].widget.attrs["rows"] = 5 for field_name in self.fixed_fields: self.fields[field_name].disabled = True self.fields[field_name].required = False