Пример #1
0
    def edit(self, id):
        dbFacade = self.dbFacade()

        c.participant = dbFacade.meetings.participantDao.find_by_token(id)
        if c.participant is None:
            abort(404)

        c.meeting = c.participant.meeting

        def edit_show(errors):
            c.form_errors = errors
            return render_jinja('meetings/edit.jinja')

        def edit_update(result):
            c.meeting.title = result.get('title')
            c.meeting.description = result.get('description', '')
            c.meeting.html_description = result.get('html_description', '')
            c.meeting.occurred_on = result.get('occurred_on', date.today())

            current_participants = dict([[participant.email, True] for participant in c.meeting.participants])
            for participants_email in [pe.lower() for pe in result.get('participants')]:
                if participants_email in current_participants:
                    continue
                
                mp = dbFacade.model.MeetingParticipant(screenname='', email=participants_email)
                c.meeting.participants.append(mp)
                self._send_invitation_email(c.meeting, mp)

            dbFacade.meetings.meetingDao.save(c.meeting)
            dbFacade.db.commit()
            redirect_to(h.url_for(action='show', id=c.participant.token))

        return handle_validation(edit_show, edit_update, EditMeetingFormSchema)
Пример #2
0
    def add(self):
        dbFacade = self.dbFacade()

        c.meeting = dbFacade.model.Meeting()
        c.meeting.title = _('Meeting/lunch/party')
        c.meeting.description = _('Put details here...')

        if h.authenticated_user():
            c.meeting.participants.append(dbFacade.model.MeetingParticipant(admin=True, was_here=True, email=h.authenticated_user().email))

        def add_show(errors):
            c.form_errors = errors
            return render_jinja('meetings/add.jinja')

        def add_update(result):
            c.meeting = dbFacade.model.Meeting()
            c.meeting.title = result.get('title')
            c.meeting.description = result.get('description', '')
            c.meeting.html_description = result.get('html_description', '')
            c.meeting.occurred_on = result.get('occurred_on', date.today())

            for participants_email in [pe.lower() for pe in result.get('participants')]:
                mp = dbFacade.model.MeetingParticipant(screenname='', email=participants_email)
                c.meeting.participants.append(mp)
                self._send_invitation_email(c.meeting, mp)
            
            dbFacade.meetings.meetingDao.save(c.meeting)
            dbFacade.db.commit()

            redirect_to(h.url_for(action='created', id=None))

        return handle_validation(add_show, add_update, AddMeetingFormSchema)
Пример #3
0
    def add_obligation(self, id):
        dbFacade = self.dbFacade()
        expense_uid = request.params['expense_uid']

        c.participant = dbFacade.meetings.participantDao.find_by_token(id)
        if c.participant is None:
            abort(404)

        c.meeting = c.participant.meeting

        def show(errors):
            c.form_errors = errors
            return render_jinja('meetings/add_obligation.jinja')

        def update(result):
            obligation = dbFacade.model.MeetingObligation()
            obligation.meeting = c.meeting
            obligation.participant_uid = c.participant.uid
            obligation.title = result.get('title')
            obligation.expense = False
            obligation.amount = result.get('amount')
            c.meeting.obligations.append(obligation)
            dbFacade.db.save(obligation)

            obligation.relates_to = [obligation for obligation in c.meeting.obligations if str(obligation.uid) == expense_uid][0]
            
            dbFacade.meetings.meetingDao.save(c.meeting)
            dbFacade.db.commit()

            redirect_to(h.url_for(action='show', id=c.participant.token))

        return handle_validation(show, update, EditMeetingObligationFormSchema)
Пример #4
0
    def add_comment(self, id):
        dbFacade = self.dbFacade()

        c.participant = dbFacade.meetings.participantDao.find_by_token(id)
        if c.participant is None:
            abort(404)

        if c.participant.meeting is None:
            abort(403)

        c.meeting = c.participant.meeting

        def show(errors):
            c.form_errors = errors
            return self.show(id)

        def update(result):
            comment = dbFacade.model.MeetingComment()
            comment.participant_screenname = c.participant.screenname
            comment.participant_email = c.participant.email
            comment.comment = result.get('comment')

            c.meeting.comments.append(comment)

            dbFacade.meetings.meetingDao.save(c.meeting)
            dbFacade.db.commit()
            redirect_to(h.url_for(action='show', id=c.participant.token))

        return handle_validation(show, update, AddCommentFormSchema)
Пример #5
0
    def edit_expense(self, id):
        dbFacade = self.dbFacade()
        expense_uid = request.params.get('expense_uid')

        c.participant = dbFacade.meetings.participantDao.find_by_token(id)
        if c.participant is None:
            abort(404)

        c.meeting = c.participant.meeting

        c.obligation = dbFacade.meetings.obligationDao.find_by_uid(expense_uid)
        if not c.obligation or c.obligation.participant_uid != c.participant.uid:
            redirect_to(h.url_for(action='show', id=c.participant.token))

        def edit_expense_update(result):
            obligation = c.obligation
            obligation.description = result.get('description')
            obligation.html_description = result.get('html_description')
            obligation.amount = h.parse_decimal(result.get('amount'))
            obligation.shared_amount = 0
            if result.get('shared') == 'part':
                obligation.shared_amount = result.get('shared_amount') or Decimal(0)
            elif result.get('shared') == 'all':
                obligation.shared_amount = obligation.amount

            dbFacade.db.commit()

            redirect_to(h.url_for(action='show', id=c.participant.token))

        return handle_validation(self._expense_show, edit_expense_update, EditMeetingExpenseFormSchema)
Пример #6
0
    def add_expense(self, id):
        dbFacade = self.dbFacade()

        c.participant = dbFacade.meetings.participantDao.find_by_token(id)
        if c.participant is None:
            abort(404)

        c.meeting = c.participant.meeting

        def add_expense_update(result):
            obligation = dbFacade.model.MeetingObligation()
            obligation.meeting = c.meeting
            obligation.title = _('Expense %d') % (len(c.meeting.obligations) + 1)
            obligation.participant_uid = c.participant.uid
            obligation.description = result.get('description')
            obligation.html_description = result.get('html_description')
            obligation.expense = True
            obligation.amount = result.get('amount')
            if result.get('shared') == 'part':
                obligation.shared_amount = result.get('shared_amount') or Decimal(0)
            elif result.get('shared') == 'all':
                obligation.shared_amount = obligation.amount

            c.meeting.obligations.append(obligation)
            dbFacade.meetings.meetingDao.save(c.meeting)
            dbFacade.db.commit()

            redirect_to(h.url_for(action='show', id=c.participant.token))

        return handle_validation(self._expense_show, add_expense_update, EditMeetingExpenseFormSchema)
Пример #7
0
    def firstday(self):
        configuration = self.dbFacade().get_configuration(h.authenticated_user())
        
        def show(errors):
            c.errors = errors
            c.firstday = configuration.get(self.firstday_key, '1')
            return render_jinja('balances/settings/firstday.jinja')

        def update(result):
            configuration[self.firstday_key] = result['firstday']
            self.dbFacade().set_configuration(h.authenticated_user(), configuration)
            self.dbFacade().db.commit()
            return redirect_to(h.url_for(action='summary'))

        return handle_validation(show, update, FirstdaySchema)
Пример #8
0
    def unsubscribe(self):
        def unsubscribe_show(errors):
            c.form_errors = errors
            
            if 'email' in request.params:
                c.email = request.params.get('email')
            return render_jinja2('newsletter/unsubscribe.jinja')

        def unsubscribe_update(result):
            dbFacade = self.dbFacade()

            subscriber = dbFacade.newsletter.subscriberDao.find_by_email(result.get('email'))
            if subscriber is not None:
                dbFacade.db.delete(subscriber)
                dbFacade.db.commit()

            self.return_to_rp_if_set()
            c.email = result.get('email')
            return render_jinja2('newsletter/saved.jinja')

        return handle_validation(unsubscribe_show, unsubscribe_update, schema=EmailFormSchema)
Пример #9
0
    def number(self, id):
        dbFacade = self.dbFacade()
        c.balance = dbFacade.balances.balanceDao.find_by_uid(id)
        if not c.balance:
            abort(404)

        if not c.balance.can_see_balance(h.authenticated_user().uid):
            abort(403)

        def show(errors):
            c.errors = errors
            return render_jinja2('balances/settings/number.jinja')

        def update(result):
            if result.get('number'):
                c.balance.iban = 'PL'+result.get('number')
            else:
                c.balance.iban = ''
            self.dbFacade().db.commit()
            return redirect_to(h.url_for(action='summary', id=None))

        return handle_validation(show, update, NumberSchema)
Пример #10
0
    def show_csv(self, id, saved_id):
        dbFacade = self.dbFacade()

        c.balance = dbFacade.balances.balanceDao.find_by_uid(id)
        if not c.balance:
            abort(404)

        if not c.balance.can_modify_balance(h.authenticated_user().uid):
            abort(403)
        
        c.charset = request.params.get('charset', 'cp1250')
        saved_fn = self._uploaded_file_path(saved_id)
        try:
            c.csv = parse_csv(saved_fn, c.charset)
            c.rows = isinstance(c.csv, list) and len(c.csv) or 0
            if c.rows and isinstance(c.csv[0], list):
                c.columns = len(c.csv[0])
        except:
            if path.exists(saved_fn) and path.isfile(saved_fn):
                unlink(saved_fn)

            return render_jinja('balances/import/error.jinja')

        def show(errors):
            c.errors = errors
            return render_jinja('balances/import/show_csv.jinja')

        def update(result):
            amount = 0
            occurred_on = 0
            description = []
            for i in range(1, c.columns+1):
                value = result.get("column_type_%d" %i)
                if value == "occurred_on":
                    occurred_on = i-1
                elif value == "amount":
                    amount = i-1
                elif value == "description":
                    description.append(i-1)

            dbFacade = self.dbFacade()
            other_category = dbFacade.balances.changeCategoryDao.find_by_name("Inne")

            changes = []
            for row in c.csv:
                try:
                    changes.append(dbFacade.model.BalanceChange(
                        amount=h.parse_decimal(row[amount]),
                        occurred_on=h.parse_date(row[occurred_on]),
                        description=reduce(lambda x, y: x + " " + y, [row[d] for d in description]),))
                except:
                    pass

            c.start_date = changes[0].occurred_on
            c.end_date = changes[0].occurred_on
            
            c.imported = 0
            for change in changes:
                try:
                    c.start_date = min(c.start_date, change.occurred_on)
                    c.end_date = max(c.end_date, change.occurred_on)

                    change.change_category_uid = other_category.uid
                    change.user_uid = h.authenticated_user().uid

                    dbFacade.balances.add_balance_change(c.balance, change)
                    dbFacade.db.commit()
                    c.imported += 1
                except:
                    pass

            if path.exists(saved_fn) and path.isfile(saved_fn):
                unlink(saved_fn)
            
            return render_jinja('balances/import/summary.jinja')

        try:
            return handle_validation(show, update, ImportCsvFormSchema(c.columns))
        except:
            return render_jinja('balances/import/error.jinja')