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: else:
scheme = 'http://' scheme = 'http://'
fullhost = request.get_host() fullhost = request.get_host()
port = fullhost.split(":")[1]
if port == 80 or port == 443:
base = fullhost.split(":")[0] base = fullhost.split(":")[0]
else:
base = fullhost
return {'BASE_URL': scheme + base, } 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 id="collapse{{ feed.id }}" class="collapse" aria-labelledby="heading{{ feed.id }}" data-parent="#accordionExample">
<div class="card-body"> <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> <p><a class="btn btn-danger" href="{% url 'feed_delete' feed.id %}">Delete</a></p>
</div> </div>
</div> </div>

View File

@ -5,7 +5,7 @@
<div class="col-lg-12 text-center"> <div class="col-lg-12 text-center">
<h1 class="mt-5">Generate RSS out of any website</h1> <h1 class="mt-5">Generate RSS out of any website</h1>
{% if error %}<div class="alert alert-danger" role="alert">{{ error }}</div>{% endif %} {% if error %}<div class="alert alert-danger" role="alert">{{ error }}</div>{% endif %}
<form action="/" method="post"> <form action="{% url 'homepage' %}" method="post">
{% csrf_token %} {% csrf_token %}
<div class="form-group"> <div class="form-group">
<input type="text" class="form-control" name="url" id="url" placeholder="http://" {% if url %}value="{{ url }}"{% endif %}> <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> <code style="display:block" id="link-selector"></code>
</li> </li>
<li> <li>
<form action="/newfeed" method="post"> <form action="{% url 'newfeed' %}" method="post">
{% csrf_token %} {% csrf_token %}
<input type="hidden" id="url" name="url" value="{{ url }}"> <input type="hidden" id="url" name="url" value="{{ url }}">
<input type="hidden" id="element" name="element" value=""> <input type="hidden" id="element" name="element" value="">
@ -44,7 +44,7 @@
</ul> </ul>
</div> </div>
<!-- /#sidebar-wrapper --> <!-- /#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> <script>
$(function() { $(function() {
function handleResize() { function handleResize() {

View File

@ -26,14 +26,14 @@
<!-- Navigation --> <!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark static-top"> <nav class="navbar navbar-expand-lg navbar-dark bg-dark static-top">
<div class="container"> <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"> <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> <span class="navbar-toggler-icon"></span>
</button> </button>
<div class="collapse navbar-collapse" id="navbarResponsive"> <div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto"> <ul class="navbar-nav ml-auto">
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="/">New <a class="nav-link" href="{% url 'homepage' %}">New
<span class="sr-only">(current)</span> <span class="sr-only">(current)</span>
</a> </a>
</li> </li>

View File

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