Exemplo n.º 1
0
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
 def handle(self, interval='', **options):
     """Handles the send_event_emails admin command."""
     # Check if there is an aggregation class defined.
     start_of_command = timezone.now()
     if interval not in ('realtime', 'daily', 'weekly', 'monthly'):
         raise CommandError('Please provide a valid interval argument'
                            ' (realtime, daily, weekly, monthly)')
     aggregation = load_member_from_setting('USER_AGGREGATION_CLASS',
                                            app_settings)()
     if not isinstance(aggregation, UserAggregationBase):
         raise CommandError(
             'Your user aggregation class must inherit UserAggregationBase')
     # Check interval argument and functions in the aggregation class.
     users = getattr(aggregation, 'get_users')(interval)
     if not users:
         print('No users to send a {0} email.'.format(interval))
         return
     # Get all events , which hasn't been sent yet.
     object_events = ObjectEvent.objects.filter(
         email_sent=False, user__pk__in=users).order_by('user__pk')
     if not object_events:
         print('No events to send.')
         return
     email_context = {}
     current_user = None
     self.sent_emails = 0
     for object_event in object_events:
         if current_user != object_event.user and email_context:
             self.send_mail_to_user(email_context, current_user)
             email_context = {}
         current_user = object_event.user
         if email_context.get(object_event.event_type.title):
             email_context[object_event.event_type.title].append(
                 object_event)
         else:
             email_context.update({
                 '{0}'.format(object_event.event_type.title):
                 [object_event]
             })
         object_event.email_sent = True
         object_event.save()
     # Send email even for the last user in the queryset, who cannot have
     # a follower
     if email_context:
         self.send_mail_to_user(email_context, current_user)
     print('The command took {0} seconds to finish. Sent {1} emails for {2}'
           ' events.'.format((timezone.now() - start_of_command).seconds,
                             self.sent_emails, object_events.count()))
 def handle(self, interval='', **options):
     """Handles the send_event_emails admin command."""
     # Check if there is an aggregation class defined.
     start_of_command = timezone.now()
     if interval not in ('realtime', 'daily', 'weekly', 'monthly'):
         raise CommandError('Please provide a valid interval argument'
                            ' (realtime, daily, weekly, monthly)')
     aggregation = load_member_from_setting(
         'USER_AGGREGATION_CLASS', app_settings)()
     if not isinstance(aggregation, UserAggregationBase):
         raise CommandError(
             'Your user aggregation class must inherit UserAggregationBase')
     # Check interval argument and functions in the aggregation class.
     users = getattr(aggregation, 'get_users')(interval)
     if not users:
         print('No users to send a {0} email.'.format(interval))
         return
     # Get all events , which hasn't been sent yet.
     object_events = ObjectEvent.objects.filter(
         email_sent=False, user__pk__in=users).order_by('user__pk')
     if not object_events:
         print('No events to send.')
         return
     email_context = {}
     current_user = None
     self.sent_emails = 0
     for object_event in object_events:
         if current_user != object_event.user and email_context:
             self.send_mail_to_user(email_context, current_user)
             email_context = {}
         current_user = object_event.user
         if email_context.get(object_event.event_type.title):
             email_context[object_event.event_type.title].append(
                 object_event)
         else:
             email_context.update({'{0}'.format(
                 object_event.event_type.title): [object_event]})
         object_event.email_sent = True
         object_event.save()
     # Send email even for the last user in the queryset, who cannot have
     # a follower
     if email_context:
         self.send_mail_to_user(email_context, current_user)
     print('The command took {0} seconds to finish. Sent {1} emails for {2}'
           ' events.'.format((timezone.now() - start_of_command).seconds,
                             self.sent_emails, object_events.count()))
Exemplo n.º 4
0
def is_access_allowed(owner, requester, obj, field_name=None):
    get_clearance_level = load_member_from_setting(
        'PRIVACY_CLEARANCE_LEVEL_FUNCTION')
    clearance_level = get_clearance_level(owner, requester)
    kwargs = {
        'content_type': ContentType.objects.get_for_model(obj),
        'object_id': obj.pk,
    }
    if field_name:
        kwargs.update({'field_name': field_name})
    else:
        kwargs.update({'field_name': ''})
    try:
        privacy_setting = PrivacySetting.objects.get(**kwargs)
    except ObjectDoesNotExist:
        return True  # No settings given? Allow for everyone
    if privacy_setting.level.clearance_level <= clearance_level:
        # Level has to be at least as high as the setting's label of the
        # object/field
        return True
    return False
Exemplo n.º 5
0
def is_access_allowed(owner, requester, obj, field_name=None):
    get_clearance_level = load_member_from_setting(
        'PRIVACY_CLEARANCE_LEVEL_FUNCTION')
    clearance_level = get_clearance_level(owner, requester)
    kwargs = {
        'content_type': ContentType.objects.get_for_model(obj),
        'object_id': obj.pk,
    }
    if field_name:
        kwargs.update({'field_name': field_name})
    else:
        kwargs.update({'field_name': ''})
    try:
        privacy_setting = PrivacySetting.objects.get(**kwargs)
    except ObjectDoesNotExist:
        return True  # No settings given? Allow for everyone
    if privacy_setting.level.clearance_level <= clearance_level:
        # Level has to be at least as high as the setting's label of the
        # object/field
        return True
    return False
Exemplo n.º 6
0
# flake8: noqa
from django_libs.loaders import load_member_from_setting
from event_rsvp import settings

from .base import EventForm

# importing GuestForm from settings
try:
    GuestForm = load_member_from_setting('GUEST_FORM', settings)
except:
    from .base import GuestForm