Test coverage report: markupmirror.widgets

# markupmirror.widgets: 33 total statements, 37.9% covered

Generated: Wed 2012-04-11 05:19 CDT

Source file: /home/buechler/Sites/django-markupmirror/markupmirror/widgets.py

Stats: 11 executed, 18 missed, 4 excluded, 37 ignored

1. `from django import forms`
2. `from django.contrib.admin.widgets import AdminTextareaWidget`
3. ``
4. `from markupmirror import settings`
5. `from markupmirror.markup.base import markup_pool`
6. ``
7. ``
8. `class MarkupMirrorTextarea(forms.Textarea):`
9. ``
10. `css_class = 'item-markupmirror'`
11. ``
12. `def __init__(self, attrs=None):`
13. `"""Adds the ``item-markupmirror`` class to the textarea to make sure`
14. `it can be identified through JS.`
15. ``
16. `"""`
17. `css_class = self.css_class`
18. `if attrs and 'class' in attrs:`
19. `css_class += ' %s' % attrs.pop('class')`
20. ``
21. `default_attrs = {`
22. `'class': css_class,`
23. `}`
24. ``
25. `if attrs:`
26. `default_attrs.update(attrs)`
27. `super(MarkupMirrorTextarea, self).__init__(attrs=default_attrs)`
28. ``
29. `def render(self, name, value, attrs=None):`
30. `if value is not None and not isinstance(value, unicode):`
31. `value = value.raw`
32. `return super(MarkupMirrorTextarea, self).render(name, value, attrs)`
33. ``
34. `class Media:`
35. `css = {`
36. `'all': settings.MARKUPMIRROR_CSS`
37. `}`
38. `js = settings.MARKUPMIRROR_JS`
39. ``
40. ``
41. `class AdminMarkupMirrorTextareaWidget(`
42. `MarkupMirrorTextarea, AdminTextareaWidget):`
43. ``
44. `css_class = 'vLargeTextField item-markupmirror'`
45. ``
46. `def render(self, name, value, attrs=None):`
47. `"""Adds attributes necessary to load CodeMirror for each textarea`
48. `in the admin.`
49. ``
50. `"""`
51. `default_attrs = {}`
52. ``
53. `if value and hasattr(value, 'markup_type'):`
54. `# get markup converter by type.`
55. `# ``value`` is ``markupmirror.fields.Markup``.`
56. `markup_type = value.markup_type`
57. `markup = markup_pool.get_markup(markup_type)`
58. ``
59. `default_attrs = {`
60. `'data-mode': markup.codemirror_mode,`
61. `'data-markuptype': markup_type,`
62. `}`
63. ``
64. `if attrs:`
65. `default_attrs.update(attrs)`
66. `return super(AdminMarkupMirrorTextareaWidget, self).render(`
67. `name, value, default_attrs)`
68. ``
69. ``
70. `__all__ = ('MarkupMirrorTextarea', 'AdminMarkupMirrorTextareaWidget')`