jp (event/attendee/list): added --missing to show missing people (ones who didn't replied) and --no-rsvp to hide ones who answered
This commit is contained in:
parent
1d3680445d
commit
72ba9316f2
1 changed files with 86 additions and 35 deletions
|
|
@ -216,7 +216,8 @@ class InviteesList(base.CommandBase):
|
|||
self.need_loop=True
|
||||
|
||||
def add_parser_options(self):
|
||||
pass
|
||||
self.parser.add_argument('-m', '--missing', action='store_true', help=_(u'show missing people (invited but no R.S.V.P. so far)'))
|
||||
self.parser.add_argument('-R', '--no-rsvp', action='store_true', help=_(u"don't show people which gave R.S.V.P."))
|
||||
|
||||
def _attend_filter(self, attend):
|
||||
if attend == u'yes':
|
||||
|
|
@ -228,13 +229,14 @@ class InviteesList(base.CommandBase):
|
|||
return A.color(attend_color, attend)
|
||||
|
||||
def _guests_filter(self, guests):
|
||||
return u'(' + guests + ')' if guests else u''
|
||||
return u'(' + unicode(guests) + ')' if guests else u''
|
||||
|
||||
def default_output(self, event_data):
|
||||
data = []
|
||||
attendees_yes = 0
|
||||
attendees_maybe = 0
|
||||
attendees_no = 0
|
||||
attendees_missing = 0
|
||||
guests = 0
|
||||
guests_maybe = 0
|
||||
for jid_, jid_data in event_data.iteritems():
|
||||
|
|
@ -243,15 +245,19 @@ class InviteesList(base.CommandBase):
|
|||
guests_int = int(jid_data['guests'])
|
||||
except (ValueError, KeyError):
|
||||
pass
|
||||
if jid_data[u'attend'] == 'yes':
|
||||
attend = jid_data.get(u'attend',u'')
|
||||
if attend == 'yes':
|
||||
attendees_yes += 1
|
||||
guests += guests_int
|
||||
elif jid_data[u'attend'] == 'maybe':
|
||||
elif attend == 'maybe':
|
||||
attendees_maybe += 1
|
||||
guests_maybe += guests_int
|
||||
elif jid_data[u'attend'] == 'no':
|
||||
elif attend == 'no':
|
||||
attendees_no += 1
|
||||
jid_data[u'guests'] = ''
|
||||
else:
|
||||
attendees_missing += 1
|
||||
jid_data[u'guests'] = ''
|
||||
data.append(jid_data)
|
||||
|
||||
show_table = OUTPUT_OPT_TABLE in self.args.output_opts
|
||||
|
|
@ -275,48 +281,93 @@ class InviteesList(base.CommandBase):
|
|||
else:
|
||||
table.display_blank(show_header=False, col_sep=u'')
|
||||
|
||||
self.disp(u'')
|
||||
self.disp(A.color(
|
||||
C.A_SUBHEADER,
|
||||
_(u'Attendees: '),
|
||||
A.RESET,
|
||||
unicode(len(data)),
|
||||
_(u' ('),
|
||||
C.A_SUCCESS,
|
||||
_(u'yes: '),
|
||||
unicode(attendees_yes),
|
||||
A.FG_WHITE,
|
||||
_(u', maybe: '),
|
||||
unicode(attendees_maybe),
|
||||
u', ',
|
||||
C.A_FAILURE,
|
||||
_(u'no: '),
|
||||
unicode(attendees_no),
|
||||
A.RESET,
|
||||
u')'
|
||||
))
|
||||
self.disp(A.color(C.A_SUBHEADER, _(u'confirmed guests: '), A.RESET, unicode(guests)))
|
||||
self.disp(A.color(C.A_SUBHEADER, _(u'unconfirmed guests: '), A.RESET, unicode(guests_maybe)))
|
||||
self.disp(A.color(C.A_SUBHEADER, _(u'total: '), A.RESET, unicode(guests+guests_maybe)))
|
||||
if not self.args.no_rsvp:
|
||||
self.disp(u'')
|
||||
self.disp(A.color(
|
||||
C.A_SUBHEADER,
|
||||
_(u'Attendees: '),
|
||||
A.RESET,
|
||||
unicode(len(data)),
|
||||
_(u' ('),
|
||||
C.A_SUCCESS,
|
||||
_(u'yes: '),
|
||||
unicode(attendees_yes),
|
||||
A.FG_WHITE,
|
||||
_(u', maybe: '),
|
||||
unicode(attendees_maybe),
|
||||
u', ',
|
||||
C.A_FAILURE,
|
||||
_(u'no: '),
|
||||
unicode(attendees_no),
|
||||
A.RESET,
|
||||
u')'
|
||||
))
|
||||
self.disp(A.color(C.A_SUBHEADER, _(u'confirmed guests: '), A.RESET, unicode(guests)))
|
||||
self.disp(A.color(C.A_SUBHEADER, _(u'unconfirmed guests: '), A.RESET, unicode(guests_maybe)))
|
||||
self.disp(A.color(C.A_SUBHEADER, _(u'total: '), A.RESET, unicode(guests+guests_maybe)))
|
||||
if attendees_missing:
|
||||
self.disp('')
|
||||
self.disp(A.color(C.A_SUBHEADER, _(u'missing people (no reply): '), A.RESET, unicode(attendees_missing)))
|
||||
|
||||
def eventInviteesListCb(self, event_data):
|
||||
for jid_, data in event_data.iteritems():
|
||||
def eventInviteesListCb(self, event_data, prefilled_data):
|
||||
"""fill nicknames and keep only requested people
|
||||
|
||||
@param event_data(dict): R.S.V.P. answers
|
||||
@param prefilled_data(dict): prefilled data with all people
|
||||
only filled if --missing is used
|
||||
"""
|
||||
if self.args.no_rsvp:
|
||||
for jid_ in event_data:
|
||||
# if there is a jid in event_data
|
||||
# it must be there in prefilled_data too
|
||||
# so no need to check for KeyError
|
||||
del prefilled_data[jid_]
|
||||
else:
|
||||
# we replace empty dicts for existing people with R.S.V.P. data
|
||||
prefilled_data.update(event_data)
|
||||
|
||||
# we get nicknames for everybody, make it easier for organisers
|
||||
for jid_, data in prefilled_data.iteritems():
|
||||
id_data = self.host.bridge.identityGet(jid_, self.profile)
|
||||
data[u'nick'] = id_data.get(u'nick', u'')
|
||||
self.output(event_data)
|
||||
|
||||
self.output(prefilled_data)
|
||||
self.host.quit()
|
||||
|
||||
def start(self):
|
||||
common.checkURI(self.args)
|
||||
def getList(self, prefilled_data={}):
|
||||
self.host.bridge.eventInviteesList(
|
||||
self.args.service,
|
||||
self.args.node,
|
||||
self.profile,
|
||||
callback=self.eventInviteesListCb,
|
||||
callback=partial(self.eventInviteesListCb,
|
||||
prefilled_data=prefilled_data),
|
||||
errback=partial(self.errback,
|
||||
msg=_(u"can't get event data: {}"),
|
||||
exit_code=C.EXIT_BRIDGE_ERRBACK))
|
||||
|
||||
def psNodeAffiliationsGetCb(self, affiliations):
|
||||
# we fill all affiliations with empty data
|
||||
# answered one will be filled in eventInviteesListCb
|
||||
# we only consider people with "publisher" affiliation as invited, creators are not, and members can just observe
|
||||
prefilled = {jid_: {} for jid_, affiliation in affiliations.iteritems() if affiliation in (u'publisher',)}
|
||||
self.getList(prefilled)
|
||||
|
||||
def start(self):
|
||||
if self.args.no_rsvp and not self.args.missing:
|
||||
self.parser.error(_(u"you need to use --missing if you use --no-rsvp"))
|
||||
common.checkURI(self.args)
|
||||
if self.args.missing:
|
||||
self.host.bridge.psNodeAffiliationsGet(
|
||||
self.args.service,
|
||||
self.args.node,
|
||||
self.profile,
|
||||
callback=self.psNodeAffiliationsGetCb,
|
||||
errback=partial(self.errback,
|
||||
msg=_(u"can't get event data: {}"),
|
||||
exit_code=C.EXIT_BRIDGE_ERRBACK))
|
||||
else:
|
||||
self.getList()
|
||||
|
||||
|
||||
class InviteeInvite(base.CommandBase):
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue