示例#1
0
def create(data, uid):
    new = Event(uid, data['event_type'], data['title'], data['content'],
                data['location'], data['organization'], data['begin_time'],
                data['end_time'], data.get('url'), data.get('cover_image'))
    db.session.add(new)
    db.session.commit()
    return util.obj2dict(new)
示例#2
0
    def construct_event(
            self,
            title="A+ Event",
            description="A delightful event destined to create rejoicing",
            street_address1="123 Some Pl",
            street_address2="Apt. 45",
            is_draft=False,
            city="Stauntonville",
            state="QX",
            zip="99775",
            phone="555-555-5555",
            website="http://stardrive.org",
            date=datetime.datetime.now() + datetime.timedelta(days=7),
            organization_name="Event Org"):

        event = Event(title=title,
                      description=description,
                      street_address1=street_address1,
                      street_address2=street_address2,
                      city=city,
                      state=state,
                      zip=zip,
                      phone=phone,
                      website=website,
                      date=date,
                      is_draft=is_draft,
                      organization_name=organization_name)
        db.session.add(event)

        db_event = db.session.query(Event).filter_by(title=event.title).first()
        self.assertEqual(db_event.website, event.website)
        elastic_index.add_document(db_event, 'Event')
        return db_event
示例#3
0
def create_event():
    ev = Event()
    ev.fee = int(request.form.get('fee', 0)) * 100
    if ev.fee < 0:
        return Response(code=ResponseCode.PARAMETER_ERROR, msg='输入收费错误').out()
    ev.shop_id = request.form.get('shop_id', 0)
    ev.show_num = request.form.get('show_num') == 'on'
    ev.title = request.form.get('title')
    ev.user_limit = request.form.get('user_limit', 0)
    ev.description = request.form.get('description')
    ev.creator = request.user.id
    ev.open_at = request.form.get('open_at')
    ev.close_at = request.form.get('close_at')

    file = request.files.get('poster')
    if not file or file.filename == '':
        return Response(code=ResponseCode.OPERATE_ERROR, msg='请选择上传文件').out()
    elif allowed_file(file.filename):
        filename = '%s_%s' % (request.user.id,
                              datetime.now().strftime('%Y%m%d%H%M%S'))
        QiniuCloud.upload_file(file, filename, conf.qiniu_img_bucket)
        ev.poster_url = conf.qiniu_img_prefix + filename
        ev.save()
    else:
        return Response(code=ResponseCode.OPERATE_ERROR,
                        msg='请选择正确的上传格式文件').out()

    return str(Response())
示例#4
0
    def load_events(self):
        items = []
        with open(self.event_file, newline='') as csvfile:
            reader = csv.reader(csvfile, delimiter=csv.excel.delimiter, quotechar=csv.excel.quotechar)
            next(reader, None)  # skip the headers
            for row in reader:
                org = self.get_org_by_name(row[5]) if row[5] else None
                geocode = self.get_geocode(
                    address_dict={'street': row[8], 'city': row[10], 'state': row[11], 'zip': row[12]},
                    lat_long_dict={'lat': row[15], 'lng': row[16]}
                )
                event = Event(title=row[0], description=row[1], date=row[2], time=row[3], ticket_cost=row[4],
                              organization=org, primary_contact=row[6], location_name=row[7], street_address1=row[8],
                              street_address2=row[9], city=row[10], state=row[11], zip=row[12], website=row[13],
                              phone=row[14], latitude=geocode['lat'], longitude=geocode['lng'])
                items.append(event)
                self.__increment_id_sequence(Resource)

                for i in range(17, len(row)):
                    if row[i] and row[i] is not '':
                        category = self.get_category_by_name(row[i].strip())
                        event_id = event.id
                        category_id = category.id
                        items.append(ResourceCategory(resource_id=event_id, category_id=category_id, type='event'))

        db.session.bulk_save_objects(items)
        db.session.commit()
        print("Events loaded.  There are now %i events in the database." % db.session.query(Event).count())
        print("There are now %i links between events and categories in the database." %
              db.session.query(ResourceCategory).filter(ResourceCategory.type == 'event').count())
示例#5
0
def ACreateEvent():
    #Access to POST/PUT fields using request.form['name']
    #Access to file fields using request.files['name']
    params = request.form.copy()
    poster = request.files.get('poster')

    if poster != None and allowed_file(poster.filename):
        filename = secure_filename(poster.filename)
        poster_path = os.path.join(upload_folder(), filename)
        poster.save(poster_path)
        params['poster_path'] = poster_path

    if "actor" in session:
        params['owner'] = session['actor']

    event = Event(params)

    if event and event.save():
        eventid = Event.last_id()
        res = {
            'label': '/event/' + str(eventid),
            'msg': [ur'Evento creado exitosamente']
        }
    else:
        res = {'label': '/events/new', 'msg': [ur'Error al crear evento']}

    #Action code ends here
    if "actor" in res:
        if res['actor'] is None:
            session.pop("actor", None)
        else:
            session['actor'] = res['actor']
    return json.dumps(res)
示例#6
0
    def get(self):
        """ get port count """

        # get data
        event = Event()
        event_data = event.port_count()

        return event_data
示例#7
0
def events():
    evs = Event.query(fetchone=False,
                      extra={"state <": Event.State.DELETED},
                      orderby='open_at asc')
    resp = []
    for each in evs:
        ev = Event(**each)
        r = ev.to_dict()
        r['creator'] = ev.get_creator().to_dict()
        r['num'] = UserEvent.count(event_id=ev.id, state=UserEvent.State.INIT)
        resp.append(r)
    return str(Response(data=resp))
示例#8
0
def published_events():
    evs = Event.query(fetchone=False,
                      creator=request.user.id,
                      extra={"state <": Event.State.DELETED},
                      orderby='id desc')
    resp = []
    for each in evs:
        ev = Event(**each)
        r = ev.to_dict()
        r['num'] = UserEvent.count(event_id=ev.id, state=UserEvent.State.INIT)
        resp.append(r)
    return str(Response(data=resp))
示例#9
0
    def load_events(self):
        items = []
        with open(self.event_file, newline='') as csvfile:
            reader = csv.reader(csvfile, delimiter=csv.excel.delimiter, quotechar=csv.excel.quotechar)
            next(reader, None)  # skip the headers
            for row in reader:
                org = row[5] if row[5] else None
                geocode = self.get_geocode(
                    address_dict={'street': row[8], 'city': row[10], 'state': row[11], 'zip': row[12]},
                    lat_long_dict={'lat': row[15], 'lng': row[16]}
                )
                event = Event(title=row[0], description=row[1], date=row[2], time=row[3], ticket_cost=row[4],
                              organization_name=org, primary_contact=row[6], location_name=row[7],
                              street_address1=row[8], street_address2=row[9], city=row[10], state=row[11], zip=row[12],
                              website=row[13], phone=row[14], latitude=geocode['lat'], longitude=geocode['lng'], ages=[],
                              languages=[], covid19_categories=[], is_draft=False, is_uva_education_content=True)
                self.__increment_id_sequence(Resource)

                for i in range(26, 29):
                    if row[i]:
                        event.ages.extend(AgeRange.get_age_range_for_csv_data(row[i]))
                for i in range(29, 36):
                    if row[i]:
                        event.languages.append(row[i])
                for i in range(36, len(row)):
                    if row[i]:
                        event.covid19_categories.append(row[i])
                db.session.add(event)
                db.session.commit()

                for i in range(17, 25):
                    if row[i] and row[i] != '':
                        category = self.get_category_by_name(row[i].strip())
                        event_id = event.id
                        category_id = category.id
                        db.session.add(ResourceCategory(resource_id=event_id, category_id=category_id, type='event'))

        db.session.commit()
        print("Events loaded.  There are now %i events in the database." % db.session.query(Event).count())
        print("There are now %i links between events and categories in the database." %
              db.session.query(ResourceCategory).filter(ResourceCategory.type == 'event').count())