Compare commits
4 Commits
3db28b38a6
...
8211feb33b
Author | SHA1 | Date | |
---|---|---|---|
8211feb33b | |||
bf9b928620 | |||
af482c7449 | |||
f2f6095080 |
|
@ -166,6 +166,7 @@ def text_post(socket, data):
|
|||
post_text = post_text.replace("\n", "<br>")
|
||||
|
||||
# handle image
|
||||
post_text = handle_img(post_text)
|
||||
|
||||
p = Post(
|
||||
quest=quest,
|
||||
|
@ -367,6 +368,7 @@ def edit_post(socket, data):
|
|||
post_text = post_text.replace("\n", "<br>")
|
||||
|
||||
# handle image
|
||||
post_text = handle_img(post_text)
|
||||
|
||||
p.post_text = post_text
|
||||
p.save()
|
||||
|
|
|
@ -43,11 +43,14 @@ class EditQuestForm(forms.Form):
|
|||
"""
|
||||
Form for the /edit_quest page.
|
||||
"""
|
||||
quest_title = forms.CharField(max_length=100)
|
||||
anon_name = forms.CharField(max_length=20)
|
||||
live = forms.BooleanField(required=False)
|
||||
live_date = forms.DateField(required=False)
|
||||
live_time = forms.TimeField(required=False)
|
||||
timezone = forms.IntegerField()
|
||||
description = forms.CharField(max_length=256, required=False)
|
||||
banner_url = forms.URLField(required=False)
|
||||
|
||||
|
||||
class QuestForm(forms.ModelForm):
|
||||
|
@ -56,7 +59,7 @@ class QuestForm(forms.ModelForm):
|
|||
"""
|
||||
class Meta:
|
||||
model = Quest
|
||||
fields = ('title', 'description', 'tags')
|
||||
fields = ('title', 'description', 'tags', 'banner_url')
|
||||
|
||||
|
||||
class PostForm(forms.ModelForm):
|
||||
|
|
|
@ -29,8 +29,16 @@
|
|||
</tr>
|
||||
<tr>
|
||||
<td>Live time:</td>
|
||||
<td><input type="date" name="live_date" id="live_date" value="{% if quest.live_time %}{{ localtime(quest.live_time).strftime('%Y-%m-%d') }}{% endif %}"></td>
|
||||
<td><input type="time" name="live_time" id="live_time" step="60" value="{% if quest.live_time %}{{ localtime(quest.live_time).strftime('%H:%M:%S') }}{% endif %}"></td>
|
||||
<td><input type="date" name="live_date" id="live_date" value="{% if quest.live_time %}{{ localtime(quest.live_time).strftime('%Y-%m-%d') }}{% endif %}">
|
||||
<input type="time" name="live_time" id="live_time" step="60" value="{% if quest.live_time %}{{ localtime(quest.live_time).strftime('%H:%M:%S') }}{% endif %}"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Description:</td>
|
||||
<td><textarea name="description">{{ quest.description }}</textarea></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Banner Image URL:</td>
|
||||
<td><input type="text" name="banner_url" maxlength="200" value="{% if quest.banner_url %}{{ quest.banner_url }}{% endif %}"></td>
|
||||
</tr>
|
||||
</table>
|
||||
<input type="hidden" name="timezone" id="timezone">
|
||||
|
|
|
@ -13,9 +13,9 @@
|
|||
<br>Tags: <input type="text" name="tags">
|
||||
<br>Order by:
|
||||
<select name="order_by">
|
||||
<option value="creation_date"{% if order_by == 'creation_date' %} selected{% endif %}>Creation date</option>
|
||||
<option value="last_post"{% if order_by == 'last_post' %} selected{% endif %}>Last post</option>
|
||||
<option value="next_live"{% if order_by == 'next_live' %} selected{% endif %}>Next live</option>
|
||||
<option value="creation_date"{% if order_by == 'id' %} selected{% endif %}>Creation date</option>
|
||||
<option value="last_post"{% if order_by == 'latest_post_date' %} selected{% endif %}>Last post</option>
|
||||
<option value="next_live"{% if order_by == 'live_time' %} selected{% endif %}>Next live</option>
|
||||
</select>
|
||||
<select name="order_way">
|
||||
<option value="desc"{% if order_way == 'desc' %} selected{% endif %}>Descending</option>
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
<form method="post" action="{{ url('quest:new_quest') }}">
|
||||
{{ csrf_input }}
|
||||
<input type="text" placeholder="Quest Title" name="title" maxlength="100" required><br>
|
||||
<input type="text" placeholder="Banner URL" name="banner_url" maxlength="200" required><br>
|
||||
<textarea name="description" maxlength="256"></textarea><br>
|
||||
<input type="text" placeholder="Tags" name="tags" id=><br>
|
||||
<input type="submit" name="submit" value="Submit">
|
||||
|
|
|
@ -47,7 +47,8 @@
|
|||
{% endblock %}
|
||||
{% block content %}
|
||||
<div id="questPane" style="width:{% if request.session.get("hide_chat") == True %}100%{% else %}70%{% endif %};">
|
||||
<center><h1>{{ quest.title }}</h1></center>
|
||||
<h1 id="questTitle">{{ quest.title }}</h1>
|
||||
{% if quest.banner_url %}<img id="banner" src="{{ quest.banner_url }}">{% endif %}
|
||||
<div id="questPosts">
|
||||
{% for post in posts %}
|
||||
{% if post.post_type == "text" %}
|
||||
|
|
|
@ -54,7 +54,9 @@
|
|||
{% endblock %}
|
||||
{% block content %}
|
||||
<div id="questPane" style="width:{% if request.session.get("hide_chat") == True %}100%{% else %}70%{% endif %};">
|
||||
<center><h1>{{ quest.title }}</h1></center>
|
||||
<h1 id="questTitle">{{ quest.title }}</h1>
|
||||
{% if quest.banner_url %}<img id="banner" src="{{ quest.banner_url }}">{% endif %}
|
||||
{% if quest.description %}<div id="description">{{ quest.description }}</div>{% endif %}
|
||||
<div id="tags">
|
||||
Tags: {% for tag in quest.tags.names() %}<a href="{{ url('quest:index') + '?tags=' + tag }}">{{ tag }}</a>{% if not loop.last %}, {% endif %}{% endfor %}
|
||||
</div>
|
||||
|
|
18
quest/migrations/0010_quest_banner_url.py
Normal file
18
quest/migrations/0010_quest_banner_url.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 2.1.1 on 2018-10-11 12:57
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('quest', '0009_quest_latest_post_date'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='quest',
|
||||
name='banner_url',
|
||||
field=models.URLField(blank=True, null=True),
|
||||
),
|
||||
]
|
|
@ -22,6 +22,7 @@ class Quest(models.Model):
|
|||
anonymize = models.BooleanField(default=True)
|
||||
description = models.CharField(max_length=256, blank=True, null=True)
|
||||
latest_post_date = models.DateTimeField(null=True, blank=True)
|
||||
banner_url = models.URLField(null=True, blank=True)
|
||||
|
||||
def update_post_date(self):
|
||||
try:
|
||||
|
|
|
@ -26,6 +26,10 @@ h3 {
|
|||
width: 70%;
|
||||
}
|
||||
|
||||
#questTitle {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#tags {
|
||||
padding-bottom: 0.25em;
|
||||
}
|
||||
|
|
|
@ -98,6 +98,10 @@ function edit_post(post_id) {
|
|||
let post = document.getElementById('questPostData-' + post_id);
|
||||
let post_text = post.innerHTML.trim();
|
||||
post_text = post_text.replace(/<br>/g, '\n');
|
||||
post_text.split('\n').forEach(function(line) {
|
||||
new_line = line.replace(/<img src="(.*)" title="(.*)">/, '[img title="$2"]$1[/img]');
|
||||
post_text = post_text.replace(line, new_line);
|
||||
});
|
||||
post.innerHTML = '<textarea class="editPostText">' + post_text + '</textarea>';
|
||||
post.firstElementChild.style.height = post.firstElementChild.scrollHeight + 'px';
|
||||
document.getElementById('savePost-' + post_id).style.display = 'initial';
|
||||
|
|
|
@ -30,6 +30,10 @@ def download_img(url):
|
|||
# TODO: file size limits
|
||||
# https://stackoverflow.com/questions/22346158/
|
||||
# TODO: prevent overwriting
|
||||
url = url.replace('..', '')
|
||||
if url.startswith(settings.IMG_SVR_URL):
|
||||
if '/' not in url.replace(settings.IMG_SVR_URL, ''):
|
||||
return url
|
||||
try:
|
||||
res = requests.get(url)
|
||||
res.raise_for_status()
|
||||
|
@ -60,16 +64,22 @@ def handle_img(text, limit=5):
|
|||
(unlinked) url will be inserted.
|
||||
"""
|
||||
# TODO: handle webms
|
||||
urls = re.findall(r"\[img\](.*?)\[/img\]", text)
|
||||
urls = re.findall(
|
||||
r"""\[img(?: title=['"](.*)['"])?\](.*)\[\/img\]""",
|
||||
text.replace('<br', '\n')
|
||||
)
|
||||
urls = urls[:limit]
|
||||
|
||||
for ext_url in urls:
|
||||
for match_pair in urls:
|
||||
title, ext_url = match_pair
|
||||
int_url = download_img(ext_url)
|
||||
if int_url in ["INVALID_URL", "INVALID_MIME_TYPE", "UNKNOWN_ERROR"]:
|
||||
text = text.replace("[img]" + ext_url + "[/img]", ext_url, 1)
|
||||
alt_text = os.path.basename(ext_url)
|
||||
img_tag = f'<img src="{int_url}" title="{alt_text}">'
|
||||
text = re.sub(r"\[img.*?\[\/img\]", ext_url, text, 1)
|
||||
if not title:
|
||||
title = os.path.basename(ext_url)
|
||||
img_tag = f'<img src="{int_url}" title="{title}">'
|
||||
|
||||
text = text.replace("[img]" + ext_url + "[/img]", img_tag, 1)
|
||||
text = re.sub(r"\[img.*?\[\/img\]", img_tag, text, 1)
|
||||
|
||||
return text
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ from django.conf import settings
|
|||
from .models import Quest, DiceRoll, PollOption, PollVote, Page, Post
|
||||
from .forms import EditQuestForm, QuestForm, PostForm
|
||||
from user.models import User
|
||||
from .tools import send_to_websocket
|
||||
from .tools import download_img, send_to_websocket
|
||||
|
||||
def index(request):
|
||||
"""The quest page index."""
|
||||
|
@ -90,8 +90,13 @@ def edit_quest(request, quest_id, page_num='0'):
|
|||
if request.method == 'POST':
|
||||
form = EditQuestForm(request.POST)
|
||||
if form.is_valid():
|
||||
quest.title = form.cleaned_data['quest_title']
|
||||
quest.anon_name = form.cleaned_data['anon_name']
|
||||
quest.live = form.cleaned_data['live']
|
||||
quest.description = form.cleaned_data['description']
|
||||
quest.banner_url = download_img(form.cleaned_data['banner_url'])
|
||||
if not quest.banner_url.startswith('http'):
|
||||
quest.banner_url = None
|
||||
|
||||
live_date = form.cleaned_data['live_date']
|
||||
live_time = form.cleaned_data['live_time']
|
||||
|
@ -135,6 +140,9 @@ def new_quest(request):
|
|||
if quest_form.is_valid():
|
||||
quest = quest_form.save(commit=False)
|
||||
quest.owner = request.user
|
||||
quest.banner_url = download_img(quest.banner_url)
|
||||
if not quest.banner_url.startswith('http'):
|
||||
quest.banner_url = None
|
||||
quest.save()
|
||||
quest_form.save_m2m()
|
||||
print(quest.tags.names())
|
||||
|
|
Loading…
Reference in New Issue
Block a user