mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-13 06:34:25 -04:00
commit
6c704fa8cf
2 changed files with 17 additions and 0 deletions
|
@ -114,12 +114,23 @@ class AddView(UserPassesTestMixin, FormView):
|
||||||
template_name = "add_links.html"
|
template_name = "add_links.html"
|
||||||
form_class = AddLinkForm
|
form_class = AddLinkForm
|
||||||
|
|
||||||
|
def get_initial(self):
|
||||||
|
"""Prefill the AddLinkForm with the 'url' GET parameter"""
|
||||||
|
if self.request.method == 'GET':
|
||||||
|
url = self.request.GET.get('url', None)
|
||||||
|
if url:
|
||||||
|
return {'url': url}
|
||||||
|
else:
|
||||||
|
return super().get_initial()
|
||||||
|
|
||||||
def test_func(self):
|
def test_func(self):
|
||||||
return PUBLIC_ADD_VIEW or self.request.user.is_authenticated
|
return PUBLIC_ADD_VIEW or self.request.user.is_authenticated
|
||||||
|
|
||||||
def get_context_data(self, *args, **kwargs):
|
def get_context_data(self, *args, **kwargs):
|
||||||
context = super().get_context_data(*args, **kwargs)
|
context = super().get_context_data(*args, **kwargs)
|
||||||
context["title"] = "Add URLs"
|
context["title"] = "Add URLs"
|
||||||
|
# We can't just call request.build_absolute_uri in the template, because it would include query parameters
|
||||||
|
context["absolute_add_path"] = self.request.build_absolute_uri(self.request.path)
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
|
|
|
@ -49,6 +49,12 @@
|
||||||
<small>(it's safe to leave this page, adding will continue in the background)</small>
|
<small>(it's safe to leave this page, adding will continue in the background)</small>
|
||||||
</div>
|
</div>
|
||||||
</center>
|
</center>
|
||||||
|
{% if absolute_add_path %}
|
||||||
|
<center id="bookmarklet">
|
||||||
|
<p>Bookmark this link to quickly add to your archive:
|
||||||
|
<a href="javascript:void(window.open('{{ absolute_add_path }}?url='+document.location.href));">Add to ArchiveBox</a></p>
|
||||||
|
</center>
|
||||||
|
{% endif %}
|
||||||
<script>
|
<script>
|
||||||
document.getElementById('add-form').addEventListener('submit', function(event) {
|
document.getElementById('add-form').addEventListener('submit', function(event) {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue