Conditions | 9 |
Total Lines | 146 |
Code Lines | 33 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | #coding: utf8 |
||
241 | def designThread(content: data.Content, content_revision: data.ContentRevisionRO, comments) -> str: |
||
242 | hist = content.get_history(drop_empty_revision=False) |
||
243 | |||
244 | allT = [] |
||
245 | allT += comments |
||
246 | allT += hist |
||
247 | allT.sort(key=lambda x: x.created, reverse=True) |
||
248 | |||
249 | disc = '' |
||
250 | participants = {} |
||
251 | for t in allT: |
||
252 | if t.type == CONTENT_TYPES.Comment.slug: |
||
253 | disc += ''' |
||
254 | <div class="row comment comment-row"> |
||
255 | <i class="fa fa-comment-o comment-icon"></i> |
||
256 | <div class="comment-content"> |
||
257 | <h5> |
||
258 | <span class="comment-author"><b>%s</b> wrote :</span> |
||
259 | <div class="pull-right text-right">%s</div> |
||
260 | </h5> |
||
261 | %s |
||
262 | </div> |
||
263 | </div> |
||
264 | ''' % (t.owner.display_name, create_readable_date(t.created), t.description) |
||
265 | |||
266 | if t.owner.display_name not in participants: |
||
267 | participants[t.owner.display_name] = [1, t.created] |
||
268 | else: |
||
269 | participants[t.owner.display_name][0] += 1 |
||
270 | else: |
||
271 | if isinstance(t, VirtualEvent) and t.type.id != 'comment': |
||
272 | label = _LABELS[t.type.id] |
||
273 | |||
274 | disc += ''' |
||
275 | <div class="%s row comment comment-row to-hide"> |
||
276 | <i class="fa %s comment-icon"></i> |
||
277 | <div class="comment-content"> |
||
278 | <h5> |
||
279 | <span class="comment-author"><b>%s</b></span> |
||
280 | <div class="pull-right text-right">%s</div> |
||
281 | </h5> |
||
282 | %s %s |
||
283 | </div> |
||
284 | </div> |
||
285 | ''' % ('warning' if t.id == content_revision.revision_id else '', |
||
286 | t.type.fa_icon, |
||
287 | t.owner.display_name, |
||
288 | t.create_readable_date(), |
||
289 | label, |
||
290 | # NOTE: (WABDAV_HIST_DEL_DISABLED) Disabled for beta 1.0 |
||
291 | '<i class="fa fa-caret-left"></i> shown' if t.id == content_revision.revision_id else '' # else '''<span><a class="revision-link" href="/.history/%s/%s-%s">(View revision)</a></span>''' % ( |
||
292 | # content.label, |
||
293 | # t.id, |
||
294 | # t.ref_object.label) if t.type.id in ['revision', 'creation', 'edition'] else '') |
||
295 | ) |
||
296 | |||
297 | thread = ''' |
||
298 | <html> |
||
299 | <head> |
||
300 | <meta charset="utf-8" /> |
||
301 | <title>%s</title> |
||
302 | <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> |
||
303 | <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> |
||
304 | <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css"> |
||
305 | <style>%s</style> |
||
306 | <script type="text/javascript" src="/home/arnaud/Documents/css/script.js"></script> |
||
307 | </head> |
||
308 | <body> |
||
309 | <div id="left" class="col-lg-12 col-md-12 col-sm-12 col-xs-12"> |
||
310 | <div class="title thread"> |
||
311 | <div class="title-text"> |
||
312 | <i class="fa fa-comments-o title-icon thread"></i> |
||
313 | <h1>%s</h1> |
||
314 | <h6>thread created on <b>%s</b> by <b>%s</b></h6> |
||
315 | </div> |
||
316 | <div class="pull-right"> |
||
317 | <div class="btn-group btn-group-vertical"> |
||
318 | <!-- NOTE: Not omplemented yet, don't display not working link |
||
319 | <a class="btn btn-default" onclick="hide_elements()"> |
||
320 | <i id="hideshow" class="fa fa-eye-slash"></i> <span id="hideshowtxt" >Hide history</span></a> |
||
321 | </a>--> |
||
322 | <a class="btn btn-default"> |
||
323 | <i class="fa fa-external-link"></i> View in tracim</a> |
||
324 | </a> |
||
325 | </div> |
||
326 | </div> |
||
327 | </div> |
||
328 | <div class="content col-xs-12 col-sm-12 col-md-12 col-lg-12"> |
||
329 | <div class="description"> |
||
330 | <span class="description-text">%s</span> |
||
331 | </div> |
||
332 | %s |
||
333 | </div> |
||
334 | </div> |
||
335 | <script type="text/javascript"> |
||
336 | window.onload = function() { |
||
337 | file_location = window.location.href |
||
338 | file_location = file_location.replace(/\/[^/]*$/, '') |
||
339 | file_location = file_location.replace(/\/.history\/[^/]*$/, '') |
||
340 | |||
341 | // NOTE: (WABDAV_HIST_DEL_DISABLED) Disabled for beta 1.0 |
||
342 | // $('.revision-link').each(function() { |
||
343 | // $(this).attr('href', file_location + $(this).attr('href')) |
||
344 | // }); |
||
345 | } |
||
346 | |||
347 | function hide_elements() { |
||
348 | elems = document.getElementsByClassName('to-hide'); |
||
349 | if (elems.length > 0) { |
||
350 | for(var i = 0; i < elems.length; i++) { |
||
351 | $(elems[i]).addClass('to-show') |
||
352 | $(elems[i]).hide(); |
||
353 | } |
||
354 | while (elems.length>0) { |
||
355 | $(elems[0]).removeClass('comment-row'); |
||
356 | $(elems[0]).removeClass('to-hide'); |
||
357 | } |
||
358 | $('#hideshow').addClass('fa-eye').removeClass('fa-eye-slash'); |
||
359 | $('#hideshowtxt').html('Show history'); |
||
360 | } |
||
361 | else { |
||
362 | elems = document.getElementsByClassName('to-show'); |
||
363 | for(var i = 0; i<elems.length; i++) { |
||
364 | $(elems[0]).addClass('comment-row'); |
||
365 | $(elems[i]).addClass('to-hide'); |
||
366 | $(elems[i]).show(); |
||
367 | } |
||
368 | while (elems.length>0) { |
||
369 | $(elems[0]).removeClass('to-show'); |
||
370 | } |
||
371 | $('#hideshow').removeClass('fa-eye').addClass('fa-eye-slash'); |
||
372 | $('#hideshowtxt').html('Hide history'); |
||
373 | } |
||
374 | } |
||
375 | </script> |
||
376 | </body> |
||
377 | </html> |
||
378 | ''' % (content_revision.label, |
||
379 | style, |
||
380 | content_revision.label, |
||
381 | content.created.strftime("%B %d, %Y at %H:%m"), |
||
382 | content.owner.display_name, |
||
383 | content_revision.description, |
||
384 | disc) |
||
385 | |||
386 | return thread |
||
387 |