Commit 2f883ad4 authored by Robin Sonnabend's avatar Robin Sonnabend

Delete orphans, don't overcheck topics

parent e5f0b794
"""empty message
Revision ID: 579c9c7756
Revises: 546e34fac4
Create Date: 2015-11-13 16:17:22.756119
"""
# revision identifiers, used by Alembic.
revision = '579c9c7756'
down_revision = '546e34fac4'
from alembic import op
import sqlalchemy as sa
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_constraint('topics_name_key', 'topics', type_='unique')
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.create_unique_constraint('topics_name_key', 'topics', ['name'])
### end Alembic commands ###
......@@ -69,12 +69,12 @@ class Event(db.Model):
class Topic(db.Model):
__tablename__ = "topics"
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String, unique=True)
name = db.Column(db.String)
mode = db.Column(db.String)
event_id = db.Column(db.Integer, db.ForeignKey("events.id"))
index = db.Column(db.Integer)
event = relationship("Event", backref=backref("topics",order_by=id), foreign_keys=[event_id], cascade="all")
event = relationship("Event", backref=backref("topics",order_by=id), foreign_keys=[event_id], cascade="all, delete-orphan", single_parent=True)
def __init__(self, name, mode, event_id):
self.name = name
......@@ -128,7 +128,7 @@ class Speaker(db.Model):
name = db.Column(db.String)
number = db.Column(db.Integer)
event_id = db.Column(db.Integer, db.ForeignKey("events.id"))
event = relationship("Event", backref=backref("speakers",order_by=id), cascade="all")
event = relationship("Event", backref=backref("speakers",order_by=id), cascade="all, delete-orphan", single_parent=True)
def __init__(self, name, number, event_id):
self.name = name
......@@ -171,8 +171,8 @@ class Statement(db.Model):
is_meta = db.Column(db.Boolean, default=False)
is_current = db.Column(db.Boolean, default=False)
speaker = relationship("Speaker", backref=backref("statements",order_by=id), cascade="all")
topic = relationship("Topic", backref=backref("statements",order_by=id), cascade="all")
speaker = relationship("Speaker", backref=backref("statements",order_by=id), cascade="all, delete-orphan", single_parent=True)
topic = relationship("Topic", backref=backref("statements",order_by=id), cascade="all, delete-orphan", single_parent=True)
def __init__(self, speaker_id, topic_id, insertion_time=None, executed=False, execution_time=None, is_meta=False, is_current=False):
self.speaker_id = speaker_id
......
......@@ -158,20 +158,20 @@ def topic_show():
@login_required
@admin_permission.require()
def topic_new():
event_id = request.args.get("event_id", None)
form = NewTopicForm()
if form.validate_on_submit():
if Topic.query.filter_by(name=form.name.data).count() > 0:
if Topic.query.filter_by(event_id=event_id, name=form.name.data).count() > 0:
flash("There already is an topic with that name.", "alert-error")
return render_layout("admin_topic_new.html", form=form)
topic = Topic(form.name.data, form.mode.data, form.event_id.data)
db.session.add(topic)
db.session.commit()
return redirect(url_for(".event_show", id=topic.event.id))
event_id = request.args.get("event_id", None)
if event_id is None:
return redirect(url_for(".index"))
form.event_id.data = event_id
event = Event.query.filter_by(id=event_id).first()
form.event_id.data = event_id
return render_layout("admin_topic_new.html", form=form, event=event)
@admin.route("/topic/delete")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment