Skip to content

Commit

Permalink
make rouxcode/django-text-ckeditor optional
Browse files Browse the repository at this point in the history
  • Loading branch information
wullerot committed May 23, 2018
1 parent 4526ba4 commit a106481
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 9 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Simple terms and condition notify app

## Install
```shell
$ pip install -e git+https://github.com/rouxcode/[email protected].6#egg=django-tac
$ pip install -e git+https://github.com/rouxcode/[email protected].7#egg=django-tac
```

## Usage
Expand Down Expand Up @@ -39,6 +39,10 @@ use the template tag:
```html
{% tac_popup %}
```
or if rouxcode/django-text-ckeditor is not installed
```html
{% tac_popup_no_ckeditor %}
```

### javascript
jquery needs to be loaded before:
Expand Down
2 changes: 1 addition & 1 deletion tac/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import unicode_literals


__version__ = '0.0.6'
__version__ = '0.0.7'
default_app_config = 'tac.apps.TACConfig'
10 changes: 6 additions & 4 deletions tac/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

from django.contrib import admin

from .link import PopupLink, PopupLinkAdmin
from .popup import PopupContent, PopupContentAdmin

try:
from .link import PopupLink, PopupLinkAdmin
admin.site.register(PopupLink, PopupLinkAdmin)
except Exception:
pass

from .popup import PopupContent, PopupContentAdmin
admin.site.register(PopupContent, PopupContentAdmin)
admin.site.register(PopupLink, PopupLinkAdmin)
5 changes: 4 additions & 1 deletion tac/admin/popup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
from django import forms
from django.contrib import admin

from text_ckeditor.widgets import CKEditorWidget
try:
from text_ckeditor.widgets import CKEditorWidget
except Exception:
from .widgets import CKEditorWidget

from .. import conf
from ..models import PopupContent
Expand Down
14 changes: 14 additions & 0 deletions tac/admin/widgets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from __future__ import unicode_literals

from django import forms


class CKEditorWidget(forms.Textarea):

def __init__(self, *args, **kwargs):
try:
kwargs.popu('conf')
except Exception:
pass

super(CKEditorWidget, self).__init__(*args, **kwargs)
4 changes: 4 additions & 0 deletions tac/templates/tac/tags/popup_no_ckeditor.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% if show %}<div class="tac-popup tac-popup-no-ckeditor">
<div class="tac-popup-text">{{ object.text|safe }}</div>
<a class="tac-popup-button" href="{{ url }}" data-apiurl="{{ apiurl }}">{{ object.get_button_label }}</a>
</div>{% endif %}
5 changes: 5 additions & 0 deletions tac/templatetags/tac_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ def tac_popup(context):
'url': './?tac=accepted',
'apiurl': reverse('tac-api-accept'),
}


@register.inclusion_tag('tac/tags/popup_no_ckeditor.html', takes_context=True)
def tac_popup_no_ckeditor(context):
return tac_popup(context)
2 changes: 1 addition & 1 deletion testproject/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
'testproject',
'tac',
'compressor',
'text_ckeditor',
# 'text_ckeditor',

'django.contrib.redirects',
'django.contrib.admin',
Expand Down
2 changes: 1 addition & 1 deletion testproject/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{% placeholder 'body' %}
{% endblock %}
</div>
{% tac_popup %}
{% tac_popup_no_ckeditor %}
{% compress js %}
<script src="{{ STATIC_URL }}js/jquery.js"></script>
<script src="{{ STATIC_URL }}tac/js/tac.accept.js"></script>
Expand Down

0 comments on commit a106481

Please sign in to comment.