Beispiel #1
0
    def render_page(self, handler):
        handler.send_response(200)
        handler.send_header('Content-type','text/html')
        handler.end_headers()
        self.common_headers(handler.wfile)
        self.write(handler.wfile, "<body>\n")
        user_email = Auth.get_user_email(handler)
        self.menu_bar(handler.wfile)

        # If there's a report start time specified use that. Otherwise,
        # generate the report according to the current time.
        query_components = urllib.parse.parse_qs(urlparse(handler.path).query)
        if 'report_start' in query_components:
            report_start = datetime.datetime.strptime(
                    query_components['report_start'][0], Constants.datetime_fmt)
            report_start = Config.meeting_timezone.localize(report_start)
            report = Util.report_from_start(report_start)
        else:
            now = datetime.datetime.now(pytz.utc)
            report = Util.report(now)

        self.write(handler.wfile, "Report for the current week:")
        self.get_acks(handler.wfile, report)
        self.render_eng_updates(handler.wfile)
        self.write(handler.wfile, "</body></html>\n")
Beispiel #2
0
 def insert_acks(self, user, acks, haiku):
     ack_time = Util.adjust_ack_ts(datetime.datetime.now(pytz.utc))
     conn = Util.get_db_conn()
     cur = conn.cursor()
     for ack in acks:
         cur.execute(
             "INSERT INTO ack (msg, inserted_at, user_email) VALUES (%s, %s, %s)",
             (ack, ack_time, user))
     haiku = haiku.rstrip()
     if len(haiku) > 0:
         cur.execute(
             "INSERT INTO ack (msg, inserted_at, user_email) VALUES (%s, %s, %s)",
             (haiku, ack_time, user))
     conn.commit()
     cur.close()
     conn.close()
Beispiel #3
0
 def get_acks(self, wfile, report):
     conn = Util.get_db_conn()
     cur = conn.cursor()
     self.report_header(
             wfile,
             report,
             generate_links=True,
             msg="Report for week:",
     )
     cur.execute("SELECT id, msg FROM ack WHERE inserted_at>%s AND inserted_at<%s", 
             (report.start, report.end))
     raw_acks = cur.fetchall()
     acks = [Ack(id=ack[0], msg=ack[1]) for ack in raw_acks]
     # Sort acks by the first word. Assuming that many of them start with
     # the name of a person, those will sort together.
     acks = sorted(acks, key=lambda ack: ack.msg.split()[0])
     self.write(wfile,
         """
         <p>
         Acks:<br>
         {0}
         """.format(self.render_acks(acks))
     )
     cur.close()
     conn.close()
Beispiel #4
0
 def delete_bounty(self, bounty_id):
     conn = Util.get_db_conn()
     cur = conn.cursor()
     cur.execute("DELETE FROM bounties WHERE id=%s", (bounty_id, ))
     conn.commit()
     cur.close()
     conn.close()
Beispiel #5
0
 def delete_ack(self, ack_id):
     conn = Util.get_db_conn()
     cur = conn.cursor()
     cur.execute("DELETE FROM ack WHERE id=%s", (ack_id, ))
     conn.commit()
     cur.close()
     conn.close()
Beispiel #6
0
 def delete_eng_update(self, update_id):
     conn = Util.get_db_conn()
     cur = conn.cursor()
     cur.execute("DELETE FROM eng_updates WHERE id=%s", (update_id, ))
     conn.commit()
     cur.close()
     conn.close()
Beispiel #7
0
 def close_bounty(self, bounty_id):
     conn = Util.get_db_conn()
     cur = conn.cursor()
     cur.execute("update bounties set active=false where id=%s", (bounty_id,))
     conn.commit()
     cur.close()
     conn.close()
Beispiel #8
0
def serve_acks(handler, verb):
    user_email = Auth.get_user_email(handler)
    handler.send_response(200)
    handler.send_header('Content-type', 'application/json')
    handler.end_headers()
    now = datetime.datetime.now(pytz.utc)
    report = Util.ReportWindow(now + datetime.timedelta(days=-7), now)
    conn = Util.get_db_conn()
    cur = conn.cursor()
    cur.execute("SELECT msg FROM ack WHERE inserted_at>%s AND inserted_at<%s",
                (report.start, report.end))
    acks = cur.fetchall()
    handler.wfile.write(
        bytes(json.dumps({"acks": [ack[0] for ack in acks]}), "utf8"))
    cur.close()
    conn.close()
    return
Beispiel #9
0
 def insert_eng_update(self, user, eng_update):
     now = datetime.datetime.now(pytz.utc)
     conn = Util.get_db_conn()
     cur = conn.cursor()
     cur.execute(
         "INSERT INTO eng_updates (msg, inserted_at, user_email) VALUES (%s, %s, %s)",
         (eng_update, now, user))
     conn.commit()
     cur.close()
     conn.close()
Beispiel #10
0
 def render_eng_updates(self, wfile):
     self.write(wfile, "<p>Suggested eng updates:<br>")
     now = datetime.datetime.now(pytz.utc)
     report = Util.report(now)
     updates = DB.get_eng_updates(report, None)
     s = "<ol>"
     for upd in updates:
             s += "<li>{0}</li>".format(upd.msg)
     s += "</ol>"
     self.write(wfile, s)
Beispiel #11
0
    def render_page(self, handler):
        handler.send_response(200)
        handler.send_header('Content-type', 'text/html')
        handler.end_headers()
        self.common_headers(handler.wfile)
        self.write(
            handler.wfile, """
        <body>
        <form method=post action=/myacks accept-charset="UTF-8" id="action-form">
            <input type="hidden" name="delete-id" id="delete-id">
            <input type="hidden" name="delete-eng-update-id" id="delete-eng-update-id">
            <input type="hidden" name="delete-bounty-id" id="delete-bounty-id">
            <input type="hidden" name="close-bounty-id" id="close-bounty-id">
        </form>
        """)
        user_email = Auth.get_user_email(handler)
        self.menu_bar(handler.wfile)

        # If there's a report start time specified use that. Otherwise,
        # generate the report according to the current time.
        query_components = urllib.parse.parse_qs(urlparse(handler.path).query)
        if 'report_start' in query_components:
            report_start = datetime.datetime.strptime(
                query_components['report_start'][0], Constants.datetime_fmt)
            report_start = Config.meeting_timezone.localize(report_start)
            report = Util.report_from_start(report_start)
        else:
            now = datetime.datetime.now(pytz.utc)
            report = Util.report(now)

        now = datetime.datetime.now(pytz.utc)
        self.report_header(
            handler.wfile,
            report,
            generate_links=True,
            msg="My acks for week:",
        )
        self.get_my_acks(handler.wfile, user_email, report)
        self.render_my_eng_updates(handler.wfile, user_email, report)
        self.render_my_bounties(handler.wfile, user_email)
        self.write(handler.wfile, "</body></html>")
Beispiel #12
0
 def get_my_acks(self, wfile, email, report):
     conn = Util.get_db_conn()
     cur = conn.cursor()
     cur.execute("SELECT id, msg FROM ack WHERE user_email=%s "+
             "AND inserted_at>%s AND inserted_at<%s",
             (email, report.start, report.end))
     acks = cur.fetchall()
     self.write(wfile, '<table border="1">')
     for ack in acks:
         self.render_ack(wfile, Ack(ack[0], ack[1]))
     self.write(wfile, "</table>")
     cur.close()
     conn.close()
Beispiel #13
0
 def get_open_bounties():
     conn = Util.get_db_conn()
     cur = conn.cursor()
     cur.execute("select id, author, created, updated, msg, active " +
                 "from bounties where active = true order by updated desc")
     bounties_raw = cur.fetchall()
     bounties = [
         Bounty(id=b[0],
                author=b[1],
                created=b[2],
                updated=b[3],
                msg=b[4],
                active=b[5]) for b in bounties_raw
     ]
     cur.close()
     conn.close()
     return bounties
Beispiel #14
0
 def get_eng_updates(report, user_email):
     conn = Util.get_db_conn()
     cur = conn.cursor()
     if user_email is None:
         cur.execute(
             "SELECT id, msg FROM eng_updates WHERE " +
             "inserted_at>%s AND inserted_at<%s",
             (report.start, report.end))
     else:
         cur.execute(
             "SELECT id, msg FROM eng_updates WHERE " +
             "inserted_at>%s AND inserted_at<%s AND user_email=%s",
             (report.start, report.end, user_email))
     updates_raw = cur.fetchall()
     updates = [EngUpdate(id=upd[0], msg=upd[1]) for upd in updates_raw]
     cur.close()
     conn.close()
     return updates
Beispiel #15
0
    def handle_add_bounty(self, data, user):
        msg = ""
        if b'bounty' in data:
            msg = data[b'bounty'][0].decode("utf-8")
        else:
            return False

        created_ts = datetime.datetime.now(pytz.utc)
        updated_ts = created_ts
        conn = Util.get_db_conn()
        cur = conn.cursor()
        cur.execute(
            "INSERT INTO bounties (author, created, updated, msg, active) " +
            "VALUES (%s, %s, %s, %s, %s)",
            (user, created_ts, updated_ts, msg, "true"))
        conn.commit()
        cur.close()
        conn.close()
        return True
Beispiel #16
0
    def do_get(self, handler):
        handler.send_response(200)
        handler.send_header('Content-type', 'text/html')
        handler.end_headers()

        self.common_headers(handler.wfile)
        self.write(handler.wfile, "<body>")
        user_email = Auth.get_user_email(handler)
        self.menu_bar(handler.wfile)

        num_acks, bounty = self.just_inserted(handler)
        if num_acks != 0:
            self.ack_butterbar(handler.wfile,
                               '%d peer ack(s) saved :thumb-up:' % (num_acks))
        elif bounty:
            self.ack_butterbar(handler.wfile, 'bounty saved :thumb-up:')

        now = datetime.datetime.now(pytz.utc)
        adjusted = Util.adjust_ack_ts(now)
        self.report_header(
            handler.wfile,
            Util.report(adjusted, slack=False),
            generate_links=False,
            msg="Sending acks for week:",
        )

        self.generate_bounty_pane(handler.wfile)

        msg = """
            <p1>How did they poke their head above the Roach's high expectations this week?
            <p>
            <form action=/ack method=post accept-charset="UTF-8">
                <fieldset id="fieldset" disabled="true">
                    One ack per line:<br><textarea name=ack rows="10" cols="80"></textarea>
                    <p>
                    Haiku (one multi-line ack):<br><textarea name=haiku rows="4" cols="80"></textarea><br>
                    <input type=submit><br>
                </fieldset>

                <fieldset id="fieldset-eng-updates" disabled="true">
                    Engineering updates: <img src="question-mark.png" height="16px" title="Suggest eng updates to Peter. Brag about your PR, your friend's PR, shout about a scary issue.">
                    <br><textarea name=eng-updates rows="4" cols="80"></textarea><br>
                    <input type=submit><br>
                </fieldset>
            </form>
        """
        self.write(handler.wfile, msg)

        self.write(handler.wfile, "<p>Suggested eng updates:<br>")
        userID = Auth.get_user_email(handler)
        if userID is None:
            self.write(handler.wfile, "Not logged in")
        else:
            self.write(handler.wfile, "\n<table>\n")
            now = datetime.datetime.now(pytz.utc)
            report = Util.report(now)
            eng_updates = DB.get_eng_updates(report, None)
            for update in eng_updates:
                self.render_eng_update(handler.wfile, update)
            self.write(handler.wfile, "\n</table>\n")
        self.write(handler.wfile, "\n</body></html>\n")