Ticket #3240: 3240_2.patch

File 3240_2.patch, 8.2 KB (added by TimothyClemans, 14 years ago)
  • sage/server/notebook/notebook.py

    # HG changeset patch
    # User Timothy Clemans <timothy.clemans@gmail.com>
    # Date 1211175221 25200
    # Node ID 7451d5155cf6dcda5a4c255e66cc56baa8ab8e3f
    # Parent  13541feacb6e4f8797f240f930c20044e69ffcad
    documentations, little frontend change to publish page before publication, bugs related to old worksheets fixed
    
    diff -r 13541feacb6e -r 7451d5155cf6 sage/server/notebook/notebook.py
    a b class Notebook(SageObject): 
    431431        else:
    432432            dirname = '0'
    433433
    434         W = worksheet.Worksheet(worksheet_name, dirname, self,
     434        W = worksheet.Worksheet(worksheet_name, dirname,
    435435                                system = self.system(username),
    436436                                owner=username,
    437437                                docbrowser = docbrowser,
    function save_worksheet_and_close() { 
    19311931        """%(head, body)
    19321932   
    19331933    def html_beforepublish_window(self, worksheet, username):
     1934        """
     1935        Returns the html code for a page dedicated to worksheet publishing prior to the
     1936        publication of the given worksheet.
     1937       
     1938        INPUT:
     1939            worksheet - instance of Worksheet
     1940            username - string
     1941        """
    19341942        msg = """You can publish your worksheet to the Internet, where anyone will be able to access and view it online.
    19351943        Your worksheet will be assigned a unique address (URL) that you can send to your friends and colleagues.<br/><br/>
     1944        Do you want to publish this worksheet?<br/><br/>
    19361945        <form method="get" action=".">
    19371946        <input type="hidden" name="yes" value="" />
    1938         <input type="submit" value="Yes" />
     1947        <input type="submit" value="Yes" style="margin-left:10px" />
    19391948        <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
     1949        <input type="checkbox" name="auto" style="margin-left:13px" /> Automatically re-publish when changes are made
    19411950        </form>
    19421951        """
    19431952        head, body = self.html_worksheet_page_template(worksheet, username, msg, select="publish", backwards=True)
    function save_worksheet_and_close() { 
    19501959        """%(head, body)
    19511960       
    19521961    def html_afterpublish_window(self, worksheet, username, addr, dtime):
     1962        """
     1963        Returns the html code for a page dedicated to worksheet publishing after the
     1964        publication of the given worksheet.
     1965       
     1966        INPUT:
     1967            worksheet - instance of Worksheet
     1968            username - string
     1969            addr - string
     1970            dtime - instance of time.struct_time
     1971        """
    19531972        from time import strftime
    19541973        time = strftime("%B %d, %Y %I:%M %p", dtime)
    19551974        msg = """Worksheet is publicly viewable at <a href="%s" style="color:#FFF" target="_blank">%s</a><br />
  • sage/server/notebook/twist.py

    diff -r 13541feacb6e -r 7451d5155cf6 sage/server/notebook/twist.py
    a b class Worksheet_publish(WorksheetResourc 
    11691169    addSlash = True
    11701170   
    11711171    def render(self, ctx):
     1172        # Publishes worksheet and also sets worksheet to be published automatically when saved
    11721173        if 'yes' in ctx.args and 'auto' in ctx.args:
    11731174            notebook.publish_worksheet(self.worksheet, self.username)
    11741175            self.worksheet.set_auto_publish()
    11751176            return http.RedirectResponse("/home/%s/publish" % (self.worksheet.filename()))
     1177        # Just publishes worksheet
    11761178        elif 'yes' in ctx.args:
    11771179            notebook.publish_worksheet(self.worksheet, self.username)
    11781180            return http.RedirectResponse("/home/%s/publish" % (self.worksheet.filename()))
     1181        # Stops publication of worksheet
    11791182        elif 'stop' in ctx.args:
    11801183            notebook.delete_worksheet(self.worksheet.published_version().filename())
    11811184            return http.RedirectResponse("/home/%s/publish" % (self.worksheet.filename()))
     1185        # Re-publishes worksheet
    11821186        elif 're' in ctx.args:
    11831187            W = notebook.publish_worksheet(self.worksheet, self.username)
    11841188            return http.RedirectResponse("/home/%s/publish" % (self.worksheet.filename()))
     1189        # Sets worksheet to be published automatically when saved
    11851190        elif 'auto' in ctx.args:
    11861191            self.worksheet.set_auto_publish()
    11871192            return http.RedirectResponse("/home/%s/publish" % (self.worksheet.filename()))
     1193        # Returns boolean of "Is this worksheet set to be published automatically when saved?"
    11881194        elif 'is_auto' in ctx.args:
    11891195            return http.Response(stream=str(self.worksheet.is_auto_publish()))
     1196        # Returns the publication page
    11901197        else:
     1198            # Page for when worksheet already published
    11911199            if self.worksheet.has_published_version():
    11921200                addr = 'http%s://' % ('' if not notebook.secure else 's')
    11931201                addr += notebook.address
    class Worksheet_publish(WorksheetResourc 
    11951203                addr += '/home/' + self.worksheet.published_version().filename()
    11961204                dtime = self.worksheet.published_version().date_edited()
    11971205                return http.Response(stream=notebook.html_afterpublish_window(self.worksheet, self.username, addr, dtime))
     1206            # Page for when worksheet is not already published
    11981207            else:
    11991208                return http.Response(stream=notebook.html_beforepublish_window(self.worksheet, self.username))
    12001209       
  • sage/server/notebook/worksheet.py

    diff -r 13541feacb6e -r 7451d5155cf6 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, auto_publish=False):
     108    def __init__(self, name, dirname, 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: 
    115115        self.__collaborators = []
    116116        self.__docbrowser = docbrowser
    117117        self.__autopublish = auto_publish
    118         self.__notebook = notebook
    119118
    120119        # Initialize the cell id counter.
    121120        self.__next_id = 0
    class Worksheet: 
    287286    # Publication
    288287    ##########################################################
    289288    def is_auto_publish(self):
     289        """
     290        Returns boolean of "Is this worksheet set to be published automatically when saved?"
     291        if private variable "autopublish" is set otherwise False is returned and the variable
     292        is set to False.
     293        """
    290294        try:
    291295            return self.__autopublish
    292296        except AttributeError:
    class Worksheet: 
    294298            return False
    295299   
    296300    def set_auto_publish(self):
    297         self.__autopublish = False if self.__autopublish else True
     301        """
     302        Sets the worksheet to be published automatically when the worksheet is saved if the worksheet
     303        isn't already set to this otherwise it is set not to.
     304        """
     305        try:
     306            self.__autopublish = False if self.__autopublish else True
     307        except AttributeError:
     308            self.__autopublish = True
    298309   
    299310    def is_published(self):
    300311        return self.owner() == 'pub'
    class Worksheet: 
    635646            self.__saved_by_info = X
    636647        X[basename] = user
    637648        if self.is_auto_publish():
    638             self.__notebook.publish_worksheet(self, user)
     649            self.notebook().publish_worksheet(self, user)
    639650
    640651    def get_snapshot_text_filename(self, name):
    641652        path = self.snapshot_directory()
    class Worksheet: 
    10691080            return t
    10701081   
    10711082    def date_edited(self):
     1083        """
     1084        Returns the date the worksheet was last edited if already recorded otherwise
     1085        the current local time is recorded and returned.
     1086        """
    10721087        try:
    10731088            return self.__date_edited[0]
    10741089        except AttributeError: