Added basic creation of document buffers in communities
This commit is contained in:
parent
21895d307b
commit
3f7c069ce0
@ -500,6 +500,25 @@ class topicBuffer(feedBuffer):
|
|||||||
return
|
return
|
||||||
a = presenters.displayTopicPresenter(session=self.session, postObject=post, group_id=self.kwargs["group_id"], interactor=interactors.displayPostInteractor(), view=views.displayTopic())
|
a = presenters.displayTopicPresenter(session=self.session, postObject=post, group_id=self.kwargs["group_id"], interactor=interactors.displayPostInteractor(), view=views.displayTopic())
|
||||||
|
|
||||||
|
class documentBuffer(feedBuffer):
|
||||||
|
|
||||||
|
def create_tab(self, parent):
|
||||||
|
self.tab = home.documentTab(parent)
|
||||||
|
self.connect_events()
|
||||||
|
self.tab.name = self.name
|
||||||
|
if hasattr(self, "can_post") and self.can_post == False and hasattr(self.tab, "post"):
|
||||||
|
self.tab.post.Enable(False)
|
||||||
|
|
||||||
|
def onFocus(self, *args, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def open_post(self, *args, **kwargs):
|
||||||
|
""" Opens the currently focused post."""
|
||||||
|
post = self.get_post()
|
||||||
|
if post == None:
|
||||||
|
return
|
||||||
|
print(post)
|
||||||
|
|
||||||
class audioBuffer(feedBuffer):
|
class audioBuffer(feedBuffer):
|
||||||
""" this buffer was supposed to be used with audio elements
|
""" this buffer was supposed to be used with audio elements
|
||||||
but is deprecated as VK removed its audio support for third party apps."""
|
but is deprecated as VK removed its audio support for third party apps."""
|
||||||
|
@ -191,7 +191,7 @@ class Controller(object):
|
|||||||
# disable post loading if the community has already loaded posts.
|
# disable post loading if the community has already loaded posts.
|
||||||
if current_buffer.can_get_items:
|
if current_buffer.can_get_items:
|
||||||
menu.load_posts.Enable(False)
|
menu.load_posts.Enable(False)
|
||||||
# Disable loading of audios, videos or topics depending in two conditions.
|
# Disable loading of audios, videos, documents or topics depending in two conditions.
|
||||||
# 1. If the buffer already exists, which means they are already loaded, or
|
# 1. If the buffer already exists, which means they are already loaded, or
|
||||||
# 2. If the group_info does not have counters for such items, which would indicate there are no items posted yet.
|
# 2. If the group_info does not have counters for such items, which would indicate there are no items posted yet.
|
||||||
if self.search(current_buffer.name+"_audios") != False:
|
if self.search(current_buffer.name+"_audios") != False:
|
||||||
@ -206,12 +206,17 @@ class Controller(object):
|
|||||||
menu.load_topics.Enable(False)
|
menu.load_topics.Enable(False)
|
||||||
elif hasattr(current_buffer, "group_info") and "topics" not in current_buffer.group_info["counters"]:
|
elif hasattr(current_buffer, "group_info") and "topics" not in current_buffer.group_info["counters"]:
|
||||||
menu.load_topics.Enable(False)
|
menu.load_topics.Enable(False)
|
||||||
|
|
||||||
|
if self.search(current_buffer.name+"_documents") != False:
|
||||||
|
menu.load_documents.Enable(False)
|
||||||
|
elif hasattr(current_buffer, "group_info") and "docs" not in current_buffer.group_info["counters"]:
|
||||||
|
menu.load_documents.Enable(False)
|
||||||
# Connect the rest of the functions.
|
# Connect the rest of the functions.
|
||||||
widgetUtils.connect_event(menu, widgetUtils.MENU, self.load_community_posts, menuitem=menu.load_posts)
|
widgetUtils.connect_event(menu, widgetUtils.MENU, self.load_community_posts, menuitem=menu.load_posts)
|
||||||
widgetUtils.connect_event(menu, widgetUtils.MENU, self.load_community_topics, menuitem=menu.load_topics)
|
widgetUtils.connect_event(menu, widgetUtils.MENU, self.load_community_topics, menuitem=menu.load_topics)
|
||||||
widgetUtils.connect_event(menu, widgetUtils.MENU, self.load_community_audios, menuitem=menu.load_audios)
|
widgetUtils.connect_event(menu, widgetUtils.MENU, self.load_community_audios, menuitem=menu.load_audios)
|
||||||
widgetUtils.connect_event(menu, widgetUtils.MENU, self.load_community_videos, menuitem=menu.load_videos)
|
widgetUtils.connect_event(menu, widgetUtils.MENU, self.load_community_videos, menuitem=menu.load_videos)
|
||||||
|
widgetUtils.connect_event(menu, widgetUtils.MENU, self.load_community_documents, menuitem=menu.load_documents)
|
||||||
# Deal with the communities section itself.
|
# Deal with the communities section itself.
|
||||||
if current_buffer.name == "communities":
|
if current_buffer.name == "communities":
|
||||||
menu = wx.Menu()
|
menu = wx.Menu()
|
||||||
@ -819,6 +824,18 @@ class Controller(object):
|
|||||||
new_name = current_buffer.name+"_topics"
|
new_name = current_buffer.name+"_topics"
|
||||||
wx.CallAfter(pub.sendMessage, "create_buffer", buffer_type="topicBuffer", buffer_title=_("Topics"), parent_tab=current_buffer.tab.name, get_items=True, kwargs=dict(parent=self.window.tb, name=new_name, composefunc="render_topic", session=self.session, endpoint="getTopics", parent_endpoint="board", count=100, group_id=-1*current_buffer.kwargs["owner_id"], extended=1))
|
wx.CallAfter(pub.sendMessage, "create_buffer", buffer_type="topicBuffer", buffer_title=_("Topics"), parent_tab=current_buffer.tab.name, get_items=True, kwargs=dict(parent=self.window.tb, name=new_name, composefunc="render_topic", session=self.session, endpoint="getTopics", parent_endpoint="board", count=100, group_id=-1*current_buffer.kwargs["owner_id"], extended=1))
|
||||||
|
|
||||||
|
def load_community_documents(self, *args, **kwargs):
|
||||||
|
current_buffer = self.get_current_buffer()
|
||||||
|
# Get group_info if the community buffer does not have it already, so future menus will be able to use it.
|
||||||
|
if not hasattr(current_buffer, "group_info"):
|
||||||
|
group_info = self.session.vk.client.groups.getById(group_ids=-1*current_buffer.kwargs["owner_id"], fields="counters")[0]
|
||||||
|
current_buffer.group_info = group_info
|
||||||
|
if "docs" not in current_buffer.group_info["counters"]:
|
||||||
|
commonMessages.community_no_items()
|
||||||
|
return
|
||||||
|
new_name = current_buffer.name+"_documents"
|
||||||
|
wx.CallAfter(pub.sendMessage, "create_buffer", buffer_type="documentBuffer", buffer_title=_("Documents"), parent_tab=current_buffer.tab.name, get_items=True, kwargs=dict(parent=self.window.tb, name=new_name, composefunc="render_document", session=self.session, endpoint="get", parent_endpoint="docs", owner_id=current_buffer.kwargs["owner_id"]))
|
||||||
|
|
||||||
def load_community_buffers(self, *args, **kwargs):
|
def load_community_buffers(self, *args, **kwargs):
|
||||||
""" Load all community buffers regardless of the setting present in optional buffers tab of the preferences dialog."""
|
""" Load all community buffers regardless of the setting present in optional buffers tab of the preferences dialog."""
|
||||||
call_threaded(self.get_communities, self.session.user_id, force_action=True)
|
call_threaded(self.get_communities, self.session.user_id, force_action=True)
|
||||||
@ -831,3 +848,4 @@ class Controller(object):
|
|||||||
self.window.remove_buffer(buff)
|
self.window.remove_buffer(buff)
|
||||||
self.buffers.remove(buffer)
|
self.buffers.remove(buffer)
|
||||||
del self.session.groups
|
del self.session.groups
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ Chat messages, audios, videos, photos, comments in posts, etc)"""
|
|||||||
import arrow
|
import arrow
|
||||||
import languageHandler
|
import languageHandler
|
||||||
import logging
|
import logging
|
||||||
|
from update.utils import convert_bytes
|
||||||
from . utils import seconds_to_string, clean_text
|
from . utils import seconds_to_string, clean_text
|
||||||
|
|
||||||
log = logging.getLogger(__file__)
|
log = logging.getLogger(__file__)
|
||||||
@ -244,6 +245,8 @@ def render_audio_message(audio_message, session=None):
|
|||||||
return [seconds_to_string(audio_message["duration"])]
|
return [seconds_to_string(audio_message["duration"])]
|
||||||
|
|
||||||
def render_topic(topic, session):
|
def render_topic(topic, session):
|
||||||
|
""" Render topics for a community.
|
||||||
|
Reference: https://vk.com/dev/objects/topic"""
|
||||||
user = session.get_user(topic["created_by"])
|
user = session.get_user(topic["created_by"])
|
||||||
title = topic["title"]
|
title = topic["title"]
|
||||||
comments = topic["comments"]
|
comments = topic["comments"]
|
||||||
@ -252,3 +255,12 @@ def render_topic(topic, session):
|
|||||||
last_commenter.update(date=last_update)
|
last_commenter.update(date=last_update)
|
||||||
lastupdate = _("Last post by {user1_nom} {date}").format(**last_commenter)
|
lastupdate = _("Last post by {user1_nom} {date}").format(**last_commenter)
|
||||||
return [user["user1_nom"], title, str(comments), lastupdate]
|
return [user["user1_nom"], title, str(comments), lastupdate]
|
||||||
|
|
||||||
|
def render_document(document, session):
|
||||||
|
doc_types = {1: _("Text document"), 2: _("Archive"), 3: _("Gif"), 4: _("Image"), 5: _("Audio"), 6: _("Video"), 7: _("Ebook"), 8: _("Unknown document")}
|
||||||
|
user = session.get_user(document["owner_id"])
|
||||||
|
title = document["title"]
|
||||||
|
size = convert_bytes(document["size"])
|
||||||
|
date = arrow.get(document["date"]).humanize(locale=languageHandler.curLang[:2])
|
||||||
|
doc_type = doc_types[document["type"]]
|
||||||
|
return [user["user1_nom"], title, doc_type, size, date]
|
@ -68,7 +68,7 @@ class vkSession(object):
|
|||||||
# Example of this behaviour is when you upload an audio and inmediately delete the audio, VK still sends the post stating that you uploaded an audio file,
|
# Example of this behaviour is when you upload an audio and inmediately delete the audio, VK still sends the post stating that you uploaded an audio file,
|
||||||
# But without the audio data, making socializer to render an empty post.
|
# But without the audio data, making socializer to render an empty post.
|
||||||
# Here we check if the post contains data of the type it advertises.
|
# Here we check if the post contains data of the type it advertises.
|
||||||
if i.get("type") != None and post_types.get(i["type"]) not in i:
|
if i.get("type") != None and isinstance(i["type"], str) and post_types.get(i["type"]) not in i:
|
||||||
log.error("Detected invalid or unsupported post. Skipping...")
|
log.error("Detected invalid or unsupported post. Skipping...")
|
||||||
log.error(i)
|
log.error(i)
|
||||||
continue
|
continue
|
||||||
|
@ -110,4 +110,5 @@ class communityBufferMenu(wx.Menu):
|
|||||||
self.load_topics = load.Append(wx.NewId(), _("Load topics"))
|
self.load_topics = load.Append(wx.NewId(), _("Load topics"))
|
||||||
self.load_audios = load.Append(wx.NewId(), _("Load audios"))
|
self.load_audios = load.Append(wx.NewId(), _("Load audios"))
|
||||||
self.load_videos = load.Append(wx.NewId(), _("Load videos"))
|
self.load_videos = load.Append(wx.NewId(), _("Load videos"))
|
||||||
|
self.load_documents = load.Append(wx.NewId(), _("Load documents"))
|
||||||
self.Append(wx.NewId(), _("Load"), load)
|
self.Append(wx.NewId(), _("Load"), load)
|
@ -147,6 +147,18 @@ class topicTab(homeTab):
|
|||||||
self.list.set_size()
|
self.list.set_size()
|
||||||
self.list.list.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnKeyDown)
|
self.list.list.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnKeyDown)
|
||||||
|
|
||||||
|
class documentTab(homeTab):
|
||||||
|
def create_list(self):
|
||||||
|
self.lbl = wx.StaticText(self, wx.NewId(), _("Documents"))
|
||||||
|
self.list = widgetUtils.list(self, *[_("User"), _("Title"), _("Type"), _("Size"), _("Date")], style=wx.LC_REPORT)
|
||||||
|
self.list.set_windows_size(0, 200)
|
||||||
|
self.list.set_windows_size(1, 128)
|
||||||
|
self.list.set_windows_size(2, 35)
|
||||||
|
self.list.set_windows_size(3, 15)
|
||||||
|
self.list.set_windows_size(4, 25)
|
||||||
|
self.list.set_size()
|
||||||
|
self.list.list.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnKeyDown)
|
||||||
|
|
||||||
class empty(wx.Panel):
|
class empty(wx.Panel):
|
||||||
def __init__(self, parent, name):
|
def __init__(self, parent, name):
|
||||||
super(empty, self).__init__(parent=parent, name=name)
|
super(empty, self).__init__(parent=parent, name=name)
|
||||||
|
Loading…
Reference in New Issue
Block a user