Mercurial > agora
comparison templates/snippet/snippet_details.djhtml @ 102:f872c643b056
Updates to snippet functionality (see details)
Sorry about the large commit, but it was difficult to break it up as a lot
of new functionality was introduced. Most of it is specific to the snippet
feature but there are some other changes as well.
Commit highlights:
* Added the ability to switch the syntax highlighting colour scheme when
viewing a snippet. This is currently done on a per-snippet basis only,
but eventually it will be possible to set a default in your profile to
have all the snippets you view use that colour scheme. There are currently
8 different colour schemes, all of which were taken from the default
pygments stylesheets (some were modified).
* Added a "num_views" field to the Snippet model, with the field being
incremented any time the snippet view is called (raw or regular view).
* Created a simple "explore" view that lists the recently-posted snippets.
Will implement pagination and sorting by other attributes ("popularity",
for example, based on number of views) as well.
* Added a post-save hook to the User model to ensure that a Profile is created
for every user as soon as the User itself is created. This alleviates the
need for a get_profile method that checks if the user has a profile or not
and creates one if necessary. (The code is currently still there, will be
cleaned up soon).
* Added back the wordwrap toggling feature. Currently, if you want to enable
word-wrapping, the line numbers have to be hidden in order to ensure that
the lines and their numbers don't go out of sync. This will be fixed soon.
* History/diff view is back
* And some other minor cosmetic changes.
Note: since some existing models have been changed, you'll likely need to
delete the existing sqlite database before running syncdb. The alternative
is to determine the necessary column changes/additions and run the SQL
query yourself.
author | dellsystem <ilostwaldo@gmail.com> |
---|---|
date | Fri, 31 Aug 2012 02:53:22 -0400 |
parents | d48e8676b18f |
children | 7d753658dc0e |
comparison
equal
deleted
inserted
replaced
101:a8da60d611f7 | 102:f872c643b056 |
---|---|
3 {% load i18n %} | 3 {% load i18n %} |
4 | 4 |
5 {% block extrahead %} | 5 {% block extrahead %} |
6 {% if request.session.userprefs %} | 6 {% if request.session.userprefs %} |
7 <style type="text/css" media="all"> | 7 <style type="text/css" media="all"> |
8 .code{ | 8 .highlight { |
9 {# FIXME: Thats stupid #} | 9 {# FIXME: Thats stupid #} |
10 {% ifnotequal request.session.userprefs.font_family "None" %} | 10 {% ifnotequal request.session.userprefs.font_family "None" %} |
11 font-family: {{ request.session.userprefs.font_family }} !important; | 11 font-family: {{ request.session.userprefs.font_family }} !important; |
12 {% endifnotequal %} | 12 {% endifnotequal %} |
13 {% ifnotequal request.session.userprefs.font_size "None" %} | 13 {% ifnotequal request.session.userprefs.font_size "None" %} |
20 </style> | 20 </style> |
21 {% endif %} | 21 {% endif %} |
22 {% endblock %} | 22 {% endblock %} |
23 | 23 |
24 {% block title %} | 24 {% block title %} |
25 {% trans "Snippet" %} #{{ snippet.pk }} | 25 Viewing snippet — {{ snippet.get_title }} |
26 {% endblock title %} | 26 {% endblock title %} |
27 | 27 |
28 {% block headline %} | 28 {% block headline %} |
29 <h1> | 29 <h1> |
30 {% trans "Snippet" %} #{{ snippet.pk }} | 30 {% trans "Snippet" %} #{{ snippet.pk }} |
40 {% endblock headline %} | 40 {% endblock headline %} |
41 | 41 |
42 {% load snippet_tags %} | 42 {% load snippet_tags %} |
43 | 43 |
44 {% block content %} | 44 {% block content %} |
45 | 45 <div id="non-sidebar"> |
46 <h2>Snippet view</h2> | 46 <div id="diff"> |
47 | |
48 <div class="accordion"> | |
49 <div class="info"> | |
50 | |
51 <div id="diff" style="display:none;"> | |
52 diff | |
53 </div> | 47 </div> |
54 | 48 |
55 <h3> | 49 <h1>{{ snippet.get_title }}</h1> |
56 {% if snippet.title %} | 50 <div class="snippet-options"> |
57 {{ snippet.title }} | |
58 {% else %} | |
59 {% trans "Snippet" %} #{{ snippet.id}} | |
60 {% endif %} | |
61 </h3> | |
62 | |
63 <div class="whitebox"> | |
64 | |
65 <div class="snippet-options"> | |
66 <abbr title="{% trans "Time to live" %}" | 51 <abbr title="{% trans "Time to live" %}" |
67 >TTL: | 52 >TTL: |
68 </abbr> | 53 </abbr> |
69 {{ snippet.expires|timeuntil }} | 54 {{ snippet.expires|timeuntil }} |
70 — | 55 — |
71 {% if snippet.pk|in_list:request.session.snippet_list %} | 56 {% if snippet.pk|in_list:request.session.snippet_list %} |
72 <a onclick="return confirm('{% trans "Really delete this snippet?" %}')" | 57 <a onclick="return confirm('{% trans "Really delete this snippet?" %}')" |
73 href="{% url snippet_delete snippet.secret_id %}"> | 58 href="{% url snippet_delete snippet.secret_id %}"> |
74 Delete now! | 59 Delete this snippet |
75 </a> | 60 </a> |
76 — | 61 — |
77 {% endif %} | 62 {% endif %} |
78 <a id="toggleWordwrap" href="#">{% trans "Wordwrap" %}</a> | 63 <a id="toggle-wordwrap" href="#">{% trans "Toggle wordwrap" %}</a> |
64 — | |
65 Syntax highlighting style: | |
66 <select id="change-highlighting" | |
67 data-default="{{ default_style }}"> | |
68 {% for pygments_style in pygments_styles %} | |
69 <option name="{{ pygments_style }}"> | |
70 {{ pygments_style }} | |
71 {% if pygments_style == default_style %} | |
72 (default) | |
73 {% endif %} | |
74 </option> | |
75 {% endfor %} | |
76 </select> | |
79 <div> | 77 <div> |
80 Author: | 78 Author: |
81 {% if snippet.author %} | 79 {% if snippet.author %} |
82 <a href="{% url agora.apps.profile.views.showprofile snippet.author %}"> | 80 <a href="{% url agora.apps.profile.views.showprofile snippet.author %}"> |
83 {{ snippet.author }} | 81 {{ snippet.author }} |
84 </a> | 82 </a> |
85 {% else %} | 83 {% else %} |
86 anonymous | 84 anonymous |
87 {% endif %} | 85 {% endif %} |
88 — | 86 — |
89 Language: {{language}} | 87 Language: {{language}} |
90 </div> | 88 </div> |
91 </div> | 89 </div> |
90 <br /> | |
91 <div class="snippet"> | |
92 <table> | |
93 <tr> | |
94 <th id="line-numbers"> | |
95 {# this has to look like this due to the pre tags #} | |
96 <pre class="numbers">{% for l in lines %}<a href="#l{{ forloop.counter }}" id="l{{ forloop.counter }}">{{ forloop.counter }}</a> | |
97 {% endfor %}</pre> | |
98 </th> | |
99 <td> | |
100 {# this has to look like this due to the pre tags #} | |
101 <pre class="highlight {{ default_style }}">{% for line in snippet.content_splitted %}<span class="line" id="l{{ forloop.counter }}">{% if line %}{{ line|safe }}{% else %} {% endif %}</span> | |
102 {% endfor %}</pre> | |
103 </td> | |
104 </tr> | |
105 </table> | |
106 </div> | |
92 | 107 |
93 <br /> | 108 <br /> |
94 | 109 |
95 <div class="snippet"> | 110 <h2 id="revise">{% trans "Revise this snippet" %}</h2> |
96 <table> | |
97 <tr> | |
98 <th> | |
99 {# this has to look like this due to the pre tags #} | |
100 <pre class="code">{% for l in lines %}<a href="#l{{ forloop.counter }}" id="l{{ forloop.counter }}">{{ forloop.counter }}</a> | |
101 {% endfor %}</pre> | |
102 </th> | |
103 <td> | |
104 {# this has to look like this due to the pre tags #} | |
105 <pre class="code">{% for line in snippet.content_splitted %}<span class="line" id="l{{ forloop.counter }}">{% if line %}{{ line|safe }}{% else %} {% endif %}</span> | |
106 {% endfor %}</pre> | |
107 </td> | |
108 </tr> | |
109 </table> | |
110 </div> | |
111 | 111 |
112 </div> {#whitebox#} | 112 {% include "snippet/snippet_form.djhtml" %} |
113 | 113 </div><div id="sidebar"> |
114 </div> {# info #} | 114 <h2>{% trans "History" %}</h2> |
115 | 115 {% if no_descendants %} |
116 <div class="info"> | 116 <p>{% trans "This snippet has no children!" %}</p> |
117 <h3>{% trans "Write an answer" %} →</h3> | 117 <p> |
118 <div class="accordion" style="display: none;"> | 118 <a href="#revise"> |
119 <div class="whitebox"> | 119 {% trans "Make one" %} » |
120 {% include "snippet/snippet_form.djhtml" %} | 120 </a> |
121 </div> | 121 </p> |
122 </div> | 122 {% else %} |
123 </div> | |
124 </div> | |
125 {% endblock %} | |
126 | |
127 | |
128 | |
129 {% block content-related %} | |
130 <div class="info"> | |
131 | |
132 <h3>{% trans "History" %}</h3> | |
133 | |
134 <div class="whitebox"> | |
135 | |
136 <form method="get" id="diffform" action="{% url snippet_diff %}"> | 123 <form method="get" id="diffform" action="{% url snippet_diff %}"> |
137 <div class="tree"> | 124 <div class="tree"> |
138 {% for tree_item,structure in tree|tree_info %} | 125 {% for tree_item,structure in tree|tree_info %} |
139 {% if structure.new_level %} | 126 {% if structure.new_level %} |
140 <ul> | 127 <ul> |
156 {% ifequal snippet tree_item %} | 143 {% ifequal snippet tree_item %} |
157 checked="checked" | 144 checked="checked" |
158 {% endifequal %}/> | 145 {% endifequal %}/> |
159 </span> | 146 </span> |
160 {% ifequal snippet tree_item %} | 147 {% ifequal snippet tree_item %} |
161 <strong> | 148 <strong>{{ tree_item.get_title }}</strong> |
162 {% if tree_item.title %} | |
163 {{ tree_item.title }} | |
164 {% else %} | |
165 {% trans "Snippet" %} #{{ tree_item.id }} | |
166 {% endif %} | |
167 </strong> | |
168 {% else %} | 149 {% else %} |
169 <a href="{{ tree_item.get_absolute_url }}"> | 150 <a href="{{ tree_item.get_absolute_url }}"> |
170 {% if tree_item.title %} | 151 {{ tree_item.get_title }} |
171 {{ tree_item.title }} | 152 </a> |
172 {% else %} | |
173 {% trans "Snippet" %} #{{ tree_item.id }} | |
174 {% endif %} | |
175 </a> | |
176 {% endifequal %} | 153 {% endifequal %} |
177 </div> | 154 </div> |
178 {% for level in structure.closed_levels %} | 155 {% for level in structure.closed_levels %} |
179 </li> | 156 </li> |
180 </ul> | 157 </ul> |
183 <div class="submit"> | 160 <div class="submit"> |
184 <input type="submit" value="{% trans "Compare" %}"/> | 161 <input type="submit" value="{% trans "Compare" %}"/> |
185 </div> | 162 </div> |
186 </div> | 163 </div> |
187 </form> | 164 </form> |
188 | 165 {% endif %} |
189 </div> {# whitebox #} | 166 <br /> |
190 | 167 <h2>{% trans "Options" %}</h2> |
191 </div> {# info #} | 168 <a href="{% url snippet_details_raw snippet.secret_id %}"> |
192 | 169 {% trans "View raw" %} |
193 <div class="info"> | 170 </a> |
194 <h3>{% trans "Options" %}</h3> | |
195 <div class="whitebox"> | |
196 <p> | |
197 <a href="{% url snippet_details_raw snippet.secret_id %}"> | |
198 {% trans "View raw" %} | |
199 </a> | |
200 </p> | |
201 </div> | 171 </div> |
202 {% endblock content-related %} | 172 </div> |
173 {% endblock %} | |
203 | 174 |
204 {% block script_footer %} | 175 {% block script_footer %} |
205 <script src="/static/jquery.min.js"></script> | |
206 <script src="/static/jquery-ui.min.js"></script> | |
207 <script type="text/javascript"> | 176 <script type="text/javascript"> |
208 {%include "snippet/snippet_details.js" %} | 177 {%include "snippet/snippet_details.js" %} |
209 </script> | 178 </script> |
210 {% endblock script_footer %} | 179 {% endblock script_footer %} |