def update_content_details(id): content = get_content_or_404(id) if not content.is_editable: # Translators, shown when content is not editable (it's on air, etc) response.flash(_('This content is not editable')) redirect(i18n_path(content.path)) errors = {} title = request.forms.getunicode('title', '').strip() license = request.forms.get('license') or None if not content.title and not title: errors['title'] = _('Title cannot be blank') if license and license not in Content.LICENSE_CHOICES: errors['license'] = _('Please select a license from provided choices') if not errors: to_put = [] if title and content.title != title: content.title = title to_put.append(Event.create(Event.TITLE, content.key)) if license and content.license != license: content.license = license to_put.append(Event.create(Event.LICENSE, content.key)) if to_put: # If we have events in to_put list, we also need to put the content to_put.append(content) ndb.put_multi(to_put) response.flash(_('Content has been updated')) redirect(content.path) return dict(vals=request.forms, errors=erorrs, content=content)
def update_content_details(id): to_put = [] content = get_content_or_404(id) ref_path = i18n_path(request.forms.get('back', content.path)) if not content.is_editable: response.flash(_('Voting is disabled for content that is being ' 'broadcast')) redirect(ref_path) vote = request.forms.get('vote') if vote not in ['up', 'down']: response.flash(_('There was a problem with the request. Please try ' 'again later.')) redirect(ref_path) if vote == 'up': content.upvotes += 1 to_put.append(Event.create(Event.UPVOTE, content.key)) elif vote == 'down': content.downvotes += 1 to_put.append(Event.create(Event.DOWNVOTE, content.key)) to_put.append(content) ndb.put_multi(to_put) redirect(ref_path)
def handle_content_edits(): sel = request.params.get('select', '0') == '1' to_put = [] selection = request.forms.getall('selection') if not selection: # Translators, used as error message on broadcast page when there is # no selection to operate on finish_with_message(_('No content selected')) keys = [ndb.Key('Content', key) for key in selection] action = request.forms.get('action') if action == 'status': archive = request.forms.get('archive') or None if archive not in Content.ARCHIVE_CHOICES: finish_with_message(_('Invalid request')) for content in ndb.get_multi(keys): if content.archive != archive: content.archive = archive if archive == None: to_put.append(Event.create(Event.UNBROADCAST, content.key)) else: to_put.append(Event.create(Event.BROADCAST, content.key)) to_put.append(content) ndb.put_multi(to_put) elif action == 'delete': ndb.delete_multi(keys) finish_with_message(_('Broadcast data updated'))
def update_content_details(id): to_put = [] content = get_content_or_404(id) ref_path = i18n_path(request.forms.get('back', content.path)) if not content.is_editable: response.flash( _('Voting is disabled for content that is being ' 'broadcast')) redirect(ref_path) vote = request.forms.get('vote') if vote not in ['up', 'down']: response.flash( _('There was a problem with the request. Please try ' 'again later.')) redirect(ref_path) if vote == 'up': content.upvotes += 1 to_put.append(Event.create(Event.UPVOTE, content.key)) elif vote == 'down': content.downvotes += 1 to_put.append(Event.create(Event.DOWNVOTE, content.key)) to_put.append(content) ndb.put_multi(to_put) redirect(ref_path)
def test_add_event(self): event = Event(id=2, name='test', server='2', date=datetime.datetime.now()) self.session.add(event) self.session.commit() self.assertEqual( self.session.query(Event).filter(Event.id == 2).count(), 1)
def new_demo_event(ad_start_seconds=5): event = Event() event.registration_start = datetime.now() - timedelta(days=14) event.registration_end = datetime.now() - timedelta(days=2) event.start = datetime.now() event.end = datetime.now() + timedelta(hours=12) event.attack_defense_start = datetime.now() + timedelta( seconds=ad_start_seconds) event.is_demo = 1 db_session.add(event) db_session.commit() return event
def event2model(event: EventIn, session) -> Event: model = Event(type=event.type, title=event.title, agenda=event.agenda, start=event.start, end=event.end) # add proposals to an event proposals = session.query(Proposal).filter(Proposal.id.in_( event.proposals)).all() model.proposals.extend(proposals) return model
async def create(self, ctx, name: str, date: str, time: str='0:00am'): '''Creates an event with specified name and date example: ?create party 12/22/2017 1:40pm ''' server = ctx.message.server.name date_time = '{} {}'.format(date, time) try: event_date = datetime.strptime(date_time, '%m/%d/%Y %I:%M%p') event = Event(name=name, server=server, date=event_date) self.session.add(event) self.session.commit() await self.bot.say('Event {} created successfully for {}'.format(name, event.date)) except Exception as e: await self.bot.say('Could not complete your command') self.logger.error(e)
def update_event(c_id, e_id): form = CreateEventForm() if form.validate_on_submit(): e = Event().query.get(e_id) e.name = form.name.data e.start_on = form.start.data e.end_on = form.end.data e.modified_by = g.user.id e.description = form.description.data db.session.add(e) db.session.commit() updated_event = construct_event(e.community_id)(e) return jsonify(success = True, data=updated_event) return jsonify(success = False, errors = form.errors)
async def update_events(events_id: int, events: EventIn_Pydantic, user: User = Depends( fastapi_users.get_current_active_user)): await Event.filter(id=events_id).update(**events.dict(exclude_unset=True)) return await Event_Pydantic.from_queryset_single(Event.get(id=events_id))
user_2.tokens.append( UserToken(token="0a821f8ce58965eadc5ef884cf6f7ad99e0e7f58f429f584b2")) db_session.add(user_admin) db_session.add(user_1) db_session.add(user_2) # -------------------- CREATE EVENTS -------------------- day_period = datetime.timedelta(days=1) event_hackatoon = Event( created_at=datetime.datetime.now(), name="event1", description="description 1", type=EventTypeEnum.hackathon, start_date=datetime.datetime.now() + (day_period * 3), finish_date=datetime.datetime.now() + (day_period * 5), owner_id=0, poster="logo.png", registered=[user_1, user_2]) event_livecoding = Event( created_at=datetime.datetime.now(), name="event2", description="descr2", type=EventTypeEnum.livecoding, start_date=datetime.datetime.now() - (day_period * 5), finish_date=datetime.datetime.now() - (day_period * 4), owner_id=1, registered=[user_2])
def test_add_wrong_event(self): event = Event(id=1, name='test', server='2', date='2') with self.assertRaises(Exception): self.session.add(event) self.session.commit()