Added possible base_url

This commit is contained in:
Amazed 2018-11-28 23:13:12 +01:00
parent 91d7839703
commit f61a6c42c5
6 changed files with 17 additions and 13 deletions

View File

@ -7,5 +7,9 @@ def BASE_URL(request):
else:
scheme = 'http://'
fullhost = request.get_host()
port = fullhost.split(":")[1]
if port == 80 or port == 443:
base = fullhost.split(":")[0]
else:
base = fullhost
return {'BASE_URL': scheme + base, }

View File

@ -19,7 +19,7 @@
<div id="collapse{{ feed.id }}" class="collapse" aria-labelledby="heading{{ feed.id }}" data-parent="#accordionExample">
<div class="card-body">
<code>{{ BASE_URL }}/{{ feed.uurl }}.rss</code>
<code>{{ BASE_URL }}{% url 'rss' uurl=feed.uurl %}</code>
<p><a class="btn btn-danger" href="{% url 'feed_delete' feed.id %}">Delete</a></p>
</div>
</div>

View File

@ -5,7 +5,7 @@
<div class="col-lg-12 text-center">
<h1 class="mt-5">Generate RSS out of any website</h1>
{% if error %}<div class="alert alert-danger" role="alert">{{ error }}</div>{% endif %}
<form action="/" method="post">
<form action="{% url 'homepage' %}" method="post">
{% csrf_token %}
<div class="form-group">
<input type="text" class="form-control" name="url" id="url" placeholder="http://" {% if url %}value="{{ url }}"{% endif %}>

View File

@ -29,7 +29,7 @@
<code style="display:block" id="link-selector"></code>
</li>
<li>
<form action="/newfeed" method="post">
<form action="{% url 'newfeed' %}" method="post">
{% csrf_token %}
<input type="hidden" id="url" name="url" value="{{ url }}">
<input type="hidden" id="element" name="element" value="">
@ -44,7 +44,7 @@
</ul>
</div>
<!-- /#sidebar-wrapper -->
<iframe id="preview" style="width:100%" src="/iframe/{{ url }}"></iframe>
<iframe id="preview" style="width:100%" src="{% url 'iframe' url=url %}"></iframe>
<script>
$(function() {
function handleResize() {

View File

@ -26,14 +26,14 @@
<!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark static-top">
<div class="container">
<a class="navbar-brand" href="/">HRSS</a>
<a class="navbar-brand" href="{% url 'homepage' %}">HRSS</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="/">New
<a class="nav-link" href="{% url 'homepage' %}">New
<span class="sr-only">(current)</span>
</a>
</li>

View File

@ -68,7 +68,7 @@ def homepage(request):
if "url" in request.POST and request.POST["url"]:
url = request.POST["url"]
if is_valid_url(url):
return redirect("/setup/"+url)
return redirect("setup", url=url)
else:
return render(request, 'homepage.html', {"url": url, "error": url+" is not a valid URL."})
return render(request, 'homepage.html')
@ -77,7 +77,7 @@ def setup(request, url):
if is_valid_url(url):
return render(request, 'setup.html', {"url": url})
else:
return redirect("/")
return redirect("homepage")
def newfeed(request):
@ -110,9 +110,9 @@ def newfeed(request):
feed = Feed(url=url, element=element, title=title, content=content, date=date, author=author, link=link)
feed.save()
return redirect("/feeds")
return redirect("feeds")
else:
return redirect("/")
return redirect("homepage")
def feeds(request):
feeds = Feed.objects.all()
@ -124,11 +124,11 @@ def feed_delete(request, id):
if not request.get_host() == "hrss.hipstercat.fr:443":
Feed.objects.get(pk=id).delete()
logger.info("Removed feed ID "+id)
return redirect("/feeds")
return redirect("feeds")
else:
return HttpResponse("Deleting is disabled on demo website.", status=403)
except ObjectDoesNotExist:
return redirect("/feeds")
return redirect("feeds")
def rss(request, uurl):
try: