# HG changeset patch # User Timothy Clemans # Date 1211065660 25200 # Node ID 13541feacb6e4f8797f240f930c20044e69ffcad # Parent 2339ff5c0a10fa75e3c8649e2175cbc3f480b23a #3240 diff -r 2339ff5c0a10 -r 13541feacb6e sage/server/notebook/notebook.py --- a/sage/server/notebook/notebook.py Sat May 17 10:32:27 2008 -0700 +++ b/sage/server/notebook/notebook.py Sat May 17 16:07:40 2008 -0700 @@ -434,7 +434,8 @@ class Notebook(SageObject): W = worksheet.Worksheet(worksheet_name, dirname, self, system = self.system(username), owner=username, - docbrowser = docbrowser) + docbrowser = docbrowser, + auto_publish = False) if add_to_list: self.__worksheets[W.filename()] = W @@ -1503,11 +1504,11 @@ class Notebook(SageObject): """%(head, body) - def html_worksheet_page_template(self, worksheet, username, title, select=None): + def html_worksheet_page_template(self, worksheet, username, title, select=None, backwards=False): head = self._html_head(worksheet_filename=worksheet.filename(), username=username) head += ''%(worksheet.filename(), worksheet.name()) body = self._html_body(worksheet.filename(), top_only=True, username=username) - body += self.html_worksheet_topbar(worksheet, select=select, username=username) + body += self.html_worksheet_topbar(worksheet, select=select, username=username, backwards=backwards) body += '
' body += '%s'%title body += '
'*3 @@ -1758,7 +1759,7 @@ class Notebook(SageObject): head +=' \n' # this must stay in the return head - def html_worksheet_topbar(self, worksheet, select=None, username='guest'): + def html_worksheet_topbar(self, worksheet, select=None, username='guest', backwards=False): body = '' body += """ @@ -1770,7 +1771,7 @@ class Notebook(SageObject):
"""%(worksheet.html_title(username), worksheet.html_save_discard_buttons(), - worksheet.html_menu(), worksheet.html_share_publish_buttons(select=select)) + worksheet.html_menu(), worksheet.html_share_publish_buttons(select=select, backwards=backwards)) body += self.html_slide_controls() return body @@ -1922,6 +1923,42 @@ function save_worksheet_and_close() { """%(t.count("\n")+1,t) + return """ + + %s + %s + + """%(head, body) + + def html_beforepublish_window(self, worksheet, username): + msg = """You can publish your worksheet to the Internet, where anyone will be able to access and view it online. + Your worksheet will be assigned a unique address (URL) that you can send to your friends and colleagues.

+
+ + +

+ Automatically re-publish when changes are made +
+ """ + head, body = self.html_worksheet_page_template(worksheet, username, msg, select="publish", backwards=True) + + return """ + + %s + %s + + """%(head, body) + + def html_afterpublish_window(self, worksheet, username, addr, dtime): + from time import strftime + time = strftime("%B %d, %Y %I:%M %p", dtime) + msg = """Worksheet is publicly viewable at %s
+ Published on %s

+

+ Automatically re-publish when changes are made + """ % (addr, addr, time, ' checked="true" ' if worksheet.is_auto_publish() else '') + head, body = self.html_worksheet_page_template(worksheet, username, msg, select="publish", backwards=True) + return """ %s diff -r 2339ff5c0a10 -r 13541feacb6e sage/server/notebook/twist.py --- a/sage/server/notebook/twist.py Sat May 17 10:32:27 2008 -0700 +++ b/sage/server/notebook/twist.py Sat May 17 16:07:40 2008 -0700 @@ -1166,10 +1166,37 @@ class Worksheet_eval(WorksheetResource, ######################################################## class Worksheet_publish(WorksheetResource, resource.Resource): + addSlash = True + def render(self, ctx): - W = notebook.publish_worksheet(self.worksheet, self.username) - addr = '/home/' + W.filename() - return http.RedirectResponse(addr) + if 'yes' in ctx.args and 'auto' in ctx.args: + notebook.publish_worksheet(self.worksheet, self.username) + self.worksheet.set_auto_publish() + return http.RedirectResponse("/home/%s/publish" % (self.worksheet.filename())) + elif 'yes' in ctx.args: + notebook.publish_worksheet(self.worksheet, self.username) + return http.RedirectResponse("/home/%s/publish" % (self.worksheet.filename())) + elif 'stop' in ctx.args: + notebook.delete_worksheet(self.worksheet.published_version().filename()) + return http.RedirectResponse("/home/%s/publish" % (self.worksheet.filename())) + elif 're' in ctx.args: + W = notebook.publish_worksheet(self.worksheet, self.username) + return http.RedirectResponse("/home/%s/publish" % (self.worksheet.filename())) + elif 'auto' in ctx.args: + self.worksheet.set_auto_publish() + return http.RedirectResponse("/home/%s/publish" % (self.worksheet.filename())) + elif 'is_auto' in ctx.args: + return http.Response(stream=str(self.worksheet.is_auto_publish())) + else: + if self.worksheet.has_published_version(): + addr = 'http%s://' % ('' if not notebook.secure else 's') + addr += notebook.address + addr += ':%s' % notebook.port + addr += '/home/' + self.worksheet.published_version().filename() + dtime = self.worksheet.published_version().date_edited() + return http.Response(stream=notebook.html_afterpublish_window(self.worksheet, self.username, addr, dtime)) + else: + return http.Response(stream=notebook.html_beforepublish_window(self.worksheet, self.username)) class Worksheet_rating_info(WorksheetResource, resource.Resource): diff -r 2339ff5c0a10 -r 13541feacb6e sage/server/notebook/worksheet.py --- a/sage/server/notebook/worksheet.py Sat May 17 10:32:27 2008 -0700 +++ b/sage/server/notebook/worksheet.py Sat May 17 16:07:40 2008 -0700 @@ -105,7 +105,7 @@ def worksheet_filename(name, owner): return owner + '/' + _notebook.clean_name(name) class Worksheet: - def __init__(self, name, dirname, notebook, system, owner, docbrowser=False, pretty_print=False): + def __init__(self, name, dirname, notebook, system, owner, docbrowser=False, pretty_print=False, auto_publish=False): # Record the basic properties of the worksheet self.__system = system @@ -114,6 +114,8 @@ class Worksheet: self.__viewers = [] self.__collaborators = [] self.__docbrowser = docbrowser + self.__autopublish = auto_publish + self.__notebook = notebook # Initialize the cell id counter. self.__next_id = 0 @@ -284,6 +286,16 @@ class Worksheet: ########################################################## # Publication ########################################################## + def is_auto_publish(self): + try: + return self.__autopublish + except AttributeError: + self.__autopublish = False + return False + + def set_auto_publish(self): + self.__autopublish = False if self.__autopublish else True + def is_published(self): return self.owner() == 'pub' @@ -600,6 +612,7 @@ class Worksheet: ########################################################## # Saving ########################################################## + def save(self): path = self.__dir E = self.edit_text() @@ -621,6 +634,8 @@ class Worksheet: X = {} self.__saved_by_info = X X[basename] = user + if self.is_auto_publish(): + self.__notebook.publish_worksheet(self, user) def get_snapshot_text_filename(self, name): path = self.snapshot_directory() @@ -906,7 +921,7 @@ class Worksheet: """ - def html_share_publish_buttons(self, select=None): + def html_share_publish_buttons(self, select=None, backwards=False): if self.is_doc_worksheet(): return '' def cls(x): @@ -914,17 +929,17 @@ class Worksheet: return "control-select" else: return "control" - + backwards = '../' if backwards else '' return """ PrintPrint Worksheet - Edit - Text - Undo - Share - Publish - """%(cls('use'),cls('edit'),cls('text'),cls('revisions'),cls('share')) + Edit + Text + Undo + Share + Publish + """%(cls('use'),cls('edit'),backwards,cls('text'),backwards,cls('revisions'),backwards,cls('share'),backwards,cls('publish'),backwards) def html_data_options_list(self): D = self.attached_data_files() @@ -1052,6 +1067,14 @@ class Worksheet: t = time.time() self.__last_edited = (t, self.owner()) return t + + def date_edited(self): + try: + return self.__date_edited[0] + except AttributeError: + t = time.localtime() + self.__date_edited = (t, self.owner()) + return t def last_to_edit(self): try: @@ -1061,6 +1084,7 @@ class Worksheet: def record_edit(self, user): self.__last_edited = (time.time(), user) + self.__date_edited = (time.localtime(), user) self.autosave(user) def time_since_last_edited(self):