comparison frontends/src/jp/cmd_invitation.py @ 2220:0d27d95652a7

jp (invitation): added modify command
author Goffi <goffi@goffi.org>
date Mon, 03 Apr 2017 00:23:01 +0200
parents 5831e8fcc5f8
children a41a4729c2d8
comparison
equal deleted inserted replaced
2219:77a3d0a28642 2220:0d27d95652a7
128 errback=partial(self.errback, 128 errback=partial(self.errback,
129 msg=_(u"can't get invitation data: {}"), 129 msg=_(u"can't get invitation data: {}"),
130 exit_code=C.EXIT_BRIDGE_ERRBACK)) 130 exit_code=C.EXIT_BRIDGE_ERRBACK))
131 131
132 132
133 class Modify(base.CommandBase):
134
135 def __init__(self, host):
136 base.CommandBase.__init__(self, host, 'modify', use_profile=False, help=_(u'modify existing invitation'))
137 self.need_loop=True
138
139 def add_parser_options(self):
140 self.parser.add_argument("--replace", action='store_true', help='replace the whole data')
141 self.parser.add_argument("-n", "--name", type=base.unicode_decoder, default='', help='name of the invitee')
142 self.parser.add_argument("-N", "--host-name", type=base.unicode_decoder, default='', help='name of the host')
143 self.parser.add_argument("-e", "--email", type=base.unicode_decoder, default='', help='email to send the invitation to (if --no-email is set, email will just be saved)')
144 self.parser.add_argument("-l", "--lang", type=base.unicode_decoder, default='', help='main language spoken by the invitee')
145 self.parser.add_argument("-x", "--extra", metavar=('KEY', 'VALUE'), type=base.unicode_decoder, action='append', nargs=2, default=[], help='extra data to associate with invitation/invitee')
146 self.parser.add_argument("-p", "--profile", type=base.unicode_decoder, default='', help="profile doing the invitation (default: don't associate profile")
147 self.parser.add_argument("id", type=base.unicode_decoder,
148 help=_(u"invitation UUID"))
149
150 def invitationModifyCb(self):
151 self.disp(_(u'invitations have been modified correctly'))
152 self.host.quit(C.EXIT_OK)
153
154 def invitationModifyEb(self, failure_):
155 self.disp(u"can't create invitation: {reason}".format(
156 reason=failure_), error=True)
157 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
158
159 def start(self):
160 extra = dict(self.args.extra)
161 for arg_name in ('name', 'host_name', 'email', 'lang', 'profile'):
162 value = getattr(self.args, arg_name)
163 if not value:
164 continue
165 if arg_name in extra:
166 self.parser.error(_(u"you can't set {arg_name} in both optional argument and extra").format(arg_name=arg_name))
167 extra[arg_name] = value
168 self.host.bridge.invitationModify(
169 self.args.id,
170 extra,
171 self.args.replace,
172 callback=self.invitationModifyCb,
173 errback=self.invitationModifyEb)
174
175
133 class Invitation(base.CommandBase): 176 class Invitation(base.CommandBase):
134 subcommands = (Create, Get) 177 subcommands = (Create, Get, Modify)
135 178
136 def __init__(self, host): 179 def __init__(self, host):
137 super(Invitation, self).__init__(host, 'invitation', use_profile=False, help=_(u'invitation of user(s) without XMPP account')) 180 super(Invitation, self).__init__(host, 'invitation', use_profile=False, help=_(u'invitation of user(s) without XMPP account'))