def _new(self): # Do we allow account creation? if lca_info['account_creation']: """Create a new person submit. """ # Remove fields not in class results = self.form_result['person'] del results['password_confirm'] del results['email_address2'] c.person = Person(**results) c.person.email_address = c.person.email_address.lower() meta.Session.add(c.person) #for sn in self.form_result['social_network']: # network = SocialNetwork.find_by_name(sn['name']) # if sn['account_name']: # c.person.social_networks[network] = sn['account_name'] meta.Session.commit() if lca_rego['confirm_email_address'] == 'no': redirect_to(controller='person', action='confirm', confirm_hash=c.person.url_hash) else: email(c.person.email_address, render('/person/new_person_email.mako')) return render('/person/thankyou.mako') else: return render('/not_allowed.mako')
def _edit(self, id): # We need to recheck auth in here so we can pass in the id if not h.auth.authorized(h.auth.Or(h.auth.is_same_zookeepr_funding_submitter(id), h.auth.has_organiser_role)): # Raise a no_auth error h.auth.no_role() if not h.auth.authorized(h.auth.has_organiser_role): if c.funding_editing == 'closed': return render("funding/editing_closed.mako") elif c.funding_editing == 'not_open': return render("funding/editing_not_open.mako") if self.form_result['funding']['male'] == 1: self.form_result['funding']['male'] = True elif self.form_result['funding']['male'] == 0: self.form_result['funding']['male'] = False c.funding = Funding.find_by_id(id) for key in self.form_result['funding']: setattr(c.funding, key, self.form_result['funding'][key]) c.person = c.funding.person meta.Session.commit() h.flash("Funding for %s edited!"%c.person.firstname) return redirect_to('/funding')
def _forgotten_password(self): """Action to let the user request a password change. GET returns a form for emailing them the password change confirmation. POST checks the form and then creates a confirmation record: date, email_address, and a url_hash that is a hash of a combination of date, email_address, and a random nonce. The email address must exist in the person database. The second half of the password change operation happens in the ``confirm`` action. """ c.email = self.form_result['email_address'] c.person = Person.find_by_email(c.email) if c.person is not None: # Check if there is already a password recovery in progress reset = PasswordResetConfirmation.find_by_email(c.email) if reset is not None: return render('person/in_progress.mako') # Ok kick one off c.conf_rec = PasswordResetConfirmation(email_address=c.email) meta.Session.add(c.conf_rec) meta.Session.commit() email(c.email, render('person/confirmation_email.mako')) return render('person/password_confirmation_sent.mako')
def new(self): if c.cfp_status == 'closed': if not h.auth.authorized(h.auth.Or(h.auth.has_organiser_role, h.auth.has_late_submitter_role)): return render("proposal/closed.mako") elif c.cfp_status == 'not_open': return render("proposal/not_open.mako") c.person = h.signed_in_person() defaults = { 'proposal.type': 1, 'proposal.video_release': 1, 'proposal.slides_release': 1, 'proposal.travel_assistance' : 1, 'proposal.accommodation_assistance' : 1, 'person.name': c.person.firstname + " " + c.person.lastname, 'person.mobile': c.person.mobile, 'person.experience': c.person.experience, 'person.bio': c.person.bio, 'person.url': c.person.url, } defaults['person_to_edit'] = c.person.id defaults['name'] = c.person.firstname + " " + c.person.lastname form = render("proposal/new.mako") return htmlfill.render(form, defaults)
def new(self): c.signed_in_person = h.signed_in_person() c.events = Event.find_all() c.schedule = Schedule.find_all() c.time_slot = TimeSlot.find_all() if not c.signed_in_person.registration: return render('/vote/no_rego.mako') c.votes = Vote.find_by_rego(c.signed_in_person.registration.id) defaults = { 'vote.vote_value': 1 } args = request.GET eventid = args.get('eventid',0) revoke = args.get('revoke',0) c.eventid = eventid if int(eventid) != 0 and c.votes.count() < 4 and revoke == 0: c.vote = Vote() c.vote.rego_id = c.signed_in_person.registration.id c.vote.vote_value = 1 c.vote.event_id = eventid meta.Session.add(c.vote) meta.Session.commit() if int(eventid) != 0 and int(revoke) != 0: c.vote = Vote.find_by_event_rego(eventid,c.signed_in_person.registration.id) meta.Session.delete(c.vote) meta.Session.commit() redirect_to('new') form = render('/vote/new.mako') return htmlfill.render(form, defaults)
def _edit(self, id): # We need to recheck auth in here so we can pass in the id if not h.auth.authorized(h.auth.Or(h.auth.is_same_zookeepr_submitter(id), h.auth.has_organiser_role)): # Raise a no_auth error h.auth.no_role() if not h.auth.authorized(h.auth.has_organiser_role): if c.paper_editing == 'closed' and not h.auth.authorized(h.auth.has_late_submitter_role): return render("proposal/editing_closed.mako") elif c.paper_editing == 'not_open': return render("proposal/editing_not_open.mako") c.proposal = Proposal.find_by_id(id) for key in self.form_result['proposal']: setattr(c.proposal, key, self.form_result['proposal'][key]) c.proposal.abstract = self.clean_abstract(c.proposal.abstract) c.person = self.form_result['person_to_edit'] if (c.person.id == h.signed_in_person().id or h.auth.authorized(h.auth.has_organiser_role)): for key in self.form_result['person']: setattr(c.person, key, self.form_result['person'][key]) p_edit = "and author" else: p_edit = "(but not author)" meta.Session.commit() if lca_info['proposal_update_email'] != '': body = "Subject: %s Proposal Updated\n\nID: %d\nTitle: %s\nType: %s\nURL: %s" % (h.lca_info['event_name'], c.proposal.id, c.proposal.title, c.proposal.type.name.lower(), "http://" + h.host_name() + h.url_for(action="view")) email(lca_info['proposal_update_email'], body) h.flash("Proposal %s edited!"%p_edit) return redirect_to('/proposal')
def new(self): # call for miniconfs has closed if c.cfmini_status == 'closed': return render("proposal/closed_mini.mako") elif c.cfmini_status == 'not_open': return render("proposal/not_open_mini.mako") c.proposal_type = ProposalType.find_by_name('Miniconf') c.person = h.signed_in_person() defaults = { 'proposal.type': c.proposal_type.id, 'proposal.technical_requirements': "", 'proposal.accommodation_assistance': 1, 'proposal.travel_assistance': 1, 'proposal.video_release': 0, 'proposal.slides_release': 0, 'person.name' : c.person.firstname + " " + c.person.lastname, 'person.mobile' : c.person.mobile, 'person.experience' : c.person.experience, 'person.bio' : c.person.bio, } form = render("proposal/new_mini.mako") return htmlfill.render(form, defaults)
def _new(self): person_results = self.form_result['person'] proposal_results = self.form_result['proposal'] attachment_results = self.form_result['attachment'] proposal_results['status'] = ProposalStatus.find_by_name('Pending') c.proposal = Proposal(**proposal_results) meta.Session.add(c.proposal) if not h.signed_in_person(): c.person = model.Person(**person_results) meta.Session.add(c.person) email(c.person.email_address, render('/person/new_person_email.mako')) else: c.person = h.signed_in_person() for key in person_results: setattr(c.person, key, self.form_result['person'][key]) c.person.proposals.append(c.proposal) if attachment_results is not None: c.attachment = Attachment(**attachment_results) c.proposal.attachments.append(c.attachment) meta.Session.add(c.attachment) meta.Session.commit() email(c.person.email_address, render('proposal/thankyou_mini_email.mako')) h.flash("Proposal submitted!") return redirect_to(controller='proposal', action="index", id=None)
def _check_invoice(self, person, invoice, ignore_overdue = False): c.invoice = invoice if person.invoices: if invoice.paid() or invoice.bad_payments().count() > 0: c.status = [] if invoice.total()==0: c.status.append('zero balance') if invoice.good_payments().count() > 0: c.status.append('paid') if invoice.good_payments().count()>1: c.status[-1] += ' (%d times)' % invoice.good_payments().count() if invoice.bad_payments().count() > 0: c.status.append('tried to pay') if invoice.bad_payments().count()>1: c.status[-1] += ' (%d times)' % invoice.bad_payments().count() c.status = ' and '.join(c.status) return render('/invoice/already.mako') if invoice.is_void(): c.signed_in_person = h.signed_in_person() return render('/invoice/invalid.mako') if not ignore_overdue and invoice.overdue(): for ii in invoice.items: if ii.product and not ii.product.available(): return render('/invoice/expired.mako') return None # All fine
def edit(self, id): # We need to recheck auth in here so we can pass in the id if not h.auth.authorized(h.auth.Or(h.auth.is_same_zookeepr_funding_submitter(id), h.auth.has_organiser_role)): # Raise a no_auth error h.auth.no_role() if not h.auth.authorized(h.auth.has_organiser_role): if c.funding_editing == 'closed': return render("funding/editing_closed.mako") elif c.funding_editing == 'not_open': return render("funding/editing_not_open.mako") c.funding = Funding.find_by_id(id) defaults = {} defaults.update(h.object_to_defaults(c.funding, 'funding')) # This is horrible, don't know a better way to do it if c.funding.type: defaults['funding.type'] = defaults['funding.funding_type_id'] if c.funding.male: defaults['funding.male'] = 1 else: defaults['funding.male'] = 0 form = render('/funding/edit.mako') return htmlfill.render(form, defaults)
def table(self, day=None): filter = dict(request.GET) if len(c.scheduled_dates) == 0: return render('/schedule/no_schedule_available.mako') c.display_date = None available_days = {} for scheduled_date in c.scheduled_dates: available_days[scheduled_date.strftime('%A').lower()] = scheduled_date if day in available_days: c.display_date = available_days[day] if c.display_date is None: if date.today() in c.scheduled_dates: c.display_date = date.today() else: c.display_date = c.scheduled_dates[0] c.time_slots = TimeSlot.find_by_date(c.display_date) c.primary_times = {} for time_slot in TimeSlot.find_by_date(c.display_date, primary=True): c.primary_times[time_slot.start_time] = time_slot event_type = EventType.find_by_name('presentation') c.locations = Location.find_scheduled_by_date_and_type(c.display_date, event_type) event_type = EventType.find_by_name('mini-conf') c.locations = c.locations + Location.find_scheduled_by_date_and_type(c.display_date, event_type) c.schedule_collection = Schedule.find_by_date(c.display_date) c.time_increment = timedelta(minutes=5) c.programme = OrderedDict() for time_slot in c.time_slots: time = time_slot.start_time while time < time_slot.end_time: c.programme[time] = {} time = time + c.time_increment for schedule in c.schedule_collection: exclusive_event = schedule.time_slot.exclusive_event() time = schedule.time_slot.start_time if exclusive_event: c.programme[time]['exclusive'] = exclusive_event else: c.programme[time][schedule.location] = schedule if filter.has_key('raw'): return render('/schedule/table_raw.mako') else: return render('/schedule/table.mako')
def index(self): c.DAYS_OPEN = DAYS_OPEN c.open_date = lca_info.lca_info['date'] days_open = (datetime.date.today() - c.open_date.date()).days photo_db = PhotoCompEntry.read_db() photos = [ photo for days in photo_db.values() for entries in days for photo in entries if photo is not None and photo.day < days_open] c.no_photos = not photos day_filter = request.GET.get('day', 'All') if day_filter and day_filter != 'All': photos = [p for p in photos if str(p.day) == day_filter] person_filter = request.GET.get('person', 'All') if person_filter and person_filter != 'All': photos = [p for p in photos if str(p.person_id) == person_filter] submitted = request.GET.get('s', None) randomise = not submitted or 'randomise' in request.GET if randomise: random.shuffle(photos) else: photos.sort(key=lambda p: (p.day, p.person_id, p.entry_id)) person_map = {} for photo in photos: photo.write_scaled() person_map[photo.person_id] = None c.all_person = [] for person_id in person_map: person = Person.find_by_id(person_id) person_map[person_id] = person c.all_person.append(person) c.all_person.sort(key=lambda person: (person.firstname + " " + person.lastname).lower()) c.photos = photos def photo_title(photo): return "%s %s, %s entry %s, %s" % ( person_map[photo.person_id].firstname, person_map[photo.person_id].lastname, (c.open_date + datetime.timedelta(photo.day)).strftime('%A'), ENTRY_NAMES[photo.entry_id], photo.image_name,) c.photo_title = photo_title field_values = { 'day': day_filter, 'person': person_filter, } if randomise: field_values['randomise'] = '1' if submitted == 'Full Screen' and photos: html = render('/photocomp/index-fullscreen.mako') else: html = render('/photocomp/index.mako') return htmlfill.render(html, field_values)
def view_talk(self, id): try: c.day = request.GET['day'] except: c.day = 'all' try: c.talk = Proposal.find_accepted_by_id(id) except: c.talk_id = id c.webmaster_email = lca_info['webmaster_email'] return render('/schedule/invalid_talkid.mako') return render('/schedule/table_view.mako')
def new(self): if c.funding_status == 'closed': if not h.auth.authorized(h.auth.has_late_submitter_role): return render("funding/closed.mako") elif c.funding_status == 'not_open': return render("funding/not_open.mako") c.person = h.signed_in_person() defaults = { 'funding.type': 1, } form = render("funding/new.mako") return htmlfill.render(form, defaults)
def _reset_password(self, url_hash): """Confirm a password change request, and let the user change their password. `url_hash` is a hash of the email address, with which we can look up the confuirmation record in the database. If `url_hash` doesn't exist, 404. If `url_hash` exists and the date is older than 24 hours, warn the user, offer to send a new confirmation, and delete the confirmation record. GET returns a form for setting their password, with their email address already shown. POST checks that the email address (in the session, not in the form) is part of a valid person record (again). If the record exists, then update the password, hashed. Report success to the user. Delete the confirmation record. If the record doesn't exist, throw an error, delete the confirmation record. """ c.conf_rec = PasswordResetConfirmation.find_by_url_hash(url_hash) now = datetime.datetime.now(c.conf_rec.timestamp.tzinfo) delta = now - c.conf_rec.timestamp if delta > datetime.timedelta(hours=24): # this confirmation record has expired meta.Session.delete(c.conf_rec) meta.Session.commit() return render('person/expired.mako') person = Person.find_by_email(c.conf_rec.email_address) if person is None: raise RuntimeError, "Person doesn't exist %s" % c.conf_rec.email_address # set the password person.password = self.form_result['password'] # also make sure the person is activated person.activated = True # delete the conf rec meta.Session.delete(c.conf_rec) meta.Session.commit() return render('person/success.mako')
def void(self, id): if not h.auth.authorized(h.auth.Or(h.auth.is_same_zookeepr_attendee(id), h.auth.has_organiser_role)): # Raise a no_auth error h.auth.no_role() c.invoice = Invoice.find_by_id(id, True) if c.invoice.is_void(): h.flash("Invoice was already voided.") return redirect_to(action='view', id=c.invoice.id) if h.auth.authorized(h.auth.has_organiser_role): c.invoice.void = "Administration Change" meta.Session.commit() h.flash("Invoice was voided.") return redirect_to(action='view', id=c.invoice.id) else: if c.invoice.paid(): h.flash("Cannot void a paid invoice.") return redirect_to(action='view', id=c.invoice.id) c.invoice.void = "User cancellation" c.person = c.invoice.person meta.Session.commit() email(lca_info['contact_email'], render('/invoice/user_voided.mako')) h.flash("Previous invoice was voided.") return redirect_to(controller='registration', action='pay', id=c.person.registration.id)
def _pay(self, id): payment = Payment.find_by_id(self.form_result['payment_id']) c.invoice = payment.invoice person = c.invoice.person if not h.auth.authorized(h.auth.Or(h.auth.is_same_zookeepr_user(person.id), h.auth.has_organiser_role, h.auth.has_unique_key())): # Raise a no_auth error h.auth.no_role() error = self._check_invoice(person, c.invoice) if error is not None: return error client_ip = request.environ['REMOTE_ADDR'] if 'HTTP_X_FORWARDED_FOR' in request.environ: client_ip = request.environ['HTTP_X_FORWARDED_FOR'] # Prepare fields for PxPay params = { 'payment_id': payment.id, 'amount': "%#.*f" % (2, payment.amount / 100.0), 'invoice_id': payment.invoice.id, 'email_address': payment.invoice.person.email_address, 'client_ip' : client_ip, 'return_url' : 'https://conf.linux.org.au/payment/new', } (valid, uri) = pxpay.generate_request(params) if valid != '1': c.error_msg = "PxPay Generate Request error: " + uri return render("/payment/gateway_error.mako") else: redirect(uri)
def signout_confirm(self, id=None): """ Confirm user wants to sign out """ if id is not None: redirect_to(action='signout_confirm', id=None) return render('/person/signout.mako')
def index(self): # Check access and redirect if not h.auth.authorized(h.auth.has_organiser_role): redirect_to(action="new") c.volunteer_collection = Volunteer.find_all() return render("volunteer/list.mako")
def edit(self, id): # A person can only volunteer once c.form = "edit" c.volunteer = Volunteer.find_by_id(id) defaults = h.object_to_defaults(c.volunteer, "volunteer") form = render("/volunteer/edit.mako") return htmlfill.render(form, defaults)
def edit(self, id): c.rego_note = RegoNote.find_by_id(id) defaults = h.object_to_defaults(c.rego_note, "rego_note") form = render("rego_note/edit.mako") return htmlfill.render(form, defaults)
def edit(self, id): c.product_category = ProductCategory.find_by_id(id) defaults = h.object_to_defaults(c.product_category, 'product_category') form = render('/product_category/edit.mako') return htmlfill.render(form, defaults)
def edit(self, id): c.stream = Stream.find_by_id(id) defaults = h.object_to_defaults(c.stream, 'stream') form = render('/stream/edit.mako') return htmlfill.render(form, defaults)
def review(self, id): c.funding = Funding.find_by_id(id) c.signed_in_person = h.signed_in_person() c.next_review_id = Funding.find_next_proposal(c.funding.id, c.funding.type.id, c.signed_in_person.id) return render('/funding/review.mako')
def edit(self, id): c.location = Location.find_by_id(id) defaults = h.object_to_defaults(c.location, 'location') form = render('/location/edit.mako') return htmlfill.render(form, defaults)
def summary(self): for ft in c.funding_types: stuff = Funding.find_all_by_funding_type_id(ft.id, include_withdrawn=False) stuff.sort(self._score_sort) setattr(c, '%s_collection' % ft.name, stuff) return render('funding/summary.mako')
def withdraw(self, id): if not h.auth.authorized(h.auth.Or(h.auth.is_same_zookeepr_submitter(id), h.auth.has_organiser_role)): # Raise a no_auth error h.auth.no_role() c.proposal = Proposal.find_by_id(id) return render("/proposal/withdraw.mako")
def edit(self, id): c.rego_room = RegoRoom.find_by_id(id) defaults = h.object_to_defaults(c.rego_room, 'rego_room') form = render('rego_room/edit.mako') return htmlfill.render(form, defaults)
def withdraw(self, id): if not h.auth.authorized(h.auth.Or(h.auth.is_same_zookeepr_funding_submitter(id), h.auth.has_organiser_role)): # Raise a no_auth error h.auth.no_role() c.funding = Funding.find_by_id(id) return render("/funding/withdraw.mako")
def edit(self, id): c.special_offer = SpecialOffer.find_by_id(id) defaults = h.object_to_defaults(c.special_offer, 'special_offer') form = render('/special_offer/edit.mako') return htmlfill.render(form, defaults)
def summary(self): for pt in c.proposal_types: stuff = Proposal.find_all_by_proposal_type_id( pt.id, include_withdrawn=False) stuff.sort(self._score_sort) setattr(c, '%s_collection' % pt.name, stuff) for aat in c.accommodation_assistance_types: stuff = Proposal.find_all_by_accommodation_assistance_type_id( aat.id) setattr(c, '%s_collection' % aat.name, stuff) for tat in c.travel_assistance_types: stuff = Proposal.find_all_by_travel_assistance_type_id(tat.id) setattr(c, '%s_collection' % tat.name, stuff) return render('proposal/summary.mako')
def view(self, id): c.db_content = DbContent.find_by_id(id) if not c.db_content.published and not h.auth.authorized( h.auth.has_organiser_role): c.db_content = None return NotFoundController().view() elif not c.db_content.published: h.flash( "This content is marked as unpublished and is only viewable by organisers.", 'Warning') if c.db_content.type.name == 'Redirect': redirect_to(c.db_content.body.encode("latin1"), _code=301) c.html_headers, c.html_body, c.menu_contents = self.parse_dbpage( c.db_content.body) return render('/db_content/view.mako')
def edit(self, id): c.time_slot = TimeSlot.find_by_id(id) defaults = h.object_to_defaults(c.time_slot, 'time_slot') defaults['time_slot.start_date'] = c.time_slot.start_time.strftime( '%d/%m/%y') defaults['time_slot.start_time'] = c.time_slot.start_time.strftime( '%H:%M:%S') defaults['time_slot.end_date'] = c.time_slot.end_time.strftime( '%d/%m/%y') defaults['time_slot.end_time'] = c.time_slot.end_time.strftime( '%H:%M:%S') form = render('/time_slot/edit.mako') return htmlfill.render(form, defaults)
def delete_file(self): try: if request.GET['file'] is not None: c.file += request.GET['file'] c.current_folder += request.GET['folder'] except KeyError: abort(404) directory = file_paths['public_path'] defaults = dict(request.POST) if defaults: os.remove(directory + c.file) h.flash("File Removed") redirect_to(action="list_files", folder=c.current_folder) return render('/db_content/delete_file.mako')
def list_news(self): if c.db_content_types: page = 1 if request.GET.has_key('page'): page = request.GET['page'] pagination = paginate.Page(DbContent.find_all_by_type("News"), page=page, items_per_page=10) c.db_content_pages = pagination c.db_content_collection = pagination.items c.result = True else: c.result = False return render('/db_content/list_news.mako')
def printable(self, id): if not h.auth.authorized( h.auth.Or(h.auth.is_same_zookeepr_attendee(id), h.auth.has_organiser_role, h.auth.has_unique_key())): # Raise a no_auth error h.auth.no_role() c.printable = True c.invoice = Invoice.find_by_id(id, True) c.payment_received = None c.payment = None if c.invoice.paid() and c.invoice.total() > 0: c.payment_received = c.invoice.good_payments()[0] c.payment = c.payment_received.payment return render('/invoice/view_printable.mako')
def new_manual(self, id): c.payment = Payment.find_by_id(id) payment = None c.person = c.payment.invoice.person defaults = { 'payment.approved': 1, 'payment.email_address': c.person.email_address, 'payment.success_code': 'Received', 'payment.amount_paid': c.payment.amount, 'payment.currency_used': 'AUD', } form = render('/payment/new.mako') return htmlfill.render(form, defaults)
def pdf(self, id): if not h.auth.authorized( h.auth.Or(h.auth.is_same_zookeepr_attendee(id), h.auth.has_organiser_role, h.auth.has_unique_key())): # Raise a no_auth error h.auth.no_role() import os, tempfile, libxml2, libxslt c.invoice = Invoice.find_by_id(id, True) xml_s = render('/invoice/pdf.mako') xsl_f = file_paths['zk_root'] + '/zookeepr/templates/invoice/pdf.xsl' xsl_s = libxml2.parseFile(xsl_f) xsl = libxslt.parseStylesheetDoc(xsl_s) xml = libxml2.parseDoc(xml_s) svg_s = xsl.applyStylesheet(xml, None) (svg_fd, svg) = tempfile.mkstemp('.svg') xsl.saveResultToFilename(svg, svg_s, 0) xsl.freeStylesheet() xml.freeDoc() svg_s.freeDoc() (pdf_fd, pdf) = tempfile.mkstemp('.pdf') os.close(svg_fd) os.close(pdf_fd) os.system('inkscape -z -f %s -A %s' % (svg, pdf)) pdf_f = file(pdf) res = Response(pdf_f.read()) pdf_f.close() res.headers['Content-type'] = 'application/pdf' #res.headers['Content-type']='application/octet-stream' #res.headers['Content-type']='text/plain; charset=utf-8' filename = lca_info['event_shortname'] + '_' + str( c.invoice.id) + '.pdf' res.headers['Content-Disposition'] = ('attachment; filename=%s' % filename) # We should really remove the pdf file, shouldn't we. return res
def list_files(self): # Taken from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/170242 def caseinsensitive_sort(stringList): """case-insensitive string comparison sort doesn't do locale-specific compare though that would be a nice addition usage: stringList = caseinsensitive_sort(stringList)""" tupleList = [(x.lower(), x) for x in stringList] tupleList.sort() return [x[1] for x in tupleList] directory = file_paths['public_path'] download_path = file_paths['public_html'] current_path = "/" try: if request.GET['folder'] is not None: directory += request.GET['folder'] download_path += request.GET['folder'] current_path = request.GET['folder'] except KeyError: download_path += '/' defaults = dict(request.POST) if defaults: try: if request.POST['folder'] is not None: os.mkdir(directory + request.POST['folder']) except KeyError: h.flash("Error creating folder. Check file permissions.", 'error') else: h.flash("Folder Created") files = [] folders = [] for filename in os.listdir(directory): if os.path.isdir(directory + "/" + filename): folders.append(filename + "/") else: files.append(filename) c.file_list = caseinsensitive_sort(files) c.folder_list = caseinsensitive_sort(folders) c.current_path = current_path c.download_path = download_path return render('/db_content/list_files.mako')
def accept(self, id): volunteer = Volunteer.find_by_id(id) category = ProductCategory.find_by_name('Ticket') products = Product.find_by_category(category.id) defaults = {} if volunteer.ticket_type: defaults['ticket_type'] = volunteer.ticket_type.id c.products_select = [] c.products_select.append(['', 'No Ticket']) for p in products: if 'Volunteer' in p.description: c.products_select.append([ p.id, p.description + ' - ' + h.number_to_currency(p.cost / 100) ]) form = render('volunteer/accept.mako') return htmlfill.render(form, defaults)
def review(self, id): c.streams = Stream.select_values() c.proposal = Proposal.find_by_id(id) c.signed_in_person = h.signed_in_person() # TODO: currently not enough (see TODOs in model/proposal.py) #if not h.auth.authorized(h.auth.has_organiser_role): # # You can't review your own proposal # for person in c.proposal.people: # if person.id == c.signed_in_person.id: # h.auth.no_role() c.next_review_id = Proposal.find_next_proposal(c.proposal.id, c.proposal.type.id, c.signed_in_person.id) return render('/proposal/review.mako')
def edit(self, id): # We need to recheck auth in here so we can pass in the id if not h.auth.authorized( h.auth.Or(h.auth.is_same_zookeepr_user(id), h.auth.has_organiser_role)): # Raise a no_auth error h.auth.no_role() c.form = 'edit' c.person = Person.find_by_id(id) c.social_networks = SocialNetwork.find_all() c.person.fetch_social_networks() defaults = h.object_to_defaults(c.person, 'person') defaults['person.email_address2'] = c.person.email_address form = render('/person/edit.mako') return htmlfill.render(form, defaults)
def view(self, id): c.volunteer = Volunteer.find_by_id(id) # We need to recheck auth in here so we can pass in the id if not h.auth.authorized( h.auth.Or(h.auth.is_same_zookeepr_user(c.volunteer.person.id), h.auth.has_organiser_role)): # Raise a no_auth error h.auth.no_role() c.can_edit = h.auth.is_same_zookeepr_user(c.volunteer.person.id) c.volunteer = Volunteer.find_by_id(id) if c.volunteer is None: abort(404, "No such object") return render('volunteer/view.mako')
def review_index(self): c.person = h.signed_in_person() c.num_proposals = 0 reviewer_role = Role.find_by_name('reviewer') c.num_reviewers = len(reviewer_role.people) for pt in c.proposal_types: stuff = Proposal.find_all_by_proposal_type_id( pt.id, include_withdrawn=False) c.num_proposals += len(stuff) setattr(c, '%s_collection' % pt.name, stuff) for aat in c.accommodation_assistance_types: stuff = Proposal.find_all_by_accommodation_assistance_type_id( aat.id) setattr(c, '%s_collection' % aat.name, stuff) for tat in c.travel_assistance_types: stuff = Proposal.find_all_by_travel_assistance_type_id(tat.id) setattr(c, '%s_collection' % tat.name, stuff) return render('proposal/list_review.mako')
def index(self): """The home page of the website. If the user has not signed in, then they are presented with the default page. Otherwise, they're shown the customised page. We rely on `c.signed_in_person` containing the Person object for the currently signed in user, but we don't want to redirect to the signin action if we're not signed in so we duplicate the __before__ code from SecureController here. """ if 'signed_in_person_id' in session: c.signed_in_person = self.dbsession.query(Person).filter_by( id=session['signed_in_person_id']).one() c.db_content = DbContent.find_by_url('/home', abort_404=False) return render('/home.mako')
def delete_folder(self): try: if request.GET['folder'] is not None: c.folder += request.GET['folder'] c.current_folder += request.GET['current_path'] except KeyError: abort(404) directory = file_paths['public_path'] defaults = dict(request.POST) if defaults: try: os.rmdir(directory + c.folder) except OSError: h.flash("Can not delete. The folder contains items.", 'error') redirect_to(action="list_files", folder=c.current_folder) h.flash("Folder deleted.") redirect_to(action="list_files", folder=c.current_folder) return render('/db_content/delete_folder.mako')
def edit(self, id): c.ceiling = Ceiling.find_by_id(id) defaults = h.object_to_defaults(c.ceiling, 'ceiling') defaults['ceiling.products'] = [] for product in c.ceiling.products: defaults['ceiling.products'].append(product.id) if c.ceiling.available_from: defaults[ 'ceiling.available_from'] = c.ceiling.available_from.strftime( '%d/%m/%y') if c.ceiling.available_until: defaults[ 'ceiling.available_until'] = c.ceiling.available_until.strftime( '%d/%m/%y') form = render('/ceiling/edit.mako') return htmlfill.render(form, defaults)
def _withdraw(self, id): if not h.auth.authorized( h.auth.Or(h.auth.is_same_zookeepr_submitter(id), h.auth.has_organiser_role)): # Raise a no_auth error h.auth.no_role() c.proposal = Proposal.find_by_id(id) status = ProposalStatus.find_by_name('Withdrawn') c.proposal.status = status meta.Session.commit() c.person = h.signed_in_person() # Make sure the organisers are notified of this c.email_address = h.lca_info['emails'][c.proposal.type.name.lower()] email(c.email_address, render('/proposal/withdraw_email.mako')) h.flash("Proposal withdrawn. The organisers have been notified.") return redirect_to(controller='proposal', action="index", id=None)
def edit(self, id=None): # # Helpfully redirect to the correct URL. # if id is None: return redirect_to(h.url_for(id=h.signed_in_person().id)) # # Only an organiser can edit someone elses photos. # if not h.auth.authorized(h.auth.Or(h.auth.is_same_zookeepr_user(id), h.auth.has_organiser_role)): h.auth.no_role() person_id = int(id, 10) c.open_date = lca_info.lca_info['date'] c.days_open = (datetime.date.today() - c.open_date.date()).days photo_db = PhotoCompEntry.read_db() c.photo = lambda day, entry: PhotoCompEntry.get(photo_db, person_id, day, entry) c.is_organiser = h.auth.authorized(h.auth.has_organiser_role) c.DAYS_OPEN = DAYS_OPEN c.ENTRY_NAMES = ENTRY_NAMES return render('/photocomp/edit.mako')
def _roles(self, id): """ Lists and changes the person's roles. """ c.person = Person.find_by_id(id) c.roles = Role.find_all() role = self.form_result['role'] action = self.form_result['action'] role = Role.find_by_name(name=role) if action == 'Revoke' and role in c.person.roles: c.person.roles.remove(role) h.flash('Role ' + role.name + ' Revoked') elif action == 'Grant' and role not in c.person.roles: c.person.roles.append(role) h.flash('Role ' + role.name + ' Granted') else: h.flash("Nothing to do") meta.Session.commit() return render('person/roles.mako')
def generate_hash(self, id): if not h.auth.authorized( h.auth.Or(h.auth.is_same_zookeepr_attendee(id), h.auth.has_organiser_role, h.auth.has_unique_key())): # Raise a no_auth error h.auth.no_role() url = h.url_for(action='view', id=id) c.hash = URLHash.find_by_url(url=url) if c.hash is None: c.hash = URLHash() c.hash.url = url meta.Session.add(c.hash) meta.Session.commit() # create an entry for the payment page (not needed) # TODO: depending on how the gateway works, you may need to make sure you have permissions for the page you get redirected to #c.hash = URLHash() #c.hash.url = h.url_for(action='pay') #meta.Session.add(c.hash) #meta.Session.commit() return render('/invoice/generate_url.mako')
def pay(self, id): """Request confirmation from user """ invoice = Invoice.find_by_id(id, True) person = invoice.person if not h.auth.authorized( h.auth.Or(h.auth.is_same_zookeepr_user(person.id), h.auth.has_organiser_role, h.auth.has_unique_key())): # Raise a no_auth error h.auth.no_role() #return render('/registration/really_closed.mako') error = self._check_invoice(person, invoice) if error is not None: return error c.payment = Payment() c.payment.amount = invoice.total() c.payment.invoice = invoice meta.Session.commit() return render("/invoice/payment.mako")
def index(self): c.can_edit = True c.ceiling_collection = Ceiling.find_all() return render('/ceiling/list.mako')
def special_cases(self, id): c.ceiling = Ceiling.find_by_id(id) return render('/ceiling/special_cases.mako')
def view(self, id): c.ceiling = Ceiling.find_by_id(id) return render('/ceiling/view.mako')
def new(self): return render('/ceiling/new.mako')
def index(self): c.event_collection = Event.find_all() return render('/event/list.mako')
def index(self): c.can_edit = True c.special_offer_collection = SpecialOffer.find_all() return render('/special_offer/list.mako')
def view(self, id): c.special_offer = SpecialOffer.find_by_id(id) c.registrations = SpecialRegistration.find_by_offer(id) return render('/special_offer/view.mako')
def new(self): return render('/special_offer/new.mako')