Ticket #3240: 3240.patch

File 3240.patch, 12.1 KB (added by TimothyClemans, 14 years ago)

depends on #3050

  • sage/server/notebook/notebook.py

    # HG changeset patch
    # User Timothy Clemans <timothy.clemans@gmail.com>
    # Date 1211065660 25200
    # Node ID 13541feacb6e4f8797f240f930c20044e69ffcad
    # Parent  2339ff5c0a10fa75e3c8649e2175cbc3f480b23a
    #3240
    
    diff -r 2339ff5c0a10 -r 13541feacb6e sage/server/notebook/notebook.py
    a b class Notebook(SageObject): 
    434434        W = worksheet.Worksheet(worksheet_name, dirname, self,
    435435                                system = self.system(username),
    436436                                owner=username,
    437                                 docbrowser = docbrowser)
     437                                docbrowser = docbrowser,
     438                                auto_publish = False)
    438439
    439440        if add_to_list:
    440441            self.__worksheets[W.filename()] = W
    class Notebook(SageObject): 
    15031504        </html>
    15041505        """%(head, body)
    15051506
    1506     def html_worksheet_page_template(self, worksheet, username, title, select=None):
     1507    def html_worksheet_page_template(self, worksheet, username, title, select=None, backwards=False):
    15071508        head = self._html_head(worksheet_filename=worksheet.filename(), username=username)
    15081509        head += '<script  type="text/javascript">worksheet_filename="%s"; worksheet_name="%s"; server_ping_while_alive(); </script>'%(worksheet.filename(), worksheet.name())
    15091510        body = self._html_body(worksheet.filename(), top_only=True, username=username)
    1510         body += self.html_worksheet_topbar(worksheet, select=select, username=username)
     1511        body += self.html_worksheet_topbar(worksheet, select=select, username=username, backwards=backwards)
    15111512        body += '<hr class="usercontrol">'
    15121513        body += '<span class="sharebar">%s</span>'%title
    15131514        body += '<br>'*3
    class Notebook(SageObject): 
    17581759        head +=' <script>jmolInitialize("/java/jmol");</script>\n' # this must stay in the <head>
    17591760        return head
    17601761
    1761     def html_worksheet_topbar(self, worksheet, select=None, username='guest'):
     1762    def html_worksheet_topbar(self, worksheet, select=None, username='guest', backwards=False):
    17621763        body = ''
    17631764        body += """
    17641765<table width="100%%" id="topbar">
    class Notebook(SageObject): 
    17701771</tr>
    17711772</table>
    17721773"""%(worksheet.html_title(username), worksheet.html_save_discard_buttons(),
    1773      worksheet.html_menu(), worksheet.html_share_publish_buttons(select=select))
     1774     worksheet.html_menu(), worksheet.html_share_publish_buttons(select=select, backwards=backwards))
    17741775       
    17751776        body += self.html_slide_controls()
    17761777        return body
    function save_worksheet_and_close() { 
    19221923        </form>
    19231924        """%(t.count("\n")+1,t)
    19241925         
     1926        return """
     1927        <html>
     1928        <head>%s</head>
     1929        <body>%s</body>
     1930        </html>
     1931        """%(head, body)
     1932   
     1933    def html_beforepublish_window(self, worksheet, username):
     1934        msg = """You can publish your worksheet to the Internet, where anyone will be able to access and view it online.
     1935        Your worksheet will be assigned a unique address (URL) that you can send to your friends and colleagues.<br/><br/>
     1936        <form method="get" action=".">
     1937        <input type="hidden" name="yes" value="" />
     1938        <input type="submit" value="Yes" />
     1939        <input type="button" value="No" style="margin-left:5px" onClick="parent.location=\'../'"><br/><br/>
     1940        <input type="checkbox" name="auto" /> Automatically re-publish when changes are made
     1941        </form>
     1942        """
     1943        head, body = self.html_worksheet_page_template(worksheet, username, msg, select="publish", backwards=True)
     1944       
     1945        return """
     1946        <html>
     1947        <head>%s</head>
     1948        <body>%s</body>
     1949        </html>
     1950        """%(head, body)
     1951       
     1952    def html_afterpublish_window(self, worksheet, username, addr, dtime):
     1953        from time import strftime
     1954        time = strftime("%B %d, %Y %I:%M %p", dtime)
     1955        msg = """Worksheet is publicly viewable at <a href="%s" style="color:#FFF" target="_blank">%s</a><br />
     1956        Published on %s<br/><br />
     1957        <input type="button" value="Re-publish worksheet" onClick="parent.location=\'?re'"><input type="button" value="Stop publishing" style="margin-left:5px" onClick="parent.location=\'?stop'"><br /><br />
     1958<input type="checkbox" name="auto"%s onchange="parent.location=\'?auto'"/> Automatically re-publish when changes are made
     1959        """ % (addr, addr, time, ' checked="true" ' if worksheet.is_auto_publish() else '')
     1960        head, body = self.html_worksheet_page_template(worksheet, username, msg, select="publish", backwards=True)
     1961       
    19251962        return """
    19261963        <html>
    19271964        <head>%s</head>
  • sage/server/notebook/twist.py

    diff -r 2339ff5c0a10 -r 13541feacb6e sage/server/notebook/twist.py
    a b class Worksheet_eval(WorksheetResource,  
    11661166########################################################
    11671167
    11681168class Worksheet_publish(WorksheetResource, resource.Resource):
     1169    addSlash = True
     1170   
    11691171    def render(self, ctx):
    1170         W = notebook.publish_worksheet(self.worksheet, self.username)
    1171         addr = '/home/' + W.filename()
    1172         return http.RedirectResponse(addr)
     1172        if 'yes' in ctx.args and 'auto' in ctx.args:
     1173            notebook.publish_worksheet(self.worksheet, self.username)
     1174            self.worksheet.set_auto_publish()
     1175            return http.RedirectResponse("/home/%s/publish" % (self.worksheet.filename()))
     1176        elif 'yes' in ctx.args:
     1177            notebook.publish_worksheet(self.worksheet, self.username)
     1178            return http.RedirectResponse("/home/%s/publish" % (self.worksheet.filename()))
     1179        elif 'stop' in ctx.args:
     1180            notebook.delete_worksheet(self.worksheet.published_version().filename())
     1181            return http.RedirectResponse("/home/%s/publish" % (self.worksheet.filename()))
     1182        elif 're' in ctx.args:
     1183            W = notebook.publish_worksheet(self.worksheet, self.username)
     1184            return http.RedirectResponse("/home/%s/publish" % (self.worksheet.filename()))
     1185        elif 'auto' in ctx.args:
     1186            self.worksheet.set_auto_publish()
     1187            return http.RedirectResponse("/home/%s/publish" % (self.worksheet.filename()))
     1188        elif 'is_auto' in ctx.args:
     1189            return http.Response(stream=str(self.worksheet.is_auto_publish()))
     1190        else:
     1191            if self.worksheet.has_published_version():
     1192                addr = 'http%s://' % ('' if not notebook.secure else 's')
     1193                addr += notebook.address
     1194                addr += ':%s' % notebook.port
     1195                addr += '/home/' + self.worksheet.published_version().filename()
     1196                dtime = self.worksheet.published_version().date_edited()
     1197                return http.Response(stream=notebook.html_afterpublish_window(self.worksheet, self.username, addr, dtime))
     1198            else:
     1199                return http.Response(stream=notebook.html_beforepublish_window(self.worksheet, self.username))
    11731200       
    11741201
    11751202class Worksheet_rating_info(WorksheetResource, resource.Resource):
  • sage/server/notebook/worksheet.py

    diff -r 2339ff5c0a10 -r 13541feacb6e sage/server/notebook/worksheet.py
    a b def worksheet_filename(name, owner): 
    105105    return owner + '/' + _notebook.clean_name(name)
    106106
    107107class Worksheet:
    108     def __init__(self, name, dirname, notebook, system, owner, docbrowser=False, pretty_print=False):
     108    def __init__(self, name, dirname, notebook, system, owner, docbrowser=False, pretty_print=False, auto_publish=False):
    109109
    110110        # Record the basic properties of the worksheet
    111111        self.__system   = system
    class Worksheet: 
    114114        self.__viewers       = []
    115115        self.__collaborators = []
    116116        self.__docbrowser = docbrowser
     117        self.__autopublish = auto_publish
     118        self.__notebook = notebook
    117119
    118120        # Initialize the cell id counter.
    119121        self.__next_id = 0
    class Worksheet: 
    284286    ##########################################################
    285287    # Publication
    286288    ##########################################################
     289    def is_auto_publish(self):
     290        try:
     291            return self.__autopublish
     292        except AttributeError:
     293            self.__autopublish = False
     294            return False
     295   
     296    def set_auto_publish(self):
     297        self.__autopublish = False if self.__autopublish else True
     298   
    287299    def is_published(self):
    288300        return self.owner() == 'pub'
    289301
    class Worksheet: 
    600612    ##########################################################
    601613    # Saving
    602614    ##########################################################
     615   
    603616    def save(self):
    604617        path = self.__dir
    605618        E = self.edit_text()
    class Worksheet: 
    621634            X = {}
    622635            self.__saved_by_info = X
    623636        X[basename] = user
     637        if self.is_auto_publish():
     638            self.__notebook.publish_worksheet(self, user)
    624639
    625640    def get_snapshot_text_filename(self, name):
    626641        path = self.snapshot_directory()
    class Worksheet: 
    906921        <button name="button_save" title="Save changes" onClick="save_worksheet();">Save</button><button title="Save changes and close window" onClick="save_worksheet_and_close();" name="button_save">Save & quit</button><button title="Discard changes to this worksheet" onClick="worksheet_discard();">Discard & quit</button>
    907922        """
    908923
    909     def html_share_publish_buttons(self, select=None):
     924    def html_share_publish_buttons(self, select=None, backwards=False):
    910925        if self.is_doc_worksheet():
    911926            return ''
    912927        def cls(x):
    class Worksheet: 
    914929                return "control-select"
    915930            else:
    916931                return "control"
    917        
     932        backwards = '../' if backwards else ''
    918933        return """
    919934
    920935        <a  title="Print this worksheet" class="usercontrol" onClick="print_worksheet()"><img border=0 src="/images/icon_print.gif" alt="Print">Print</a>
    921936        <a class="%s" title="Interactively use this worksheet" onClick="edit_worksheet();">Worksheet</a>       
    922         <a class="%s" title="Edit text version of this worksheet" href="edit">Edit</a>
    923         <a class="%s" title="View plain text version of this worksheet" href="text">Text</a>
    924         <a class="%s" href="revisions" title="View changes to this worksheet over time">Undo</a>
    925         <a class="%s" href="share" title="Let others edit this worksheet">Share</a>
    926         <a class="control" onClick="publish_worksheet();" title="Let others view this worksheet">Publish</a>
    927         """%(cls('use'),cls('edit'),cls('text'),cls('revisions'),cls('share'))
     937        <a class="%s" title="Edit text version of this worksheet" href="%sedit">Edit</a>
     938        <a class="%s" title="View plain text version of this worksheet" href="%stext">Text</a>
     939        <a class="%s" href="%srevisions" title="View changes to this worksheet over time">Undo</a>
     940        <a class="%s" href="%sshare" title="Let others edit this worksheet">Share</a>
     941        <a class="%s" href="%spublish" title="Make this worksheet publicly viewable">Publish</a>
     942        """%(cls('use'),cls('edit'),backwards,cls('text'),backwards,cls('revisions'),backwards,cls('share'),backwards,cls('publish'),backwards)
    928943
    929944    def html_data_options_list(self):
    930945        D = self.attached_data_files()
    class Worksheet: 
    10521067            t = time.time()
    10531068            self.__last_edited = (t, self.owner())
    10541069            return t
     1070   
     1071    def date_edited(self):
     1072        try:
     1073            return self.__date_edited[0]
     1074        except AttributeError:
     1075            t = time.localtime()
     1076            self.__date_edited = (t, self.owner())
     1077            return t
    10551078
    10561079    def last_to_edit(self):
    10571080        try:
    class Worksheet: 
    10611084
    10621085    def record_edit(self, user):
    10631086        self.__last_edited = (time.time(), user)
     1087        self.__date_edited = (time.localtime(), user)
    10641088        self.autosave(user)
    10651089
    10661090    def time_since_last_edited(self):