'Creates a url friendly name for this page.
Will restrict the name to 30 characters, if there exists a similar name,
it will add name-1, name-2 etc.'

def autoname(self):

    from frappe.utils import cint
    if ((self.name and self.name.startswith(u'New    Page')) or (not self.name)):
        self.name = self.page_name.lower().replace(u'"', u'').replace(u"'", u'').replace(u'    ', u'-')[:20]
        if frappe.db.exists(u'Page', self.name):
            cnt = frappe.db.sql((u'select    name    from    tabPage\n DCTB  DCTB  DCTB  DCTB  DCTB where    name    like    "%s-%%"    order    by    name    desc    limit    1' % self.name))
            if cnt:
                cnt = (cint(cnt[0][0].split(u'-')[(-1)]) + 1)
            else:
                cnt = 1
            self.name += (u'-' + str(cnt))
