Fix/implement image uploads

This commit is contained in:
Yingtong Li 2018-12-07 16:12:23 +11:00
parent f0e53b56a5
commit c691a7cff2
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
5 changed files with 11 additions and 6 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@ __pycache__
settings.py
migrations
promo_uploads

View File

@ -18,6 +18,7 @@ import markdown
from django.contrib.staticfiles.storage import staticfiles_storage
from django.conf import settings
from django.urls import reverse
from django.utils import timezone
@ -32,6 +33,7 @@ def environment(**options):
'localtime': lambda dt: timezone.localtime(dt).strftime('%Y-%m-%d %H:%M'),
'static': staticfiles_storage.url,
'url': reverse,
'MEDIA_URL': settings.MEDIA_URL,
})
env.filters.update({
'markdown': lambda x: Markup(markdown.markdown(x))

View File

@ -14,6 +14,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import include, path
@ -23,4 +25,4 @@ urlpatterns = [
path('treasury/', include('sstreasury.urls')),
path('promotions/', include('sspromotions.urls')),
path('', include('ssmain.urls')),
]
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

View File

@ -23,7 +23,7 @@
{% block maincontent %}
<h1>{% if request.resolver_match.url_name == 'bulletin_new' %}New{% else %}Edit{% endif %} bulletin item</h1>
<form class="ui form" method="POST">
<form class="ui form" method="POST" enctype="multipart/form-data">
<div class="ui disabled inline grid field">
<label class="three wide column">ID</label>
<input class="eleven wide column" type="text" name="id" value="{{ item.id if item.id != None else '' }}">

View File

@ -59,7 +59,7 @@
<table>
<tr>
<th>
<a href="#"><img src="{{ item.image }}" alt="{{ item.title }}"></a>
{% if item.link %}<a href="{{ item.link }}">{% endif %}<img src="{{ MEDIA_URL }}{{ item.image }}" alt="{{ item.title }}">{% if item.link %}</a>{% endif %}
</th>
</tr>
</table>
@ -71,7 +71,7 @@
<th>
<b><h5>{{ item.title }}</h5></b>
<p>{{ item.content | markdown }}</p>
{% if item.link %}<p><a href="{{ item.link }}">Click Here &#x203A;</a></p>{% endif %}
{% if item.link %}<p><a href="{{ item.link }}">Read more &#x203A;</a></p>{% endif %}
</th>
</tr>
</table>
@ -99,10 +99,10 @@
<table>
<tr>
<th>
{% if item.image %}{% if item.link %}<a href="{{ item.link }}">{% endif %}<img src="{{ item.image }}" alt="{{ item.title }}">{% if item.link %}</a>{% endif %}<br>{% endif %}
{% if item.image %}{% if item.link %}<a href="{{ item.link }}">{% endif %}<img src="{{ MEDIA_URL }}{{ item.image }}" alt="{{ item.title }}">{% if item.link %}</a>{% endif %}<br>{% endif %}
<b><h5>{{ item.title }}</h5></b>
<p>{{ item.content }}</p>
{% if item.link %}<p><a href="{{ item.link }}">Click Here &#x203A;</a></p>{% endif %}
{% if item.link %}<p><a href="{{ item.link }}">Read more &#x203A;</a></p>{% endif %}
</th>
</tr>
</table>