Example #1
0
 def __init__(self, reviewed_item, user=None, *args, **kwargs):
     self.user = user
     self.reviewed_item = reviewed_item
     self.widget = load_member(
         getattr(settings, 'REVIEW_FORM_CHOICE_WIDGET',
                 'django.forms.widgets.Select')
     )()
     super(ReviewForm, self).__init__(*args, **kwargs)
     # Dynamically add fields for each rating category
     for category in RatingCategory.objects.all():
         field_name = 'category_{0}'.format(category.pk)
         choices = category.get_choices()
         self.fields[field_name] = forms.ChoiceField(
             choices=choices, label=category.name,
             help_text=category.question,
             widget=self.widget,
         )
         self.fields[field_name].required = category.required
         if self.instance.pk:
             try:
                 self.initial.update({
                     'category_{0}'.format(category.pk): Rating.objects.get(
                         review=self.instance, category=category).value,
                 })
             except Rating.DoesNotExist:
                 pass
Example #2
0
 def __init__(self, reviewed_item, user=None, *args, **kwargs):
     self.user = user
     self.reviewed_item = reviewed_item
     self.widget = load_member(
         getattr(settings, 'REVIEW_FORM_CHOICE_WIDGET',
                 'django.forms.widgets.Select'))()
     super(ReviewForm, self).__init__(*args, **kwargs)
     # Dynamically add fields for each rating category
     for category in RatingCategory.objects.all():
         field_name = 'category_{0}'.format(category.pk)
         choices = category.get_choices()
         self.fields[field_name] = forms.ChoiceField(
             choices=choices,
             label=category.name,
             help_text=category.question,
             widget=self.widget,
         )
         self.fields[field_name].required = category.required
         if self.instance.pk:
             try:
                 self.initial.update({
                     'category_{0}'.format(category.pk):
                     Rating.objects.get(review=self.instance,
                                        category=category).value,
                 })
             except Rating.DoesNotExist:
                 pass
def get_sprints():
    """
    Returns all sprints, enriched with their assigned tasks.

    The project should only have one ``sprints.py`` module. We will define it's
    path via the ``RAPID_PROTOTYPING_SPRINTS_MODULE`` setting. The setting
    should be the fully qualified name of the ``sprints.py`` module (i.e.
    ``projectname.context.sprints.sprints``).

    Furthermore the project can have any amount of ``*_costs.py`` modules in
    any folder (as long as they are on the pythonpath).

    This function will find all ``*_costs.py`` modules and add those tasks,
    that have been assigned to a sprint, to the corresponding sprints in the
    ``sprints.py`` module.

    """
    sprints = load_member_from_setting(
        'RAPID_PROTOTYPING_SPRINTS_MODULE')

    all_tasks = []
    # TODO The onerror parameter is basically a workaround to ignore errors
    # The reason for that being, that in my case, the GeoDjango package was in
    # the path, permanently requesting certain libraries on import. Since they
    # were not present, the search was aborted with an OSError.
    for importer, package_name, _ in pkgutil.walk_packages(
            onerror=lambda p: p):
        if not package_name.endswith('_costs'):
            continue
        if not getattr(settings, 'TEST_RUN', None) and (
                '.test_app.' in package_name):  # pragma: nocover
            continue
        costs = load_member(package_name + '.costs')
        for task in costs:
            all_tasks.append(task)
    sorted_tasks = sorted(all_tasks, key=itemgetter('id'))

    for sprint in sprints:
        remaining_time = 0
        sprint['tasks'] = []
        for task in sorted_tasks:
            if task.get('sprint') == sprint.get('id'):
                if not task.get('actual_time'):
                    remaining_time += \
                        task.get('developer_time') or task.get('time')
                sprint.get('tasks').append(task)
        sprint['remaining_time'] = remaining_time
        sprint['remaining_hours'] = round(float(remaining_time) / 60, 2)
    return sprints
Example #4
0
 def get_context_data(self, **kwargs):
     ctx = []
     for processor_path in PROCESSORS:
         processor = load_member(processor_path)
         try:
             ctx.append(processor())
         except Exception as ex:
             response = {
                 'label':
                 'error',
                 'status':
                 SERVER_STATUS['DANGER'],
                 'info':
                 ('The server encountered an error while running this'
                  ' processor: "{0}"'.format(ex))
             }
             ctx.append(response)
     return ctx
Example #5
0
 def get_form_class(self):
     if hasattr(settings, 'CONVERSATION_MESSAGE_FORM'):
         return load_member(settings.CONVERSATION_MESSAGE_FORM)
     return MessageForm
Example #6
0
    def get_form_class(self):
        print("Get Form Class")

        if hasattr(settings, 'CONVERSATION_MESSAGE_FORM'):
            return load_member(settings.CONVERSATION_MESSAGE_FORM)
        return MessageForm