Exemplo n.º 1
0
def regenerate_pdf(request):
    """
    Staffers can regenerate an applicants PDF and send it to her.
    """
    code = request.matchdict['code']
    member = C3sMember.get_by_code(code)

    if member is None:
        return get_dashboard_redirect(request)
    membership_application = request.registry.membership_application.get(
        member.id)

    appstruct = {
        'firstname': member.firstname,
        'lastname': member.lastname,
        'address1': member.address1,
        'address2': member.address2,
        'postcode': member.postcode,
        'city': member.city,
        'email': member.email,
        'email_confirm_code': membership_application['payment_token'],
        'country': member.country,
        'locale': member.locale,
        'membership_type': membership_application['membership_type'],
        'num_shares': membership_application['shares_quantity'],
        'date_of_birth': member.date_of_birth,
        'date_of_submission': membership_application['date_of_submission'],
    }
    LOG.info("%s regenerated the PDF for code %s",
             authenticated_userid(request), code)
    return generate_pdf(appstruct)
Exemplo n.º 2
0
def verify_mailaddress_conf(request):
    '''
    let member confirm her email address by clicking a link
    '''
    user_email = request.matchdict['email']
    refcode = request.matchdict['refcode']
    token = request.matchdict['token']
    # try to get entry from DB
    afm = C3sMember.get_by_code(refcode)
    if isinstance(afm, NoneType):  # no entry?
        #print "entry not found"
        return {
            'confirmed': False,
            'firstname': 'foo',
            'lastname': 'bar',
            'result_msg': 'bad URL / bad codes. please contact [email protected]!',
        }
    # check token
    if ('_used' in afm.email_confirm_token):  # token was invalidated already
        #print "the token is empty"
        return {
            'confirmed': False,
            'firstname': afm.firstname,
            'lastname': afm.lastname,
            'result_msg': 'your token is invalid. please contact [email protected]!',
        }

    try:
        assert(afm.email_confirm_token in token)
        assert(token in afm.email_confirm_token)
        assert(afm.email in user_email)
        assert(user_email in afm.email)
    except:
        return {
            'confirmed': False,
            'firstname': 'foo',
            'lastname': 'bar',
            'result_msg': 'bad token/email. please contact [email protected]!',
        }

    afm.email_is_confirmed = True
    afm.email_confirm_token += u'_used'
    DBSession.flush()
    # notify staff
    message = Message(
        subject='[C3S Yes!] afm email confirmed',
        sender='*****@*****.**',
        recipients=[request.registry.settings['c3smembership.mailaddr'], ],
        body=u'see {}/detail/{}'.format(
            request.registry.settings['c3smembership.url'],
            afm.id)
    )
    mailer = get_mailer(request)
    mailer.send(message)
    return {
        'confirmed': True,
        'firstname': afm.firstname,
        'lastname': afm.lastname,
        'result_msg': u'',
    }
Exemplo n.º 3
0
def regenerate_pdf(request):
    """
    Staffers can regenerate an applicants PDF and send it to her.
    """
    code = request.matchdict['code']
    member = C3sMember.get_by_code(code)

    if member is None:
        return get_dashboard_redirect(request)
    appstruct = {
        'firstname': member.firstname,
        'lastname': member.lastname,
        'address1': member.address1,
        'address2': member.address2,
        'postcode': member.postcode,
        'city': member.city,
        'email': member.email,
        'email_confirm_code': member.email_confirm_code,
        'country': member.country,
        '_LOCALE_': member.locale,
        'membership_type': member.membership_type,
        'num_shares': member.num_shares,
        'date_of_birth': member.date_of_birth,
        'date_of_submission': member.date_of_submission,
    }
    LOG.info(
        "%s regenerated the PDF for code %s",
        authenticated_userid(request),
        code)
    return generate_pdf(appstruct)
Exemplo n.º 4
0
def regenerate_pdf(request):
    """
    staffers can regenerate a users pdf
    """
    _code = request.matchdict['code']
    _member = C3sMember.get_by_code(_code)

    if _member is None:  # that memberid did not produce good results
        return HTTPFound(  # back to base
            request.route_url('dashboard_only'))
    _appstruct = {
        'firstname': _member.firstname,
        'lastname': _member.lastname,
        'address1': _member.address1,
        'address2': _member.address2,
        'postcode': _member.postcode,
        'city': _member.city,
        'email': _member.email,
        'email_confirm_code': _member.email_confirm_code,
        'country': _member.country,
        '_LOCALE_': _member.locale,
        'membership_type': _member.membership_type,
        'num_shares': _member.num_shares,
        'date_of_birth': _member.date_of_birth,
        'date_of_submission': _member.date_of_submission,
    }
    log.info(
        "%s regenerated the PDF for code %s" % (
            authenticated_userid(request), _code))
    return generate_pdf(_appstruct)
Exemplo n.º 5
0
def search_codes(request):
    '''
    Search for Reference Codes

    We use a form with autocomplete to let staff find entries faster.
    '''
    # check for input from "find people" form
    if 'code_to_show' in request.POST:
        try:
            _code = request.POST['code_to_show']
            # print u"_code = {}".format(_code)
            _code_ = _code.split(' ')[0]
            # print u"_code_ = {}".format(_code_)
            _entry = C3sMember.get_by_code(_code_)
            # print _entry

            return HTTPFound(
                location=request.route_url(
                    'detail',
                    memberid=_entry.id)
            )
        except:
            pass

    '''
    we use another form with autocomplete to let staff find entries faster
    '''
    class AutocompleteRefCodeForm(colander.MappingSchema):
        code_to_show = colander.SchemaNode(
            colander.String(),
            title='Code finden (quicksearch; Groß-/Kleinschreibung beachten!)',
            widget=deform.widget.AutocompleteInputWidget(
                min_length=1,
                css_class="form-inline",
                values=request.route_path(
                    'autocomplete_input_values',
                    traverse=('autocomplete_input_values')
                )
            )
        )

    schema = AutocompleteRefCodeForm()
    form = deform.Form(
        schema,
        css_class="form-inline",
        buttons=('go!',),
    )
    refcodeformhtml = form.render()

    return {
        'refcodeform': refcodeformhtml,
    }
    '''
Exemplo n.º 6
0
def search_people(request):
    '''
    Search for people.

    We use a form with autocomplete to let staff find entries faster.
    '''
    # check for input from "find people" form
    if 'code_to_show' in request.POST:
        try:
            _code = request.POST['code_to_show']
            # print u"_code = {}".format(_code)
            _code_ = _code.split(' ')[0]
            # print u"_code_ = {}".format(_code_)
            _entry = C3sMember.get_by_code(_code_)

            return HTTPFound(
                location=request.route_url(
                    'detail',
                    memberid=_entry.id)
            )
        except:
            pass

    class AutocompleteForm(colander.MappingSchema):
        code_to_show = colander.SchemaNode(
            colander.String(),
            title='Personen finden (Nachname: Groß-/Kleinschr. beachten!)',
            widget=deform.widget.AutocompleteInputWidget(
                min_length=1,
                css_class="form-inline",
                values=request.route_path(
                    'autocomplete_people_search',
                    traverse=('autocomplete_people_search')
                )
            )
        )

    schema = AutocompleteForm()
    form = deform.Form(
        schema,
        css_class="form-inline",
        buttons=('go!',),
    )
    autoformhtml = form.render()

    return {
        'autoform': autoformhtml,
    }
Exemplo n.º 7
0
def success_verify_email(request):
    """
    This view is called via links sent in mails to verify mail addresses.
    It extracts both email and verification code from the URL.
    It will ask for a password
    and checks if there is a match in the database.

    If the password matches, and all is correct,
    the view shows a download link and further info.
    """
    # collect data from the URL/matchdict
    user_email = request.matchdict['email']
    confirm_code = request.matchdict['code']
    # if we want to ask the user for her password (through a form)
    # we need to have a url to send the form to
    post_url = '/verify/' + user_email + '/' + confirm_code

    if 'submit' in request.POST:
        request.session.pop_flash('message_above_form')
        request.session.pop_flash('message_above_login')
        # check for password ! ! !
        if 'password' in request.POST:
            _passwd = request.POST['password']

        # get matching dataset from DB
        member = C3sMember.get_by_code(confirm_code)  # returns member or None

        if isinstance(member, NoneType):
            # member not found: FAIL!
            not_found_msg = _(
                u"Not found. Check verification URL. "
                "If all seems right, please use the form again.")
            return {
                'correct': False,
                'namepart': '',
                'result_msg': not_found_msg,
            }
Exemplo n.º 8
0
def success_verify_email(request):
    """
    This view is called via links sent in mails to verify mail addresses.
    It extracts both email and verification code from the URL.
    It will ask for a password
    and checks if there is a match in the database.

    If the password matches, and all is correct,
    the view shows a download link and further info.
    """
    # collect data from the URL/matchdict
    user_email = request.matchdict['email']
    confirm_code = request.matchdict['code']
    # if we want to ask the user for her password (through a form)
    # we need to have a url to send the form to
    post_url = '/verify/' + user_email + '/' + confirm_code

    # ToDo unify errors for not_found email, wrong password and wrong confirm code to avoid leaking
    error_message = _(
        u'Your email, password, or confirmation code could not be found')

    if 'submit' in request.POST:
        # print("the form was submitted")
        request.session.pop_flash('message_above_form')
        request.session.pop_flash('message_above_login')
        # check for password ! ! !
        if 'password' in request.POST:
            _passwd = request.POST['password']

        # get matching dataset from DB
        member = C3sMember.get_by_code(confirm_code)  # returns member or None

        if isinstance(member, NoneType):
            # member not found: FAIL!
            not_found_msg = _(u"Not found. Check verification URL. "
                              "If all seems right, please use the form again.")
            return {
                'correct': False,
                'namepart': '',
                'result_msg': not_found_msg,
            }

        # check if the password is valid
        try:
            correct = C3sMember.check_password(member.id, _passwd)
        except AttributeError:
            correct = False
            request.session.flash(_(u'Wrong Password!'), 'message_above_login')

        # check if info from DB makes sense
        # -member

        if (member.email == user_email) and correct:
            # print("-- found member, code matches, password too. COOL!")
            # set the email_is_confirmed flag in the DB for this signee
            member.email_is_confirmed = True
            # dbsession.flush()
            namepart = member.firstname + member.lastname
            import re
            pdf_file_name_part = re.sub(  # replace characters
                '[^a-zA-Z0-9]',  # other than these
                '_',  # with an underscore
                namepart)

            appstruct = {
                'firstname': member.firstname,
                'lastname': member.lastname,
                'email': member.email,
                'email_confirm_code': member.email_confirm_code,
                'address1': member.address1,
                'address2': member.address2,
                'postcode': member.postcode,
                'city': member.city,
                'country': member.country,
                'locale': member.locale,
                'date_of_birth': member.date_of_birth,
                'date_of_submission': member.date_of_submission,
                # 'activity': set(activities),
                # 'invest_member': u'yes' if member.invest_member else u'no',
                'membership_type': member.membership_type,
                'member_of_colsoc':
                u'yes' if member.member_of_colsoc else u'no',
                'name_of_colsoc': member.name_of_colsoc,
                # 'opt_band': signee.opt_band,
                # 'opt_URL': signee.opt_URL,
                'num_shares': member.num_shares,
            }
            request.session['appstruct'] = appstruct

            # log this person in, using the session
            log.info('verified code and password for id %s', member.id)
            request.session.save()
            return {
                'firstname': member.firstname,
                'lastname': member.lastname,
                'code': member.email_confirm_code,
                'correct': True,
                'namepart': pdf_file_name_part,
                'result_msg': _("Success. Load your PDF!")
            }
    # else: code did not match OR SOMETHING...
    # just display the form
    request.session.flash(_(u"Please enter your password."),
                          'message_above_login',
                          allow_duplicate=False)
    return {
        'post_url': post_url,
        'firstname': '',
        'lastname': '',
        'namepart': '',
        'correct': False,
        'result_msg': "something went wrong."
    }
Exemplo n.º 9
0
def success_verify_email(request):
    """
    This view is called via links sent in mails to verify mail addresses.
    It extracts both email and verification code from the URL
    and checks if there is a match in the database.
    """
    #dbsession = DBSession()
    # collect data from the URL/matchdict
    user_email = request.matchdict['email']
    #print(user_email)
    confirm_code = request.matchdict['code']
    #print(confirm_code)
    # get matching dataset from DB
    member = C3sMember.get_by_code(confirm_code)  # returns a member or None
    #print(member)
    # check if info from DB makes sense
    # -member
    from types import NoneType
    if isinstance(member, NoneType):
        # member not found: FAIL!
        #print("a matching entry for this code was not found.")
        not_found_msg = _(u"""Not found. check URL.
        If all seems right, please use the form again.""")
        return {
            #'firstname': '',
            #'lastname': '',
            'namepart': '',
            'result_msg': not_found_msg,
        }
    elif (member.email == user_email):
        #print("-- found member, code matches. COOL!")
        # set the email_is_confirmed flag in the DB for this signee
        member.email_is_confirmed = True
        #dbsession.flush()
        namepart = member.firstname + member.lastname
        import re
        PdfFileNamePart = re.sub(  # replace characters
            '[^a-zA-Z0-9]',  # other than these
            '_',  # with an underscore
            namepart)

        #activities = []
        #if signee.is_composer:
        #    activities.append(u'composer')
        #if signee.is_lyricist:
        #    activities.append(u'lyricist')
        #if signee.is_producer:
        #    activities.append(u'music producer')
        #if signee.is_remixer:
        #    activities.append(u'remixer')
        #if signee.is_dj:
        #    activities.append(u'dj')

        appstruct = {
            'firstname': member.firstname,
            'lastname': member.lastname,
            'email': member.email,
            'address1': member.address1,
            'address2': member.address2,
            'postcode': member.postcode,
            'city': member.city,
            'country': member.country,
            '_LOCALE_': member.locale,
            'date_of_birth': member.date_of_birth,
            'date_of_submission': member.date_of_submission,
            #'activity': set(activities),
            'invest_member': u'yes' if member.invest_member else u'no',
            'member_of_colsoc': u'yes' if member.member_of_colsoc else 'no',
            'name_of_colsoc': member.name_of_colsoc,
            #'opt_band': signee.opt_band,
            #'opt_URL': signee.opt_URL,
            'num_shares': member.num_shares,
        }
        request.session['appstruct'] = appstruct
        return {
            'firstname': member.firstname,
            'lastname': member.lastname,
            'namepart': PdfFileNamePart,
            'result_msg': _("Success. Load your PDF!")
        }
    # else: code did not match OR SOMETHING...
    return {
        'firstname': '',
        'lastname': '',
        'namepart': '',
        'result_msg': "something went wrong."
    }
Exemplo n.º 10
0
def success_verify_email(request):
    """
    This view is called via links sent in mails to verify mail addresses.
    It extracts both email and verification code from the URL.
    It will ask for a password
    and checks if there is a match in the database.

    If the password matches, and all is correct,
    the view shows a download link and further info.
    """
    # collect data from the URL/matchdict
    user_email = request.matchdict['email']
    confirm_code = request.matchdict['code']
    # if we want to ask the user for her password (through a form)
    # we need to have a url to send the form to
    post_url = '/verify/' + user_email + '/' + confirm_code

    if 'submit' in request.POST:
        # print("the form was submitted")
        request.session.pop_flash('message_above_form')
        request.session.pop_flash('message_above_login')
        # check for password ! ! !
        if 'password' in request.POST:
            _passwd = request.POST['password']

        # get matching dataset from DB
        member = C3sMember.get_by_code(confirm_code)  # returns member or None

        if isinstance(member, NoneType):
            # member not found: FAIL!
            not_found_msg = _(
                u"Not found. Check verification URL. "
                "If all seems right, please use the form again.")
            return {
                'correct': False,
                'namepart': '',
                'result_msg': not_found_msg,
            }

        # check if the password is valid
        try:
            correct = C3sMember.check_password(member.id, _passwd)
        except AttributeError:
            correct = False
            request.session.flash(
                _(u'Wrong Password!'),
                'message_above_login')

        # check if info from DB makes sense
        # -member

        if (member.email == user_email) and correct:
            # print("-- found member, code matches, password too. COOL!")
            # set the email_is_confirmed flag in the DB for this signee
            member.email_is_confirmed = True
            # dbsession.flush()
            namepart = member.firstname + member.lastname
            import re
            pdf_file_name_part = re.sub(  # replace characters
                '[^a-zA-Z0-9]',  # other than these
                '_',  # with an underscore
                namepart)

            appstruct = {
                'firstname': member.firstname,
                'lastname': member.lastname,
                'email': member.email,
                'email_confirm_code': member.email_confirm_code,
                'address1': member.address1,
                'address2': member.address2,
                'postcode': member.postcode,
                'city': member.city,
                'country': member.country,
                '_LOCALE_': member.locale,
                'date_of_birth': member.date_of_birth,
                'date_of_submission': member.date_of_submission,
                # 'activity': set(activities),
                # 'invest_member': u'yes' if member.invest_member else u'no',
                'membership_type': member.membership_type,
                'member_of_colsoc':
                    u'yes' if member.member_of_colsoc else u'no',
                'name_of_colsoc': member.name_of_colsoc,
                # 'opt_band': signee.opt_band,
                # 'opt_URL': signee.opt_URL,
                'num_shares': member.num_shares,
            }
            request.session['appstruct'] = appstruct

            # log this person in, using the session
            log.info('verified code and password for id %s', member.id)
            request.session.save()
            return {
                'firstname': member.firstname,
                'lastname': member.lastname,
                'code': member.email_confirm_code,
                'correct': True,
                'namepart': pdf_file_name_part,
                'result_msg': _("Success. Load your PDF!")
            }
    # else: code did not match OR SOMETHING...
    # just display the form
    request.session.flash(
        _(u"Please enter your password."),
        'message_above_login',
        allow_duplicate=False
    )
    return {
        'post_url': post_url,
        'firstname': '',
        'lastname': '',
        'namepart': '',
        'correct': False,
        'result_msg': "something went wrong."
    }
Exemplo n.º 11
0
def membership_status_fixer(request):
    '''
    let member confirm her email membership details by filling a form
    '''
    user_email = request.matchdict['email']
    refcode = request.matchdict['refcode']
    token = request.matchdict['token']
    # try to get entry from DB
    afm = C3sMember.get_by_code(refcode)
    if isinstance(afm, NoneType):  # no entry?
        #print "entry not found"
        request.session.flash(
            'bad URL / bad codes. please contact [email protected]!',
            'message_above_form'
        )
        return {
            'form': '',
            'confirmed': False,
            'firstname': 'foo',
            'lastname': 'bar',
            'result_msg': 'bad URL / bad codes. please contact [email protected]!',
        }
    # check token
    #if isinstance(afm.mtype_confirm_token, NoneType):
    #    #request.session.flash('no ')
    #    #return HTTPFound(request.route_url('dashboard_only'))
    # check token even more
    if len(afm.mtype_confirm_token) == 0:  # token was invalidated already
    #    #print "the token is empty"
        request.session.flash(
            'your token is invalid. please contact [email protected]!',
            'message_above_form'
        )
        return {
            'form': '',
            'confirmed': False,
    #        'firstname': afm.firstname,
    #        'lastname': afm.lastname,
            'result_msg': 'your token is invalid. please contact [email protected]!',
        }

    try:
        print "token: {}".format(token)
        assert(afm.mtype_confirm_token in token)
        assert(token in afm.mtype_confirm_token)
        assert(afm.email in user_email)
        assert(user_email in afm.email)
    except:
        request.session.flash(
            'bad token/email. please contact [email protected]!',
            'message_above_form')
        return {
            'form': '',
            'confirmed': False,
            #         'firstname': 'foo',
            #         'lastname': 'bar',
            'result_msg': 'bad token/email. please contact [email protected]!',
        }

    # construct a form
    class MembershipInfo(colander.Schema):
        yes_no = ((u'yes', _(u'Yes')),
                  (u'no', _(u'No')))
        membership_type = colander.SchemaNode(
            colander.String(),
            title=_(u'I want to become a ... (choose '
                    'membership type, see C3S SCE statute sec. 4)'),
            description=_(u'choose the type of membership.'),
            widget=deform.widget.RadioChoiceWidget(
                values=(
                    (u'normal',
                     _(u'FULL member. Full members have to be natural persons '
                       'who register at least three works with C3S they '
                       'created themselves. This applies to composers, '
                       'lyricists and remixers. They get a vote.')),
                    (u'investing',
                     _(u'INVESTING member. Investing members can be natural '
                       'or legal entities or private companies that do not '
                       'register works with C3S. They do not get a vote, '
                       'but may counsel.'))
                ),
            )
        )
        member_of_colsoc = colander.SchemaNode(
            colander.String(),
            title=_(
                u'Currently, I am a member of (at least) one other '
                'collecting society.'),
            validator=colander.OneOf([x[0] for x in yes_no]),
            widget=deform.widget.RadioChoiceWidget(values=yes_no),
            oid="other_colsoc",
            #validator=colsoc_validator
        )
        name_of_colsoc = colander.SchemaNode(
            colander.String(),
            title=_(u'If so, which one(s)? (comma separated)'),
            description=_(
                u'Please tell us which collecting societies '
                'you are a member of. '
                'If more than one, please separate them by comma(s).'),
            missing=unicode(''),
            oid="colsoc_name",
        )

    class MembershipForm(colander.Schema):
        """
        The Form consists of
        - Membership Information
        """
        membership_info = MembershipInfo(
            title=_(u"Membership Requirements")
        )

    schema = MembershipForm()

    form = deform.Form(
        schema,
        buttons=[
            deform.Button('submit', _(u'Submit')),
            deform.Button('reset', _(u'Reset'))
        ],
        use_ajax=True,
        renderer=zpt_renderer
    )
    # if the form has NOT been used and submitted, remove error messages if any
    if not 'submit' in request.POST:
        request.session.pop_flash()

    # if the form has been used and SUBMITTED, check contents
    if 'submit' in request.POST:
        controls = request.POST.items()
        try:
            appstruct = form.validate(controls)
            #print("the appstruct from the form: %s \n") % appstruct
            #for thing in appstruct:
            #    print("the thing: %s") % thing
            #    print("type: %s") % type(thing)

            # data sanity: if not in collecting society, don't save
            #  collsoc name even if it was supplied through form
            if 'no' in appstruct['membership_info']['member_of_colsoc']:
                appstruct['membership_info']['name_of_colsoc'] = ''
                print appstruct['membership_info']['name_of_colsoc']
                #print '-'*80

        except ValidationFailure, e:
            #print("the appstruct from the form: %s \n") % appstruct
            #for thing in appstruct:
            #    print("the thing: %s") % thing
            #    print("type: %s") % type(thing)
            print(e)
            #message.append(
            request.session.flash(
                _(u"Please note: There were errors, "
                  "please check the form below."),
                'message_above_form',
                allow_duplicate=False)
            return{
                'confirmed': True,
                'form': e.render()}
        # all good, store the information
        afm.membership_type = appstruct['membership_info']['membership_type']
        #print 'afm.membership_type: {}'.format(afm.membership_type)
        afm.member_of_colsoc = (
            appstruct['membership_info']['member_of_colsoc'] == u'yes')
        #print 'afm.member_of_colsoc: {}'.format(afm.member_of_colsoc)
        afm.name_of_colsoc = appstruct['membership_info']['name_of_colsoc']
        #print 'afm.name_of_colsoc: {}'.format(afm.name_of_colsoc)

        # delete token
        afm.mtype_confirm_token = u''
        # # notify staff
        message = Message(
            subject='[C3S Yes!] membership status confirmed',
            sender='*****@*****.**',
            recipients=[
                request.registry.settings['c3smembership.mailaddr'],
            ],
            body=u'see {}/detail/{}'.format(
                request.registry.settings['c3smembership.url'],
                afm.id)
        )
        mailer = get_mailer(request)
        mailer.send(message)

        return HTTPFound(request.route_url('mtype_thanks'))
Exemplo n.º 12
0
def accountants_desk(request):
    """
    This view lets accountants view applications and set their status:
    has their signature arrived? how about the payment?
    """
    _number_of_datasets = C3sMember.get_number()
    try:  # check if page number, orderby and order were supplied with the URL
        _page_to_show = int(request.matchdict['number'])
        _order_by = request.matchdict['orderby']
        _order = request.matchdict['order']
    except:
        #print("Using default values")
        _page_to_show = 0
        _order_by = 'id'
        _order = 'asc'

    # check for input from "find dataset by confirm code" form
    if 'code_to_show' in request.POST:
        try:
            _code = request.POST['code_to_show']
            log.info(
                "%s searched for code %s" % (
                    authenticated_userid(request), _code))
            _entry = C3sMember.get_by_code(_code)

            return HTTPFound(
                location=request.route_url(
                    'detail',
                    memberid=_entry.id)
            )
        except:
            pass

    """
    num_display determines how many items are to be shown on one page
    """
    if 'num_to_show' in request.POST:
        try:
            _num = int(request.POST['num_to_show'])
            if isinstance(_num, type(1)):
                num_display = _num
        except:
            # choose default
            num_display = 20
    elif 'num_display' in request.cookies:
        #print("found it in cookie")
        num_display = int(request.cookies['num_display'])
    else:
        #print("setting default")
        num_display = request.registry.settings[
            'c3smembership.dashboard_number']

    '''
    we use a form with autocomplete to let staff find entries faster
    '''
    #the_codes = C3sMember.get_all_codes()
    #print("the codes: %s" % the_codes)

    class AutocompleteForm(colander.MappingSchema):
        code_to_show = colander.SchemaNode(
            colander.String(),
            title='Code finden (quicksearch; Groß-/Kleinschreibung beachten!)',
            #title='',
            widget=deform.widget.AutocompleteInputWidget(
                min_length=1,
                css_class="form-inline",
                #values=the_codes,  # XXX input matching ones only
                values=request.route_path(
                    'autocomplete_input_values',
                    traverse=('autocomplete_input_values')
                )
            )
        )

    schema = AutocompleteForm()
    form = deform.Form(
        schema,
        css_class="form-inline",
        buttons=('go!',),
    )
    autoformhtml = form.render()
    """
    base_offset helps us to minimize impact on the database
    when querying for results.
    we can choose just those results we need for the page to show
    """
    base_offset = int(_page_to_show) * int(num_display)

    # get data sets from DB
    _members = C3sMember.member_listing(
        _order_by, how_many=num_display, offset=base_offset, order=_order)

    # calculate next-previous-navi
    next_page = (int(_page_to_show) + 1)
    if (int(_page_to_show) > 0):
        previous_page = int(_page_to_show) - 1
    else:
        previous_page = int(_page_to_show)
    _last_page = int(math.ceil(_number_of_datasets / int(num_display)))
    if next_page > _last_page:
        next_page = _last_page
    # store info about current page in cookie
    request.response.set_cookie('on_page', value=str(_page_to_show))
    request.response.set_cookie('num_display', value=str(num_display))
    request.response.set_cookie('order', value=str(_order))
    request.response.set_cookie('orderby', value=str(_order_by))

    _message = None
    if 'message' in request.GET:
        _message = request.GET['message']

    return {'autoform': autoformhtml,
            '_number_of_datasets': _number_of_datasets,
            'members': _members,
            'num_display': num_display,
            'next': next_page,
            'previous': previous_page,
            'current': _page_to_show,
            'orderby': _order_by,
            'order': _order,
            'message': _message,
            'last_page': _last_page,
            'is_last_page': _page_to_show == _last_page,
            'is_first_page': _page_to_show == 0,
            }
Exemplo n.º 13
0
def accountants_desk(request):
    """
    This view lets accountants view applications and set their status:
    has their signature arrived? how about the payment?
    """
    _number_of_datasets = C3sMember.get_number()
    try:  # check if page number, orderby and order were supplied with the URL
        _page_to_show = int(request.matchdict['number'])
        _order_by = request.matchdict['orderby']
        _order = request.matchdict['order']
    except:
        print("Using default values")
        _page_to_show = 0
        _order_by = 'id'
        _order = 'asc'

    # check for input from "find dataset by confirm code" form
    if 'code_to_show' in request.POST:
        try:
            _code = request.POST['code_to_show']
            log.info(
                "%s searched for code %s" % (
                    authenticated_userid(request), _code))
            _entry = C3sMember.get_by_code(_code)

            return HTTPFound(
                location=request.route_url(
                    'detail',
                    memberid=_entry.id)
            )
        except:
            pass

    """
    num_display determines how many items are to be shown on one page
    """
    if 'num_to_show' in request.POST:
        try:
            _num = int(request.POST['num_to_show'])
            if isinstance(_num, type(1)):
                num_display = _num
        except:
            # choose default
            num_display = 20
    elif 'num_display' in request.cookies:
        #print("found it in cookie")
        num_display = int(request.cookies['num_display'])
    else:
        #print("setting default")
        num_display = request.registry.settings[
            'c3smembership.dashboard_number']

    """
    base_offset helps us to minimize impact on the database
    when querying for results.
    we can choose just those results we need for the page to show
    """
    base_offset = int(_page_to_show) * int(num_display)

    # get data sets from DB

    _members = C3sMember.member_listing(
        _order_by, how_many=num_display, offset=base_offset, order=_order)

    # calculate next-previous-navi
    next_page = (int(_page_to_show) + 1)
    if (int(_page_to_show) > 0):
        previous_page = int(_page_to_show) - 1
    else:
        previous_page = int(_page_to_show)
    _last_page = int(math.ceil(_number_of_datasets / int(num_display)))
    if next_page > _last_page:
        next_page = _last_page
    # store info about current page in cookie
    request.response.set_cookie('on_page', value=str(_page_to_show))
    request.response.set_cookie('num_display', value=str(num_display))
    request.response.set_cookie('order', value=str(_order))
    request.response.set_cookie('orderby', value=str(_order_by))



    _message = None
    if 'message' in request.GET:
        _message = request.GET['message']

    return {'_number_of_datasets': _number_of_datasets,
            'members': _members,
            'num_display': num_display,
            'next': next_page,
            'previous': previous_page,
            'current': _page_to_show,
            'orderby': _order_by,
            'order': _order,
            'message': _message,
            'last_page': _last_page,
            'is_last_page': _page_to_show == _last_page,
            'is_first_page': _page_to_show == 0,
            }