Ejemplo n.º 1
0
 def validateShortURL(tag, target):
     if tag.isdigit():
         raise ValueError(
             _("Short URL tag is a number: '%s'. Please add at least one non-digit."
               ) % tag)
     if not re.match(r'^[a-zA-Z0-9/._-]+$', tag) or '//' in tag:
         raise ValueError(
             _("Short URL tag contains invalid chars: '%s'. Please select another one."
               ) % tag)
     if tag[0] == '/' or tag[-1] == '/':
         raise ValueError(
             _("Short URL tag may not begin/end with a slash: '%s'. Please select another one."
               ) % tag)
     mapper = ShortURLMapper()
     if mapper.hasKey(tag) and mapper.getById(tag) != target:
         raise ValueError(
             _("Short URL tag already used: '%s'. Please select another one."
               ) % tag)
     if conference.ConferenceHolder().hasKey(tag):
         # Reject existing event ids. It'd be EXTREMELY confusing and broken to allow such a shorturl
         raise ValueError(
             _("Short URL tag is an event id: '%s'. Please select another one."
               ) % tag)
     ep = endpoint_for_url(Config.getInstance().getShortEventURL() + tag)
     if not ep or ep[0] != 'event.shorturl':
         # URL does not match the shorturl rule or collides with an existing rule that does does not
         # know about shorturls.
         # This shouldn't happen anymore with the /e/ namespace but we keep the check just to be safe
         raise ValueError(
             _("Short URL tag conflicts with an URL used by Indico: '%s'. Please select another one."
               ) % tag)
Ejemplo n.º 2
0
 def setValues(c, confData, notify=False):
     from MaKaC.webinterface.common.tools import escape_tags_short_url
     c.setTitle( confData["title"] )
     c.setDescription( confData["description"] )
     c.setOrgText(confData.get("orgText",""))
     c.setComments(confData.get("comments",""))
     c.setKeywords( confData["keywords"] )
     c.setChairmanText( confData.get("chairText", "") )
     if "shortURLTag" in confData.keys():
         tag = confData["shortURLTag"].strip()
         tag = escape_tags_short_url(tag)
         if c.getUrlTag() != tag:
             from MaKaC.common.url import ShortURLMapper
             sum = ShortURLMapper()
             sum.remove(c)
             c.setUrlTag(tag)
             if tag:
                 sum.add(tag, c)
     c.setContactInfo( confData.get("contactInfo","") )
     #################################
     # Fermi timezone awareness      #
     #################################
     c.setTimezone(confData["Timezone"])
     tz = confData["Timezone"]
     try:
         sDate = timezone(tz).localize(datetime(int(confData["sYear"]), \
                              int(confData["sMonth"]), \
                              int(confData["sDay"]), \
                              int(confData["sHour"]), \
                              int(confData[ "sMinute"])))
     except ValueError,e:
         raise FormValuesError("The start date you have entered is not correct: %s"%e, "Event")
Ejemplo n.º 3
0
def _event_or_shorturl(confId, shorturl_namespace=False, ovw=False):
    from MaKaC.conference import ConferenceHolder
    from MaKaC.common.url import ShortURLMapper

    with DBMgr.getInstance().global_connection():
        ch = ConferenceHolder()
        su = ShortURLMapper()
        if ch.hasKey(confId):
            # For obvious reasons an event id always comes first.
            # If it's used within the short url namespace we redirect to the event namespace, otherwise
            # we call the RH to display the event
            if shorturl_namespace:
                url = UHConferenceDisplay.getURL(ch.getById(confId))
                func = lambda: redirect(url)
            else:
                params = request.args.to_dict()
                params['confId'] = confId
                if ovw:
                    params['ovw'] = 'True'
                func = lambda: conferenceDisplay.RHConferenceDisplay(None).process(params)
        elif (shorturl_namespace or app.config['INDICO_COMPAT_ROUTES']) and su.hasKey(confId):
            if shorturl_namespace:
                # Correct namespace => redirect to the event
                url = UHConferenceDisplay.getURL(su.getById(confId))
                func = lambda: redirect(url)
            else:
                # Old event namespace => 301-redirect to the new shorturl first to get Google etc. to update it
                url = url_for('.shorturl', confId=confId)
                func = lambda: redirect(url, 301)
        else:
            raise NotFound(
                _('The specified event with id or tag "%s" does not exist or has been deleted') % confId)

    return func()
Ejemplo n.º 4
0
 def setValues(c, confData, notify=False):
     c.setTitle( confData["title"] )
     c.setDescription( confData["description"] )
     c.setOrgText(confData.get("orgText",""))
     c.setComments(confData.get("comments",""))
     c.setKeywords( confData["keywords"] )
     c.setChairmanText( confData.get("chairText", "") )
     
     # Ictp
     if confData.has_key('roles'):
         if confData["roles"] == '[]' or not confData["roles"]:
             c.setRoles([])
         else:
             c.setRolesJS( confData["roles"] )
         
     if "shortURLTag" in confData.keys():
         tag = confData["shortURLTag"].strip()
         if tag:
             try:
                 UtilsConference.validateShortURL(tag, c)
             except ValueError, e:
                 raise FormValuesError(e.message)
         if c.getUrlTag() != tag:
             mapper = ShortURLMapper()
             mapper.remove(c)
             c.setUrlTag(tag)
             if tag:
                 mapper.add(tag, c)
Ejemplo n.º 5
0
def _event_or_shorturl(confId, shorturl_namespace=False, ovw=False):
    from MaKaC.conference import ConferenceHolder
    from MaKaC.common.url import ShortURLMapper

    with DBMgr.getInstance().global_connection():
        ch = ConferenceHolder()
        su = ShortURLMapper()
        if ch.hasKey(confId):
            # For obvious reasons an event id always comes first.
            # If it's used within the short url namespace we redirect to the event namespace, otherwise
            # we call the RH to display the event
            if shorturl_namespace:
                url = UHConferenceDisplay.getURL(ch.getById(confId))
                func = lambda: redirect(url)
            else:
                params = request.args.to_dict()
                params['confId'] = confId
                if ovw:
                    params['ovw'] = 'True'
                func = lambda: conferenceDisplay.RHConferenceDisplay(None).process(params)
        elif (shorturl_namespace or app.config['INDICO_COMPAT_ROUTES']) and su.hasKey(confId):
            if shorturl_namespace:
                # Correct namespace => redirect to the event
                url = UHConferenceDisplay.getURL(su.getById(confId))
                func = lambda: redirect(url)
            else:
                # Old event namespace => 301-redirect to the new shorturl first to get Google etc. to update it
                url = url_for('.shorturl', confId=confId)
                func = lambda: redirect(url, 301)
        else:
            raise NotFound(
                _('The specified event with id or tag "%s" does not exist or has been deleted') % confId)

    return func()
Ejemplo n.º 6
0
 def _handleSet(self):
     mapper = ShortURLMapper()
     if self._value:
         try:
             UtilsConference.validateShortURL(self._value, self._target)
         except ValueError, e:
             raise NoReportError(e.message)
Ejemplo n.º 7
0
 def setValues(cls, c, confData, notify=False):
     c.setTitle( confData["title"] )
     c.setDescription( confData["description"] )
     c.setOrgText(confData.get("orgText",""))
     c.setComments(confData.get("comments",""))
     c.as_event.keywords = confData["keywords"]
     c.setChairmanText( confData.get("chairText", "") )
     if "shortURLTag" in confData.keys():
         tag = confData["shortURLTag"].strip()
         if tag:
             try:
                 UtilsConference.validateShortURL(tag, c)
             except ValueError, e:
                 raise FormValuesError(e.message)
         if c.getUrlTag() != tag:
             mapper = ShortURLMapper()
             mapper.remove(c)
             c.setUrlTag(tag)
             if tag:
                 mapper.add(tag, c)
Ejemplo n.º 8
0
 def setValues(c, confData, notify=False):
     from MaKaC.webinterface.common.tools import escape_tags_short_url
     c.setTitle(confData["title"])
     c.setDescription(confData["description"])
     c.setOrgText(confData.get("orgText", ""))
     c.setComments(confData.get("comments", ""))
     c.setKeywords(confData["keywords"])
     c.setChairmanText(confData.get("chairText", ""))
     if "shortURLTag" in confData.keys():
         tag = confData["shortURLTag"].strip()
         tag = escape_tags_short_url(tag)
         if c.getUrlTag() != tag:
             from MaKaC.common.url import ShortURLMapper
             sum = ShortURLMapper()
             sum.remove(c)
             c.setUrlTag(tag)
             if tag:
                 sum.add(tag, c)
     c.setContactInfo(confData.get("contactInfo", ""))
     #################################
     # Fermi timezone awareness      #
     #################################
     c.setTimezone(confData["Timezone"])
     tz = confData["Timezone"]
     try:
         sDate = timezone(tz).localize(datetime(int(confData["sYear"]), \
                              int(confData["sMonth"]), \
                              int(confData["sDay"]), \
                              int(confData["sHour"]), \
                              int(confData[ "sMinute"])))
     except ValueError, e:
         raise FormValuesError(
             "The start date you have entered is not correct: %s" % e,
             "Event")
Ejemplo n.º 9
0
 def validateShortURL(tag, target):
     if tag.isdigit():
         raise ValueError(_("Short URL tag is a number: '%s'. Please add at least one non-digit.") % tag)
     if not re.match(r'^[a-zA-Z0-9/._-]+$', tag) or '//' in tag:
         raise ValueError(
             _("Short URL tag contains invalid chars: '%s'. Please select another one.") % tag)
     if tag[0] == '/' or tag[-1] == '/':
         raise ValueError(
             _("Short URL tag may not begin/end with a slash: '%s'. Please select another one.") % tag)
     mapper = ShortURLMapper()
     if mapper.hasKey(tag) and mapper.getById(tag) != target:
         raise ValueError(_("Short URL tag already used: '%s'. Please select another one.") % tag)
     if conference.ConferenceHolder().hasKey(tag):
         # Reject existing event ids. It'd be EXTREMELY confusing and broken to allow such a shorturl
         raise ValueError(_("Short URL tag is an event id: '%s'. Please select another one.") % tag)
     ep = endpoint_for_url(Config.getInstance().getShortEventURL() + tag)
     if not ep or ep[0] != 'event.shorturl':
         # URL does not match the shorturl rule or collides with an existing rule that does does not
         # know about shorturls.
         # This shouldn't happen anymore with the /e/ namespace but we keep the check just to be safe
         raise ValueError(
             _("Short URL tag conflicts with an URL used by Indico: '%s'. Please select another one.") % tag)
Ejemplo n.º 10
0
 def setValues(cls, c, confData, notify=False):
     c.setTitle(confData["title"])
     c.setDescription(confData["description"])
     c.setOrgText(confData.get("orgText", ""))
     c.setComments(confData.get("comments", ""))
     c.as_event.keywords = confData["keywords"]
     c.setChairmanText(confData.get("chairText", ""))
     if "shortURLTag" in confData.keys():
         tag = confData["shortURLTag"].strip()
         if tag:
             try:
                 UtilsConference.validateShortURL(tag, c)
             except ValueError, e:
                 raise FormValuesError(e.message)
         if c.getUrlTag() != tag:
             mapper = ShortURLMapper()
             mapper.remove(c)
             c.setUrlTag(tag)
             if tag:
                 mapper.add(tag, c)
Ejemplo n.º 11
0
        usage()
        sys.exit(0)
    id = None
    tag = None
    for o, a in opts:
        if o == "-i":
            id = str(a)
        elif o == "-t":
            tag = str(a)
        else:
            assert False, "unhandled option"

    dbi = DBMgr.getInstance()
    dbi.startRequest()

    if id and tag:
        ch = ConferenceHolder()
        conf = ch.getById(id)
        print "Setting ShortURLTag of %s to %s" % (conf.getTitle(), tag)
        sum = ShortURLMapper()
        sum.add(tag, conf)
    else:
        usage()
        sys.exit(0)
    dbi.endRequest()
    dbi.commit()


if __name__ == "__main__":
    main()