예제 #1
0
    def fromJson(json_obj):

        ModelValidator.json('event', json_obj)

        event = Event(
            name=json_obj["name"],
            datetime=parser.parse(json_obj["datetime"]),
            venue_id=json_obj["venue_id"],
            creator_id=json_obj["creator_id"],
        )

        #create invitations
        for p in json_obj['participant_ids']:
            user = User.query.get(p)
            if user is not None:
                i = Invitation()
                i.user = user
                event.participant_ids.append(i)

        if 'public' in json_obj:
            event.public = json_obj["public"]

        if 'tags' in json_obj:
            for t in json_obj['tags']:
                tag = Tag.get_or_create(name=t)
                event.tags.append(tag)

        return event
예제 #2
0
파일: event.py 프로젝트: inkrement/server
    def fromJson(json_obj):

        ModelValidator.json('event', json_obj)

        event = Event(
            name =json_obj["name"],
            datetime=parser.parse(json_obj["datetime"]),
            venue_id = json_obj["venue_id"],
            creator_id = json_obj["creator_id"],
        )

        #create invitations
        for p in json_obj['participant_ids']:
            user = User.query.get(p)
            if user is not None:
                i = Invitation()
                i.user = user
                event.participant_ids.append(i)

        if 'public' in json_obj:
            event.public = json_obj["public"]

        if 'tags' in json_obj:
            for t in json_obj['tags']:
                tag = Tag.get_or_create(name = t)
                event.tags.append(tag)

        return event
예제 #3
0
def user_reg(email, password, sex, name):
    from afconfig import af_conf
    email = email.lower()
    if User.is_exist({'email':email}):
        return 6 #'existed user'
    if af_conf['needinvite']:
        if not Invitation.is_exist({'email':email}):
            return 7 #'not invited'
    password = encrypt(password)
    token = unicode(random_string(20), 'utf-8')
    usr = User(attrs={'email':email})
    doc = {
        'sex' : sex,
        'name' : name,
        'password' : password,
        'token' : token,
        'domain' : usr.uid,
        'account_status' : 'unverified',
    }
    usr.set_propertys(**doc)
    
    m_status = email_verification(usr)
    if m_status is False:
        logging.error('+'*30) 
        logging.error('Email send Failed')
        logging.error('%s %s %s' % (email, token, name))
        logging.error('+'*30)
        return 8 #'mail error'
    return 0
예제 #4
0
def user_reg(email, password, sex, name):
    from afconfig import af_conf
    email = email.lower()
    if User.is_exist({'email': email}):
        return 6  #'existed user'
    if af_conf['needinvite']:
        if not Invitation.is_exist({'email': email}):
            return 7  #'not invited'
    password = encrypt(password)
    token = unicode(random_string(20), 'utf-8')
    usr = User(attrs={'email': email})
    doc = {
        'sex': sex,
        'name': name,
        'password': password,
        'token': token,
        'domain': usr.uid,
        'account_status': 'unverified',
    }
    usr.set_propertys(**doc)

    m_status = email_verification(usr)
    if m_status is False:
        logging.error('+' * 30)
        logging.error('Email send Failed')
        logging.error('%s %s %s' % (email, token, name))
        logging.error('+' * 30)
        return 8  #'mail error'
    return 0
예제 #5
0
def invite_other(invitor, invitee_mail):
    from invitation import Invitation
    from mails import send_invite

    invitee_mail = invitee_mail.lower()
    if not Invitation.is_exist({'email':invitee_mail}):
        gcnt = global_info['invitations_count']
        if gcnt >= af_conf['invitation_limit']:
            return 4 #invitation not available, full
        if invitor.invitations <= 0:
            return 1 #your pool is empty
        invi = Invitation(attrs={'email' : invitee_mail})
        invi.date = datetime.now()
        invi.invitor = invitor.email
        global_info.inc('invitations_count')
        invitor.invitations -= 1
    if send_invite(invitor, invitee_mail):
        return 0 #successfull
    return 2 #mail sending error
예제 #6
0
def invite_other(invitor, invitee_mail):
    from invitation import Invitation
    from mails import send_invite

    invitee_mail = invitee_mail.lower()
    if not Invitation.is_exist({'email': invitee_mail}):
        gcnt = global_info['invitations_count']
        if gcnt >= af_conf['invitation_limit']:
            return 4  #invitation not available, full
        if invitor.invitations <= 0:
            return 1  #your pool is empty
        invi = Invitation(attrs={'email': invitee_mail})
        invi.date = datetime.now()
        invi.invitor = invitor.email
        global_info.inc('invitations_count')
        invitor.invitations -= 1
    if send_invite(invitor, invitee_mail):
        return 0  #successfull
    return 2  #mail sending error
예제 #7
0
# -*- coding: utf-8 -*-
from invitation import db, Invitation

if __name__ == '__main__':
    db.drop_all()
    db.create_all()
    inv = Invitation(
        'janeandjohn', 'Jane & John',
        'You all know us. And we all know you. We are getting married.')
    db.session.add(inv)
    db.session.commit()
 def invitations(self):
     gci = self.invitationQuery.get_current_invitiations_for_site
     retval = [Invitation(self.context, i['invitation_id'])
                 for i in gci(self.siteInfo.id, self.userInfo.id)]
     return retval
예제 #9
0
from audience import Audience
from bag import Bag
from invitation import Invitation
from ticket import Ticket
from ticketseller import TicketSeller
from ticketbox import TicketBox

if __name__ == "__main__":
    TICKET_PRICE = 5000

    invitation = Invitation()

    bag_with_invitation = Bag(invitation=invitation)
    bag_with_money = Bag(money=TICKET_PRICE)
    
    hit_audience = Audience(bag=bag_with_invitation)
    non_hit_audience = Audience(bag=bag_with_money)

    ticket1 = Ticket(price=TICKET_PRICE)
    ticket2 = Ticket(price=TICKET_PRICE)

    ticketbox = TicketBox(tickets=[ticket1, ticket2], money=0)
    ticketsellor = TicketSeller(ticketbox=ticketbox)

    ticketsellor.sell_ticket_to_audience(audience=hit_audience)
    ticketsellor.sell_ticket_to_audience(audience=non_hit_audience)