예제 #1
0
    def editPayment(self, member_id, year=None, month=None, idPayment='0'):
        """ Add or edit a payment to/of a specific user """
        if not self.is_admin() and not member_id == self.session.get(
                'username'):
            raise HTTPError(403, 'Forbidden')

        c = TemplateContext()
        c.member_id = member_id
        c.status_0 = False
        c.status_1 = False
        c.status_2 = False

        # vary form depending on mode (do that over ajax)
        if idPayment == '0':
            c.payment = Payment()
            action = 'Adding'

            try:
                ParamChecker.checkYear('year', param=True)
                ParamChecker.checkMonth('month', param=True)
                c.date = str(datetime.date(int(year), int(month), 1))
            except:
                '''Don't care ... just let the user enter a new date'''
                pass

        elif not idPayment == '' and IsInt(idPayment) and int(idPayment) > 0:
            # @fixme convert IsInt to new class
            action = 'Editing'
            payment_q = self.db.query(Payment).filter(
                Payment.id == int(idPayment))
            try:
                payment = payment_q.one()

                # @TODO allow member editing if not verified???
                if payment.verified and not self.is_admin():
                    raise HTTPError(403, 'Forbidden')

                c.payment = payment
                setattr(c, 'status_' + str(payment.status), True)
            except NoResultFound:
                print "oops"
                raise HTTPRedirect('/members/index')
        else:
            raise HTTPRedirect('/members/index')

        c.heading = _('%s payment for user %s') % (action, c.member_id)
        self.sidebar.append({
            'name': _('List payments'),
            'args': {
                'controller': 'payments',
                'action': 'listPayments',
                'params': {
                    'member_id': member_id
                }
            }
        })

        return self.render('/payments/editPayment.mako', template_context=c)
예제 #2
0
  def editPayment(self, member_id, year=None, month=None, idPayment='0'):
    """ Add or edit a payment to/of a specific user """
    if not self.is_admin() and not member_id == self.session.get('username'):
      raise HTTPError(403, 'Forbidden')

    c = TemplateContext()
    c.member_id = member_id
    c.status_0 = False
    c.status_1 = False
    c.status_2 = False

    # vary form depending on mode (do that over ajax)
    if idPayment == '0':
      c.payment = Payment()
      action = 'Adding'

      try:
        ParamChecker.checkYear('year', param=True)
        ParamChecker.checkMonth('month', param=True)
        c.date = str(datetime.date(int(year), int(month), 1))
      except:
        '''Don't care ... just let the user enter a new date'''
        pass

    elif not idPayment == '' and IsInt(idPayment) and int(idPayment) > 0:
      # @fixme convert IsInt to new class
      action = 'Editing'
      payment_q = self.db.query(Payment).filter(Payment.id == int(idPayment))
      try:
        payment = payment_q.one()

        # @TODO allow member editing if not verified???
        if payment.verified and not self.is_admin():
          raise HTTPError(403, 'Forbidden')

        c.payment = payment
        setattr(c, 'status_' + str(payment.status), True)
      except NoResultFound:
        print "oops"
        raise HTTPRedirect('/members/index')
    else:
      raise HTTPRedirect('/members/index')

    c.heading = _('%s payment for user %s') % (action, c.member_id)
    self.sidebar.append({'name': _('List payments'), 'args': {'controller': 'payments', 'action': 'listPayments', 'params': {'member_id': member_id}}})

    return self.render('/payments/editPayment.mako', template_context=c)