Пример #1
0
 async def create_event(self,
                        *,
                        category_id=None,
                        host_user_id=None,
                        name='The Event Name',
                        slug=None,
                        start_ts=datetime(2020, 1, 28, 19, 0),
                        short_description=None,
                        long_description=None,
                        **kwargs):
     long_description = long_description or lorem.paragraph()
     event_id = await self.conn.fetchval_b(
         'INSERT INTO events (:values__names) VALUES :values RETURNING id',
         values=Values(
             category=category_id or self.category_id,
             host=host_user_id or self.user_id,
             name=name,
             slug=slug or slugify(name),
             long_description=long_description,
             start_ts=start_ts,
             short_description=(short_description
                                or shorten(long_description,
                                           width=random.randint(100, 140),
                                           placeholder='...')),
             **kwargs))
     self.event_id = self.event_id or event_id
     return event_id
Пример #2
0
 async def create_company(
     self,
     name='Testing',
     slug=None,
     image='https://www.example.org/main.png',
     domain='127.0.0.1',
     stripe_public_key='stripe_key_xxx',
     stripe_secret_key='stripe_secret_xxx',
     stripe_webhook_secret='stripe_webhook_secret_xxx',
     **kwargs,
 ):
     company_id = await self.conn.fetchval_b(
         'INSERT INTO companies (:values__names) VALUES :values RETURNING id',
         values=Values(
             name=name,
             slug=slug or slugify(name),
             image=image,
             domain=domain,
             stripe_public_key=stripe_public_key,
             stripe_secret_key=stripe_secret_key,
             stripe_webhook_secret=stripe_webhook_secret,
             **kwargs,
         ),
     )
     self.company_id = self.company_id or company_id
     return company_id
Пример #3
0
 def prepare_add_data(self, data):
     data = self.prepare(data)
     data.update(
         slug=slugify(data['name']),
         host=self.request['session'].get('user_id'),
     )
     return data
Пример #4
0
    async def prepare_add_data(self, data):
        data = self.prepare(data)

        session = self.request['session']
        data.update(
            slug=slugify(data['name']),
            short_description=shorten(clean_markdown(data['long_description']), width=140, placeholder='…'),
            host=session['user_id'],
        )
        q = 'SELECT status FROM users WHERE id=$1'
        if session['role'] == 'admin' or 'active' == await self.conn.fetchval(q, session['user_id']):
            data['status'] = 'published'
        return data
Пример #5
0
    async def create_event(self,
                           *,
                           category_id=None,
                           host_user_id=None,
                           name='The Event Name',
                           slug=None,
                           start_ts=london.localize(
                               datetime(2020, 6, 28, 19, 0)),
                           timezone='Europe/London',
                           duration=timedelta(hours=1),
                           short_description=None,
                           long_description=None,
                           price=None,
                           **kwargs):
        long_description = long_description or lorem.paragraph()
        event_id = await self.conn.fetchval_b(
            'INSERT INTO events (:values__names) VALUES :values RETURNING id',
            values=Values(
                category=category_id or self.category_id,
                host=host_user_id or self.user_id,
                name=name,
                slug=slug or slugify(name),
                long_description=long_description,
                start_ts=start_ts,
                timezone=timezone,
                duration=duration,
                short_description=(short_description
                                   or shorten(long_description,
                                              width=random.randint(100, 140),
                                              placeholder='...')),
                **kwargs))
        self.event_id = self.event_id or event_id
        ticket_type_id = await self.conn.fetchval_b(
            'INSERT INTO ticket_types (:values__names) VALUES :values RETURNING id',
            values=Values(
                event=event_id,
                price=price,
                name='Standard',
            ))
        self.ticket_type_id = self.ticket_type_id or ticket_type_id

        await self.conn.execute_b(
            'INSERT INTO actions (:values__names) VALUES :values RETURNING id',
            values=Values(
                company=self.company_id,
                user_id=host_user_id or self.user_id,
                type=ActionTypes.create_event,
                event=event_id,
            ))
        return event_id
Пример #6
0
 async def create_cat(self,
                      *,
                      company_id=None,
                      name='Supper Clubs',
                      slug=None,
                      image='https://www.example.com/co.png',
                      **kwargs):
     cat_id = await self.conn.fetchval_b(
         'INSERT INTO categories (:values__names) VALUES :values RETURNING id',
         values=Values(company=company_id or self.company_id,
                       name=name,
                       image=image,
                       slug=slug or slugify(name),
                       **kwargs))
     self.category_id = self.category_id or cat_id
     return cat_id
Пример #7
0
 async def create_company(self,
                          name='Testing',
                          slug=None,
                          image='https://www.example.com/co.png',
                          domain='127.0.0.1',
                          **kwargs):
     company_id = await self.conn.fetchval_b(
         'INSERT INTO companies (:values__names) VALUES :values RETURNING id',
         values=Values(
             name=name,
             slug=slug or slugify(name),
             image=image,
             domain=domain,
             **kwargs,
         ))
     self.company_id = self.company_id or company_id
     return company_id
Пример #8
0
    async def prepare_add_data(self, data):
        data = self.prepare(data)

        session = self.request['session']
        mode: EventMode = data.pop('mode', EventMode.tickets)
        data.update(
            slug=slugify(data['name'], 63),
            short_description=shorten(clean_markdown(data['long_description']),
                                      width=140,
                                      placeholder='…'),
            host=session['user_id'],
            allow_tickets=mode in (EventMode.tickets, EventMode.both),
            allow_donations=mode in (EventMode.donations, EventMode.both),
        )

        q = 'SELECT status FROM users WHERE id=$1'
        if session['role'] == 'admin' or 'active' == await self.conn.fetchval(
                q, session['user_id']):
            data['status'] = 'published'
        return data
Пример #9
0
    async def execute(self, m: Model):
        old_event_id = int(self.request.match_info['id'])
        slug = slugify(m.name)

        tz = await self.conn.fetchval(
            """
            SELECT timezone FROM events e
            JOIN categories c ON e.category = c.id
            WHERE e.id=$1 AND c.company=$2
            """,
            old_event_id,
            self.request['company_id'],
        )
        if not tz:
            raise JsonErrors.HTTPNotFound(message='Event not found')

        start, duration = prepare_event_start(m.date.dt, m.date.dur,
                                              pytz.timezone(tz))
        kwargs = dict(slug=slug,
                      old_event_id=old_event_id,
                      name=m.name,
                      start=start,
                      duration=duration,
                      status=m.status.value)

        async with self.conn.transaction():
            new_event_id = await self.conn.fetchval_b(self.clone_event_sql,
                                                      **kwargs)
            while new_event_id is None:
                # event with this slug already exists
                kwargs['slug'] = slug + '-' + pseudo_random_str(4)
                new_event_id = await self.conn.fetchval_b(
                    self.clone_event_sql, **kwargs)

            await self.conn.execute(self.duplicate_ticket_types_sql,
                                    old_event_id, new_event_id)

        return {'id': new_event_id, 'status_': 201}
Пример #10
0
 async def prepare_add_data(self, data):
     data.update(company=self.request['company_id'],
                 slug=slugify(data['name']))
     return data
Пример #11
0
    async def create_event(
        self,
        *,
        category_id=None,
        host_user_id=None,
        name='The Event Name',
        slug=None,
        allow_tickets=True,
        allow_donations=False,
        start_ts=london.localize(datetime(2032, 6, 28, 19, 0)),
        timezone='Europe/London',
        duration=timedelta(hours=1),
        youtube_video_id=None,
        short_description=None,
        long_description=None,
        description_intro=None,
        price=None,
        suggested_donation=10,
        **kwargs,
    ):
        long_description = long_description or lorem.paragraph()
        event_id = await self.conn.fetchval_b(
            'INSERT INTO events (:values__names) VALUES :values RETURNING id',
            values=Values(
                category=category_id or self.category_id,
                host=host_user_id or self.user_id,
                name=name,
                slug=slug or slugify(name),
                allow_tickets=allow_tickets,
                allow_donations=allow_donations,
                youtube_video_id=youtube_video_id,
                long_description=long_description,
                description_intro=description_intro or lorem.paragraph(),
                start_ts=start_ts,
                timezone=timezone,
                duration=duration,
                short_description=(short_description
                                   or shorten(long_description,
                                              width=random.randint(100, 140),
                                              placeholder='...')),
                **kwargs,
            ),
        )
        self.event_id = self.event_id or event_id
        ticket_type_ids = await self.conn.fetch_b(
            'INSERT INTO ticket_types (:values__names) VALUES :values RETURNING id',
            values=MultipleValues(
                Values(event=event_id,
                       name='Standard',
                       price=price,
                       mode='ticket',
                       custom_amount=False),
                Values(event=event_id,
                       name='Standard',
                       price=suggested_donation,
                       mode='donation',
                       custom_amount=False),
                Values(event=event_id,
                       name='Custom Amount',
                       price=None,
                       mode='donation',
                       custom_amount=True),
            ),
        )
        # debug(ticket_type_ids)
        self.ticket_type_id = self.ticket_type_id or ticket_type_ids[0]['id']
        self.donation_ticket_type_id_1 = self.donation_ticket_type_id_1 or ticket_type_ids[
            1]['id']
        self.donation_ticket_type_id_2 = self.donation_ticket_type_id_2 or ticket_type_ids[
            2]['id']

        await self.conn.execute_b(
            'INSERT INTO actions (:values__names) VALUES :values RETURNING id',
            values=Values(
                company=self.company_id,
                user_id=host_user_id or self.user_id,
                type=ActionTypes.create_event,
                event=event_id,
            ),
        )
        return event_id