Beispiel #1
0
    def post(self, *args, **kwargs):
        tally_id = kwargs.get('tally_id')
        form_class = self.get_form_class()
        form = self.get_form(form_class)

        if form.is_valid():
            barcode = form.cleaned_data['barcode'] or\
                        form.cleaned_data['barcode_scan']
            result_form = get_object_or_404(ResultForm,
                                            barcode=barcode,
                                            tally__id=tally_id)

            possible_states = [
                FormState.CORRECTION, FormState.DATA_ENTRY_1,
                FormState.DATA_ENTRY_2, FormState.INTAKE,
                FormState.QUALITY_CONTROL, FormState.ARCHIVING,
                FormState.UNSUBMITTED
            ]

            if groups.SUPER_ADMINISTRATOR in groups.user_groups(
                    self.request.user):
                possible_states.append(FormState.ARCHIVED)

            form = safe_form_in_state(result_form, possible_states, form)

            if form:
                return self.form_invalid(form)

            self.request.session['result_form'] = result_form.pk

            return redirect(self.success_url, tally_id=tally_id)
        else:
            return self.form_invalid(form)
Beispiel #2
0
    def post(self, *args, **kwargs):
        tally_id = kwargs.get('tally_id')
        post_data = self.request.POST

        if 'result_form' in post_data:
            pk = session_matches_post_result_form(post_data, self.request)

            result_form = get_object_or_404(ResultForm,
                                            pk=pk,
                                            tally__id=tally_id)
            form_in_state(result_form, FormState.AUDIT)

            # Track audit clerks result form processing time
            if groups.user_groups(self.request.user)[0] == groups.AUDIT_CLERK:
                encoded_start_time = self.request.session.get(
                    'encoded_result_form_audit_start_time')
                save_result_form_processing_stats(self.request,
                                                  encoded_start_time,
                                                  result_form)

            del self.request.session['result_form']

            return redirect('audit', tally_id=tally_id)

        return self.render_to_response(
            self.get_context_data(result_form=result_form, tally_id=tally_id))
Beispiel #3
0
    def post(self, *args, **kwargs):
        form_class = self.get_form_class()
        form = self.get_form(form_class)

        if form.is_valid():
            barcode = form.cleaned_data['barcode']
            result_form = get_object_or_404(ResultForm, barcode=barcode)

            possible_states = [FormState.CORRECTION,
                               FormState.DATA_ENTRY_1,
                               FormState.DATA_ENTRY_2,
                               FormState.ARCHIVING,
                               FormState.QUALITY_CONTROL]

            if groups.SUPER_ADMINISTRATOR in groups.user_groups(
                    self.request.user):
                possible_states.append(FormState.ARCHIVED)

            form = safe_form_in_state(result_form, possible_states, form)

            if form:
                return self.form_invalid(form)

            result_form.reject(new_state=FormState.AUDIT)
            result_form.audited_count += 1
            result_form.save()

            Audit.objects.create(result_form=result_form,
                                 user=self.request.user)

            return redirect(self.success_url)
        else:
            return self.form_invalid(form)
Beispiel #4
0
    def post(self, *args, **kwargs):
        form_class = self.get_form_class()
        form = self.get_form(form_class)

        if form.is_valid():
            barcode = form.cleaned_data['barcode']
            result_form = get_object_or_404(ResultForm, barcode=barcode)

            possible_states = [
                FormState.CORRECTION, FormState.DATA_ENTRY_1,
                FormState.DATA_ENTRY_2, FormState.INTAKE,
                FormState.QUALITY_CONTROL, FormState.ARCHIVING,
                FormState.UNSUBMITTED
            ]

            if groups.SUPER_ADMINISTRATOR in groups.user_groups(
                    self.request.user):
                possible_states.append(FormState.ARCHIVED)

            form = safe_form_in_state(result_form, possible_states, form)

            if form:
                return self.form_invalid(form)

            self.template_name = 'check_clearance_center_details.html'
            form_action = reverse(self.success_url)
            return self.render_to_response(
                self.get_context_data(result_form=result_form,
                                      header_text=_('Create Clearance'),
                                      form_action=form_action))
        else:
            return self.form_invalid(form)
Beispiel #5
0
    def post(self, *args, **kwargs):
        form_class = self.get_form_class()
        form = self.get_form(form_class)

        if form.is_valid():
            barcode = form.cleaned_data['barcode']
            result_form = get_object_or_404(ResultForm, barcode=barcode)

            possible_states = [
                FormState.CORRECTION, FormState.DATA_ENTRY_1,
                FormState.DATA_ENTRY_2, FormState.INTAKE,
                FormState.QUALITY_CONTROL, FormState.ARCHIVING,
                FormState.UNSUBMITTED
            ]

            if groups.SUPER_ADMINISTRATOR in groups.user_groups(
                    self.request.user):
                possible_states.append(FormState.ARCHIVED)

            form = safe_form_in_state(result_form, possible_states, form)

            if form:
                return self.form_invalid(form)

            result_form.reject(FormState.CLEARANCE)
            Clearance.objects.create(result_form=result_form,
                                     user=self.request.user)

            return redirect(self.success_url)
        else:
            return self.form_invalid(form)
Beispiel #6
0
    def post(self, *args, **kwargs):
        tally_id = kwargs.get('tally_id')
        form_class = self.get_form_class()
        form = self.get_form(form_class)

        if form.is_valid():
            barcode = form.cleaned_data['barcode']
            result_form = get_object_or_404(ResultForm, barcode=barcode, tally__id=tally_id)

            possible_states = [FormState.CORRECTION,
                               FormState.DATA_ENTRY_1,
                               FormState.DATA_ENTRY_2,
                               FormState.INTAKE,
                               FormState.QUALITY_CONTROL,
                               FormState.ARCHIVING,
                               FormState.UNSUBMITTED]

            if groups.SUPER_ADMINISTRATOR in groups.user_groups(
                    self.request.user):
                possible_states.append(FormState.ARCHIVED)

            form = safe_form_in_state(result_form, possible_states, form)

            if form:
                return self.form_invalid(form)

            self.request.session['result_form'] = result_form.pk

            return redirect(self.success_url, tally_id=tally_id)
        else:
            return self.form_invalid(form)
Beispiel #7
0
    def post(self, *args, **kwargs):
        tally_id = kwargs.get('tally_id')
        form_class = self.get_form_class()
        form = self.get_form(form_class)

        if form.is_valid():
            barcode = form.cleaned_data['barcode']
            result_form = get_object_or_404(ResultForm, barcode=barcode, tally__id=tally_id)

            possible_states = [FormState.CORRECTION,
                               FormState.DATA_ENTRY_1,
                               FormState.DATA_ENTRY_2,
                               FormState.INTAKE,
                               FormState.QUALITY_CONTROL,
                               FormState.ARCHIVING,
                               FormState.UNSUBMITTED]

            if groups.SUPER_ADMINISTRATOR in groups.user_groups(
                    self.request.user):
                possible_states.append(FormState.ARCHIVED)

            form = safe_form_in_state(result_form, possible_states, form)

            if form:
                return self.form_invalid(form)

            self.template_name = 'check_clearance_center_details.html'
            form_action = reverse(self.success_url, kwargs={'tally_id':tally_id})
            return self.render_to_response(
                self.get_context_data(result_form=result_form,
                                      header_text=_('Create Clearance'),
                                      form_action=form_action,
                                      tally_id=tally_id))
        else:
            return self.form_invalid(form)
Beispiel #8
0
def is_superadmin(request):
    is_superadmin = False

    if getattr(request, 'user'):
        is_superadmin = groups.SUPER_ADMINISTRATOR in groups.user_groups(
            request.user)

    return {'is_superadmin': is_superadmin}
Beispiel #9
0
def is_tallymanager(request):
    is_tallymanager = False

    if getattr(request, 'user'):
        is_tallymanager = groups.TALLY_MANAGER in groups.user_groups(
            request.user)

    return {'is_tallymanager': is_tallymanager}
Beispiel #10
0
def is_superadmin(request):
    _is_superadmin = False

    if hasattr(request, "user"):
        _is_superadmin = groups.SUPER_ADMINISTRATOR in groups.user_groups(
            request.user
        )

    return {"is_superadmin": _is_superadmin}
Beispiel #11
0
def is_tallymanager(request):
    _is_tallymanager = False

    if hasattr(request, "user"):
        _is_tallymanager = groups.TALLY_MANAGER in groups.user_groups(
            request.user
        )

    return {"is_tallymanager": _is_tallymanager}
Beispiel #12
0
    def post(self, *args, **kwargs):
        self.tally_id = kwargs['tally_id']
        form_class = self.get_form_class()
        form = self.get_form(form_class)

        if form.is_valid():
            barcode = form.cleaned_data['barcode'] or\
                        form.cleaned_data['barcode_scan']
            result_form = get_object_or_404(ResultForm,
                                            barcode=barcode,
                                            tally__id=self.tally_id)
            url = self.success_url
            user = self.request.user
            possible_states = states_for_form(
                user, [FormState.INTAKE, FormState.UNSUBMITTED], result_form)

            if groups.INTAKE_SUPERVISOR in groups.user_groups(user) and\
                    result_form.form_state == FormState.DATA_ENTRY_1:
                url = 'intake-printcover'

            form = safe_form_in_state(result_form, possible_states, form)

            if form:
                return self.form_invalid(form)

            self.request.session['result_form'] = result_form.pk

            duplicated_forms = result_form.get_duplicated_forms()
            if duplicated_forms:
                # a form already exists, send to clearance
                self.request.session[
                    'intake-error'] = INTAKE_DUPLICATE_ERROR_MESSAGE
                if result_form.form_state != FormState.CLEARANCE:
                    result_form.send_to_clearance()

                for oneDuplicatedForm in duplicated_forms:
                    if oneDuplicatedForm.form_state != FormState.CLEARANCE:
                        oneDuplicatedForm.send_to_clearance()

                return redirect('intake-clearance', tally_id=self.tally_id)

            if result_form.form_state != FormState.DATA_ENTRY_1:
                result_form.form_state = FormState.INTAKE
                result_form.duplicate_reviewed = False
                result_form.user = user.userprofile
                result_form.save()

            if result_form.center:
                return redirect(url, tally_id=self.tally_id)
            else:
                return redirect('intake-enter-center', tally_id=self.tally_id)
        else:
            return self.form_invalid(form)
Beispiel #13
0
    def post(self, *args, **kwargs):
        self.tally_id = kwargs['tally_id']
        form_class = self.get_form_class()
        form = self.get_form(form_class)

        if form.is_valid():
            barcode = form.cleaned_data['barcode'] or\
                        form.cleaned_data['barcode_scan']
            result_form = get_object_or_404(ResultForm,
                                            barcode=barcode,
                                            tally__id=self.tally_id)
            url = self.success_url
            user = self.request.user
            possible_states = states_for_form(
                user, [FormState.INTAKE, FormState.UNSUBMITTED], result_form)

            if groups.INTAKE_SUPERVISOR in groups.user_groups(user) and\
                    result_form.form_state == FormState.DATA_ENTRY_1:
                url = 'intake-printcover'

            form = safe_form_in_state(result_form, possible_states, form)

            if form:
                return self.form_invalid(form)

            self.request.session['result_form'] = result_form.pk

            duplicated_forms = result_form.get_duplicated_forms()
            if duplicated_forms:
                # a form already exists, send to clearance
                self.request.session[
                    'intake-error'] = INTAKE_DUPLICATE_ERROR_MESSAGE
                if result_form.form_state != FormState.CLEARANCE:
                    result_form.send_to_clearance()

                for oneDuplicatedForm in duplicated_forms:
                    if oneDuplicatedForm.form_state != FormState.CLEARANCE:
                        oneDuplicatedForm.send_to_clearance()

                return redirect('intake-clearance', tally_id=self.tally_id)

            if result_form.form_state != FormState.DATA_ENTRY_1:
                result_form.form_state = FormState.INTAKE
                result_form.duplicate_reviewed = False
                result_form.user = user.userprofile
                result_form.save()

            if result_form.center:
                return redirect(url, tally_id=self.tally_id)
            else:
                return redirect('intake-enter-center', tally_id=self.tally_id)
        else:
            return self.form_invalid(form)
Beispiel #14
0
    def has_tally_access(self, userprofile, tally):
        user_groups = groups.user_groups(userprofile)

        has_access = False
        if groups.TALLY_MANAGER in user_groups:
            has_access = True

        elif groups.SUPER_ADMINISTRATOR in user_groups and \
                userprofile.administrated_tallies.filter(id=tally.id):
            has_access = True

        elif userprofile.tally == tally:
            has_access = True

        return has_access
Beispiel #15
0
    def has_tally_access(self, userprofile, tally):
        user_groups = groups.user_groups(userprofile)

        has_access = False
        if groups.TALLY_MANAGER in user_groups:
            has_access = True

        elif groups.SUPER_ADMINISTRATOR in user_groups and \
                userprofile.administrated_tallies.filter(id=tally.id):
            has_access = True

        elif userprofile.tally == tally:
            has_access = True

        return has_access
Beispiel #16
0
def check_membership(allowed_groups, user):
    """Check required group(s).

    Verify that the user is in a permitted group, always returns True if
    the user is a Super Administrator.

    :param allowed_groups: The groups permitted.

    :returns: True if user is in an allowed group, otherwise False.
    """
    user_groups = set(groups.user_groups(user))

    # super admin skips group check
    return admin_groups & user_groups or\
        set(listify(allowed_groups)) & user_groups
Beispiel #17
0
    def check_membership(self, allowed_groups):
        """Check required group(s).

        Verify that the user is in a permitted group, always returns True if
        the user is a Super Administrator.

        :param allowed_groups: The groups permitted.

        :returns: True if user is in an allowed group, otherwise False.
        """
        # super admin skips group check
        user_groups = groups.user_groups(self.request.user)

        return groups.SUPER_ADMINISTRATOR in user_groups or\
            set(listify(allowed_groups)) & set(user_groups)
Beispiel #18
0
    def check_membership(self, allowed_groups):
        """Check required group(s).

        Verify that the user is in a permitted group, always returns True if
        the user is a Super Administrator.

        :param allowed_groups: The groups permitted.

        :returns: True if user is in an allowed group, otherwise False.
        """
        # super admin skips group check
        user_groups = groups.user_groups(self.request.user)

        return groups.SUPER_ADMINISTRATOR in user_groups or\
            set(listify(allowed_groups)) & set(user_groups)
Beispiel #19
0
def states_for_form(user, result_form, states=[FormState.ARCHIVING]):
    """Get the possible states for this result_form.

    Archive supervisors can modify archived forms, check the user and see if
    this state should be added.

    :param user: The user to determine form states for.
    :param result_form: The form to check the state of.
    :param states: The initial states a form can be in.

    :returns: A list of states that a form may be in.
    """
    if groups.ARCHIVE_SUPERVISOR in groups.user_groups(user) and result_form.form_state == FormState.ARCHIVED:
        states.append(FormState.ARCHIVED)

    return states
Beispiel #20
0
def states_for_form(user, result_form, states=[FormState.ARCHIVING]):
    """Get the possible states for this result_form.

    Archive supervisors can modify archived forms, check the user and see if
    this state should be added.

    :param user: The user to determine form states for.
    :param result_form: The form to check the state of.
    :param states: The initial states a form can be in.

    :returns: A list of states that a form may be in.
    """
    if groups.QUALITY_CONTROL_ARCHIVE_SUPERVISOR in groups.user_groups(user)\
            and result_form.form_state == FormState.ARCHIVED:
        states.append(FormState.ARCHIVED)

    return states
Beispiel #21
0
    def post(self, *args, **kwargs):
        form_class = self.get_form_class()
        form = self.get_form(form_class)

        if form.is_valid():
            barcode = form.cleaned_data['barcode']
            result_form = get_object_or_404(ResultForm, barcode=barcode)
            url = self.success_url
            user = self.request.user
            possible_states = states_for_form(
                user, [FormState.INTAKE, FormState.UNSUBMITTED], result_form)

            if groups.INTAKE_SUPERVISOR in groups.user_groups(user) and\
                    result_form.form_state == FormState.DATA_ENTRY_1:
                url = 'intake-printcover'

            form = safe_form_in_state(result_form, possible_states, form)

            if form:
                return self.form_invalid(form)

            if result_form.intaken():
                # a form already exists, send to clearance
                self.request.session['intake-error'] = INTAKEN_MESSAGE
                result_form.send_to_clearance()
                return redirect('intake-clearance')

            if result_form.form_state != FormState.DATA_ENTRY_1:
                result_form.form_state = FormState.INTAKE
                result_form.user = user
                result_form.save()

            self.request.session['result_form'] = result_form.pk

            if result_form.center:
                return redirect(url)
            else:
                return redirect('intake-enter-center')
        else:
            return self.form_invalid(form)
Beispiel #22
0
    def post(self, *args, **kwargs):
        form_class = self.get_form_class()
        form = self.get_form(form_class)

        if form.is_valid():
            barcode = form.cleaned_data['barcode']
            result_form = get_object_or_404(ResultForm, barcode=barcode)
            url = self.success_url
            user = self.request.user
            possible_states = states_for_form(
                user, [FormState.INTAKE, FormState.UNSUBMITTED], result_form)

            if groups.INTAKE_SUPERVISOR in groups.user_groups(user) and\
                    result_form.form_state == FormState.DATA_ENTRY_1:
                url = 'intake-printcover'

            form = safe_form_in_state(result_form, possible_states, form)

            if form:
                return self.form_invalid(form)

            if result_form.intaken():
                # a form already exists, send to clearance
                self.request.session['intake-error'] = INTAKEN_MESSAGE
                result_form.send_to_clearance()
                return redirect('intake-clearance')

            if result_form.form_state != FormState.DATA_ENTRY_1:
                result_form.form_state = FormState.INTAKE
                result_form.user = user
                result_form.save()

            self.request.session['result_form'] = result_form.pk

            if result_form.center:
                return redirect(url)
            else:
                return redirect('intake-enter-center')
        else:
            return self.form_invalid(form)
Beispiel #23
0
def check_group_for_state(result_form, user, form):
    """Ensure only data entry 1 clerk can access forms in data entry 1 state
    and similarly for data entry 2.

    Always allow access for the super administrator.

    :param result_form: The result form to check access to.
    :param user: The user to check group of.
    :param form: The Django form to attach an error to.

    :returns: A form with an error if access denied, else None.
    """
    if groups.SUPER_ADMINISTRATOR in groups.user_groups(user):
        return None

    if ((result_form.form_state == FormState.DATA_ENTRY_1 and
       not user_is_data_entry_1(user)) or
       (result_form.form_state == FormState.DATA_ENTRY_2 and
            not user_is_data_entry_2(user))):
        message = _(u"Return form to %s" % result_form.form_state_name)

        return add_generic_error(form, message)
Beispiel #24
0
    def post(self, *args, **kwargs):
        tally_id = kwargs.get('tally_id')

        form_class = self.get_form_class()
        form = self.get_form(form_class)

        post_data = self.request.POST
        pk = session_matches_post_result_form(post_data, self.request)

        result_form = get_object_or_404(ResultForm, pk=pk, tally__id=tally_id)
        form_in_state(result_form, FormState.AUDIT)

        if form.is_valid():
            user = self.request.user
            audit = create_or_get_audit(post_data, user.userprofile,
                                        result_form, form)
            url = audit_action(audit, post_data, result_form, self.success_url)

            # Track supervisors result form reviewing processing time
            if groups.user_groups(user)[0] in [
                    groups.AUDIT_SUPERVISOR, groups.SUPER_ADMINISTRATOR,
                    groups.TALLY_MANAGER
            ]:
                encoded_start_time = self.request.session.get(
                    'encoded_result_form_audit_start_time')
                approved_by_supervisor =\
                    audit.for_superadmin and audit.active
                save_result_form_processing_stats(self.request,
                                                  encoded_start_time,
                                                  result_form,
                                                  approved_by_supervisor,
                                                  audit.reviewed_supervisor)

            return redirect(url, tally_id=tally_id)
        else:
            return self.render_to_response(
                self.get_context_data(form=form,
                                      result_form=result_form,
                                      tally_id=tally_id))
Beispiel #25
0
def check_group_for_state(result_form, user, form):
    """Ensure only data entry 1 clerk can access forms in data entry 1 state
    and similarly for data entry 2.

    Always allow access for the super administrator.

    :param result_form: The result form to check access to.
    :param user: The user to check group of.
    :param form: The Django form to attach an error to.

    :returns: A form with an error if access denied, else None.
    """
    if groups.SUPER_ADMINISTRATOR in groups.user_groups(user):
        return None

    if ((result_form.form_state == FormState.DATA_ENTRY_1
         and not user_is_data_entry_1(user))
            or (result_form.form_state == FormState.DATA_ENTRY_2
                and not user_is_data_entry_2(user))):
        message = _(u"Return form to %s" % result_form.form_state_name)

        return add_generic_error(form, message)
Beispiel #26
0
    def post(self, *args, **kwargs):
        tally_id = kwargs.get('tally_id')
        form_class = self.get_form_class()
        form = self.get_form(form_class)

        if form.is_valid():
            barcode = form.cleaned_data['barcode'] or\
                        form.cleaned_data['barcode_scan']
            result_form = get_object_or_404(ResultForm,
                                            barcode=barcode,
                                            tally__id=tally_id)

            possible_states = [
                FormState.CORRECTION, FormState.DATA_ENTRY_1,
                FormState.DATA_ENTRY_2, FormState.QUALITY_CONTROL
            ]

            if groups.SUPER_ADMINISTRATOR in groups.user_groups(
                    self.request.user):
                possible_states.append(FormState.ARCHIVED)

            form = safe_form_in_state(result_form, possible_states, form)

            if form:
                return self.form_invalid(form)

            result_form.reject(new_state=FormState.AUDIT)
            result_form.audited_count += 1
            result_form.save()

            Audit.objects.create(result_form=result_form,
                                 user=self.request.user.userprofile)

            return redirect(self.success_url, tally_id=tally_id)
        else:
            return self.form_invalid(form)
Beispiel #27
0
def user_is_data_entry_2(user):
    return groups.DATA_ENTRY_2_CLERK in groups.user_groups(user)
Beispiel #28
0
def states_for_form(user, states, result_form):
    if groups.INTAKE_SUPERVISOR in groups.user_groups(user)\
            and result_form.form_state == FormState.DATA_ENTRY_1:
        states.append(FormState.DATA_ENTRY_1)

    return states
Beispiel #29
0
def states_for_form(user, states, result_form):
    if groups.INTAKE_SUPERVISOR in groups.user_groups(user)\
            and result_form.form_state == FormState.DATA_ENTRY_1:
        states.append(FormState.DATA_ENTRY_1)

    return states
Beispiel #30
0
def user_is_data_entry_2(user):
    return groups.DATA_ENTRY_2_CLERK in groups.user_groups(user)