3538
3560
sCoC_util.modifySignature(sig_id, self.user, comment, False)
3563
class PersonEditWikiNamesView(LaunchpadFormView):
3564
"""View for ~person/+editwikinames"""
3567
fields = ['wiki', 'wikiname']
3568
# Use custom widgets solely to get the width correct. The URIWidget has a
3569
# CSS class that does not respect the displayWidth, thus the need to use a
3570
# different cssClass.
3571
custom_widget('wiki', URIWidget, displayWidth=40, cssClass="textType")
3572
custom_widget('wikiname', TextWidget, displayWidth=40)
3576
return smartquote("%s's wiki names" % self.context.displayname)
3580
return canonical_url(self.context)
3582
cancel_url = next_url
3584
def setUpFields(self):
3585
super(PersonEditWikiNamesView, self).setUpFields()
3586
if self.context.wiki_names.count() > 0:
3587
# Make the wiki and wiki_name entries optional on the edit page if
3588
# one or more ids already exist, which allows the removal of ids
3589
# without filling out the new wiki fields.
3590
wiki_field = self.form_fields['wiki']
3591
wikiname_field = self.form_fields['wikiname']
3592
# Copy the fields so as not to modify the interface.
3593
wiki_field.field = copy_field(wiki_field.field)
3594
wiki_field.field.required = False
3595
wikiname_field.field = copy_field(wikiname_field.field)
3596
wikiname_field.field.required = False
3598
def _validateWikiURL(self, url):
3599
"""Validate the URL.
3601
Make sure that the result is a valid URL with only the
3602
appropriate schemes. The url is assumed to be a string.
3608
if uri.scheme not in ('http', 'https'):
3612
'The URL scheme "%(scheme)s" is not allowed. '
3613
'Only http or https URLs may be used.',
3615
except InvalidURIError:
3619
'"%(url)s" is not a valid URL.', url=url))
3621
def _validateWikiName(self, name):
3622
"""Ensure the wikiname is valid.
3624
It must not be longer than 100 characters. Name is assumed to be a
3628
if len(name) > max_len:
3632
'The wiki name cannot exceed %d characters.' % max_len))
3634
def _sanitizeWikiURL(self, url):
3635
"""Strip whitespaces and make sure :url ends in a single '/'."""
3638
return '%s/' % url.strip().rstrip('/')
3640
def validate(self, data):
3641
# If there are already form errors then just show them.
3644
wikiurl = self._sanitizeWikiURL(data.get('wiki'))
3645
wikiname = data.get('wikiname')
3646
if wikiurl or wikiname:
3651
'The Wiki URL must be specified.'))
3656
'The Wiki name must be specified.'))
3661
if wikiurl is not None:
3662
self._validateWikiURL(wikiurl)
3663
if wikiname is not None:
3664
self._validateWikiName(wikiname)
3669
wikinameset = getUtility(IWikiNameSet)
3670
existingwiki = wikinameset.getByWikiAndName(wikiurl, wikiname)
3672
if existingwiki.person != self.context:
3673
owner_name = urllib.quote(existingwiki.person.name)
3675
'%s/+requestmerge?field.dupe_person=%s'
3676
% (canonical_url(getUtility(IPersonSet)), owner_name))
3680
'The WikiName %s%s is already registered by '
3681
'<a href="%s">%s</a>. If you think this is a '
3682
'duplicated account, you can <a href="%s">merge it'
3683
'</a> into your account.',
3685
canonical_url(existingwiki.person),
3686
existingwiki.person.displayname, merge_url))
3688
# The person already has this wiki.
3691
'The WikiName %s%s already belongs to you.' %
3692
(wikiurl, wikiname))
3694
def _save(self, wikiurl, wikiname):
3695
"""Given a wikiurl and wikiname, attempt to save it.
3697
Verify someone else doesn't have it already.
3700
@action(_("Save Changes"), name="save")
3701
def save(self, action, data):
3702
"""Process the wiki names form."""
3703
form = self.request.form
3704
for obj in self.context.wiki_names:
3705
if form.get('remove_%s' % obj.id):
3709
wikiurl = self._sanitizeWikiURL(data.get('wiki'))
3710
wikiname = data.get('wikiname')
3711
# If either url or name are present then they both must be
3713
if wikiurl and wikiname:
3714
wikinameset = getUtility(IWikiNameSet)
3715
wikinameset.new(self.context, wikiurl, wikiname)
3541
3718
class PersonEditIRCNicknamesView(LaunchpadFormView):
3543
3720
schema = Interface