def new_announcement(): """Create new announcement.""" def respond(): response = dict( template='', # template='admin/new_announcement.html', title=gettext("Write a new post"), form=form) return handle_content_type(response) form = AnnouncementForm() del form.id # project_sanitized, owner_sanitized = sanitize_project_owner(project, owner, current_user) if request.method != 'POST': ensure_authorized_to('create', Announcement()) return respond() if not form.validate(): flash(gettext('Please correct the errors'), 'error') return respond() announcement = Announcement(title=form.title.data, body=form.body.data, user_id=current_user.id) ensure_authorized_to('create', announcement) announcement_repo.save(announcement) msg_1 = gettext('Annnouncement created!') flash('<i class="icon-ok"></i> ' + msg_1, 'success') return redirect_content_type(url_for('admin.announcement'))
def new_announcement(): """Create new announcement.""" def respond(): response = dict(template='admin/new_announcement.html', title=gettext("Write a new post"), form=form) return handle_content_type(response) form = AnnouncementForm() del form.id # project_sanitized, owner_sanitized = sanitize_project_owner(project, owner, current_user) if request.method != 'POST': ensure_authorized_to('create', Announcement()) return respond() if not form.validate(): flash(gettext('Please correct the errors'), 'error') return respond() announcement = Announcement(title=form.title.data, body=form.body.data, published=form.published.data, media_url=form.media_url.data, user_id=current_user.id) ensure_authorized_to('create', announcement) announcement_repo.save(announcement) msg_1 = gettext('Annnouncement created!') markup = Markup('<i class="icon-ok"></i> {}') flash(markup.format(msg_1), 'success') return redirect_content_type(url_for('admin.announcement'))
def new_announcement(): """Create new announcement.""" def respond(): response = dict(template='admin/new_announcement.html', title=gettext("Write a new post"), levelOptions=json.dumps( current_app.config['ANNOUNCEMENT_LEVEL_OPTIONS']), form=form) return handle_content_type(response) form = AnnouncementForm() del form.id # project_sanitized, owner_sanitized = sanitize_project_owner(project, owner, current_user) if request.method != 'POST': ensure_authorized_to('create', Announcement()) return respond() if not form.validate(): flash(gettext('Please correct the errors'), 'error') return respond() announcement = Announcement(title=form.title.data, body=form.body.data, info=json.loads(form.info.data), published=form.published.data, media_url=form.media_url.data, user_id=current_user.id) ensure_authorized_to('create', announcement) announcement_repo.save(announcement) msg_1 = gettext('Annnouncement created!') markup = Markup('<i class="icon-ok"></i> {}') flash(markup.format(msg_1), 'success') return redirect_content_type(url_for('admin.announcement'))