self.slug = slugify(self.title)
- duplicate = check_media_slug_used(mg_globals.database,
- self.uploader, self.slug, self.id)
+ duplicate = check_media_slug_used(self.uploader, self.slug, self.id)
if duplicate:
if self.id is not None:
Session.commit()
-def check_media_slug_used(dummy_db, uploader_id, slug, ignore_m_id):
- filt = (MediaEntry.uploader == uploader_id) \
- & (MediaEntry.slug == slug)
+def check_media_slug_used(uploader_id, slug, ignore_m_id):
+ query = MediaEntry.query.filter_by(uploader=uploader_id, slug=slug)
if ignore_m_id is not None:
- filt = filt & (MediaEntry.id != ignore_m_id)
- does_exist = Session.query(MediaEntry.id).filter(filt).first() is not None
+ query = query.filter(MediaEntry.id != ignore_m_id)
+ does_exist = query.first() is not None
return does_exist
if request.method == 'POST' and form.validate():
# Make sure there isn't already a MediaEntry with such a slug
# and userid.
- slug_used = check_media_slug_used(request.db, media.uploader,
- request.form['slug'], media.id)
+ slug_used = check_media_slug_used(media.uploader, request.form['slug'],
+ media.id)
if slug_used:
form.slug.errors.append(