Esempio n. 1
0
 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
Esempio n. 2
0
 def __init__(self, user, *args, **kwargs):
     super(StatusForm, self).__init__(*args, **kwargs)
     self.user = user
     self.fields["operator"].set_operator(user, user.is_superuser)
     self.fields["operator"].initial = user.pk
     self.fields["timestamp"].initial = datetime.datetime.now()
     self.fields["process_classes"].choices = utils.choices_of_content_types(
         cls for cls in get_all_addable_physical_process_models() if self.is_editable(cls))
     self.fields["process_classes"].widget.attrs["size"] = 24
Esempio n. 3
0
 def __init__(self, user, *args, **kwargs):
     super(StatusForm, self).__init__(*args, **kwargs)
     self.user = user
     self.fields["operator"].set_operator(user, user.is_staff)
     self.fields["operator"].initial = user.pk
     self.fields["timestamp"].initial = datetime.datetime.now()
     self.fields[
         "process_classes"].choices = utils.choices_of_content_types(
             cls for cls in get_all_addable_physical_process_models()
             if self.is_editable(cls))
     self.fields["process_classes"].widget.attrs["size"] = 24
Esempio n. 4
0
 def __init__(self, user, *args, **kwargs):
     super(UserDetailsForm, self).__init__(*args, **kwargs)
     self.fields["auto_addition_topics"].queryset = user.topics
     choices = []
     processes = [process_class for process_class in jb_common_utils.get_all_models().values()
                 if issubclass(process_class, models.Process) and not process_class._meta.abstract
                 and process_class not in [models.Process, models.Deposition]]
     for department in user.samples_user_details.show_users_from_departments.iterator():
         process_from_department = set(process for process in processes
                                       if process._meta.app_label == department.app_label)
         choices.append((department.name, utils.choices_of_content_types(process_from_department)))
     if not choices:
         choices = (("", 9 * "-"),)
     self.fields["default_folded_process_classes"].choices = choices
     self.fields["default_folded_process_classes"].initial = [content_type.id for content_type
                                                  in user.samples_user_details.default_folded_process_classes.iterator()]
     self.fields["default_folded_process_classes"].widget.attrs["size"] = "15"
     self.fields["subscribed_feeds"].choices = utils.choices_of_content_types(
         list(get_all_addable_physical_process_models()) + [models.Sample, models.SampleSeries, Topic])
     self.fields["subscribed_feeds"].widget.attrs["size"] = "15"
     self.fields["show_users_from_departments"].choices = [(department.pk, department.name)
                                                         for department in Department.objects.iterator()]
     self.fields["show_users_from_departments"].initial = \
                 user.samples_user_details.show_users_from_departments.values_list("id", flat=True)
Esempio n. 5
0
 def __init__(self, user, *args, **kwargs):
     super(UserDetailsForm, self).__init__(*args, **kwargs)
     self.fields["auto_addition_topics"].queryset = user.topics
     choices = []
     processes = [process_class for process_class in jb_common_utils.get_all_models().values()
                 if issubclass(process_class, models.Process) and not process_class._meta.abstract
                 and process_class not in [models.Process, models.Deposition]]
     for department in user.samples_user_details.show_users_from_departments.iterator():
         processes_from_department = set(process for process in processes
                                         if process._meta.app_label == department.app_label)
         choices.append((department.name, utils.choices_of_content_types(processes_from_department)))
     if not choices:
         choices = (("", 9 * "-"),)
     self.fields["default_folded_process_classes"].choices = choices
     self.fields["default_folded_process_classes"].initial = [content_type.id for content_type
                                                  in user.samples_user_details.default_folded_process_classes.iterator()]
     self.fields["default_folded_process_classes"].widget.attrs["size"] = "15"
     self.fields["subscribed_feeds"].choices = utils.choices_of_content_types(
         list(get_all_addable_physical_process_models()) + [models.Sample, models.SampleSeries, Topic])
     self.fields["subscribed_feeds"].widget.attrs["size"] = "15"
     self.fields["show_users_from_departments"].choices = [(department.pk, department.name)
                                                         for department in Department.objects.iterator()]
     self.fields["show_users_from_departments"].initial = \
                 user.samples_user_details.show_users_from_departments.values_list("id", flat=True)
Esempio n. 6
0
 def __init__(self, user, data=None, **kwargs):
     super(ChooseTaskListsForm, self).__init__(data, **kwargs)
     choices = []
     for department in user.samples_user_details.show_users_from_departments.iterator():
         process_from_department = set(process for process in permissions.get_all_addable_physical_process_models().keys()
                                       if process._meta.app_label == department.app_label)
         choices.append((department.name, utils.choices_of_content_types(process_from_department)))
     if len(choices) == 1:
         choices = choices[0][1]
     if not choices:
         choices = (("", 9 * "-"),)
     self.fields["visible_task_lists"].choices = choices
     self.fields["visible_task_lists"].initial = [content_type.id for content_type
                                                  in user.samples_user_details.visible_task_lists.iterator()]
     self.fields["visible_task_lists"].widget.attrs["size"] = "15"
Esempio n. 7
0
 def __init__(self, user, data=None, **kwargs):
     super(ChooseTaskListsForm, self).__init__(data, **kwargs)
     choices = []
     for department in user.samples_user_details.show_users_from_departments.iterator(
     ):
         process_from_department = set(
             process for process in
             permissions.get_all_addable_physical_process_models().keys()
             if process._meta.app_label == department.app_label)
         choices.append(
             (department.name,
              utils.choices_of_content_types(process_from_department)))
     if len(choices) == 1:
         choices = choices[0][1]
     if not choices:
         choices = (("", 9 * "-"), )
     self.fields["visible_task_lists"].choices = choices
     self.fields["visible_task_lists"].initial = [
         content_type.id for content_type in
         user.samples_user_details.visible_task_lists.iterator()
     ]
     self.fields["visible_task_lists"].widget.attrs["size"] = "15"
Esempio n. 8
0
 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