Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
thalia
concrexit
Commits
dc83a6f2
Verified
Commit
dc83a6f2
authored
May 10, 2017
by
Sébastiaan Versteeg
Browse files
Add HTMLField for announcements
parent
ae728405
Changes
5
Hide whitespace changes
Inline
Side-by-side
website/announcements/admin.py
View file @
dc83a6f2
from
django.contrib
import
admin
from
django.template.defaultfilters
import
striptags
from
thaliawebsite.templatetags.bleach_tags
import
bleach
from
utils.translation
import
TranslatedModelAdmin
from
.models
import
Announcement
...
...
@@ -7,7 +9,12 @@ from .models import Announcement
@
admin
.
register
(
Announcement
)
class
AnnouncementAdmin
(
TranslatedModelAdmin
):
list_display
=
(
'content'
,
'since'
,
'until'
,
'visible'
)
list_display
=
(
'content_html'
,
'since'
,
'until'
,
'visible'
)
def
content_html
(
self
,
obj
):
# Both bleach and striptags.
# First to convert HTML entities and second to strip all HTML
return
bleach
(
striptags
(
obj
.
content
))
def
visible
(
self
,
obj
):
return
obj
.
is_visible
...
...
website/announcements/migrations/0003_auto_20170517_1925.py
0 → 100644
View file @
dc83a6f2
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2017-05-17 17:25
from
__future__
import
unicode_literals
from
django.db
import
migrations
import
tinymce.models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'announcements'
,
'0002_auto_20170402_1339'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'announcement'
,
name
=
'content_en'
,
field
=
tinymce
.
models
.
HTMLField
(
help_text
=
'The content of the announcement; what text to display.'
,
max_length
=
500
,
verbose_name
=
'Content (EN)'
),
),
migrations
.
AlterField
(
model_name
=
'announcement'
,
name
=
'content_nl'
,
field
=
tinymce
.
models
.
HTMLField
(
help_text
=
'The content of the announcement; what text to display.'
,
max_length
=
500
,
verbose_name
=
'Content (NL)'
),
),
]
website/announcements/models.py
View file @
dc83a6f2
from
django.db
import
models
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils
import
timezone
from
tinymce.models
import
HTMLField
from
utils.translation
import
ModelTranslateMeta
,
MultilingualField
class
Announcement
(
models
.
Model
,
metaclass
=
ModelTranslateMeta
):
content
=
MultilingualField
(
models
.
Char
Field
,
HTML
Field
,
verbose_name
=
_
(
'Content'
),
help_text
=
_
(
'The content of the announcement; what text to display.'
),
blank
=
False
,
...
...
website/announcements/static/announcements/css/style.scss
View file @
dc83a6f2
...
...
@@ -9,4 +9,20 @@
.close
{
color
:
#FFFFFF
;
}
p
{
display
:
inline
;
margin-left
:
5px
;
}
a
{
color
:
white
;
text-decoration
:
underline
;
}
a
:hover
{
color
:
#F0F0EE
;
text-decoration
:
underline
;
cursor
:
pointer
;
}
}
website/announcements/templates/announcements/announcement.html
View file @
dc83a6f2
{% load bleach_tags %}
{% for announcement in announcements %}
<div
class=
'announcement'
>
<i
class=
"fa fa-{{ announcement.icon }}"
></i>
{{ announcement.content }}
<i
class=
"fa fa-{{ announcement.icon }}"
></i>
{{ announcement.content
|bleach
}}
{% if announcement.closeable %}
<button
type=
"button"
class=
"close"
aria-label=
"Close"
data-announcement-id=
"{{ announcement.pk }}"
>
<span
aria-hidden=
"true"
>
×
</span>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment