def test_initial(database): assert Document(slug='awerty').initial == 'a' assert Document(title='QWERTY').initial == 'q' assert Document(slug='awerty', title='QWERTY').initial == 'q' assert Document.get('a').initial == 'a' assert Document.get('b').initial == 'b'
def test_timestamp(database): assert Document().ymd is None assert Document().hm is None assert Document().ymd_hm is None assert Document.get('a').ymd is not None assert Document.get('a').hm is not None assert Document.get('a').ymd_hm is not None
def edit(slug): if request.method == 'GET': return render_template('edit.j2', page=Document.get(slug)) current_revision = Document.get(slug=slug) if not request.form['revision'] == str(current_revision.id): return render_template('error.j2', error=_('This page has been ' 'modified while you were working on it.')), 400 if not current_revision.id: current_revision.body = '' # For byte delta computation edition_policy = param('edition_policy', '') if edition_policy == 'users': if not current_user.is_authenticated: return render_template('error.j2', error=_('Edition is limited to ' 'registered users only')), 403 if edition_policy == 'admins': if not current_user.admin: return render_template('error.j2', error=_('Edition is limited to ' 'administrators only')), 403 Metadata.deactivate(slug) Document.deactivate(slug) parsed = parse(request.form['body']) for key, values in parsed['meta'].items(): for value in values: Metadata(slug=slug, key=key, value=value) \ .save() title = parsed['title'] or slug body = request.form['body'] comment = request.form['comment'] or None bytes_delta = len(body) - len(current_revision.body) page = Document(slug=slug, title=title, body=body, comment=comment, bytes_delta=bytes_delta) if current_user.is_authenticated: page.user_id = current_user.id page.save() if not current_user.is_anonymous: Notification.add(slug, current_user, 'automatic') db.session.commit() Notification.send(page, current_user) flash(_('Thank you for your changes. Your attention to detail ' 'is appreciated.')) return redirect(url_for('read', slug=slug))
def database(): db.drop_all() db.create_all() Document(slug='a', title='A', body='111').save() db.session.commit() Document.deactivate('a') db.session.commit() Document(slug='a', title='A', body='222').save() Document(slug='b', title='B', body='111').save() Document(slug='c', title='C', body='111').save() Metadata(slug='a', key='x', value='1').save() Metadata(slug='a', key='y', value='2').save() Metadata(slug='b', key='x', value='1').save() Metadata(slug='b', key='x', value='2').save() db.session.commit()
def load_fixtures(): '''Load fixtures into the database.''' cwd = getcwd() dir = path.join(cwd, FIXTURES_DIR) for filename in listdir(dir): file = path.join(dir, filename) if not path.isfile(file) or not file.endswith('.md'): continue print(' * Loading %s' % filename) slug = filename[:-3] page = Document.get(slug=slug) if page.id: print(' * Document exists, skipping') continue body = codecs.open(file, 'r', 'utf-8') \ .read() parsed = parse(body) title = parsed['title'] or slug Metadata.deactivate(slug) Document.deactivate(slug) for key, values in parsed['meta'].items(): for value in values: Metadata(slug=slug, key=key, value=value) \ .save() Document(slug=slug, title=title, body=body) \ .save() db.session.commit()