Added error when there is a restricted audios buffer
This commit is contained in:
parent
561ed25054
commit
73d9400dc8
@ -12,6 +12,7 @@ from sessionmanager import session
|
|||||||
from mysc.thread_utils import call_threaded
|
from mysc.thread_utils import call_threaded
|
||||||
from wxUI import commonMessages
|
from wxUI import commonMessages
|
||||||
from vk import upload
|
from vk import upload
|
||||||
|
from vk.exceptions import VkAPIMethodError
|
||||||
|
|
||||||
class baseBuffer(object):
|
class baseBuffer(object):
|
||||||
""" a basic representation of a buffer. Other buffers should be derived from this class"""
|
""" a basic representation of a buffer. Other buffers should be derived from this class"""
|
||||||
@ -44,8 +45,15 @@ class baseBuffer(object):
|
|||||||
|
|
||||||
def get_items(self, show_nextpage=False):
|
def get_items(self, show_nextpage=False):
|
||||||
""" Retrieves items from the VK API. This function is called repeatedly by the main controller and users could call it implicitly as well with the update buffer option.
|
""" Retrieves items from the VK API. This function is called repeatedly by the main controller and users could call it implicitly as well with the update buffer option.
|
||||||
show_nextpage boolean: If it's true, it will try to load previous results."""
|
show_nextpage boolean: If it's true, it will try to load previous results.
|
||||||
|
"""
|
||||||
|
retrieved = True # Control variable for handling unauthorised/connection errors.
|
||||||
|
try:
|
||||||
num = getattr(self.session, "get_newsfeed")(show_nextpage=show_nextpage, name=self.name, *self.args, **self.kwargs)
|
num = getattr(self.session, "get_newsfeed")(show_nextpage=show_nextpage, name=self.name, *self.args, **self.kwargs)
|
||||||
|
except VkAPIMethodError as err:
|
||||||
|
print(u"Error {0}: {1}".format(err.code, err.message))
|
||||||
|
retrieved = err.code
|
||||||
|
return retrieved
|
||||||
if show_nextpage == False:
|
if show_nextpage == False:
|
||||||
if self.tab.list.get_count() > 0 and num > 0:
|
if self.tab.list.get_count() > 0 and num > 0:
|
||||||
print "inserting a value"
|
print "inserting a value"
|
||||||
@ -57,6 +65,7 @@ class baseBuffer(object):
|
|||||||
else:
|
else:
|
||||||
if num > 0:
|
if num > 0:
|
||||||
[self.insert(i, False) for i in self.session.db[self.name]["items"][:num]]
|
[self.insert(i, False) for i in self.session.db[self.name]["items"][:num]]
|
||||||
|
return retrieved
|
||||||
|
|
||||||
def get_more_items(self):
|
def get_more_items(self):
|
||||||
self.get_items(show_nextpage=True)
|
self.get_items(show_nextpage=True)
|
||||||
@ -140,7 +149,7 @@ class baseBuffer(object):
|
|||||||
def pause_audio(self, *args, **kwargs):
|
def pause_audio(self, *args, **kwargs):
|
||||||
player.player.pause()
|
player.player.pause()
|
||||||
|
|
||||||
def remove_buffer(self): return False
|
def remove_buffer(self, mandatory): return False
|
||||||
|
|
||||||
def get_users(self):
|
def get_users(self):
|
||||||
post = self.session.db[self.name]["items"][self.tab.list.get_selected()]
|
post = self.session.db[self.name]["items"][self.tab.list.get_selected()]
|
||||||
@ -152,8 +161,14 @@ class baseBuffer(object):
|
|||||||
class feedBuffer(baseBuffer):
|
class feedBuffer(baseBuffer):
|
||||||
|
|
||||||
def get_items(self, show_nextpage=False):
|
def get_items(self, show_nextpage=False):
|
||||||
|
retrieved = True
|
||||||
|
try:
|
||||||
num = getattr(self.session, "get_page")(show_nextpage=show_nextpage, name=self.name, *self.args, **self.kwargs)
|
num = getattr(self.session, "get_page")(show_nextpage=show_nextpage, name=self.name, *self.args, **self.kwargs)
|
||||||
print num
|
print num
|
||||||
|
except VkAPIMethodError as err:
|
||||||
|
print(u"Error {0}: {1}".format(err.code, err.message))
|
||||||
|
retrieved = err.code
|
||||||
|
return retrieved
|
||||||
if show_nextpage == False:
|
if show_nextpage == False:
|
||||||
if self.tab.list.get_count() > 0 and num > 0:
|
if self.tab.list.get_count() > 0 and num > 0:
|
||||||
print "inserting a value"
|
print "inserting a value"
|
||||||
@ -162,6 +177,7 @@ class feedBuffer(baseBuffer):
|
|||||||
[self.insert(i, True) for i in v]
|
[self.insert(i, True) for i in v]
|
||||||
else:
|
else:
|
||||||
[self.insert(i) for i in self.session.db[self.name]["items"][:num]]
|
[self.insert(i) for i in self.session.db[self.name]["items"][:num]]
|
||||||
|
return retrieved
|
||||||
|
|
||||||
class audioBuffer(feedBuffer):
|
class audioBuffer(feedBuffer):
|
||||||
def create_tab(self, parent):
|
def create_tab(self, parent):
|
||||||
@ -190,19 +206,21 @@ class audioBuffer(feedBuffer):
|
|||||||
audios = [i for i in self.session.db[self.name]["items"][selected:]]
|
audios = [i for i in self.session.db[self.name]["items"][selected:]]
|
||||||
pub.sendMessage("play-audios", audios=audios)
|
pub.sendMessage("play-audios", audios=audios)
|
||||||
|
|
||||||
def remove_buffer(self):
|
def remove_buffer(self, mandatory):
|
||||||
if "me_audio" == self.name or "popular_audio" == self.name or "recommended_audio" == self.name:
|
if "me_audio" == self.name or "popular_audio" == self.name or "recommended_audio" == self.name:
|
||||||
output.speak(_(u"This buffer can't be deleted"))
|
output.speak(_(u"This buffer can't be deleted"))
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
|
if mandatory == False:
|
||||||
dlg = commonMessages.remove_buffer()
|
dlg = commonMessages.remove_buffer()
|
||||||
|
else:
|
||||||
|
dlg = widgetUtils.YES
|
||||||
if dlg == widgetUtils.YES:
|
if dlg == widgetUtils.YES:
|
||||||
self.session.db.pop(self.name)
|
self.session.db.pop(self.name)
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def get_more_items(self, *args, **kwargs):
|
def get_more_items(self, *args, **kwargs):
|
||||||
output.speak(_(u"This buffer doesn't support getting more items."))
|
output.speak(_(u"This buffer doesn't support getting more items."))
|
||||||
|
|
||||||
@ -218,4 +236,4 @@ class empty(object):
|
|||||||
def get_more_items(self, *args, **kwargs):
|
def get_more_items(self, *args, **kwargs):
|
||||||
output.speak(_(u"This buffer doesn't support getting more items."))
|
output.speak(_(u"This buffer doesn't support getting more items."))
|
||||||
|
|
||||||
def remove_buffer(self): return False
|
def remove_buffer(self, mandatory): return False
|
||||||
|
@ -171,10 +171,10 @@ class Controller(object):
|
|||||||
def update_status_bar(self, status):
|
def update_status_bar(self, status):
|
||||||
self.window.change_status(status)
|
self.window.change_status(status)
|
||||||
|
|
||||||
def remove_buffer(self, *args, **kwargs):
|
def remove_buffer(self, mandatory=False, *args, **kwargs):
|
||||||
buffer = self.get_current_buffer()
|
buffer = self.get_current_buffer()
|
||||||
buff = self.window.search(buffer.name)
|
buff = self.window.search(buffer.name)
|
||||||
answer = buffer.remove_buffer()
|
answer = buffer.remove_buffer(mandatory)
|
||||||
if answer == False:
|
if answer == False:
|
||||||
return
|
return
|
||||||
self.window.remove_buffer(buff)
|
self.window.remove_buffer(buff)
|
||||||
@ -217,5 +217,13 @@ class Controller(object):
|
|||||||
if buffertype == "audio":
|
if buffertype == "audio":
|
||||||
audio = buffers.audioBuffer(parent=self.window.tb, name="{0}_audio".format(user_id,), composefunc="compose_audio", session=self.session, endpoint="get", parent_endpoint="audio", full_list=True, count=self.session.settings["buffers"]["count_for_audio_buffers"], user_id=user_id)
|
audio = buffers.audioBuffer(parent=self.window.tb, name="{0}_audio".format(user_id,), composefunc="compose_audio", session=self.session, endpoint="get", parent_endpoint="audio", full_list=True, count=self.session.settings["buffers"]["count_for_audio_buffers"], user_id=user_id)
|
||||||
self.buffers.append(audio)
|
self.buffers.append(audio)
|
||||||
call_threaded(audio.get_items)
|
call_threaded(self.complete_buffer_creation, buffer=audio, name_=_(u"{0}'s audios").format(user,), position=self.window.search("timelines"))
|
||||||
self.window.insert_buffer(audio.tab, _(u"{0}'s audios").format(user,), self.window.search("timelines"))
|
|
||||||
|
def complete_buffer_creation(self, buffer, name_, position):
|
||||||
|
answer = buffer.get_items()
|
||||||
|
if answer is not True:
|
||||||
|
self.buffers.remove(buffer)
|
||||||
|
del buffer
|
||||||
|
commonMessages.show_error_code(answer)
|
||||||
|
return
|
||||||
|
self.window.insert_buffer(buffer.tab, name_, position)
|
@ -13,3 +13,11 @@ def remove_buffer():
|
|||||||
|
|
||||||
def no_user_exist():
|
def no_user_exist():
|
||||||
wx.MessageDialog(None, _(u"This user does not exist"), _(u"Error"), style=wx.ICON_ERROR).ShowModal()
|
wx.MessageDialog(None, _(u"This user does not exist"), _(u"Error"), style=wx.ICON_ERROR).ShowModal()
|
||||||
|
|
||||||
|
def show_error_code(code):
|
||||||
|
title = ""
|
||||||
|
message = ""
|
||||||
|
if code == 201:
|
||||||
|
title = _(u"Restricted access")
|
||||||
|
message = _(u"Access to user's audio is denied by the owner. Error code {0}").format(code,)
|
||||||
|
return wx.MessageDialog(None, message, title, style=wx.ICON_ERROR).ShowModal()
|
Loading…
Reference in New Issue
Block a user