Changeset db7f89e0c8116ca204eced19bfc2a590b31e1b33
- Timestamp:
- 13.05.2013 10:07:17 (8 years ago)
- Branches:
- b66903eafbcb1d49112014abc82c8bf683413db0
- Children:
- b5bbc1139f2490b82e2d4c754d8aeb6aefc86835
- Parents:
- e2a28f5f1d7bc1be2ad84929b97c18c3603d14dc
- git-author:
- Stanislaw Klekot <dozzie@…> (13.05.2013 10:07:17)
- git-committer:
- Stanislaw Klekot <dozzie@…> (13.05.2013 10:07:17)
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
dashwiki/wiki/views.py
re2a28f rdb7f89 96 96 'body': page.content if page else None, 97 97 'editable': True, 98 'message': 'Wiki page saved' 99 }) 100 98 'message': 'Wiki page saved' 99 }) 100 101 101 return HttpResponse(template.render(context)) 102 102 … … 160 160 template = loader.get_template('remove_wiki.html') 161 161 page = load_wiki_or_null(page_name) 162 if 'confirm' in request.POST: 162 if 'confirm' in request.POST: 163 163 # FIXME: How about page = None? 164 164 page.delete() … … 206 206 # macros {{{ 207 207 #----------------------------------------------------------------------------- 208 # utilities {{{ 209 210 def save_macro_to_database(name, url, in_args, out_args, result_type_name, protocol_name): 211 result_type = MacroResultType.objects.get(name = result_type_name) 212 protocol = MacroProtocol.objects.get(name = protocol_name) 213 new_macro = Macro.objects.get_or_create( 214 name = name, 215 defaults = {'result_type' : result_type, 'protocol' : protocol} 216 ) 217 new_macro = new_macro[0] 218 new_macro.url = url 219 new_macro.in_args = in_args 220 new_macro.out_args = out_args 221 new_macro.result_type = result_type 222 new_macro.protocol = protocol 223 new_macro.save() 224 return new_macro 225 226 def macro_supported_result_types(): 227 return [t.name for t in MacroResultType.objects.all()] 228 229 def macro_supported_protocols(): 230 return [p.name for p in MacroProtocol.objects.all()] 231 232 # }}} 233 #----------------------------------------------------------------------------- 208 234 # list_macros() {{{ 209 235 210 236 def list_macros(request): 211 237 template = loader.get_template('list_macros.html') 212 all_macros = Macro.objects.all() 238 all_macros = Macro.objects.all() 213 239 macros = [] 214 240 for macro in all_macros: … … 231 257 # create_macro() {{{ 232 258 233 def save_macro_to_database(name, url, in_args, out_args, result_type_name, protocol_name):234 result_type = MacroResultType.objects.get(name = result_type_name)235 protocol = MacroProtocol.objects.get(name = protocol_name)236 new_macro = Macro.objects.get_or_create(237 name = name,238 defaults = {'result_type' : result_type, 'protocol' : protocol}239 )240 new_macro = new_macro[0]241 new_macro.url = url242 new_macro.in_args = in_args243 new_macro.out_args = out_args244 new_macro.result_type = result_type245 new_macro.protocol = protocol246 new_macro.save()247 return new_macro248 249 259 @csrf_exempt 250 260 def create_macro(request): … … 280 290 'message': 'macro created', 281 291 'created': True, 292 'supported_protocols': macro_supported_protocols(), 293 'supported_result_types': macro_supported_result_types(), 282 294 }) 283 295 else: 284 296 context = Context({ 285 297 'macro': macro, 298 'supported_protocols': macro_supported_protocols(), 299 'supported_result_types': macro_supported_result_types(), 286 300 }) 287 301 … … 301 315 302 316 template = loader.get_template('edit_macro.html') 303 macro_to_edit = Macro.objects.get(name = macro_name) 317 macro_to_edit = Macro.objects.get(name = macro_name) 304 318 macro = { 305 319 'name' : macro_to_edit.name, … … 332 346 'message': 'macro saved', 333 347 'created': True, 348 'supported_protocols': macro_supported_protocols(), 349 'supported_result_types': macro_supported_result_types(), 334 350 }) 335 351 else: 336 352 context = Context({ 337 353 'macro': macro, 354 'supported_protocols': macro_supported_protocols(), 355 'supported_result_types': macro_supported_result_types(), 338 356 }) 339 357 -
templates/create_macro.html
re2a28f rdb7f89 24 24 <a href="{% url wiki.views.list_macros %}">Go back</a> to macros list. 25 25 </p> 26 {% else %} 26 {% else %} 27 27 <form method="post" action="{% url wiki.views.create_macro %}"> 28 29 28 <table> 29 <tr> 30 30 <th>name</th> 31 31 <td><input type="text" cols="80" name="name" value="{{ macro.name }}" /></td> … … 35 35 <td> 36 36 <select name="result"> 37 <option value="int">int</option> 38 <option value="float">float</option> 39 <option value="string">string</option> 40 <option value="graph">graph</option> 41 <option value="list">list</option> 37 {% for result in supported_result_types %} 38 <option value="{{ result }}">{{ result }}</option> 39 {% endfor %} 42 40 </select> 43 41 </td> … … 55 53 <td> 56 54 <select name="protocol"> 57 <option value="HTTP">HTTP</option> 58 <option value="XML-RPC">XML-RPC</option> 55 {% for proto in supported_protocols %} 56 <option value="{{ proto }}">{{ proto }}</option> 57 {% endfor %} 59 58 </select> 60 59 </td> … … 64 63 <td><input type="text" cols="80" name="destination" value="{{ macro.destination }}" /></td> 65 64 </tr> 66 67 68 69 <input type="submit" name="save" value="Submit" />70 71 72 73 74 65 <tr> 66 <td></td> 67 <td> 68 <input type="submit" name="save" value="Save" /> 69 <span>|</span> 70 <input type="submit" name="cancel" value="Cancel" /> 71 </td> 72 </tr> 73 </table> 75 74 </form> 76 75 {% endif %} -
templates/edit_macro.html
re2a28f rdb7f89 25 25 </p> 26 26 {% else %} 27 <form method="post" action="{% url wiki.views.edit_macro macro.name %}"> 27 <form method="post" action="{% url wiki.views.edit_macro macro.name %}"> 28 28 <table> 29 29 <tr> … … 35 35 <td> 36 36 <select name="result"> 37 <option value="int">int</option> 38 <option value="float">float</option> 39 <option value="string">string</option> 40 <option value="graph">graph</option> 41 <option value="list">list</option> 37 {% for result in supported_result_types %} 38 <option value="{{ result }}">{{ result }}</option> 39 {% endfor %} 42 40 </select> 43 41 </td> … … 55 53 <td> 56 54 <select name="protocol"> 57 <option value="HTTP">HTTP</option> 58 <option value="XML-RPC">XML-RPC</option> 55 {% for proto in supported_protocols %} 56 <option value="{{ proto }}">{{ proto }}</option> 57 {% endfor %} 59 58 </select> 60 59 </td> … … 64 63 <td><input type="text" cols="80" name="destination" value="{{ macro.destination }}" /></td> 65 64 </tr> 66 67 68 69 70 71 72 73 65 <tr> 66 <td></td> 67 <td> 68 <input type="submit" name="save" value="Save" /> 69 <span>|</span> 70 <input type="submit" name="cancel" value="Cancel" /> 71 </td> 72 </tr> 74 73 </table> 75 74 </form>
Note: See TracChangeset
for help on using the changeset viewer.