Merge lp:~henninge/wikkid/edit_preview into lp:wikkid

Proposed by Henning Eggers
Status: Merged
Merged at revision: 62
Proposed branch: lp:~henninge/wikkid/edit_preview
Merge into: lp:wikkid
Diff against target: 169 lines (+59/-28)
4 files modified
wikkid/skin/default/edit.html (+11/-2)
wikkid/skin/default/static/default.css (+9/-1)
wikkid/view/textfile.py (+27/-20)
wikkid/view/wiki.py (+12/-5)
To merge this branch: bzr merge lp:~henninge/wikkid/edit_preview
Reviewer Review Type Date Requested Status
Tim Penhey Needs Information
Review via email: mp+38891@code.launchpad.net

Description of the change

I added a preview button to the edit page which is quite handy when trying out the markup.

I also fixed a little mixup in the edit form where "message" was referring to two different things and the commit message got lost between reloads.

I did not write any tests but I can still add those. Anything else this branch is missing?

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote :

Hi Henning,

Looks pretty good. Why do we have a red message style now?

Nice preview image.

How about a test?

review: Needs Information
Revision history for this message
Henning Eggers (henninge) wrote :

Am 25.10.2010 07:27, schrieb Tim Penhey:
> Looks pretty good.

Thanks!

> Why do we have a red message style now?

Well, I missed the message on the screen until I saw in the template that
there should be one. It's just a way to make it more visible. This can still
be improved visually and also let the color indicate severity.

>
> How about a test?

I have started on a view test but missed some infrastructure to simulate post
requests. I started to add that, too, but my first attempt did not work. I
have not yet been able to spend more time on that.

Henning

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'wikkid/skin/default/edit.html'
2--- wikkid/skin/default/edit.html 2010-06-17 10:45:52 +0000
3+++ wikkid/skin/default/edit.html 2010-10-19 21:51:51 +0000
4@@ -6,13 +6,22 @@
5 {% endif %}
6 <form method="post" action="{{ view.save_url }}">
7 <textarea name="content">{{ view.content }}</textarea>
8- Describe the change: <input type="text" id="message" name="message" value=""/>
9+ Describe the change:
10+ <input type="text" id="description" name="description"
11+ value="{{ view.description }}" />
12 {% if view.rev_id %}
13 <input type="hidden" name="rev-id" value="{{ view.rev_id }}"/>
14 {% endif %}
15 <div class="save-cancel">
16- <input type="Submit" name="action" value="Save" />
17+ <input type="Submit" name="save" value="Save" />
18+ <input type="Submit" name="preview" value="Preview" />
19 or <a href="{{ view.cancel_url }}">Cancel</a>
20 </div>
21 </form>
22+{% if view.preview_content %}
23+<hr />
24+<div class="preview">
25+{{ view.preview_content }}
26+</div>
27+{% endif %}
28 {% endblock %}
29
30=== modified file 'wikkid/skin/default/static/default.css'
31--- wikkid/skin/default/static/default.css 2010-07-12 18:22:25 +0000
32+++ wikkid/skin/default/static/default.css 2010-10-19 21:51:51 +0000
33@@ -99,7 +99,7 @@
34 border-top:1px solid #fff;
35 }
36
37-#message {
38+#description {
39 width: 76em;
40 }
41
42@@ -110,6 +110,14 @@
43 font-size: 120%;
44 }
45
46+.message {
47+ color: red;
48+}
49+
50+.preview {
51+ background-image: url("preview.png");
52+}
53+
54 /***********************************
55 * Fonts
56 **********************************/
57
58=== added file 'wikkid/skin/default/static/preview.png'
59Binary files wikkid/skin/default/static/preview.png 1970-01-01 00:00:00 +0000 and wikkid/skin/default/static/preview.png 2010-10-19 21:51:51 +0000 differ
60=== modified file 'wikkid/view/textfile.py'
61--- wikkid/view/textfile.py 2010-06-17 10:45:52 +0000
62+++ wikkid/view/textfile.py 2010-10-19 21:51:51 +0000
63@@ -11,9 +11,11 @@
64 from webob.exc import HTTPSeeOther
65
66 from wikkid.errors import UpdateConflicts
67+from wikkid.formatter.registry import get_wiki_formatter
68 from wikkid.interface.resource import ITextFile
69 from wikkid.view.base import BaseView
70 from wikkid.view.edit import BaseEditView
71+from wikkid.view.wiki import format_content
72
73
74 class EditTextFile(BaseEditView):
75@@ -38,7 +40,7 @@
76 return byte_string.decode('ascii', 'replace')
77
78
79-class SaveNewTextContent(BaseView):
80+class SaveNewTextContent(BaseEditView):
81 """Update the text of a file."""
82
83 name = 'save'
84@@ -53,26 +55,31 @@
85 # TODO: barf if there is no user.
86 params = self.request.params
87 content = params['content']
88- message = params['message']
89- if 'rev-id' in params:
90- rev_id = params['rev-id']
91+ description = params['description']
92+ rev_id = params.get('rev-id', None)
93+ preview = params.get('preview', None)
94+ if preview is not None:
95+ self.rev_id = rev_id
96+ self.description = description
97+ self.content = content
98+ self.preview_content = format_content(
99+ content, self.context.base_name)
100 else:
101- rev_id = None
102- try:
103- self.context.put_bytes(
104- content, self.user.committer_id, rev_id, message)
105-
106- raise HTTPSeeOther(location=self.context.path)
107- except UpdateConflicts, e:
108- # Show the edit page again.
109- logger = logging.getLogger('wikkid')
110- logger.info('Conflicts detected: \n%r\n', e.content)
111- self.template = 'edit_page'
112- self.rev_id = e.basis_rev
113- self.content = e.content
114- self.message = "Conflicts detected during merge."
115- self.cancel_url = self.context.preferred_path
116- return super(SaveNewTextContent, self)._render(skin)
117+ try:
118+ self.context.put_bytes(
119+ content, self.user.committer_id, rev_id, description)
120+
121+ raise HTTPSeeOther(location=self.context.path)
122+ except UpdateConflicts, e:
123+ # Show the edit page again.
124+ logger = logging.getLogger('wikkid')
125+ logger.info('Conflicts detected: \n%r\n', e.content)
126+ self.rev_id = e.basis_rev
127+ self.content = e.content
128+ self.message = "Conflicts detected during merge."
129+
130+ self.description = description
131+ return super(SaveNewTextContent, self)._render(skin)
132
133
134 class UpdateTextFile(SaveNewTextContent):
135
136=== modified file 'wikkid/view/wiki.py'
137--- wikkid/view/wiki.py 2010-06-17 10:12:31 +0000
138+++ wikkid/view/wiki.py 2010-10-19 21:51:51 +0000
139@@ -13,6 +13,17 @@
140 from wikkid.view.base import BaseView
141
142
143+def format_content(bytes, base_name):
144+ """ Format the content with the right formatter.
145+
146+ Check the first line of the content to see if it specifies a
147+ formatter. The default is currently ReST, but we should have it
148+ configurable shortly.
149+ """
150+ content, formatter = get_wiki_formatter(bytes, 'rest')
151+ return formatter.format(base_name, content)
152+
153+
154 class WikiPage(BaseView):
155 """A wiki page is a page that is going to be rendered for viewing."""
156
157@@ -24,11 +35,7 @@
158 @property
159 def content(self):
160 bytes = self.context.get_bytes()
161- # Check the first line of the content to see if it specifies a
162- # formatter. The default is currently ReST, but we should have it
163- # configurable shortly.
164- content, formatter = get_wiki_formatter(bytes, 'rest')
165- return formatter.format(self.context.base_name, content)
166+ return format_content(bytes, self.context.base_name)
167
168 def _render(self, skin):
169 """If the page is not being viewed with the preferred path, redirect.

Subscribers

People subscribed via source and target branches