Exemplo n.º 1
0
 def add_player(self):
     first = self.form_result['first']
     last = self.form_result['last']
     position = self.form_result['position']
     session = Session()
     if session.query(Player).filter_by(first=first, last=last).count() > 0:
         h.flash("Player already exists!")
         return h.redirect_to(controller='roster')
     player = Player(first, last, position)
     session.add(player)
     session.commit()
     return h.redirect_to(controller='roster', action='index')
 def add_player(self):
     first = self.form_result['first']
     last = self.form_result['last']
     position = self.form_result['position']
     session = Session()
     if session.query(Player).filter_by(first=first, last=last).count() > 0:
         h.flash("Player already exists!")
         return h.redirect_to(controller='roster')
     player = Player(first, last, position)
     session.add(player)
     session.commit()
     return h.redirect_to(controller='roster', action='index')
Exemplo n.º 3
0
def process_release_results(context, msg, result, session):
    "Process the results of a release task"
    html = []
    context.id = msg.messageid
    errors = dict(result['errors'])
    templates = dict(
                    release='/messages/includes/released.html',
                    learn='/messages/includes/salearn.html',
                    delete='/messages/includes/delete.html'
                    )
    def rendertemplate(error_msg, action):
        "Render template"
        context.msg = error_msg
        context.success =  error_msg == ''
        html.append(render(templates[action]))

    if context.form.release.data:
        #release
        if context.form.usealt.data:
            to_addr = context.form.altrecipients.data
        else:
            to_addr = msg.to_address
        to_addr = to_addr.split(',')
        error_msg = ''
        if not result['release']:
            error_msg = errors['release']
        context.addrs = to_addr
        rendertemplate(error_msg, 'release')
    if context.form.learn.data:
        #salean
        error_msg = ''
        if not result['learn']:
            ['learn']
            error_msg = errors['learn']
        rendertemplate(error_msg, 'learn')
    if context.form.delete.data:
        #delete
        error_msg = ''
        if not result['delete']:
            error_msg = errors['delete']
        else:
            msg.isquarantined = True
            session.add(msg)
            session.commit()
        rendertemplate(error_msg, 'delete')
    return '<br />'.join(html)
Exemplo n.º 4
0
def process_release_results(context, msg, result, session):
    "Process the results of a release task"
    html = []
    context.id = msg.messageid
    errors = dict(result['errors'])
    templates = dict(
                    release='/messages/includes/released.html',
                    learn='/messages/includes/salearn.html',
                    delete='/messages/includes/delete.html'
                    )
    def rendertemplate(error_msg, action):
        "Render template"
        context.msg = error_msg
        context.success =  error_msg == ''
        html.append(render(templates[action]))

    if context.form.release.data:
        #release
        if context.form.usealt.data:
            to_addr = context.form.altrecipients.data
        else:
            to_addr = msg.to_address
        to_addr = to_addr.split(',')
        error_msg = ''
        if not result['release']:
            error_msg = errors['release']
        context.addrs = to_addr
        rendertemplate(error_msg, 'release')
    if context.form.learn.data:
        #salean
        error_msg = ''
        if not result['learn']:
            ['learn']
            error_msg = errors['learn']
        rendertemplate(error_msg, 'learn')
    if context.form.delete.data:
        #delete
        error_msg = ''
        if not result['delete']:
            error_msg = errors['delete']
        else:
            msg.isquarantined = True
            session.add(msg)
            session.commit()
        rendertemplate(error_msg, 'delete')
    return '<br />'.join(html)
Exemplo n.º 5
0
    def register(self):
        user = model.DKUser()

        user.username = request.POST["username"]
        user.passwd = md5(request.POST["passwd"]).hexdigest()
        user.master_email = request.POST["email"]
        user.phone_mobile = request.POST["phone_mobile"]
        user.phone_office = request.POST["phone_office"]
        user.phone_home = request.POST["phone_home"]
        user.org = request.POST["org"]
        user.title = request.POST["title"]
        user.addr = request.POST["addr"]
        #roles is stored as ":" seperated string
        user.roles = ":".join((meta.ROLE_USER, ))

        session = model.meta.Session
        session.add(user)
        session.commit()
        return pack_result(RS_SUCCESS)
Exemplo n.º 6
0
    def register(self):
        user = model.DKUser()

        user.username = request.POST["username"]
        user.passwd = md5(request.POST["passwd"]).hexdigest()
        user.master_email = request.POST["email"]
        user.phone_mobile = request.POST["phone_mobile"]
        user.phone_office = request.POST["phone_office"]
        user.phone_home = request.POST["phone_home"]
        user.org = request.POST["org"]
        user.title = request.POST["title"]
        user.addr = request.POST["addr"]
        #roles is stored as ":" seperated string
        user.roles = ":".join((meta.ROLE_USER, ))

        session = model.meta.Session
        session.add(user)
        session.commit()
        return pack_result(RS_SUCCESS)
Exemplo n.º 7
0
 def process_multi(self):
     log_fb_request(request)
     facebook.process_request()
     c.is_app_user = facebook.api_client.added
     if not c.is_app_user:
         return '<fb:redirect url="index" />'
     
     current_user = facebook.user
     if not current_user:
         return '<fb:redirect url="index" />'
     
     session = meta.Session()
     
     fb_user = user_logic.get_fb_userpersona(session, current_user)
     if fb_user is None:
         return '<fb:redirect url="index" />'
     
     # validate
     total_amount = request.POST.get('total_amount')
     charity_ids = request.POST.getall('charity_val')
     
     if charity_ids is None or len(charity_ids) == 0:
         c.error_msg = 'No charities were specified.'
         return render('/facebook/setup_multi.tmpl')
     
     # save (pending) multi-use token info to DB
     multiuse_token = MultiUseToken(fb_user.user.id, float(total_amount))
     session.add(multiuse_token)
     session.flush()
     caller_ref = 'wgmultiuse_%d_%s' % (multiuse_token.id, uuid.uuid1().hex)
     multiuse_token.caller_reference = caller_ref
     session.commit()
     log_payment_event('APP', 'Created multi-use token', caller_ref=caller_ref, new_status='new')
     
     # compute parameters for request to Co-Branded FPS pages
     reason = 'Authorize multiple donations'
     charity_tokens = []
     for charity_id in charity_ids:
         charity = self._get_charity(charity_id)
         if FPS_PROMO_ACTIVE:
             recipient_token = charity.promo_recipient_token_id
         else:
             recipient_token = charity.recipient_token_id
         charity_tokens.append(recipient_token)
     recipient_token_list = ",".join(charity_tokens)
     
     # info for multi-use token CBUI call:
     #
     # - minimum transaction amount: 1.00
     # - expiration: default 1 year
     # - maximum amount limit: total amount (from user)
     # - recipients: list of tokens from charities
     #
     direct_url = fps_logic.get_multiuse_cbui_url(caller_ref,
                                                  reason,
                                                  total_amount,
                                                  minimum_amount=1.0,
                                                  recipient_token_list=recipient_token_list,
                                                  return_url = c.canvas_url + '/multiuse_return',
                                                  website_desc='We Give Facebook application')
     
     return '<fb:redirect url="%s" />' % direct_url
Exemplo n.º 8
0
    def send_gift(self):
        """Render gift preview for user to review and then click 'Continue with donation'"""
        log_fb_request(request)
        facebook.process_request()
        c.is_app_user = facebook.api_client.added
        
        if not c.is_app_user:
            c.error_msg = 'You need to add this app before you can send gifts.'
            return render('/facebook/send_gift.tmpl')
        
        current_user = facebook.user
        if not current_user:
            c.error_msg = 'Error getting your user info.'
            return render('/facebook/send_gift.tmpl')
        
        session = meta.Session()
        
        fb_user = user_logic.get_fb_userpersona(session, current_user)
        if fb_user is None:
            # TODO: make sure use has added app
            # TODO: make sure user exists
            
            c.error_msg = 'You need to add this app before you can send gifts.'
            return render('/facebook/send_gift.tmpl')
        
        # validate
        c.recipient_id = request.POST.get('friend_selector_id')
        charity_id = request.params.get('charity_val')
        gift_id = request.params.get('gift_id')
        c.message = request.params.get('message')
        c.donation_amt = request.params.get('amount','1.00')
        stream_short_msg = request.params.get('stream_short_msg')
        
        form_uuid = request.params.get('uuid')
        # TODO: store & lookup uuid in memcached, to see if user is resubmitting form.  at least log the UUID.

        if c.recipient_id:
            recipient_info = facebook.api_client.users.getInfo([c.recipient_id], ['name', 'pic_square', 'locale'])[0]
            log.debug('recipient name: %s, pic: %s, locale: %s' % (recipient_info['name'], recipient_info['pic_square'], recipient_info['locale']) )
            
            recipient_userpersona = user_logic.get_fb_userpersona(session, c.recipient_id, create_if_missing=True)
        
        gift_q = meta.Session.query(Gift)
        charity_q = meta.Session.query(Charity)

        charity = charity_q.get(charity_id)
        if charity is None:
            c.error_msg = 'Charity not found'
            return render('/facebook/send_gift.tmpl')
        c.charity_name = charity.name
        
        c.gift = gift_q.get(gift_id)
        
        # save (pending) donation info to DB or session or memcache or something
        wg_user_id = fb_user.user.id
        donation = Donation(wg_user_id, recipient_userpersona.user.id, float(c.donation_amt), gift_id, charity_id)
        donation.message = c.message
        if stream_short_msg is not None and stream_short_msg.strip() != '':
            donation.stream_short_msg = stream_short_msg
        session.add(donation)
        session.commit()
        
        # check if user has multi-use token active
        multiuse_token_q = meta.Session.query(MultiUseToken)
        c.multiuse_token = multiuse_token_q.filter_by(user_id=wg_user_id).filter_by(is_active=True).filter(MultiUseToken.est_amount_remaining >= float(c.donation_amt)).first()
        
        # TODO: to prevent form resubmission, commit, then redirect to review_gift page with donation ID??
        
        # compute parameters for request to Co-Branded FPS pages
        c.caller_ref = 'wgdonation_%d_%s' % (donation.id, uuid.uuid1().hex)
        reason = 'Donation to %s' % charity.name
        if FPS_PROMO_ACTIVE:
            recipient_token = charity.promo_recipient_token_id
        else:
            recipient_token = charity.recipient_token_id
        c.direct_url = fps_logic.get_cbui_url(c.caller_ref,
                                              reason,
                                              c.donation_amt,
                                              recipient_token=recipient_token,
                                              website_desc='We Give Facebook application')
        
        log_payment_event('APP', 'Created donation', donation_id=donation.id, caller_ref=c.caller_ref, new_status='new')
        
        return render('/facebook/send_gift.tmpl')
Exemplo n.º 9
0
    def players(self):
        session = Session()
        players = [{
            'first': p.first,
            'last': p.last,
            'position': p.position,
            'id': p.id
        } for p in session.query(Player).all()]
        return players

    @jsonify
    def add_player(self):
        obj = json.loads(request.body)
        schema = PlayerForm()
        try:
            form_result = schema.to_python(obj)
        except formencode.Invalid, error:
            response.content_type = 'text/plain'
            return 'Invalid: ' + unicode(error)
        else:
            session = Session()
            first, last, position = obj['first'], obj['last'], obj['position']
            if session.query(Player).filter_by(last=last,
                                               first=first,
                                               position=position).count() == 0:
                session.add(Player(first, last, position))
                session.commit()
                return {'result': 'OK'}
            else:
                return {'result': 'fail', 'msg': 'Player already exists'}
Exemplo n.º 10
0
Arquivo: api.py Projeto: jython/book
    @jsonify
    def players(self):
        session = Session()
        players = [{'first': p.first, 
                    'last': p.last, 
                    'position': p.position, 
                    'id': p.id} for p in session.query(Player).all()]
        return players

    @jsonify
    def add_player(self):
        obj = json.loads(request.body)
        schema = PlayerForm()
        try:
            form_result = schema.to_python(obj)
        except formencode.Invalid, error:
            response.content_type = 'text/plain'
            return 'Invalid: '+unicode(error)
        else:
            session = Session()
            first, last, position = obj['first'], obj['last'], obj['position']
            if session.query(Player).filter_by(last=last, first=first,
                    position=position).count() == 0:
                session.add(Player(first, last, position))
                session.commit()
                return {'result': 'OK'}
            else:
                return {'result':'fail', 'msg': 'Player already exists'}