Example #1
0
    def addMember(self):
        c = TemplateContext()
        c.heading = _('Add member')
        c.mode = 'add'
        c.groups = []

        return self.render('/members/editMember.mako', template_context=c)
Example #2
0
    def index(self):
        c = TemplateContext()
        c.heading = _('Statistics')

        c.members = len(self.mf.getUserList())
        activeMembers = self.mf.getActiveMemberList()
        c.activeMembers = len(activeMembers)
        c.formerMembers = c.members - c.activeMembers

        c.paymentsOk = 0

        for uid in activeMembers:
            last_payment = None

            try:
                last_payment = self.db.query(Payment).filter(
                    and_(Payment.uid == uid, Payment.verified == 1)).order_by(
                        Payment.date.desc()).limit(1)[0]
            except Exception as e:
                ''' Don't care if there is no payment '''
                pass

            if last_payment:
                d = last_payment.date
                today = datetime.datetime.now().date()

                if d.year > today.year or (d.year == today.year
                                           and d.month >= today.month):
                    c.paymentsOk += 1

        c.paymentsNotOk = c.activeMembers - c.paymentsOk

        return self.render('/statistics/index.mako', template_context=c)
Example #3
0
    def exportList(self, listType='plain'):
        c = TemplateContext()
        try:
            members = self.mf.getUsers()
            c.members = []

            # make sure to clean out some vars
            for m in members:
                m.sambaNTPassword = '******'
                m.userPassword = '******'

                if not m.lockedMember:
                    c.members.append(m)

            if listType == 'RCSL':
                cherrypy.response.content_type = 'text/plain'
                return self.render('/members/exportRCSLCSV.mako',
                                   template_context=c)
            else:
                cherrypy.response.content_type = 'text/plain'
                return self.render('/members/exportCSV.mako',
                                   template_context=c)

        except LookupError as e:
            print 'Lookup error!'
            print e
            pass

        return 'ERROR 4x0'
Example #4
0
    def showAllMembers(self, _filter='active'):
        c = TemplateContext()
        try:
            c.heading = _('All members')

            members = self.mf.getUsers(clear_credentials=True)
            c.members = []

            # make sure to clean out some vars
            for m in members:
                if _filter == 'active' and not m.lockedMember:
                    c.members.append(m)
                elif _filter == 'former' and m.lockedMember:
                    c.members.append(m)
                elif _filter == 'all':
                    c.members.append(m)

            return self.render('/members/viewAll.mako', template_context=c)

        except LookupError as e:
            import sys, traceback
            traceback.print_exc(file=sys.stdout)
            print 'Lookup error!'
            print e
            pass
        except NoResultFound:
            print 'No such sql user !'

        return 'ERROR 4x0'
Example #5
0
    def edit(self):
        c = TemplateContext()
        c.heading = _('Edit profile')
        c.formDisabled = ''

        try:
            member = self.mf.getUser(self.session.get('username'))

            if member.validate:
                tm = self.db.query(TmpMember).filter(
                    TmpMember.id == member.uidNumber).first()
                member.givenName = tm.gn
                member.sn = tm.sn
                member.homePostalAddress = tm.homePostalAddress
                member.homePhone = tm.phone
                member.mobile = tm.mobile
                member.mail = tm.mail
                member.xmppID = tm.xmppID

                c.formDisabled = 'disabled'

            c.member = member
            c.member.avatarUrl = self.avatarUrl(member.uid, size=180)
            c.groups = member.groups
        except LookupError:
            return 'Edit :: No such user !'

        return self.render('/profile/edit.mako', template_context=c)
Example #6
0
    def edit(self):
        c = TemplateContext()
        c.heading = _('Edit preferences')
        c.formDisabled = ''

        try:
            member = self.session.get('user')
            c.member = member
            pref = self.db.query(Preferences).filter(
                Preferences.uidNumber == member.uidNumber).all()

            c.language = 'en'

            if len(pref) > 0:
                for p in pref:
                    if p.key == 'language':
                        c.language = p.value

            c.languages = Config.get('mematool', 'languages', ['en'])

            return self.render('preferences/edit.mako', template_context=c)

        except LookupError:
            print 'Edit :: No such user !'

        return 'ERROR 4x0'
Example #7
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)
Example #8
0
  def editAlias(self, alias=None, *args, **kwargs):
    c = TemplateContext()

    # vary form depending on mode (do that over ajax)
    if alias is None:
      action = 'Adding'
      c.mode = 'add'

      domains = self.mf.getDomains()
      c.select_domains = []
      for d in domains:
        c.select_domains.append([d.dc, d.dc])

    elif not alias == '':
      try:
        ParamChecker.checkEmail('alias')
      except:
        raise HTTPRedirect('/mails/index')

      action = 'Editing'
      c.alias = alias
      c.mode = 'edit'
      try:
        alias = self.mf.getAlias(alias)
        mail = ''

        for m in alias.mail:
          if not mail == '':
            mail += '\n'
          if not m == alias.dn_mail:
            mail += m

        c.mail = mail

        maildrop = ''

        for m in alias.maildrop:
          if not maildrop == '':
            maildrop += '\n'
          if not m == alias.dn_mail and not m in maildrop:
            maildrop += m

        c.maildrop = maildrop

      except LookupError:
        # @TODO implement better handler
        msg = _('No such alias!')
        return self.index(msg=msg)
    else:
      raise HTTPRedirect('/mails/index')

    c.heading = '{0} alias'.format(action)

    return self.render('/mails/editAlias.mako', template_context=c)
Example #9
0
    def bulkAdd(self, member_id):
        try:
            ParamChecker.checkUsername('member_id', param=True)
        except:
            raise HTTPRedirect('/payments/index')

        c = TemplateContext()
        c.member_id = member_id
        c.heading = _('Add bulk payments')

        return self.render('/payments/bulkAdd.mako', template_context=c)
Example #10
0
  def listAliases(self, domain, *args, **kwargs):
    try:
      ParamChecker.checkDomain('domain', param=True)
    except:
      raise HTTPRedirect('/mails/index')

    c = TemplateContext()
    c.heading = _('Aliases for domain: %s') % (domain)
    c.domain = domain
    c.aliases = self.mf.getAliases(domain)

    return self.render('/mails/listAliases.mako', template_context=c)
Example #11
0
    def editMember(self, member_id):
        c = TemplateContext()
        try:
            c.heading = _('Edit member')
            c.member = self.mf.getUser(member_id)
            c.mode = 'edit'

            return self.render('/members/editMember.mako', template_context=c)

        except LookupError:
            print 'No such user !'

        return 'ERROR 4x0'
Example #12
0
    def editAvatar(self):
        c = TemplateContext()
        c.heading = _('Edit avatar')

        try:
            member = self.mf.getUser(self.session['username'])
            member.avatarUrl = self.avatarUrl(member.uid, size=180)
            c.member = member

            return self.render('/profile/editAvatar.mako', template_context=c)

        except LookupError:
            print 'Edit :: No such user !'

        return 'ERROR 4x0'
Example #13
0
    def showOutstanding(self, showAll=0):
        """ Show which users still need to pay their membership fees and if a reminder has already been sent """
        if showAll == '1':
            showAll = True
        else:
            showAll = False

        activeMembers = self.mf.getActiveMemberList()

        # Prepare add payment form
        c = TemplateContext()
        c.heading = _('Outstanding payments')
        c.members = []
        c.member_ids = []
        for uid in activeMembers:
            last_payment = None

            try:
                last_payment = self.db.query(Payment).filter(
                    and_(Payment.uid == uid, Payment.verified == 1)).order_by(
                        Payment.date.desc()).limit(1)[0]
            except:
                ''' Don't care if there is no payment '''
                pass

            m = self.mf.getUser(uid)
            m.paymentGood = False

            if last_payment:
                d = last_payment.date
                today = datetime.datetime.now().date()

                if d.year > today.year or (d.year == today.year
                                           and d.month >= today.month):
                    m.paymentGood = True

            if not m.paymentGood or showAll:
                c.members.append(m)

            c.member_ids.append(uid)

        return self.render('/payments/showOutstanding.mako',
                           template_context=c)
Example #14
0
    def viewDiff(self, member_id):
        c = TemplateContext()

        try:
            member = self.mf.getUser(member_id)

            if member.validate:
                c.heading = _('View diff')
                c.member = member

                tmpmember = self.db.query(TmpMember).filter(
                    TmpMember.id == member.uidNumber).first()
                c.tmpmember = tmpmember

                return self.render('/members/viewDiff.mako',
                                   template_context=c)

        except LookupError:
            print 'No such user !'

        return 'ERROR 4x0'
Example #15
0
  def editDomain(self, domain=None):
    c = TemplateContext()
    # vary form depending on mode (do that over ajax)
    if domain is None:
      action = 'Adding'
      c.mode = 'add'
    else:
      try:
        ParamChecker.checkDomain('domain')
      except:
        return self.index()

      action = 'Editing'
      c.mode = 'edit'
      try:
        c.domain = self.mf.getDomain(domain)
      except LookupError:
        msg = _('No such domain!')
        return self.index(msg=msg)

    c.heading = '%s domain' % (action)

    return self.render('/mails/editDomain.mako', template_context=c)
Example #16
0
    def editGroup(self, gid=None):
        c = TemplateContext()

        # vary form depending on mode (do that over ajax)
        if gid is None:
            c.group = Group()
            action = 'Adding'
            c.gid = ''
        else:
            try:
                ParamChecker.checkUsername('gid', param=True)
            except:
                msg = _('Invalid format!')
                return self.index(msg=msg)

            action = 'Editing'
            c.gid = gid
            try:
                c.group = self.mf.getGroup(gid)
                print 'poll'
                users = ''

                for u in c.group.users:
                    if not users == '':
                        users += '\n'
                    users += u

                c.group.users = users
            except LookupError:
                # @TODO implement better handler
                msg = _('No such group!')
                return self.index(msg=msg)

        c.heading = '{0} group'.format(action)

        return self.render('/groups/editGroup.mako', template_context=c)
Example #17
0
    def listPayments(self, member_id=None, year=None):
        """ Show a specific user's payments """
        if member_id is None:
            if not self.is_admin() and not self.is_finance_admin():
                raise HTTPError(403, 'Forbidden')
            else:
                raise HTTPRedirect('/payments/showOutstanding/?showAll=1')
        elif not self.is_admin() and not self.is_finance_admin(
        ) and not member_id == self.session.get('username'):
            raise HTTPError(403, 'Forbidden')

        if not year is None:
            try:
                ParamChecker.checkInt('year', param=True, max_len=4)
                if int(year) > 1970 and int(year) < 2222:
                    year = int(year)
                else:
                    year = datetime.datetime.now().year
            except:
                pass

        if year is None:
            try:
                ParamChecker.checkUsername('member_id', param=True)
                year = self._getLastPayment(member_id).year
            except:
                pass

        if year is None:
            year = datetime.datetime.now().year

        c = TemplateContext()
        c.heading = _('Payments for the year {0}, user {1}'.format(
            year, member_id))
        c.member_id = member_id

        ## consider pagination
        # http://pylonsbook.com/en/1.1/starting-the-simplesite-tutorial.html#using-pagination
        try:
            #c.member.leavingDate = date(int(member.leavingDate[:4]),int(member.leavingDate[5:6]),int(member.leavingDate[7:8]))
            ## ideally, fetch monthly from member and the rest from payment (one to many relation)
            ## http://www.sqlalchemy.org/docs/05/reference/ext/declarative.html

            y_start = datetime.date(year, 1, 1)
            y_end = datetime.date(year, 12, 31)
            payment_sql = self.db.query(Payment).filter(
                Payment.uid == member_id).filter(
                    Payment.date.between(y_start, y_end)).order_by(
                        Payment.date.desc()).all()

            payments = {}
            c.unverifiedPledges = 0
            for p in payment_sql:
                if p.verified == 0:
                    c.unverifiedPledges += 1
                payments[p.date.month] = p

            c.year = year
            c.payments = payments

        except AttributeError, e:
            return 'This member has made no payments o.O ?!: %s' % e
Example #18
0
    def listGroups(self):
        c = TemplateContext()
        c.heading = _('Managed groups')
        c.groups = self.mf.getManagedGroupList()

        return self.render('/groups/listGroups.mako', template_context=c)
Example #19
0
  def listDomains(self):
    c = TemplateContext()
    c.heading = _('Managed domains')
    c.domains = self.mf.getDomains()

    return self.render('/mails/listDomains.mako', template_context=c)