Modified GUI postMenu to display a delete optoin if user has permissions

This commit is contained in:
Manuel Cortez 2019-01-03 12:08:38 -06:00
parent 81f7a5f25b
commit 6cd4b6c549
2 changed files with 18 additions and 8 deletions

View File

@ -192,10 +192,15 @@ class baseBuffer(object):
def get_menu(self): def get_menu(self):
""" Returns contextual menu options. They will change according to the focused item""" """ Returns contextual menu options. They will change according to the focused item"""
m = menus.postMenu()
p = self.get_post() p = self.get_post()
if p == None: if p == None:
return return
# determine if the current user is able to delete the object.
if "can_delete" in p:
can_delete = True==p["can_delete"]
else:
can_delete = False
m = menus.postMenu(can_delete=can_delete)
if ("likes" in p) == False: if ("likes" in p) == False:
m.like.Enable(False) m.like.Enable(False)
elif p["likes"]["user_likes"] == 1: elif p["likes"]["user_likes"] == 1:
@ -207,6 +212,7 @@ class baseBuffer(object):
widgetUtils.connect_event(m, widgetUtils.MENU, self.do_like, menuitem=m.like) widgetUtils.connect_event(m, widgetUtils.MENU, self.do_like, menuitem=m.like)
widgetUtils.connect_event(m, widgetUtils.MENU, self.do_dislike, menuitem=m.dislike) widgetUtils.connect_event(m, widgetUtils.MENU, self.do_dislike, menuitem=m.dislike)
widgetUtils.connect_event(m, widgetUtils.MENU, self.do_comment, menuitem=m.comment) widgetUtils.connect_event(m, widgetUtils.MENU, self.do_comment, menuitem=m.comment)
if hasattr(m, "view_profile"):
widgetUtils.connect_event(m, widgetUtils.MENU, self.open_person_profile, menuitem=m.view_profile) widgetUtils.connect_event(m, widgetUtils.MENU, self.open_person_profile, menuitem=m.view_profile)
return m return m

View File

@ -3,7 +3,7 @@ from __future__ import unicode_literals
import wx import wx
class postMenu(wx.Menu): class postMenu(wx.Menu):
def __init__(self, *args, **kwargs): def __init__(self, can_delete=False, *args, **kwargs):
super(postMenu, self).__init__(*args, **kwargs) super(postMenu, self).__init__(*args, **kwargs)
self.open = wx.MenuItem(self, wx.NewId(), _("Open")) self.open = wx.MenuItem(self, wx.NewId(), _("Open"))
self.Append(self.open) self.Append(self.open)
@ -14,6 +14,10 @@ class postMenu(wx.Menu):
self.Append(self.dislike) self.Append(self.dislike)
self.comment = wx.MenuItem(self, wx.NewId(), _("Add comment")) self.comment = wx.MenuItem(self, wx.NewId(), _("Add comment"))
self.Append(self.comment) self.Append(self.comment)
if can_delete:
self.delete = wx.MenuItem(self, wx.NewId(), _("Delete"))
self.Append(self.delete)
else:
self.post_in_wall = wx.MenuItem(self, wx.NewId(), _("Post to this profile")) self.post_in_wall = wx.MenuItem(self, wx.NewId(), _("Post to this profile"))
self.post_in_wall.Enable(False) self.post_in_wall.Enable(False)
self.Append(self.post_in_wall) self.Append(self.post_in_wall)