Exemplo n.º 1
0
    def _remind_resolved_bugs_user(self, user):
        """ remind (via email) user to close his resolved bugs """
        LOG(u"Starting email reminder for user %s" % (user.email, ))
        my_bugs_url = self.request.url_for('/bugs/my', resolved=1)
        list_url = self.settings['FRONTEND_PREFIX'] + my_bugs_url

        bugs = Bugs(self.request, user).get_user(resolved=True)
        if not bugs:
            LOG(u"No bugs to remind user %s of" % (user.email, ))
            return self._(u'No bugs for user ${user}', user=user.email)
        output = []
        output.append(self._(u'Hej ${user}! Masz rozwiązane niezamknięte bugi, weź je ogarnij:', user=user.name))
        output.append(u'')
        for i, bug in enumerate(bugs, 1):
            id = bug.id
            desc = bug.desc
            url = bug.get_url()
            output.append(u"%(i)s. #%(id)s %(desc)s %(url)s" % locals())
        output.append(u'')
        output.append(self._(u'Te bugi możesz również zobaczyć pod adresem ${list_url}', list_url=list_url))
        output.append(u'')
        output.append(self._(u'Pozdrawiam,\nTwój intranet'))
        message = u'\n'.join(output)

        def on_success(result):
            LOG(u'Email reminder about resolved bugs sent to user %s' % (user.email, ))
        def on_error(err):
            EXCEPTION(u'Failed to remind user %s about resolved bugs' % (user.email, ))
        topic = self._(u"[intranet] ${num} zgłoszeń do zamknięcia", num=len(bugs))
        deferred = EmailSender.send(user.email, topic, message)
        deferred.addCallbacks(on_success, on_error)
        LOG(u"Email reminder for user %s started" % (user.email, ))
        return message
Exemplo n.º 2
0
    def _remind_missing_hours(self, email, name, hours, date):
        """ remind (via email) everyone about their missing hours """
        LOG(u"Starting email reminder for user %s" % (email, ))
        time_list_url = self.request.url_for('/times/list',
                                             date=date.strftime('%d.%m.%Y'))
        hours_url = self.settings['FRONTEND_PREFIX'] + time_list_url
        message = self.HOURS_EMAIL_TEMPLATE(
            name=name,
            min_hours=MIN_HOURS,
            actual='%.2f' % hours,
            url=hours_url,
            date=date.strftime('%d.%m.%Y'),
        )

        def on_success(result):
            LOG(u'Email reminder about missing hours sent to user %s' %
                (email, ))

        def on_error(err):
            EXCEPTION(u'Failed to remind user %s about missing hours' %
                      (email, ))

        topic = self._(u"[intranet] brakujące godziny z dnia ${date}",
                       date=date.strftime('%d.%m.%Y'))
        deferred = EmailSender.send(email, topic, message)
        deferred.addCallbacks(on_success, on_error)
        LOG(u"Email reminder for user %s started" % (email, ))
        return message
Exemplo n.º 3
0
    def _send_email(self, type, date_start, date_end, days, remarks):
        name = self.request.user.name
        email = self.request.user.email
        today = datetime.date.today()
        topic, body = self.TYPES[type]

        body = self._(
            body,
            today=today.strftime('%Y-%m-%d'),
            date_start=date_start,
            date_end=date_end,
            year=today.year,
            days=days,
            remarks=remarks,
            name=name,
        )

        return EmailSender.send(
            config['ACCOUNTANT_EMAIL'],
            self._(topic),
            body,
            cc=email,
            sender_name=name,
            replay_to=','.join([email])
        )
Exemplo n.º 4
0
    def _today_hours_without_ticket(self, date, projects, omit_users):
        if not omit_users:
            # because u.id NOT IN (,) returns error
            omit_users = (987654321,)
        time_entries = self.session.query('user', 'description', 'time', 'project', 'client').from_statement("""
        SELECT
            u.name as "user", t.description as "description",
            t.time as "time", p.name as "project", c.name as "client"
        FROM
            time_entry as t, project as p, client as c, "user" as u
        WHERE
            t.deleted = False AND
            t.date = :date AND
            t.ticket_id IS NULL AND
            u.id = t.user_id AND
            p.id = t.project_id AND
            c.id = p.client_id AND
            p.id IN :projects AND
            u.id NOT IN :users
        ORDER BY u.name, c.name, p.name
        """).params(date=date, projects=tuple(projects), users=tuple(omit_users)).all()


        if not time_entries:
            LOG(u"No time entries for report with hours without ticket added on %s" % (date,))
            return u"No time entries for report with hours without ticket added on %s" % (date,)

        output = []
        total_sum = 0
        user_sum = defaultdict(lambda: 0.0)
        user_entries = defaultdict(lambda: [])

        for user, description, time, project, client in time_entries:
            total_sum += time
            user_sum[user] += time
            user_entries[user].append((description, time, project, client))

        output.append(self._(u"Daily hours report without bugs (${total_sum} h)", total_sum=u'%.2f' % total_sum))

        for user, entries in user_entries.iteritems():
            output.append(u"")
            output.append(u"\t%s (%.2f h):" % (user, user_sum[user]))

            for description, time, project, client in entries:
                output.append(u"\t\t- %s / %s / %s %.2f h" % (client, project, description, time))

        message = u'\n'.join(output)

        def on_success(result):
            LOG(u'Report with hours without ticket added on %s - sent' % (date,))
        def on_error(err):
            EXCEPTION(u'Failed to sent Report with hours without ticketadded on %s' % (date,))
        topic = self._(u"[intranet] Daily hours report without bugs")
        deferred = EmailSender.send(config['MANAGER_EMAIL'], topic, message)
        deferred.addCallbacks(on_success, on_error)
        LOG(u"Report with hours without ticket on %s - started" % (date,))
        return message
Exemplo n.º 5
0
    def _today_hours_without_ticket(self, date, projects, omit_users):
        if not omit_users:
            # because u.id NOT IN (,) returns error
            omit_users = (987654321,)
        time_entries = self.session.query('user', 'description', 'time', 'project', 'client').from_statement("""
        SELECT
            u.name as "user", t.description as "description",
            t.time as "time", p.name as "project", c.name as "client"
        FROM
            time_entry as t, project as p, client as c, "user" as u
        WHERE
            t.deleted = False AND
            t.date = :date AND
            t.ticket_id IS NULL AND
            u.id = t.user_id AND
            p.id = t.project_id AND
            c.id = p.client_id AND
            p.id IN :projects AND
            u.id NOT IN :users
        ORDER BY u.name, c.name, p.name
        """).params(date=date, projects=tuple(projects), users=tuple(omit_users)).all()


        if not time_entries:
            LOG(u"No time entries for report with hours without ticket added on %s" % (date,))
            return u"No time entries for report with hours without ticket added on %s" % (date,)

        output = []
        total_sum = 0
        user_sum = defaultdict(lambda: 0.0)
        user_entries = defaultdict(lambda: [])

        for user, description, time, project, client in time_entries:
            total_sum += time
            user_sum[user] += time
            user_entries[user].append((description, time, project, client))

        output.append(self._(u"Daily hours report without bugs (${total_sum} h)", total_sum=u'%.2f' % total_sum))

        for user, entries in user_entries.iteritems():
            output.append(u"")
            output.append(u"\t%s (%.2f h):" % (user, user_sum[user]))

            for description, time, project, client in entries:
                output.append(u"\t\t- %s / %s / %s %.2f h" % (client, project, description, time))

        message = u'\n'.join(output)

        def on_success(result):
            LOG(u'Report with hours without ticket added on %s - sent' % (date,))
        def on_error(err):
            EXCEPTION(u'Failed to sent Report with hours without ticketadded on %s' % (date,))
        topic = self._(u"[intranet] Daily hours report without bugs")
        deferred = EmailSender.send(config['MANAGER_EMAIL'], topic, message)
        deferred.addCallbacks(on_success, on_error)
        LOG(u"Report with hours without ticket on %s - started" % (date,))
        return message
Exemplo n.º 6
0
    def _hours_for_previous_months(self, date):
        current_month_start = datetime.date(date.year, date.month, 1)
        time_entries = self.session.query(
            'user', 'client', 'project', 'time',
            'description', 'ticket_id', 'entry_date', 'entry_status').from_statement("""
        SELECT
            u.name as "user", c.name as "client", p.name as "project",
            t.time as "time", t.description as "description",
            t.ticket_id as "ticket_id", t.date as "entry_date",
            t.deleted as "entry_status"
        FROM
            time_entry as t,
            "user" as u,
            client as c,
            project as p
        WHERE
            t.user_id = u.id AND
            t.project_id = p.id AND
            p.client_id = c.id AND
            DATE(t.modified_ts) = :date AND
            t.date < :current_month_start
        ORDER BY
            u.name, c.name, p.name
        """).params(current_month_start=current_month_start, date=date).all()

        if not time_entries:
            LOG(u"No time entries for previous months %s" % (date,))
            return u"No time entries for previous months %s" % (date,)

        output = []
        tmp_user = ''
        for user, client, project, time, description, ticket_id, entry_date, entry_status in time_entries:
            if tmp_user != user:
                tmp_user = user
                output.append(u"")
                output.append(u"%s:" % (user,))

            ticket_id = ticket_id and u"[%s] " % ticket_id or u""
            status = entry_status and self._(u"[Deleted]") or u""
            output.append(u"\t- [%s]%s %s / %s / %s%s %.2f h" % (entry_date, status, client, project, ticket_id, description, time))

        message = u'\n'.join(output)

        def on_success(result):
            LOG(u'Report with hours added for the previous months - sent')
        def on_error(err):
            EXCEPTION(u'Failed to sent report with hours added for the previous months')
        topic = self._(u"[intranet] Report with hours added for the previous months")
        deferred = EmailSender.send(config['MANAGER_EMAIL'], topic, message)
        deferred.addCallbacks(on_success, on_error)
        LOG(u"Report with hours added for previous months - started")
        return message
Exemplo n.º 7
0
    def _hours_for_previous_months(self, date):
        current_month_start = datetime.date(date.year, date.month, 1)
        time_entries = self.session.query(
            'user', 'client', 'project', 'time',
            'description', 'ticket_id', 'entry_date', 'entry_status').from_statement("""
        SELECT
            u.name as "user", c.name as "client", p.name as "project",
            t.time as "time", t.description as "description",
            t.ticket_id as "ticket_id", t.date as "entry_date",
            t.deleted as "entry_status"
        FROM
            time_entry as t,
            "user" as u,
            client as c,
            project as p
        WHERE
            t.user_id = u.id AND
            t.project_id = p.id AND
            p.client_id = c.id AND
            DATE(t.modified_ts) = :date AND
            t.date < :current_month_start
        ORDER BY
            u.name, c.name, p.name
        """).params(current_month_start=current_month_start, date=date).all()

        if not time_entries:
            LOG(u"No time entries for previous months %s" % (date,))
            return u"No time entries for previous months %s" % (date,)

        output = []
        tmp_user = ''
        for user, client, project, time, description, ticket_id, entry_date, entry_status in time_entries:
            if tmp_user != user:
                tmp_user = user
                output.append(u"")
                output.append(u"%s:" % (user,))

            ticket_id = ticket_id and u"[%s] " % ticket_id or u""
            status = entry_status and self._(u"[Deleted]") or u""
            output.append(u"\t- [%s]%s %s / %s / %s%s %.2f h" % (entry_date, status, client, project, ticket_id, description, time))

        message = u'\n'.join(output)

        def on_success(result):
            LOG(u'Report with hours added for the previous months - sent')
        def on_error(err):
            EXCEPTION(u'Failed to sent report with hours added for the previous months')
        topic = self._(u"[intranet] Report with hours added for the previous months")
        deferred = EmailSender.send(config['MANAGER_EMAIL'], topic, message)
        deferred.addCallbacks(on_success, on_error)
        LOG(u"Report with hours added for previous months - started")
        return message
Exemplo n.º 8
0
 def _send_email(self, date, explanation):
     topic = self._(u'${email} - Late ${date}',
                    email=self.request.user.email,
                    date=date.strftime('%d.%m.%Y')
     )
     deferred = EmailSender.send(
         config['COMPANY_MAILING_LIST'],
         topic,
         explanation,
         sender_name=self.request.user.name,
         replay_to=self.request.user.email,
     )
     return deferred
Exemplo n.º 9
0
    def post(self):
        form = LateApplicationForm(self.request.POST, user=self.request.user)
        if form.validate():
            date = form.popup_date.data
            explanation = form.popup_explanation.data
            late = Late(
                user_id=self.request.user.id,
                date=date,
                explanation=explanation,
                justified=True,
            )
            self.session.add(late)
            topic = self._(u'${email} - Late ${date}',
                           email=self.request.user.email,
                           date=date.strftime('%d.%m.%Y'))
            deferred = EmailSender.send(
                config['COMPANY_MAILING_LIST'],
                topic,
                form.popup_explanation.data,
                sender_name=self.request.user.name,
                replay_to=self.request.user.email,
            )
            datehour9 = datetime.datetime.combine(date, hour9)

            calendar = cal.Calendar(self.request.user)
            event = cal.Event(
                datehour9,
                datehour9 + cal.onehour,
                self._(u'Late'),
                explanation,
            )
            event_id = calendar.addEvent(event)

            if deferred:
                LOG(u"Late added")
                if event_id:
                    return Response(
                        self._(u'Request added. Calendar entry added'))
                else:
                    return Response(
                        self.
                        _(u'Request added. Calendar entry has <b class="red">NOT</b> beed added'
                          ))

            else:
                return Response(
                    self.
                    _(u'There was problem with sending email - request has not been added, please conntact administrator'
                      ))

        return dict(form=form)
Exemplo n.º 10
0
 def _send_mail(self, type, date_start, date_end, days, remarks):
     today = datetime.date.today().strftime('%Y-%m-%d')
     year = datetime.date.today().year
     name = self.request.user.name
     topic, body = self._resolve_type(type)
     kwargs = locals()
     kwargs.pop('self')
     body = body(**kwargs)
     return EmailSender.send(
         config['ACCOUNTANT_EMAIL'],
         topic,
         body,
         cc=self.request.user.email,
         sender_name=self.request.user.name,
         replay_to=','.join([self.request.user.email]),
     )
Exemplo n.º 11
0
    def post(self):
        form = LateApplicationForm(self.request.POST, user=self.request.user)
        if form.validate():
            date = form.popup_date.data
            explanation = form.popup_explanation.data
            late = Late(
                user_id=self.request.user.id,
                date=date,
                explanation=explanation,
                justified=True,
            )
            self.session.add(late)
            topic = self._(u'${email} - Late ${date}',
                email=self.request.user.email,
                date=date.strftime('%d.%m.%Y')
            )
            deferred = EmailSender.send(
                config['COMPANY_MAILING_LIST'],
                topic,
                form.popup_explanation.data,
                sender_name=self.request.user.name,
                replay_to=self.request.user.email,
            )
            datehour9 = datetime.datetime.combine(date, hour9)

            calendar = cal.Calendar(self.request.user)
            event = cal.Event(
                datehour9,
                datehour9+cal.onehour,
                self._(u'Late'),
                explanation,
            )
            event_id = calendar.addEvent(event)

            if deferred:
                LOG(u"Late added")
                if event_id:
                    return Response(self._(u'Request added. Calendar entry added'))
                else:
                    return Response(self._(u'Request added. Calendar entry has <b class="red">NOT</b> beed added'))

            else:
                return Response(self._(u'There was problem with sending email - request has not been added, please conntact administrator'))

        return dict(form=form)
Exemplo n.º 12
0
    def _remind_resolved_bugs_user(self, user):
        """ remind (via email) user to close his resolved bugs """
        LOG(u"Starting email reminder for user %s" % (user.email, ))
        my_bugs_url = self.request.url_for('/bugs/my', resolved=True)
        list_url = self.settings['FRONTEND_PREFIX'] + my_bugs_url

        bugs = Bugs(self.request, user).get_user(resolved=True)
        if not bugs:
            LOG(u"No bugs to remind user %s of" % (user.email, ))
            return self._(u'No bugs for user ${user}', user=user.email)
        output = []
        output.append(
            self.
            _(u'Hej ${user}! Masz rozwiązane niezamknięte bugi, weź je ogarnij:',
              user=user.name))
        output.append(u'')
        for i, bug in enumerate(bugs, 1):
            id = bug.id
            desc = bug.desc
            url = bug.get_url()
            output.append(u"%(i)s. #%(id)s %(desc)s %(url)s" % locals())
        output.append(u'')
        output.append(
            self._(u'Te bugi możesz również zobaczyć pod adresem ${list_url}',
                   list_url=list_url))
        output.append(u'')
        output.append(self._(u'Pozdrawiam,\nTwój intranet'))
        message = u'\n'.join(output)

        def on_success(result):
            LOG(u'Email reminder about resolved bugs sent to user %s' %
                (user.email, ))

        def on_error(err):
            EXCEPTION(u'Failed to remind user %s about resolved bugs' %
                      (user.email, ))

        topic = self._(u"[intranet] ${num} zgłoszeń do zamknięcia",
                       num=len(bugs))
        deferred = EmailSender.send(user.email, topic, message)
        deferred.addCallbacks(on_success, on_error)
        LOG(u"Email reminder for user %s started" % (user.email, ))
        return message
Exemplo n.º 13
0
    def _remind_missing_hours(self, email, name, hours, date):
        """ remind (via email) everyone about their missing hours """
        LOG(u"Starting email reminder for user %s" % (email, ))
        time_list_url = self.request.url_for('/times/list', date=date.strftime('%d.%m.%Y'))
        hours_url = self.settings['FRONTEND_PREFIX'] + time_list_url
        message = self.HOURS_EMAIL_TEMPLATE(
            name=name,
            min_hours=MIN_HOURS,
            actual='%.2f' % hours,
            url=hours_url,
            date=date.strftime('%d.%m.%Y'),
        )

        def on_success(result):
            LOG(u'Email reminder about missing hours sent to user %s' % (email, ))
        def on_error(err):
            EXCEPTION(u'Failed to remind user %s about missing hours' % (email, ))
        topic = self._(u"[intranet] brakujące godziny z dnia ${date}", date=date.strftime('%d.%m.%Y'))
        deferred = EmailSender.send(email, topic, message)
        deferred.addCallbacks(on_success, on_error)
        LOG(u"Email reminder for user %s started" % (email, ))
        return message
Exemplo n.º 14
0
    def _today_hours(self, date, projects, omit_users):
        time_entries = (
            self.session.query("user", "description", "time", "project", "client", "ticket_id")
            .from_statement(
                """
        SELECT
            u.name as "user", t.description as "description",
            t.time as "time", p.name as "project", c.name as "client",
            t.ticket_id as "ticket_id"
        FROM
            time_entry as t, project as p, client as c, "user" as u
        WHERE
            t.deleted = False AND
            t.date = :date AND
            u.id = t.user_id AND
            p.id = t.project_id AND
            c.id = p.client_id AND
            p.id IN :projects AND
            u.id NOT IN :users
        ORDER BY u.name, c.name, p.name
    """
            )
            .params(date=date, projects=tuple(projects), users=tuple(omit_users))
            .all()
        )

        if not time_entries:
            LOG(u"No time entries for report with hours added on %s" % (date,))
            return u"No time entries for report with hours added on %s" % (date,)

        output = []
        total_sum = 0
        user_sum = defaultdict(lambda: 0.0)
        user_entries = defaultdict(lambda: [])

        for user, description, time, project, client, ticket_id in time_entries:
            total_sum += time
            user_sum[user] += time
            user_entries[user].append((description, time, project, client, ticket_id))

        output.append(self._(u"Daily hours report (${total_sum} h)", total_sum="%.2f" % total_sum))

        for user, entries in user_entries.iteritems():
            output.append(u"")
            output.append(u"\t%s (%.2f h):" % (user, user_sum[user]))

            for description, time, project, client, ticket_id in entries:
                ticket_id = ticket_id and "[%s] " % ticket_id or u""
                output.append(u"\t\t- %s / %s / %s%s %.2f h" % (client, project, ticket_id, description, time))

        message = u"\n".join(output)

        def on_success(result):
            LOG(u"Report with hours added on %s - sent" % (date,))

        def on_error(err):
            EXCEPTION(u"Failed to sent Report with hours added on %s" % (date,))

        topic = self._(u"[intranet] Daily hours report")
        deferred = EmailSender.send(config["MANAGER_EMAIL"], topic, message)
        deferred.addCallbacks(on_success, on_error)
        LOG(u"Report with hours on %s - started" % (date,))
        return message