blob: 0c5b65f462b0660d4dcfda40283b419f1b6f0508 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
= django-sneak-peek
A Django template tag that allows you to hide pre-release features but make them available to a select group of users. By adding the "sneak peek" permission to users on your site, you can allow people within your company or trusted individuals to try out and experiment with upcoming features in your application.
== Requirements
Requires Django 1.4 or higher. Currently not configured for Django 1.7, but I'll be updating the package to add support for it once released.
{South}[https://pypi.python.org/pypi/South/0.8.4] is required for migrations. <code>django-sneak-peek</code> includes a data migration that adds a <code>ContentType</code> and <code>Permission</code>. The permission is used to determine whether or not a user can view sneak peek content.
== Installation
1. Install via <code>pip</code>:
$ pip install django-sneak-peek
2. Add <code>sneak_peek_tag</code> to <code>INSTALLED_APPS</code> in <code>settings.py</code>:
INSTALLED_APPS = (
...
'sneak_peek_tag',
...
)
3. Run migrations:
$ python manage.py migrate sneak_peek_tag
4. Run <code>collectstatic</code> to grab the CSS and image:
$ python manage.py collectstatic
== Usage
<code>django-sneak-peek</code> defines a template tag called <code>sneak_peek</code>. Markup that you want to conditionally hide gets wrapped in this template tag.
Add the <code>django-sneak-peek</code> CSS file to all pages where you plan to use the template tag:
<link rel="stylesheet" type="text/css" href="{{STATIC_URL}}sneak_peek_tag/css/django-sneak-peek.css" />
Load <code>sneak_peek</code> in your template:
{% load sneak_peek %}
Wrap secret markup in <code>sneak_peek</code> tags:
{% sneak_peek %}
<div>
<h1>Secret pre-release feature</h1>
<p>
This entire div is hidden from users who don't have the
sneak_peek permission.
</p>
</div>
{% endsneak_peek %}
== User Permissions
In order to determine whether to output the markup, <code>django-sneak-peek</code> relies on the <code>sneak_peek_tag.can_view_sneak_peek</code> permission which is installed via the included migration.
To allow a user to view sneak peek content, add this permission to their account. This can be done in the Django admin or via the shell:
>>> from django.contrib.contenttypes.models import ContentType
>>> from django.contrib.auth.models import Permission
>>>
>>> content_type = ContentType.objects.get(app_label='sneak_peek_tag')
>>> permission = Permission.objects.get(content_type=content_type, codename='can_view_sneak_peek')
>>>
>>> user = User.objects.get(username='Homer')
>>> user.user_permissions.add(permission)
== Additional Options
By default, markup under sneak peek will appear with a yellow and black "under construction" border:
## Screenshot ##
Sneak peek works by wrapping your code in a <code><div></code> and applying styles to that element with the <code>.django-sneak-peek</code> class and several modifiers.
Modifiers change the appearance of the sneak peek block.
Here are the available modifiers and different combinations thereof.
=== Outline
=== Borderless
=== Inline
=== Inline-Block
== CSS Class Modifiers
* Default: Yellow & black "under construction" border
* <code>.outline</code>: Sets <code>border: none;</code> and uses an <code>outline</code> instead
* <code>.borderless</code>: Sets <code>border: none;</code>. Markup will appear without superfluous extra styles applied by <code>django-sneak-peek</code>, but will still be surrouded by an <code><div></code> wrapper (as always).
* <code>.inline</code>: Sets <code>display: inline;</code>
* <code>.inline-block</code>: Sets <code>display: inline-block;</code>
== Customising
As you may have guessed, you can add custom display styles to <code>django-sneak-peek</code>. In addition to overriding the existing CSS classes, you can also create your own.
Here's an example of a class you can add to your CSS to add custom styles to a sneak peek element:
.django-sneak-peek.green-border {
border-color: green;
border-width: 5px;
}
This custom class can be applied with:
{% sneak_peek "green-border" %}
...
{% endsneak_peek %}
== License
|