Compare commits

..

No commits in common. "8211feb33b9092be892c924115004be11045a92f" and "3db28b38a6af6eb1b9b19fe3218ebe10e1250d82" have entirely different histories.

14 changed files with 16 additions and 79 deletions

View File

@ -166,7 +166,6 @@ def text_post(socket, data):
post_text = post_text.replace("\n", "<br>") post_text = post_text.replace("\n", "<br>")
# handle image # handle image
post_text = handle_img(post_text)
p = Post( p = Post(
quest=quest, quest=quest,
@ -368,7 +367,6 @@ def edit_post(socket, data):
post_text = post_text.replace("\n", "<br>") post_text = post_text.replace("\n", "<br>")
# handle image # handle image
post_text = handle_img(post_text)
p.post_text = post_text p.post_text = post_text
p.save() p.save()

View File

@ -43,14 +43,11 @@ class EditQuestForm(forms.Form):
""" """
Form for the /edit_quest page. Form for the /edit_quest page.
""" """
quest_title = forms.CharField(max_length=100)
anon_name = forms.CharField(max_length=20) anon_name = forms.CharField(max_length=20)
live = forms.BooleanField(required=False) live = forms.BooleanField(required=False)
live_date = forms.DateField(required=False) live_date = forms.DateField(required=False)
live_time = forms.TimeField(required=False) live_time = forms.TimeField(required=False)
timezone = forms.IntegerField() timezone = forms.IntegerField()
description = forms.CharField(max_length=256, required=False)
banner_url = forms.URLField(required=False)
class QuestForm(forms.ModelForm): class QuestForm(forms.ModelForm):
@ -59,7 +56,7 @@ class QuestForm(forms.ModelForm):
""" """
class Meta: class Meta:
model = Quest model = Quest
fields = ('title', 'description', 'tags', 'banner_url') fields = ('title', 'description', 'tags')
class PostForm(forms.ModelForm): class PostForm(forms.ModelForm):

View File

@ -29,16 +29,8 @@
</tr> </tr>
<tr> <tr>
<td>Live time:</td> <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><input type="date" name="live_date" id="live_date" value="{% if quest.live_time %}{{ localtime(quest.live_time).strftime('%Y-%m-%d') }}{% endif %}"></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="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> </tr>
</table> </table>
<input type="hidden" name="timezone" id="timezone"> <input type="hidden" name="timezone" id="timezone">

View File

@ -13,9 +13,9 @@
<br>Tags: <input type="text" name="tags"> <br>Tags: <input type="text" name="tags">
<br>Order by: <br>Order by:
<select name="order_by"> <select name="order_by">
<option value="creation_date"{% if order_by == 'id' %} selected{% endif %}>Creation date</option> <option value="creation_date"{% if order_by == 'creation_date' %} selected{% endif %}>Creation date</option>
<option value="last_post"{% if order_by == 'latest_post_date' %} selected{% endif %}>Last post</option> <option value="last_post"{% if order_by == 'last_post' %} selected{% endif %}>Last post</option>
<option value="next_live"{% if order_by == 'live_time' %} selected{% endif %}>Next live</option> <option value="next_live"{% if order_by == 'next_live' %} selected{% endif %}>Next live</option>
</select> </select>
<select name="order_way"> <select name="order_way">
<option value="desc"{% if order_way == 'desc' %} selected{% endif %}>Descending</option> <option value="desc"{% if order_way == 'desc' %} selected{% endif %}>Descending</option>

View File

@ -5,7 +5,6 @@
<form method="post" action="{{ url('quest:new_quest') }}"> <form method="post" action="{{ url('quest:new_quest') }}">
{{ csrf_input }} {{ csrf_input }}
<input type="text" placeholder="Quest Title" name="title" maxlength="100" required><br> <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> <textarea name="description" maxlength="256"></textarea><br>
<input type="text" placeholder="Tags" name="tags" id=><br> <input type="text" placeholder="Tags" name="tags" id=><br>
<input type="submit" name="submit" value="Submit"> <input type="submit" name="submit" value="Submit">

View File

@ -47,8 +47,7 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<div id="questPane" style="width:{% if request.session.get("hide_chat") == True %}100%{% else %}70%{% endif %};"> <div id="questPane" style="width:{% if request.session.get("hide_chat") == True %}100%{% else %}70%{% endif %};">
<h1 id="questTitle">{{ quest.title }}</h1> <center><h1>{{ quest.title }}</h1></center>
{% if quest.banner_url %}<img id="banner" src="{{ quest.banner_url }}">{% endif %}
<div id="questPosts"> <div id="questPosts">
{% for post in posts %} {% for post in posts %}
{% if post.post_type == "text" %} {% if post.post_type == "text" %}

View File

@ -54,9 +54,7 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<div id="questPane" style="width:{% if request.session.get("hide_chat") == True %}100%{% else %}70%{% endif %};"> <div id="questPane" style="width:{% if request.session.get("hide_chat") == True %}100%{% else %}70%{% endif %};">
<h1 id="questTitle">{{ quest.title }}</h1> <center><h1>{{ quest.title }}</h1></center>
{% 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"> <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 %} Tags: {% for tag in quest.tags.names() %}<a href="{{ url('quest:index') + '?tags=' + tag }}">{{ tag }}</a>{% if not loop.last %}, {% endif %}{% endfor %}
</div> </div>

View File

@ -1,18 +0,0 @@
# 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),
),
]

View File

@ -22,7 +22,6 @@ class Quest(models.Model):
anonymize = models.BooleanField(default=True) anonymize = models.BooleanField(default=True)
description = models.CharField(max_length=256, blank=True, null=True) description = models.CharField(max_length=256, blank=True, null=True)
latest_post_date = models.DateTimeField(null=True, blank=True) latest_post_date = models.DateTimeField(null=True, blank=True)
banner_url = models.URLField(null=True, blank=True)
def update_post_date(self): def update_post_date(self):
try: try:

View File

@ -26,10 +26,6 @@ h3 {
width: 70%; width: 70%;
} }
#questTitle {
text-align: center;
}
#tags { #tags {
padding-bottom: 0.25em; padding-bottom: 0.25em;
} }

View File

@ -98,10 +98,6 @@ function edit_post(post_id) {
let post = document.getElementById('questPostData-' + post_id); let post = document.getElementById('questPostData-' + post_id);
let post_text = post.innerHTML.trim(); let post_text = post.innerHTML.trim();
post_text = post_text.replace(/<br>/g, '\n'); 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.innerHTML = '<textarea class="editPostText">' + post_text + '</textarea>';
post.firstElementChild.style.height = post.firstElementChild.scrollHeight + 'px'; post.firstElementChild.style.height = post.firstElementChild.scrollHeight + 'px';
document.getElementById('savePost-' + post_id).style.display = 'initial'; document.getElementById('savePost-' + post_id).style.display = 'initial';

View File

@ -30,10 +30,6 @@ def download_img(url):
# TODO: file size limits # TODO: file size limits
# https://stackoverflow.com/questions/22346158/ # https://stackoverflow.com/questions/22346158/
# TODO: prevent overwriting # 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: try:
res = requests.get(url) res = requests.get(url)
res.raise_for_status() res.raise_for_status()
@ -64,22 +60,16 @@ def handle_img(text, limit=5):
(unlinked) url will be inserted. (unlinked) url will be inserted.
""" """
# TODO: handle webms # TODO: handle webms
urls = re.findall( urls = re.findall(r"\[img\](.*?)\[/img\]", text)
r"""\[img(?: title=['"](.*)['"])?\](.*)\[\/img\]""",
text.replace('<br', '\n')
)
urls = urls[:limit]
for match_pair in urls: for ext_url in urls:
title, ext_url = match_pair
int_url = download_img(ext_url) int_url = download_img(ext_url)
if int_url in ["INVALID_URL", "INVALID_MIME_TYPE", "UNKNOWN_ERROR"]: if int_url in ["INVALID_URL", "INVALID_MIME_TYPE", "UNKNOWN_ERROR"]:
text = re.sub(r"\[img.*?\[\/img\]", ext_url, text, 1) text = text.replace("[img]" + ext_url + "[/img]", ext_url, 1)
if not title: alt_text = os.path.basename(ext_url)
title = os.path.basename(ext_url) img_tag = f'<img src="{int_url}" title="{alt_text}">'
img_tag = f'<img src="{int_url}" title="{title}">'
text = re.sub(r"\[img.*?\[\/img\]", img_tag, text, 1) text = text.replace("[img]" + ext_url + "[/img]", img_tag, 1)
return text return text

View File

@ -14,7 +14,7 @@ from django.conf import settings
from .models import Quest, DiceRoll, PollOption, PollVote, Page, Post from .models import Quest, DiceRoll, PollOption, PollVote, Page, Post
from .forms import EditQuestForm, QuestForm, PostForm from .forms import EditQuestForm, QuestForm, PostForm
from user.models import User from user.models import User
from .tools import download_img, send_to_websocket from .tools import send_to_websocket
def index(request): def index(request):
"""The quest page index.""" """The quest page index."""
@ -90,13 +90,8 @@ def edit_quest(request, quest_id, page_num='0'):
if request.method == 'POST': if request.method == 'POST':
form = EditQuestForm(request.POST) form = EditQuestForm(request.POST)
if form.is_valid(): if form.is_valid():
quest.title = form.cleaned_data['quest_title']
quest.anon_name = form.cleaned_data['anon_name'] quest.anon_name = form.cleaned_data['anon_name']
quest.live = form.cleaned_data['live'] 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_date = form.cleaned_data['live_date']
live_time = form.cleaned_data['live_time'] live_time = form.cleaned_data['live_time']
@ -140,9 +135,6 @@ def new_quest(request):
if quest_form.is_valid(): if quest_form.is_valid():
quest = quest_form.save(commit=False) quest = quest_form.save(commit=False)
quest.owner = request.user 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.save()
quest_form.save_m2m() quest_form.save_m2m()
print(quest.tags.names()) print(quest.tags.names())

3
todo
View File

@ -1,13 +1,12 @@
New Features: New Features:
Notifications Notifications
Banner images
Front page to show new quests Front page to show new quests
Webm posting Webm posting
(you) counter (you) counter
Account managament Account managament
Display profile link in header bar Display profile link in header bar
Quote backlinks Quote backlinks
Email
RSS
Improvements: Improvements:
More options for text posts (lists and so on) More options for text posts (lists and so on)