fixed not beeing able to open external recipes when internal exists

This commit is contained in:
vabene1111 2019-12-25 19:47:11 +01:00
parent 6a010587bf
commit 9d0a6e63f8
4 changed files with 28 additions and 7 deletions

View File

@ -43,12 +43,15 @@
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
function openRecipe(id) { function openRecipe(id, force_external = false) {
var link = $('#a_recipe_open'); var link = $('#a_recipe_open');
link.hide(); link.hide();
$('#div_loader').show(); $('#div_loader').show();
var url = "{% url 'api_get_file_link' recipe_id=12345 %}".replace(/12345/, id); var url = "{% url 'api_get_file_link' recipe_id=12345 %}".replace(/12345/, id);
if (force_external) {
url = "{% url 'api_get_external_file_link' recipe_id=12345 %}".replace(/12345/, id);
}
link.text("{% trans 'Open Recipe' %}"); link.text("{% trans 'Open Recipe' %}");
$('#modal_recipe').modal('show'); $('#modal_recipe').modal('show');

View File

@ -110,7 +110,7 @@
{% endif %} {% endif %}
{% if recipe.storage %} {% if recipe.storage %}
<a href='#' onClick='openRecipe({{ recipe.id }})'>{% trans 'View external recipe' %} <i <a href='#' onClick='openRecipe({{ recipe.id }}, true)'>{% trans 'View external recipe' %} <i
class="fas fa-external-link-alt"></i></a> class="fas fa-external-link-alt"></i></a>
{% endif %} {% endif %}

View File

@ -54,6 +54,9 @@ urlpatterns = [
path('data/statistics', data.statistics, name='data_stats'), path('data/statistics', data.statistics, name='data_stats'),
path('api/get_file_link/<int:recipe_id>/', api.get_file_link, name='api_get_file_link'), path('api/get_file_link/<int:recipe_id>/', api.get_file_link, name='api_get_file_link'),
path('api/get_external_file_link/<int:recipe_id>/', api.get_external_file_link, name='api_get_external_file_link'),
path('api/sync_all/', api.sync_all, name='api_sync'), path('api/sync_all/', api.sync_all, name='api_sync'),
path('dal/keyword/', dal.KeywordAutocomplete.as_view(), name='dal_keyword'), path('dal/keyword/', dal.KeywordAutocomplete.as_view(), name='dal_keyword'),

View File

@ -6,7 +6,6 @@ from django.contrib.auth.decorators import login_required
from django.shortcuts import redirect from django.shortcuts import redirect
from cookbook.models import Recipe, Sync, Storage from cookbook.models import Recipe, Sync, Storage
from cookbook.provider import dropbox
from cookbook.provider.dropbox import Dropbox from cookbook.provider.dropbox import Dropbox
from cookbook.provider.nextcloud import Nextcloud from cookbook.provider.nextcloud import Nextcloud
@ -17,7 +16,23 @@ def get_file_link(request, recipe_id):
if recipe.internal: if recipe.internal:
return HttpResponse(reverse('view_recipe', args=[recipe_id])) return HttpResponse(reverse('view_recipe', args=[recipe_id]))
if recipe.storage.method == Storage.DROPBOX: if recipe.storage.method == Storage.DROPBOX: # TODO move to central location (as all provider related functions)
if recipe.link == "":
recipe.link = Dropbox.get_share_link(recipe) # TODO response validation
recipe.save()
if recipe.storage.method == Storage.NEXTCLOUD:
if recipe.link == "":
recipe.link = Nextcloud.get_share_link(recipe) # TODO response validation
recipe.save()
return HttpResponse(recipe.link)
@login_required
def get_external_file_link(request, recipe_id):
recipe = Recipe.objects.get(id=recipe_id)
if recipe.storage.method == Storage.DROPBOX: # TODO move to central location (as all provider related functions)
if recipe.link == "": if recipe.link == "":
recipe.link = Dropbox.get_share_link(recipe) # TODO response validation recipe.link = Dropbox.get_share_link(recipe) # TODO response validation
recipe.save() recipe.save()