Beispiel #1
0
def getEditor(editLine, request):
     from Sycamore.user import User, getUserLink
     from Sycamore.Page import Page
     if editLine.userid and editLine.userid.strip():
        editUser = User(request, editLine.userid)
        return getUserLink(request, editUser, wiki_name=editLine.wiki_name,
                           show_title=False)
     else:
       return '<em>unknown</em>'
Beispiel #2
0
def full_events(events, are_events_today, htmltext, macro):
    old_date = ''

    event_timezone = macro.request.config.tz

    # clear events that have passed
    yesterday_struct = time.gmtime(time.time()-60*60*24)
    yesterday = list(yesterday_struct[0:3]) + [0,0,0,0,0,0]
    yesterday = calendar.timegm(yesterday)
    macro.request.cursor.execute("""SELECT event_name, event_time
                                    FROM events
                                    WHERE event_time<%(yesterday)s and
                                          wiki_id=%(wiki_id)s""",
                                 {'yesterday':yesterday,
                                  'wiki_id':macro.request.config.wiki_id})
    macro.request.cursor.execute("""DELETE FROM events
                                    WHERE event_time<%(yesterday)s and
                                          wiki_id=%(wiki_id)s""",
                                 {'yesterday':yesterday,
                                  'wiki_id':macro.request.config.wiki_id})
    macro.request.cursor.execute(
        """SELECT uid, event_time, posted_by, text, location, event_name
           FROM events
           WHERE wiki_id=%(wiki_id)s
           ORDER BY event_time""", {'wiki_id':macro.request.config.wiki_id})
    result = macro.request.cursor.fetchone()
    while result:
        events.append(result) 
        result = macro.request.cursor.fetchone()

    current_time = macro.request.user.getFormattedDateTime(time.time())
    year_cut = string.split(current_time," ")[0]
    current_year = string.split(year_cut, "-")[0]
    month_cut = string.split(current_time," ")[0]
    current_month = string.split(month_cut,"-")[1]
    day_cut = string.split(current_time," ")[0]
    current_day = string.split(day_cut,"-")[2]
    hour_cut = string.split(current_time," ")[1]
    current_hour = string.split(hour_cut,":")[0]
    minute_cut = string.split(current_time," ")[1]
    current_minute = string.split(minute_cut,":")[1]

    for event in events:
            event_name = event[5]
            # we store it as a general time and we convert it to a local time..
            event_time_unix = event[1]

            event_time_struct = wikiutil.timeInUnixToLocal(
                                    macro.request.config.tz, event_time_unix)
            year = event_time_struct[0]
            month = event_time_struct[1]
            day = event_time_struct[2]
            hour = event_time_struct[3]
            minute = event_time_struct[4]
            posted_by = event[2]
            id = event[0]
            date = str(month) + " " +  str(day)

            if int(hour) > 12 :
               read_hour = int(hour) - 12
               if not int(minute) == 0:
                    ptime = str(read_hour) + ":" + str(minute) + " PM"
               else:
                    ptime = str(read_hour) + ":00" + " PM"
            elif int(hour) == 0:
                if not int(minute) == 0:        
                    ptime = "12:" + str(minute) + " AM"
                else:
                    ptime = "12:00 AM"
            elif int(hour) == 12:
                if not int(minute) == 0:
                    ptime = "12:" + str(minute) + " PM"
                else:
                    ptime = "12:00 PM"
            else:
                if not int(minute) == 0:
                   ptime = str(hour) + ":" + str(minute) + " AM"  
                else:
                   ptime = str(hour) + ":00 AM"

            ptime = "%s (%s)" % (ptime, macro.request.config.tz)
                
            # This is where we want to run through the wiki processor        
            text = event[3]

            event_location = event[4]
            processed_text = doParse(text,macro,keep_outer_paragraph=True)
            processed_location = doParse(event_location,macro)
            processed_name = doParse(event_name,macro)
            month_dict = {1:'January', 2:'February', 3:'March', 4:'April',
                          5:'May', 6:'June', 7:'July', 8:'August',
                          9:'September', 10:'October', 11:'November',
                          12:'December'}
            string_month = month_dict[month]
            events_page = Page("Events Board", macro.request)
            posted_by_user = user.User(macro.request, name=posted_by)
            user_link = user.getUserLink(macro.request, posted_by_user)
            if (macro.request.user.may.admin(events_page) or
                posted_by == macro.request.user.propercased_name): 
                    if date == old_date:
                        htmltext.append(
                            '<ul>\n<h4 id="head-%s">%s</h4>\n'
                            '<a href="%s/Events_Board?action=events&uid=%s&'
                                     'del=1">[delete]</a>'
                            '&nbsp;&nbsp;<b>Time:</b> %s<br>\n'
                            '<b>Location:</b> %s<br>\n'
                            '%s(Posted by %s)\n</ul>\n' %
                            (id, processed_name, macro.request.getScriptname(),
                             id, ptime, processed_location, processed_text,
                             user_link))
                    else:
                        string_day = datetoday(int(day),int(month),int(year))
                        old_date = date
                        htmltext.append(
                            '<h2>%s, %s %s, %s</h2>\n'
                            '<ul><h4 id="head-%s">%s</h4>\n'
                            '<a href="%s/Events_Board?action=events&uid=%s&'
                                     'del=1">[delete]</a>'
                            '&nbsp;&nbsp;<b>Time:</b> '
                            '%s&nbsp;&nbsp;&nbsp;&nbsp;\n'
                            '<b>Location:</b> %s<br>\n'
                            '%s(Posted by %s)\n</ul>\n' %
                            (string_day, string_month, day, year, id,
                             processed_name,macro.request.getScriptname(), id,
                             ptime, processed_location, processed_text,
                             user_link))

            else:
                if date == old_date:
                        htmltext.append(
                            '<ul>\n<h4 id="head-%s">%s</h4>\n'
                            '<b>Time:</b> %s<br>\n'
                            '<b>Location:</b> %s<br>\n'
                            '%s(Posted by %s)\n</ul>\n' %
                            (id, processed_name, ptime, processed_location,
                             processed_text, user_link))                                   

                else:                                        
                        string_day = datetoday(int(day),int(month),int(year))                                        
                        old_date = date
                        htmltext.append(
                            '<h2>%s, %s %s</h2>\n'
                            '<ul>\n<h4 id="head-%s">%s</h4>\n'
                            '<b>Time:</b> %s&nbsp;&nbsp;&nbsp;&nbsp;\n' 
                            '<b>Location:</b> %s<br>\n'
                            '%s(Posted by %s)\n</ul>\n' %
                            (string_day, string_month, day, id, processed_name,
                             ptime, processed_location, processed_text,
                             user_link))

    title = "Post a new event:"
    htmltext.append(
        '<h3>%s</h3>\n'
        '<table border="0" cellspacing="0" cellpadding="3">\n'
        '<tr><td><form method="POST" action="%s/%s">\n'
        '<input type="hidden" name="action" value="events">\n'
        '<input type="hidden" name="ticket" value="%s">\n'
        'Event name: <input class="formfields" type="text" name="event_name"'
                           'size="30" maxlength="100">&nbsp;\n'
        'Location: <input class="formfields" type="text" '
                         'name="event_location" size="25" maxlength="100">'
        '<br><br>\n' %
        (title, macro.request.getScriptname(),
         wikiutil.quoteWikiname(macro.formatter.page.proper_name()),
         createTicket()))

    monthstring = ('<p>Date: <select name="month">\n'
                   '<option value="1">January</option>\n'
                   '<option value="2">February</option>\n'
                   '<option value="3">March</option>\n'
                   '<option value="4">April</option>\n'
                   '<option value="5">May</option>\n'
                   '<option value="6">June</option>\n'
                   '<option value="7">July</option>\n '
                   '<option value="8">August</option>\n'
                   '<option value="9">September</option>\n'
                   '<option value="10">October</option>\n'
                   '<option value="11">November</option>\n'
                   '<option value="12">December</option>\n</select>\n')
    newmonthstring = monthstring.replace(
        'value="%s"' % str(int(current_month)),
        'value="%s" selected' % str(int(current_month)))
    htmltext.append(newmonthstring)
    
    daystring = ('<select name="day">\n '
                 '<option>1</option>\n '
                 '<option>2</option>\n '
                 '<option>3</option>\n '
                 '<option>4</option>\n '
                 '<option>5</option>\n '
                 '<option>6</option>\n '
                 '<option>7</option>\n '
                 '<option>8</option>\n '
                 '<option>9</option>\n '
                 '<option>10</option>\n '
                 '<option>11</option>\n '
                 '<option>12</option>\n '
                 '<option>13</option>\n '
                 '<option>14</option>\n '
                 '<option>15</option>\n '
                 '<option>16</option>\n '
                 '<option>17</option>\n '
                 '<option>18</option>\n '
                 '<option>19</option>\n '
                 '<option>20</option>\n '
                 '<option>21</option>\n '
                 '<option>22</option>\n '
                 '<option>23</option>\n '
                 '<option>24</option>\n '
                 '<option>25</option>\n '
                 '<option>26</option>\n '
                 '<option>27</option>\n '
                 '<option>28</option>\n '
                 '<option>29</option>\n '
                 '<option>30</option>\n '
                 '<option>31</option>\n '
                 '</select>\n')
    newdaystring = daystring.replace(">"+str(int(current_day))+"<",
                                     " selected>"+str(int(current_day))+"<")
    htmltext.append(newdaystring)
    
    yearstring = '<select name="year">\n'
    for year in yearList():
        yearstring += '<option>%s</option>\n' % year
    yearstring += '</select>'
    newyearstring = yearstring.replace(">" + current_year + "<",
                                       " selected>" + current_year + "<")
    htmltext.append(newyearstring)

    hourstring = ('Time: <select name="hour">\n '
                  '<option value="0">12AM</option>\n '
                  '<option value="1">1AM</option>\n '
                  '<option value="2">2AM</option>\n '
                  '<option value="3">3AM</option>\n '
                  '<option value="4">4AM</option>\n '
                  '<option value="5">5AM</option>\n '
                  '<option value="6">6AM</option>\n '
                  '<option value="7">7AM</option>\n '
                  '<option value="8">8AM</option>\n '
                  '<option value="9">9AM</option>\n '
                  '<option value="10">10AM</option>\n '
                  '<option value="11">11AM</option>\n '
                  '<option value="12">12PM</option>\n '
                  '<option value="13">1PM</option>\n '
                  '<option value="14">2PM</option>\n '
                  '<option value="15">3PM</option>\n '
                  '<option value="16">4PM</option>\n '
                  '<option value="17">5PM</option>\n '
                  '<option value="18">6PM</option>\n '
                  '<option value="19">7PM</option>\n '
                  '<option value="20">8PM</option>\n '
                  '<option value="21">9PM</option>\n '
                  '<option value="22">10PM</option>\n '
                  '<option value="23">11PM</option>\n '
                  '</select>\n')
    newhourstring = hourstring.replace('value="%s"' % str(int(current_hour)),
                                       'value="%s" selected' %
                                           str(int(current_hour)))
    htmltext.append(newhourstring)

    if not str(int(int(current_minute)/10)) == 0:
       rounded_min = str(int(int(current_minute)/10)) + "0"
    else:
       rounded_min = "0"
    minutestring = (' : <select name="minute">\n '
                    '<option value="0">00</option>\n '
                    '<option value="10">10</option>\n '
                    '<option value="20">20</option>\n '
                    '<option value="30">30</option>\n '
                    '<option value="40">40</option>\n '
                    '<option value="50">50</option>\n '
                    '</select> (in %s)</p>\n' % event_timezone)
    newminutestring = minutestring.replace('value="%s"' % rounded_min,
                                           'value="%s" selected' % rounded_min)
    htmltext.append(newminutestring)

    htmltext.append(
                '<textarea name="event_text" rows="5" cols="67" wrapping=yes>'
                'Describe event</textarea><br>\n'
                '<input class="formbutton" type="submit" name="button" '
                       'value="Add Event">\n'
                '</form></td></tr></table>')
Beispiel #3
0
def doRSS(request):
    """
    set up the RSS file
    """
    rss_init_text = (
        '<?xml version="1.0" ?>\n'
        '<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">\n'
        '<channel><title>%s Events Board</title><link>%s</link>'
            '<description>'
            'Events occuring soon, taken from the %s Events Board.'
            '</description><language>en-us</language>\n'
        '</channel>\n'
        '</rss>\n' % (request.config.sitename,
                      Page("Events Board", request).link_to(),
                      request.config.sitename))

    creator_text = 'The %s Robot' % request.config.sitename

    rss_dom = xml.dom.minidom.parseString(rss_init_text)
    channel = rss_dom.getElementsByTagName("channel")[0]

    # Check to see if the event has already passed
    import string, re
    current_time = request.user.getFormattedDateTime(time.time(),
                                                     global_time=True)
    year_cut = string.split(current_time," ")[0]
    current_year = string.split(year_cut, "-")[0]
    month_cut = string.split(current_time," ")[0]
    current_month = string.split(month_cut,"-")[1]
    day_cut = string.split(current_time," ")[0]
    current_day = string.split(day_cut,"-")[2]
    hour_cut = string.split(current_time," ")[1]
    current_hour = string.split(hour_cut,":")[0]
    string_month = findMonth(current_month)
     
    rss_text = []
    events = []
    timenow = time.time()
    today_struct = time.gmtime(timenow+request.config.tz_offset)
    today = list(today_struct[0:3]) + [0,0,0,0,0,0]
    today = calendar.timegm(today) - request.config.tz_offset
    tomorrow_struct = time.gmtime(timenow+60*60*24*7+request.config.tz_offset) # added *7 to show an entire week 2008/05/12 rtucker
    tomorrow = list(tomorrow_struct[0:3]) + [0,0,0,0,0,0]
    tomorrow = calendar.timegm(tomorrow) - request.config.tz_offset

    request.cursor.execute(
        """SELECT uid, event_time, posted_by, text, location, event_name
           from events where event_time >= %(today)s and
                             event_time < %(tomorrow)s and
                             wiki_id=%(wiki_id)s""",
        {'today':today, 'tomorrow':tomorrow, 'wiki_id':request.config.wiki_id})
    result = request.cursor.fetchone()
    while result:
        events.append(result)
        result = request.cursor.fetchone()
    
    for event in events:
        event_time_unix = event[1]

        # stupid date stuff
        time_struct = time.gmtime(event_time_unix+request.config.tz_offset)
        year = time_struct[0]
        month = time_struct[1]
        day = time_struct[2]
        hour = time_struct[3]
        minute = time_struct[4]

        posted_by = event[2]
        event_location = event[4]
        event_name = event[5]

        id = event[0]
        text = event[3]
        if event_name:
            processed_name = wikiutil.simpleStrip(request,event_name)
        else:
            processed_name = ''
        processed_text = doParse(text,request)
        processed_location = doParse(event_location,request)
        if int(hour) > 12 :
            read_hour = int(hour) - 12
            if not int(minute) == 0:
                ptime = str(read_hour) + ":" + str(minute) + " PM"
            else:
                ptime = str(read_hour) + ":00" + " PM"
        elif int(hour) == 0: 
            if not int(minute) == 0:
                ptime = "12:" + str(minute) + " AM"
            else:
                ptime = "12:00 AM"
        elif int(hour) == 12:
            if not int(minute) == 0:
                ptime = "12:" + str(minute) + " PM"
            else:
                ptime = "12:00 PM"
        else:
            if not int(minute) == 0:
                ptime = str(hour) + ":" + str(minute) + " AM"
            else:
                ptime = str(hour) + ":00 AM"
    
        total_date = "%s, %s %s" % (
            datetoday(int(day), int(month), int(year)), findMonth(month), day)
        item = rss_dom.createElement("item")
        rss_text = []

        rss_text.append('<b>Date:</b> %s<br>\n'
                    '<b>Time:</b> %s<br>\n'
                    '<b>Location:</b> %s<br><br>\n'
                    '%s&nbsp;&nbsp;(Posted by %s)\n' %
                    (total_date, ptime, processed_location, processed_text,
                     user.getUserLink(request,
                                      user.User(request, name=posted_by),
                                      absolute=True)))
        item_guid = rss_dom.createElement("guid")
        item_guid.setAttribute("isPermaLink","false")
        item_guid.appendChild(rss_dom.createTextNode(''.join(str(id))))
        item.appendChild(item_guid)
        item_description = rss_dom.createElement("description")
        item_description.appendChild(rss_dom.createTextNode(''.join(rss_text)))
        item_title = rss_dom.createElement("title")
        item_title.appendChild(rss_dom.createTextNode(processed_name))
        item.appendChild(item_title)
        item_link = rss_dom.createElement("link")
        item_link.appendChild(rss_dom.createTextNode(
            Page("Events Board", request).url(relative=False)))
        item.appendChild(item_link)
        item_date = rss_dom.createElement("dc:date")
        item_date.appendChild(rss_dom.createTextNode(
            "%s-%s-%s" % (current_year,current_month,current_day)))
        item.appendChild(item_date)
        creator = rss_dom.createElement("dc:creator")
        creator.appendChild(rss_dom.createTextNode(creator_text))
        item.appendChild(creator)
        item.appendChild(item_description)
        channel.appendChild(item)

    the_xml = rss_dom.toxml()

    return the_xml
Beispiel #4
0
def doRSS(request):
    """
    set up the RSS file
    """
    rss_init_text = (
        '<?xml version="1.0" ?>\n'
        '<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">\n'
        '<channel><title>%s Events Board</title><link>%s</link>'
            '<description>'
            'Events occuring soon, taken from the %s Events Board.'
            '</description><language>en-us</language>\n'
        '</channel>\n'
        '</rss>\n' % (request.config.sitename,
                      Page("Events Board", request).link_to(),
                      request.config.sitename))

    creator_text = 'The %s Robot' % request.config.sitename

    rss_dom = xml.dom.minidom.parseString(rss_init_text)
    channel = rss_dom.getElementsByTagName("channel")[0]

    # Check to see if the event has already passed
    import string, re
    current_time = request.user.getFormattedDateTime(time.time(),
                                                     global_time=True)
    year_cut = string.split(current_time," ")[0]
    current_year = string.split(year_cut, "-")[0]
    month_cut = string.split(current_time," ")[0]
    current_month = string.split(month_cut,"-")[1]
    day_cut = string.split(current_time," ")[0]
    current_day = string.split(day_cut,"-")[2]
    hour_cut = string.split(current_time," ")[1]
    current_hour = string.split(hour_cut,":")[0]
    string_month = findMonth(current_month)
     
    rss_text = []
    events = []
    timenow = time.time()
    today_struct = time.gmtime(timenow+request.config.tz_offset)
    today = list(today_struct[0:3]) + [0,0,0,0,0,0]
    today = calendar.timegm(today) - request.config.tz_offset
    tomorrow_struct = time.gmtime(timenow+60*60*24+request.config.tz_offset)
    tomorrow = list(tomorrow_struct[0:3]) + [0,0,0,0,0,0]
    tomorrow = calendar.timegm(tomorrow) - request.config.tz_offset

    request.cursor.execute(
        """SELECT uid, event_time, posted_by, text, location, event_name
           from events where event_time >= %(today)s and
                             event_time < %(tomorrow)s and
                             wiki_id=%(wiki_id)s""",
        {'today':today, 'tomorrow':tomorrow, 'wiki_id':request.config.wiki_id})
    result = request.cursor.fetchone()
    while result:
        events.append(result)
        result = request.cursor.fetchone()
    
    for event in events:
        event_time_unix = event[1]

        # stupid date stuff
        time_struct = time.gmtime(event_time_unix+request.config.tz_offset)
        year = time_struct[0]
        month = time_struct[1]
        day = time_struct[2]
        hour = time_struct[3]
        minute = time_struct[4]

        posted_by = event[2]
        event_location = event[4]
        event_name = event[5]

        id = event[0]
        text = event[3]
        if event_name:
            processed_name = wikiutil.simpleStrip(request,event_name)
        else:
            processed_name = ''
        processed_text = doParse(text,request)
        processed_location = doParse(event_location,request)
        if int(hour) > 12 :
            read_hour = int(hour) - 12
            if not int(minute) == 0:
                ptime = str(read_hour) + ":" + str(minute) + " PM"
            else:
                ptime = str(read_hour) + ":00" + " PM"
        elif int(hour) == 0: 
            if not int(minute) == 0:
                ptime = "12:" + str(minute) + " AM"
            else:
                ptime = "12:00 AM"
        elif int(hour) == 12:
            if not int(minute) == 0:
                ptime = "12:" + str(minute) + " PM"
            else:
                ptime = "12:00 PM"
        else:
            if not int(minute) == 0:
                ptime = str(hour) + ":" + str(minute) + " AM"
            else:
                ptime = str(hour) + ":00 AM"
    
        total_date = "%s, %s %s" % (
            datetoday(int(day), int(month), int(year)), findMonth(month), day)
        item = rss_dom.createElement("item")
        rss_text = []

        rss_text.append('<b>Date:</b> %s<br>\n'
                    '<b>Time:</b> %s<br>\n'
                    '<b>Location:</b> %s<br><br>\n'
                    '%s&nbsp;&nbsp;(Posted by %s)\n' %
                    (total_date, ptime, processed_location, processed_text,
                     user.getUserLink(request,
                                      user.User(request, name=posted_by),
                                      absolute=True)))
        item_guid = rss_dom.createElement("guid")
        item_guid.setAttribute("isPermaLink","false")
        item_guid.appendChild(rss_dom.createTextNode(''.join(str(id))))
        item.appendChild(item_guid)
        item_description = rss_dom.createElement("description")
        item_description.appendChild(rss_dom.createTextNode(''.join(rss_text)))
        item_title = rss_dom.createElement("title")
        item_title.appendChild(rss_dom.createTextNode(processed_name))
        item.appendChild(item_title)
        item_link = rss_dom.createElement("link")
        item_link.appendChild(rss_dom.createTextNode(
            Page("Events Board", request).url(relative=False)))
        item.appendChild(item_link)
        item_date = rss_dom.createElement("dc:date")
        item_date.appendChild(rss_dom.createTextNode(
            "%s-%s-%s" % (current_year,current_month,current_day)))
        item.appendChild(item_date)
        creator = rss_dom.createElement("dc:creator")
        creator.appendChild(rss_dom.createTextNode(creator_text))
        item.appendChild(creator)
        item.appendChild(item_description)
        channel.appendChild(item)

    the_xml = rss_dom.toxml()

    return the_xml
Beispiel #5
0
    def username(self, d):
        """
        Assemble the username / userprefs link
        
        @param d: parameter dictionary
        @rtype: string
        @return: username html
        """
        _ = self.request.getText
        if self.request.user.valid:
            watch_wiki = ''
            if config.wiki_farm:
                if not self.request.user.isWatchingWiki(
                    self.request.config.wiki_name):
                    watch_wiki = ('| %s ' %
                        Page(d['page_name'],self.request).link_to(
                            know_status=True, know_status_exists=True,
                            text='watch this wiki',
                            querystr='action=watch_wiki&wikiname=%s' %
                                self.request.config.wiki_name))

            if config.wiki_farm:
                wiki_base_url = farm.getBaseFarmURL(self.request)
            else:
                wiki_base_url = '%s/' % self.request.getScriptname()

            if self.request.user.name in wikiacl.Group("Admin", self.request):
                wiki_settings_pagelink = \
                    Page(config.wiki_settings_page, self.request).link_to(
                            text=config.wiki_settings_page.lower())
                admin_settings = ('%s | ' % wiki_settings_pagelink)
            else:
                admin_settings = ''

            html = (
                '<div class="user_area">'
                '<div class="welcome">Welcome, %s</div>'
                '%s'
                '<div class="user_items">'
                '(%s<a href="%s%s?from_wiki=%s">settings</a> %s| '
                '<a href="%s/%s?action=userform&amp;logout=Logout">logout</a>)'
                '</div></div>' %
                (user.getUserLink(self.request, self.request.user),
                 self.userNotificationLink(self.request.user),
                 admin_settings, wiki_base_url,
                 wikiutil.quoteWikiname(config.page_user_preferences),
                 self.request.config.wiki_name, watch_wiki,
                 self.request.getScriptname(), d['q_page_name']))
        else:
            if config.wiki_farm:
                post_url = "%s%s" % (
                    farm.getBaseFarmURL(self.request,
                                        force_ssl=config.use_ssl),
                    wikiutil.quoteWikiname(config.page_user_preferences))
                our_wiki_url = '%s/%s' % (self.request.getBaseURL(),
                                          d['q_page_name'])
                base_wiki = farm.getBaseFarmURL(self.request)
                farm_params = (
                    '<input type="hidden" name="backto_wiki" value="%s">'
                    '<input type="hidden" name="backto_page" value="%s">'
                    '<input type="hidden" name="qs" value="%s">' %
                    (self.request.config.wiki_name,
                     urllib.quote(our_wiki_url),
                     urllib.quote(self.request.query_string)))
            else:
                farm_params = ''
                post_url = '%s/%s' % (
                    self.request.getQualifiedURL(self.request.getScriptname(),
                                                 force_ssl=config.use_ssl),
                    wikiutil.quoteWikiname(config.page_user_preferences))
                base_wiki = '%s/' % self.request.getScriptname()
            html = (
                '<form action="%s" method="POST" '
                      'onsubmit="if (!canSetCookies()) { alert(\'You need '
                                    'cookies enabled to log in.\'); '
                                    'return false;}">'
                '<input type="hidden" name="action" value="userform">'
                '<div class="login_area">'
                '<table>'
                '<tr><td width="50%%" align="right" nowrap>User name:</td>'
                '<td colspan="2" align="left" nowrap>'
                '<input class="formfields" size="22" name="username" '
                       'type="text"></td> </tr> <tr>'
                '<td align="right">Password:</td>'
                '<td colspan="2" align="left" nowrap> '
                '<input class="formfields" size="22" type="password" '
                       'name="password"> '
                '<input type="hidden" name="login" value="Login">%s'
                '</td></tr><tr><td></td>'
                '<td align="left" nowrap>'
                '(<a href="%s%s?new_user=1&amp;from_wiki=%s">new user</a>)'
                '</td><td align="right">'
                '<input type="submit" name="login" value="Login" alt="login">'
                '</td></tr></table></div></form>' %
                (post_url, farm_params, base_wiki,
                 wikiutil.quoteWikiname(config.page_user_preferences),
                 self.request.config.wiki_name))
            
        return html
Beispiel #6
0
def full_events(events, are_events_today, htmltext, macro):
    old_date = ""

    # clear events that have passed
    yesterday_struct = time.gmtime(time.time() - 60 * 60 * 24)
    yesterday = list(yesterday_struct[0:3]) + [0, 0, 0, 0, 0, 0]
    yesterday = calendar.timegm(yesterday)
    macro.request.cursor.execute(
        """SELECT event_name, event_time
                                    FROM events
                                    WHERE event_time<%(yesterday)s and
                                          wiki_id=%(wiki_id)s""",
        {"yesterday": yesterday, "wiki_id": macro.request.config.wiki_id},
    )
    macro.request.cursor.execute(
        """DELETE FROM events
                                    WHERE event_time<%(yesterday)s and
                                          wiki_id=%(wiki_id)s""",
        {"yesterday": yesterday, "wiki_id": macro.request.config.wiki_id},
    )
    macro.request.cursor.execute(
        """SELECT uid, event_time, posted_by, text, location, event_name
           FROM events
           WHERE wiki_id=%(wiki_id)s
           ORDER BY event_time""",
        {"wiki_id": macro.request.config.wiki_id},
    )
    result = macro.request.cursor.fetchone()
    while result:
        events.append(result)
        result = macro.request.cursor.fetchone()

    add_event_form_box(htmltext, macro)

    for event in events:
        event_name = event[5]
        # we store it as a general time and we convert it to a local time..
        event_time_unix = event[1]

        event_time_struct = wikiutil.timeInUnixToLocal(macro.request.config.tz, event_time_unix)
        year = event_time_struct[0]
        month = event_time_struct[1]
        day = event_time_struct[2]
        hour = event_time_struct[3]
        minute = event_time_struct[4]
        posted_by = event[2]
        id = event[0]
        date = str(month) + " " + str(day)

        if int(hour) > 12:
            read_hour = int(hour) - 12
            if not int(minute) == 0:
                ptime = str(read_hour) + ":" + str(minute) + " PM"
            else:
                ptime = str(read_hour) + ":00" + " PM"
        elif int(hour) == 0:
            if not int(minute) == 0:
                ptime = "12:" + str(minute) + " AM"
            else:
                ptime = "12:00 AM"
        elif int(hour) == 12:
            if not int(minute) == 0:
                ptime = "12:" + str(minute) + " PM"
            else:
                ptime = "12:00 PM"
        else:
            if not int(minute) == 0:
                ptime = str(hour) + ":" + str(minute) + " AM"
            else:
                ptime = str(hour) + ":00 AM"

        ptime = "%s (%s)" % (ptime, macro.request.config.tz)

        # This is where we want to run through the wiki processor
        text = event[3]

        event_location = event[4]
        processed_text = doParse(text, macro, keep_outer_paragraph=True)
        processed_location = doParse(event_location, macro)
        processed_name = doParse(event_name, macro)
        month_dict = {
            1: "January",
            2: "February",
            3: "March",
            4: "April",
            5: "May",
            6: "June",
            7: "July",
            8: "August",
            9: "September",
            10: "October",
            11: "November",
            12: "December",
        }
        string_month = month_dict[month]
        events_page = Page("Events Board", macro.request)
        posted_by_user = user.User(macro.request, name=posted_by)
        user_link = user.getUserLink(macro.request, posted_by_user)
        if macro.request.user.may.admin(events_page) or posted_by == macro.request.user.propercased_name:
            if date == old_date:
                htmltext.append(
                    '<ul>\n<h4 id="head-%s">%s</h4>\n'
                    '<a href="%s/Events_Board?action=events&uid=%s&'
                    'del=1">[delete]</a>'
                    "&nbsp;&nbsp;<b>Time:</b> %s<br>\n"
                    "<b>Location:</b> %s<br>\n"
                    "%s(Posted by %s)\n</ul>\n"
                    % (
                        id,
                        processed_name,
                        macro.request.getScriptname(),
                        id,
                        ptime,
                        processed_location,
                        processed_text,
                        user_link,
                    )
                )
            else:
                string_day = datetoday(int(day), int(month), int(year))
                old_date = date
                htmltext.append(
                    "<h2>%s, %s %s, %s</h2>\n"
                    '<ul><h4 id="head-%s">%s</h4>\n'
                    '<a href="%s/Events_Board?action=events&uid=%s&'
                    'del=1">[delete]</a>'
                    "&nbsp;&nbsp;<b>Time:</b> "
                    "%s&nbsp;&nbsp;&nbsp;&nbsp;\n"
                    "<b>Location:</b> %s<br>\n"
                    "%s(Posted by %s)\n</ul>\n"
                    % (
                        string_day,
                        string_month,
                        day,
                        year,
                        id,
                        processed_name,
                        macro.request.getScriptname(),
                        id,
                        ptime,
                        processed_location,
                        processed_text,
                        user_link,
                    )
                )

        else:
            if date == old_date:
                htmltext.append(
                    '<ul>\n<h4 id="head-%s">%s</h4>\n'
                    "<b>Time:</b> %s<br>\n"
                    "<b>Location:</b> %s<br>\n"
                    "%s(Posted by %s)\n</ul>\n"
                    % (id, processed_name, ptime, processed_location, processed_text, user_link)
                )

            else:
                string_day = datetoday(int(day), int(month), int(year))
                old_date = date
                htmltext.append(
                    "<h2>%s, %s %s</h2>\n"
                    '<ul>\n<h4 id="head-%s">%s</h4>\n'
                    "<b>Time:</b> %s&nbsp;&nbsp;&nbsp;&nbsp;\n"
                    "<b>Location:</b> %s<br>\n"
                    "%s(Posted by %s)\n</ul>\n"
                    % (
                        string_day,
                        string_month,
                        day,
                        id,
                        processed_name,
                        ptime,
                        processed_location,
                        processed_text,
                        user_link,
                    )
                )