Example #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")
Example #2
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
Example #3
0
 def do_post(self, handler):
     if Auth.get_user_email(handler) is None:
         self.render_not_logged_in(handler)
         return
     content_len = int(handler.headers["content-length"])
     data = handler.rfile.read(content_len)
     data = urllib.parse.parse_qs(data)
     if b'delete-id' in data:
         del_id = data[b'delete-id'][0].decode("utf-8")
         self.delete_ack(del_id)
     if b'delete-eng-update-id' in data:
         del_id = data[b'delete-eng-update-id'][0].decode("utf-8")
         self.delete_eng_update(del_id)
     if b'delete-bounty-id' in data:
         del_id = data[b'delete-bounty-id'][0].decode("utf-8")
         self.delete_bounty(del_id)
     if b'close-bounty-id' in data:
         del_id = data[b'close-bounty-id'][0].decode("utf-8")
         self.close_bounty(del_id)
     self.render_page(handler)
Example #4
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>")
Example #5
0
    def do_post(self, handler):
        userID = Auth.get_user_email(handler)
        if userID is None:
            raise Exception("not logged in")
        # Decode and insert the acks.
        content_len = int(handler.headers["content-length"])
        data = handler.rfile.read(content_len)
        data = urllib.parse.parse_qs(data)

        action = ""
        if b'action' in data:
            action = data[b'action'][0].decode("utf-8")

        num_acks = 0
        bounty = False
        if action == "add_bounty":
            bounty = self.handle_add_bounty(data, userID)
        else:
            acks = []
            if b'ack' in data:
                raw_acks = data[b'ack'][0].decode("utf-8")
                acks = self.parse_acks(raw_acks)
            num_acks = len(acks)
            haiku = ""
            if b'haiku' in data:
                haiku = data[b'haiku'][0].decode("utf-8")
                num_acks += 1
            self.insert_acks(userID, acks, haiku)

            if b'eng-updates' in data:
                update = data[b'eng-updates'][0].decode("utf-8")
                self.insert_eng_update(userID, update)

        handler.send_response(303)  # "See-also" code.
        self.set_inserted_cookie(handler, num_acks, bounty)
        handler.send_header('Location', '/ack')
        handler.end_headers()
Example #6
0
 def __init__(self, **kwargs):
     app = kwargs["app"]
     Auth.__init__(self, app)
Example #7
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")
Example #8
0
 def do_get(self, handler):
     if Auth.get_user_email(handler) is None:
         self.render_not_logged_in(handler)
         return
     self.render_page(handler)