def adjustFairDetails(page): data=getFairDetails() page.find(pq.tagName('input')).filter(pq.hasClass('fair-date-and-time')).attr('value',str(data.date_and_time)) page.find(pq.tagName('span')).filter(pq.hasClass('fair-date-and-time')).text(str(data.date_and_time)) page.find(pq.tagName('input')).filter(pq.hasClass('fair-email')).attr('value',str(data.email)) page.find(pq.tagName('a')).filter(pq.hasClass('fair-email')).text(str(data.email)).attr('href','mailto:'+str(data.email)) page.find(pq.tagName('div')).filter(pq.hasClass('fair-message')).html( pq.parse(data.message)) return page
def makeRosterContent(stall_name): print 'prefs' prefs=getPrefs(stall_name) helpers_required=fromJson(prefs.helpers_required) result=stall_page_head helpers_by_hour=[(hour,int(helpers_required.get(str(hour),default_helpers_required(hour)))) for hour in range(8,21)] table_cols=2+max([_[1] for _ in helpers_by_hour]) while len(helpers_by_hour) and helpers_by_hour[-1][1]==0: helpers_by_hour=helpers_by_hour[0:-1] pass for hour, max_helpers in helpers_by_hour: # get OneHourOfHelp object for specified hour from datastore entry_query = OneHourOfHelp.query(OneHourOfHelp.hour == hour, ancestor=stall_key(stall_name)) entries = entry_query.fetch(1) names=[] phones=[] emails=[] if len(entries): names=entries[0].names phones=entries[0].phones emails=entries[0].emails pass if max_helpers>0: result=result+makeRow(table_cols, stall_name, hour, names, phones, emails, max_helpers, prefs.ask_for_email, prefs.ask_for_phone) pass pass result=result+stall_page_tail content=pq.parse(result,'StallPage') #lop off empty table columns helper_table=content.find(hasClass('helper_table')) helper_table.find(hasClass("top-spacer"))\ .attr('colspan',str(table_cols)) ths=helper_table.find(hasClass('helper-th')) ths[table_cols-2:].remove() #suppress roster table and heading etc if there are no rows if len(helpers_by_hour)==0: content.find(hasClass('kindycal-py-roster-el')).remove() else: content.find(hasClass('kindycal-py-noroster-el')).addClass('kc-display-none') pass content.find(hasClass('stall_name')).text(getStalls()[stall_name]['name']) content.find(hasClass('stall_image')).attr('src','fair_images/roster-%(stall_name)s.jpg'%vars()) content.find(hasClass('roster_instructions')).text( prefs.roster_instructions) return content
def cell(names,phones,emails,i,hour,stall_name): 'get name phone and email of ith person in list of names' '- return '' if there are less than i names in list' if i < len(names): name=str(names[i]) contact=[] if i < len(phones) and len(phones[i]): contact.append(str(phones[i])) if i < len(emails) and len(emails[i]): contact.append(str(emails[i])) if len(contact): contact=' ('+', '.join(contact)+')' else: contact='' pass result=pq.parse(non_empty_cell%vars()) inputs=result.find(pq.tagName('input')) inputs.filter(pq.hasClass('helper-number')).attr('value',str(i)) inputs.filter(pq.hasClass('hour')).attr('value',str(hour)) inputs.filter(pq.hasClass('stall-name')).attr('value',stall_name) return unicode(result).encode('utf-8') return empty_cell