Ticket #6855: trac_6855-published_interacts.patch

File trac_6855-published_interacts.patch, 13.9 KB (added by mpatel, 11 years ago)

Non-concurrent first version. sagenb repo.

  • sagenb/data/sage/html/worksheet/published_worksheet.html

    # HG changeset patch
    # User Mitesh Patel <qed777@gmail.com>
    # Date 1259201376 28800
    # Node ID 435af71db199a342ec58a22486e8c2bd78776608
    # Parent  5196c5888599dca1145c2f5737591941f633c24a
    #6855/notebook: Embed interacts in remote web pages
    
    diff --git a/sagenb/data/sage/html/worksheet/published_worksheet.html b/sagenb/data/sage/html/worksheet/published_worksheet.html
    a b INPUT: 
    66{% set published = true %}
    77{% set do_print = true %}
    88
     9{%- if enable_interact %}
     10<div class="worksheet" id="worksheet">
     11<div class="worksheet_cell_list" id="worksheet_cell_list">
     12{%- endif %}
     13
    914{% include "html/worksheet/worksheet_body.html" %}
    1015
     16{%- if enable_interact %}
     17</div>
     18</div>
     19{%- endif %}
    1120
    1221<script language=javascript>jsMath.ProcessBeforeShowing();</script>
  • sagenb/data/sage/html/worksheet/worksheet_body.html

    diff --git a/sagenb/data/sage/html/worksheet/worksheet_body.html b/sagenb/data/sage/html/worksheet/worksheet_body.html
    a b INPUT: 
    55#}
    66
    77<div class="cell_input_active" id="cell_resizer"></div>
    8 {% if not published %}
     8{% if not do_print and not published %}
    99<div class="worksheet_cell_list" id="worksheet_cell_list">
    1010{% endif %}
    1111
  • sagenb/data/sage/html/worksheet_listing.html

    diff --git a/sagenb/data/sage/html/worksheet_listing.html b/sagenb/data/sage/html/worksheet_listing.html
    a b  
    159159
    160160      <td class="worksheet_link">
    161161        <a title="{{ worksheet.name() | escape }}" id="name-{{ name|css_escape }}" class="worksheetname" href="/home/{{ name }}">
    162         {% if worksheet.compute_process_has_been_started() %}(running) {% endif %}
     162        {% if worksheet.compute_process_has_been_started() and not worksheet.is_published() %}(running) {% endif %}
    163163        {{ worksheet.truncated_name(50) | escape}}
    164164        </a>
    165165       
  • sagenb/notebook/cell.py

    diff --git a/sagenb/notebook/cell.py b/sagenb/notebook/cell.py
    a b class TextCell(Cell_generic): 
    204204        """
    205205        return self.__worksheet
    206206
    207     def html(self, ncols=0, do_print=False, do_math_parse=True, editing=False):
     207    def html(self, ncols=0, do_print=False, do_math_parse=True, editing=False,
     208             **kwargs):
    208209        """
    209210        Returns an HTML version of self as a string.
    210211
    class Cell(Cell_generic): 
    18751876            s = '\n\n<div id="cell_outer_%s" class="cell_visible"><div id="cell_%s" class="%s">'%(self.id(), self.id(), cls) + s + '</div></div>'
    18761877        return s
    18771878   
    1878     def html(self, wrap=None, div_wrap=True, do_print=False):
     1879    def html(self, wrap=None, div_wrap=True, do_print=False,
     1880             enable_interact=False, prep_interact=False):
    18791881        r"""
    18801882        Returns the HTML for self.
    18811883
    class Cell(Cell_generic): 
    19111913        else:
    19121914            cls = 'cell_not_evaluated'
    19131915
    1914         html_in  = self.html_in(do_print=do_print)
     1916        if do_print and self.is_interactive_cell() and enable_interact and prep_interact:
     1917            self.evaluate()
     1918            cls = 'cell_not_evaluated'
     1919
     1920        html_in  = self.html_in(do_print=do_print,
     1921                                enable_interact=enable_interact)
     1922
    19151923        introspect = "<div id='introspect_div_%s' class='introspection'></div>"%self.id()
    1916         html_out = self.html_out(wrap, do_print=do_print)
     1924
     1925        if enable_interact:
     1926            html_out = self.html_out(wrap, do_print=False)
     1927        else:
     1928            html_out = self.html_out(wrap, do_print=do_print)
    19171929
    19181930        if 'hideall' in self.percent_directives():
    19191931            s = html_out
    class Cell(Cell_generic): 
    19261938        #self._html_cache[key] = s
    19271939        return s
    19281940
    1929     def html_in(self, do_print=False, ncols=80):
     1941
     1942    def html_in(self, do_print=False, ncols=80, enable_interact=False):
    19301943        """
    19311944        Returns the HTML code for the input of this cell.
    19321945       
    class Cell(Cell_generic): 
    19511964            if 'hide' in self.percent_directives():
    19521965                return ''
    19531966
    1954             tt = escape(t).replace('\n','<br>').replace('  ',' &nbsp;') + '&nbsp;'
    1955             s += '<div class="cell_input_print">%s</div>'%tt
     1967            # We don't condition here on self.is_interactive_cell() to
     1968            # ensure that all cells have the same border style, etc.
     1969            if enable_interact:
     1970                # We could add disabled = "yes", but this "greys out"
     1971                # the textareas in some browsers and makes it more
     1972                # difficult to copy the code.
     1973                s += """<textarea class="%(cls)s" rows=%(r)s cols=%(ncols)s
     1974                           readonly   = "yes"
     1975                           id         = 'cell_input_%(id)s'
     1976                        >%(t)s</textarea>
     1977                """ % {'cls': cls, 'r': r, 'ncols': ncols, 'id': id, 't': t}
     1978            else:
     1979                tt = escape(t).replace('\n','<br>').replace('  ',' &nbsp;') + '&nbsp;'
     1980                s += '<div class="cell_input_print">%s</div>'%tt
     1981
    19561982        else:
    19571983            s += """
    19581984               <textarea class="%s" rows=%s cols=%s
  • sagenb/notebook/js.py

    diff --git a/sagenb/notebook/js.py b/sagenb/notebook/js.py
    a b def javascript(): 
    7171    # Evil" clause in the license.  Does that prevent us from
    7272    # distributing it (i.e., it adds an extra condition to the
    7373    # software)?  See http://www.crockford.com/javascript/jsmin.py.txt
    74     s = JavaScriptCompressor().getPacked(s)
    75     _cache_javascript = s
     74#    s = JavaScriptCompressor().getPacked(s)
     75#    _cache_javascript = s
    7676    return s
    7777
    7878
  • sagenb/notebook/notebook.py

    diff --git a/sagenb/notebook/notebook.py b/sagenb/notebook/notebook.py
    a b class Notebook(object): 
    17591759                        sage_jsmath_macros = sage_jsmath_macros)
    17601760   
    17611761
    1762     def html(self, worksheet_filename=None, username='guest', show_debug=False, admin=False):
     1762    def html(self, worksheet_filename=None, username='guest',
     1763             show_debug=False, admin=False, enable_interact=False,
     1764             prep_interact=False):
    17631765        r"""
    17641766        Return the HTML for a worksheet's index page.
    17651767
    class Notebook(object): 
    17971799        if W.docbrowser():
    17981800            template_page = os.path.join("html", "notebook", "doc_page.html")
    17991801           
     1802        worksheet_html = W.html(enable_interact=enable_interact,
     1803                                prep_interact=prep_interact)
     1804
    18001805        return template(template_page, worksheet = W,
    18011806                        worksheet_filename = W.filename(),
    1802                         worksheet_html = W.html(),
     1807                        worksheet_html = worksheet_html,
    18031808                        notebook = self, username = username,
    18041809                        show_debug = show_debug,
    18051810                        JSMATH = JSMATH,
  • sagenb/notebook/twist.py

    diff --git a/sagenb/notebook/twist.py b/sagenb/notebook/twist.py
    a b SEP = '___S_A_G_E___' 
    8181def encode_list(v):
    8282    return SEP.join([str(x) for x in v])
    8383
     84# Whether to enable evaluation of published interact cells.
     85enable_interact = True
     86
     87# Whether to evaluate interact cells when rendering a published
     88# worksheet.  In force only when enable_interact is True.  It's better
     89# to do this from the client, to avoid race conditions.
     90prep_interact = False
    8491
    8592
    8693############################
    class Worksheet_eval(WorksheetResource,  
    12131220        W = self.worksheet
    12141221        W.increase_state_number()
    12151222        owner = W.owner()
     1223
     1224        global enable_interact
     1225        if owner == 'pub' and enable_interact:
     1226            cell = W.get_cell_with_id(id)
     1227            cell.set_input_text(input_text)
     1228            cell.evaluate(username = self.username)
     1229            s = encode_list([id, 'no_new_cell', str(id)])
     1230            return HTMLResponse(stream=s)
     1231
    12161232        if owner != '_sage_':
    12171233            if W.owner() != self.username and not (self.username in W.collaborators()):
    12181234               return InvalidPage(msg = "can't evaluate worksheet cells", username = self.username)
     1235
    12191236        cell = W.get_cell_with_id(id)
    1220 
    12211237        cell.set_input_text(input_text)
    12221238
    12231239        if ctx.args.has_key('save_only') and ctx.args['save_only'][0] == '1':
    class Worksheet(WorksheetResource, resou 
    14631479
    14641480    def render(self, ctx):
    14651481        self.worksheet.sage()
    1466         s = notebook.html(worksheet_filename = self.name,  username=self.username)
     1482        global enable_interact, prep_interact
     1483        s = notebook.html(worksheet_filename=self.name, username=self.username,
     1484                          enable_interact=enable_interact,
     1485                          prep_interact=prep_interact)
    14671486        return HTMLResponse(stream=s)
    14681487
    14691488    def childFactory(self, request, op):
  • sagenb/notebook/worksheet.py

    diff --git a/sagenb/notebook/worksheet.py b/sagenb/notebook/worksheet.py
    a b class Worksheet(object): 
    23182318    ##########################################################
    23192319    # HTML rendering of the whole worksheet
    23202320    ##########################################################
    2321     def html_cell_list(self, do_print=False):
     2321    def html_cell_list(self, do_print=False, enable_interact=False,
     2322                       prep_interact=False):
    23222323        """
    23232324        INPUT:
    23242325       
    class Worksheet(object): 
    23352336                return self.__html
    23362337            except AttributeError:
    23372338                for cell in self.cell_list():
    2338                     cells_html += cell.html(ncols, do_print=True) + '\n'
    2339                 s = template(os.path.join('html', 'worksheet', 'published_worksheet.html'),
    2340                              ncols = ncols, cells_html = cells_html)
     2339                    cells_html += cell.html(ncols, do_print=True,
     2340                                            enable_interact=enable_interact,
     2341                                            prep_interact=prep_interact) + '\n'
     2342                s = template(os.path.join("html", "worksheet",
     2343                                          "published_worksheet.html"),
     2344                             ncols = ncols, enable_interact = enable_interact,
     2345                             cells_html = cells_html)
    23412346                self.__html = s
    23422347                return s
     2348
    23432349        for cell in self.cell_list():
    23442350            try:
    23452351                cells_html += cell.html(ncols, do_print=do_print) + '\n'
    23462352            except Exception, msg:
    2347                 # catch any exception, since this exception is raised sometimes, at least
    2348                 # for some worksheets:
    2349                 # exceptions.UnicodeDecodeError: 'ascii' codec can't decode byte
    2350                 #         0xc2 in position 825: ordinal not in range(128)
    2351                 # and this causes the entire worksheet to fail to save/render, which is
    2352                 # obviously *not* good (much worse than a weird issue with one cell).
     2353                # catch any exception, since this exception is raised
     2354                # sometimes, at least for some worksheets:
     2355
     2356                # exceptions.UnicodeDecodeError: 'ascii' codec can't
     2357                #         decode byte 0xc2 in position 825: ordinal
     2358                #         not in range(128)
     2359
     2360                # and this causes the entire worksheet to fail to
     2361                # save/render, which is obviously *not* good (much
     2362                # worse than a weird issue with one cell).
    23532363                print msg
    23542364        return cells_html
    23552365                       
    23562366    def html(self, include_title=True, do_print=False,
    2357              confirm_before_leave=False, read_only=False):
     2367             confirm_before_leave=False, read_only=False,
     2368             enable_interact=False, prep_interact=False):
    23582369        r"""
    23592370        INPUT:
    23602371       
    class Worksheet(object): 
    23732384            sage: W.html()
    23742385            '\n\n\n<div class="cell_input_active" id="cell_resizer"></div>\n\n<div class="worksheet_cell_list" id...'
    23752386        """
     2387        cells_html = self.html_cell_list(do_print = do_print,
     2388                                         enable_interact = enable_interact,
     2389                                         prep_interact = prep_interact)
     2390
    23762391        return template(os.path.join("html", "worksheet", "worksheet.html"),
    2377                         published = self.is_published(),
    2378                         do_print = do_print, confirm_before_leave = confirm_before_leave,
    2379                         cells_html = self.html_cell_list(do_print=do_print),
     2392                        published = self.is_published(), do_print = do_print,
     2393                        confirm_before_leave = confirm_before_leave,
     2394                        cells_html = cells_html,
    23802395                        cell_id_list = self.cell_id_list(),
    23812396                        state_number = self.state_number())
    23822397
    from sagenb.notebook.all import * 
    29612976       
    29622977        OUTPUT: a Sage interface
    29632978        """
    2964         if self.is_published():
    2965             return None
     2979#        if self.is_published():
     2980#            return None
    29662981        try:
    29672982            S = self.__sage
    29682983            if S.is_started(): return S
    from sagenb.notebook.all import * 
    33213336            self.record_edit(username)
    33223337
    33233338    def ping(self, username):
    3324         if self.is_published():
    3325             return
     3339#        if self.is_published():
     3340#            return
    33263341        self._record_that_we_are_computing(username)
    33273342
    33283343    ##########################################################
    from sagenb.notebook.all import * 
    33543369           beginning of the queue as possible, but after all asap
    33553370           cells. Otherwise, C goes at the end of the queue.
    33563371        """
    3357         if self.is_published():
    3358             return
     3372#        if self.is_published():
     3373#            return
    33593374        self._record_that_we_are_computing(username)
    33603375        if not isinstance(C, Cell):
    33613376            raise TypeError