Esempio n. 1
0
def get_process_analysis_menu():
    return [{
        'url': url_for('process_analysis.process_analysis', form_id=unicode(form.pk)),
        'text': form.name,
        'icon': '<i class="glyphicon glyphicon-stats"></i>'
    } for form in forms.find().filter(
        Q(form_type='INCIDENT') |
        Q(form_type='CHECKLIST', groups__fields__analysis_type='PROCESS')
    ).order_by('form_type', 'name')]
Esempio n. 2
0
def get_result_analysis_menu():
    return [{
        'url':
        url_for('result_analysis.results_analysis', form_id=unicode(form.pk)),
        'text':
        form.name,
        'icon':
        '<i class="glyphicon glyphicon-stats"></i>'
    } for form in forms.find(form_type='CHECKLIST',
                             groups__fields__analysis_type='RESULT').order_by(
                                 'form_type', 'name')]
Esempio n. 3
0
def get_process_analysis_menu():
    return [{
        'url':
        url_for('process_analysis.process_analysis', form_id=unicode(form.pk)),
        'text':
        form.name,
        'icon':
        '<i class="glyphicon glyphicon-stats"></i>'
    } for form in forms.find().filter(
        Q(form_type='INCIDENT')
        | Q(form_type='CHECKLIST', groups__fields__analysis_type='PROCESS')).
            order_by('form_type', 'name')]
Esempio n. 4
0
 class ChecklistInitForm(WTSecureForm):
     form = SelectField(_('Form'),
                        choices=_make_choices(
                            forms.find(events=g.event,
                                       form_type='CHECKLIST').scalar(
                                           'id', 'name'), _('Select form')),
                        validators=[validators.input_required()])
     role = SelectField(_('Role'),
                        choices=_make_choices(
                            participant_roles.find().scalar('id', 'name'),
                            _('Select role')),
                        validators=[validators.input_required()])
     location_type = SelectField(
         _('Location type'),
         choices=_make_choices(location_types.find().scalar('id', 'name'),
                               _('Select location type')),
         validators=[validators.input_required()])
Esempio n. 5
0
def index():
    args = request.args.copy()

    # get variables from query params, or use (hopefully) sensible defaults
    group = args.pop('group', None)
    location_type_id = args.pop('locationtype', None)

    page_title = _('Dashboard')
    template_name = 'frontend/dashboard.html'

    event = get_event()

    if not args.get('checklist_form'):
        form = forms.find(
            events=event, form_type='CHECKLIST').order_by('name').first()
    else:
        form = forms.get_or_404(pk=args.get('checklist_form'))

    if form:
        args.setdefault('checklist_form', unicode(form.id))

    queryset = submissions.find(
        form=form,
        submission_type='M'
    )
    filter_ = dashboard_filterset()(queryset, data=args)

    obs_queryset = submissions.find(
        form=form,
        submission_type='O'
    )
    obs_filter_ = dashboard_filterset()(obs_queryset, data=args)

    location = None
    if args.get('location'):
        location = locations.get_or_404(pk=args.get('location'))

    # activate sample filter
    filter_form = filter_.form
    queryset = filter_.qs
    obs_queryset = obs_filter_.qs
    next_location_type = False

    if not group:
        data = get_coverage(queryset)
        obs_data = get_coverage(obs_queryset)
    else:
        page_title = page_title + u' · {}'.format(group)
        if not location_type_id:
            location_type = location_types.find(
                is_administrative=True).order_by('ancestor_count').first()
        else:
            location_type = LocationType.objects.get_or_404(
                pk=location_type_id)

        # get the requisite location type - the way the aggregation
        # works, passing in a 'State' location type won't retrieve
        # data for the level below the 'State' type, it will retrieve
        # it for the 'State' type. in general, this isn't the behaviour
        # we want, so we need to find the lower level types and get the
        # one we want (the first of the children)
        le_temp = [lt for lt in location_type.children
                   if lt.is_administrative]

        try:
            next_location_type = le_temp[0]
        except IndexError:
            next_location_type = None

        data = get_coverage(queryset, group, location_type)
        obs_data = get_coverage(obs_queryset, group, location_type)

    # load the page context
    location_id = args.pop('location', '')
    context = {
        'args': args,
        'location_id': location_id,
        'next_location': bool(next_location_type),
        'data': data,
        'obs_data': obs_data,
        'filter_form': filter_form,
        'page_title': page_title,
        'location': location,
        'locationtype': getattr(next_location_type, 'id', ''),
        'group': group or ''
    }

    return render_template(
        template_name,
        **context
    )
Esempio n. 6
0
def main_dashboard(form_id=None):
    args = request.args.copy()

    # get variables from query params, or use (hopefully) sensible defaults
    group = args.pop('group', None)
    location_type_id = args.pop('locationtype', None)

    template_name = 'frontend/dashboard.html'

    event = get_event()

    if not form_id:
        form = forms.find(events=event,
                          form_type='CHECKLIST').order_by('name').first()
    else:
        form = forms.get_or_404(pk=form_id, form_type="CHECKLIST")

    if form is not None:
        page_title = _(u'Dashboard · %(name)s', name=form.name)
    else:
        page_title = _(u'Dashboard')

    queryset = submissions.find(form=form, submission_type='M')
    filter_ = dashboard_filterset()(queryset, data=args)

    obs_queryset = submissions.find(form=form, submission_type='O')
    obs_filter_ = dashboard_filterset()(obs_queryset, data=args)

    location = None
    if args.get('location'):
        location = locations.get_or_404(pk=args.get('location'))

    # activate sample filter
    filter_form = filter_.form
    queryset = filter_.qs
    obs_queryset = obs_filter_.qs
    next_location_type = False

    if not group:
        data = get_coverage(queryset)
        obs_data = get_coverage(obs_queryset)
    else:
        page_title = page_title + u' · {}'.format(group)
        if not location_type_id:
            location_type = location_types.find(
                is_administrative=True).order_by('ancestor_count').first()
        else:
            location_type = LocationType.objects.get_or_404(
                pk=location_type_id)

        # get the requisite location type - the way the aggregation
        # works, passing in a 'State' location type won't retrieve
        # data for the level below the 'State' type, it will retrieve
        # it for the 'State' type. in general, this isn't the behaviour
        # we want, so we need to find the lower level types and get the
        # one we want (the first of the children)
        le_temp = [lt for lt in location_type.children if lt.is_administrative]

        try:
            next_location_type = le_temp[0]
        except IndexError:
            next_location_type = None

        data = get_coverage(queryset, group, location_type)
        obs_data = get_coverage(obs_queryset, group, location_type)

    # load the page context
    location_id = args.pop('location', '')
    context = {
        'args': args,
        'location_id': location_id,
        'next_location': bool(next_location_type),
        'data': data,
        'obs_data': obs_data,
        'filter_form': filter_form,
        'page_title': page_title,
        'location': location,
        'locationtype': getattr(next_location_type, 'id', ''),
        'group': group or '',
        'form_id': unicode(form.pk) if form else None
    }

    return render_template(template_name, **context)