Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix adding 2+ shows (that need searching) using Add Existing Show #4298

Merged
merged 2 commits into from
Jun 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions medusa/server/web/home/add_shows.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from medusa.show.show import Show

from requests import RequestException
from requests.compat import unquote_plus
from requests.compat import quote_plus, unquote_plus

from simpleanidb import REQUEST_HOT

Expand All @@ -34,6 +34,21 @@
from traktor import TraktApi


def json_redirect(url, params=None):
"""
Make a JSON redirect.
:param url: URL to redirect to
:param params: Query params to append, as a list of tuple(key, value) items
"""
if not params:
params = []
url = url.strip('/')
for index, param in enumerate(params):
url += '?' if not index else '&'
url += quote_plus(param[0]) + '=' + quote_plus(param[1])
return json.dumps({'redirect': url})


@route('/addShows(/?.*)')
class HomeAddShows(Home):
def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -417,14 +432,16 @@ def addNewShow(self, whichSeries=None, indexer_lang=None, rootDir=None, defaultS
def finishAddShow():
# if there are no extra shows then go home
if not other_shows:
return self.redirect('/home/')

# peel off the next one
next_show_dir = other_shows[0]
rest_of_show_dirs = other_shows[1:]
return json_redirect('/home/')

# go to add the next show
return self.newShow(next_show_dir, rest_of_show_dirs)
return json_redirect(
'/addShows/newShow/',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this also need the other query params like if the user wants auto settings or settings picked manually for each, etc?

Copy link
Contributor Author

@sharkykh sharkykh Jun 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because the form on addShow/existingShows doesn't POST to this endpoint (addShow/addNewShow), but rather to addShow/addExistingShows (notice add at the start).
This ^ endpoint handles the promptForSettings stuff and then redirects us to the addShow/newShow page with the correct parameters. That's why the first show that needs searching always works.

It's only addShow/newShow that POSTs to addShow/addNewShow which needs this patch, at least for right now.

[
('show_to_add' if not i else 'other_shows', cur_dir)
for i, cur_dir in enumerate(other_shows)
]
)

# if we're skipping then behave accordingly
if skipShow:
Expand All @@ -442,7 +459,7 @@ def finishAddShow():
logger.log(u'Unable to add show due to show selection. Not enough arguments: %s' % (repr(series_pieces)),
logger.ERROR)
ui.notifications.error('Unknown error. Unable to add show due to problem with show selection.')
return self.redirect('/addShows/existingShows/')
return json_redirect('/addShows/existingShows/')

indexer = int(series_pieces[1])
indexer_id = int(series_pieces[3])
Expand All @@ -465,7 +482,7 @@ def finishAddShow():
# blanket policy - if the dir exists you should have used 'add existing show' numbnuts
if os.path.isdir(show_dir) and not fullShowPath:
ui.notifications.error('Unable to add show', 'Folder {path} exists already'.format(path=show_dir))
return self.redirect('/addShows/existingShows/')
return json_redirect('/addShows/existingShows/')

# don't create show dir if config says not to
if app.ADD_SHOWS_WO_DIR:
Expand All @@ -479,7 +496,7 @@ def finishAddShow():
ui.notifications.error('Unable to add show',
'Unable to create the folder {path}, can\'t add the show'.format(path=show_dir))
# Don't redirect to default page because user wants to see the new show
return self.redirect('/home/')
return json_redirect('/home/')
else:
helpers.chmod_as_parent(show_dir)

Expand Down
17 changes: 13 additions & 4 deletions themes-default/slim/static/js/vue-submit-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,19 @@ window.vueSubmitForm = async function(formId) {
// }), {});
this.$http[method](path, { body: formData, redirect: 'follow' })
.then(resp => {
// If the new url differs from our current url and the form action - we've been redirected
if (resp.url !== window.location.href && resp.url !== base + path) {
window.location.href = resp.url;
} else if (redirect) {
try {
const json = JSON.parse(resp.body);
const { redirect } = json;
if (redirect) {
window.location.href = base + redirect;
return;
}
} catch (e) {
// Ignore
}

// Fallback
if (redirect) {
window.location.href = base + redirect;
}
});
Expand Down
17 changes: 13 additions & 4 deletions themes/dark/assets/js/vue-submit-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,19 @@ window.vueSubmitForm = async function(formId) {
// }), {});
this.$http[method](path, { body: formData, redirect: 'follow' })
.then(resp => {
// If the new url differs from our current url and the form action - we've been redirected
if (resp.url !== window.location.href && resp.url !== base + path) {
window.location.href = resp.url;
} else if (redirect) {
try {
const json = JSON.parse(resp.body);
const { redirect } = json;
if (redirect) {
window.location.href = base + redirect;
return;
}
} catch (e) {
// Ignore
}

// Fallback
if (redirect) {
window.location.href = base + redirect;
}
});
Expand Down
2 changes: 1 addition & 1 deletion themes/dark/assets/js/vue-submit-form.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions themes/light/assets/js/vue-submit-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,19 @@ window.vueSubmitForm = async function(formId) {
// }), {});
this.$http[method](path, { body: formData, redirect: 'follow' })
.then(resp => {
// If the new url differs from our current url and the form action - we've been redirected
if (resp.url !== window.location.href && resp.url !== base + path) {
window.location.href = resp.url;
} else if (redirect) {
try {
const json = JSON.parse(resp.body);
const { redirect } = json;
if (redirect) {
window.location.href = base + redirect;
return;
}
} catch (e) {
// Ignore
}

// Fallback
if (redirect) {
window.location.href = base + redirect;
}
});
Expand Down
2 changes: 1 addition & 1 deletion themes/light/assets/js/vue-submit-form.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.