# Path: app/models.py
# class Respondent(db.Model):
# class Campaign(db.Model):
# class Audience(db.Model):
# class RandomBias(db.Model):
# class PossibleAbuses(db.Model):
# class BlockedClients(db.Model):
# class CallStatistics(db.Model):
# class Role(db.Model, RoleMixin):
# class User(db.Model, UserMixin):
#     def __repr__(self):
# 
# Path: app/forms.py
# class CampaignForm(Form):
#     """
#     WTForm to handle Campaign Edit view
#     """
#     id = IntegerField(label='Campaign ID')
#     name = StringField(label='Campaign name', validators=[DataRequired()])
#     description = StringField(label='Description')
#     id_audience = IntegerField(label='Audience', validators=[DataRequired()])
#     target_minutes = IntegerField(label='Campaigns Target Minutes', validators=[DataRequired()])
#     campaign_text = StringField(label='Mission Text')
# 
#     def __init__(self, *args, **kwargs):
#         super(CampaignForm, self).__init__(*args, **kwargs)


from flask import render_template, abort, flash, redirect
from flask_login import current_user
from app.models import Campaign, Audience, db
from app.forms import CampaignForm
from markdown import markdown
from lxml.html.clean import clean_html
            return render_template('frontend/campaign_edit.html', form=form, audiences=audiences)
    elif request.method == 'DELETE':
        if current_user.id == campaign.id_owner:
            db.session.delete(campaign)
            db.session.commit()
            return 'success', 200
        else:
            return abort(403)


def add(request):
    """
    handle add campaign requests
    :param request: http request
    :return: http response
    """
    form = CampaignForm(request.form)
    audiences = Audience().query.all()
    if request.method == 'GET':
        return render_template('frontend/campaign_add.html', form=form, audiences=audiences)
    elif request.method == 'POST':
        if form.validate_on_submit():
            campaign = Campaign()
            campaign.name = form.name.data
            campaign.description = form.description.data
            campaign.target_minutes = form.target_minutes.data
            campaign.id_audience = form.id_audience.data
            campaign.id_owner = current_user.id
            campaign.minutes_talked = 0
            db.session.add(campaign)

# Path: app/models.py
# class Respondent(db.Model):
# class Campaign(db.Model):
# class Audience(db.Model):
# class RandomBias(db.Model):
# class PossibleAbuses(db.Model):
# class BlockedClients(db.Model):
# class CallStatistics(db.Model):
# class Role(db.Model, RoleMixin):
# class User(db.Model, UserMixin):
#     def __repr__(self):
# 
# Path: app/forms.py
# class CampaignForm(Form):
#     """
#     WTForm to handle Campaign Edit view
#     """
#     id = IntegerField(label='Campaign ID')
#     name = StringField(label='Campaign name', validators=[DataRequired()])
#     description = StringField(label='Description')
#     id_audience = IntegerField(label='Audience', validators=[DataRequired()])
#     target_minutes = IntegerField(label='Campaigns Target Minutes', validators=[DataRequired()])
#     campaign_text = StringField(label='Mission Text')
# 
#     def __init__(self, *args, **kwargs):
#         super(CampaignForm, self).__init__(*args, **kwargs)


# Path: app/frontend/campaign.py
from flask import render_template, abort, flash, redirect
from flask_login import current_user
from app.models import Campaign, Audience, db
from app.forms import CampaignForm
from markdown import markdown
from lxml.html.clean import clean_html

            return render_template('frontend/campaign_edit.html', form=form, audiences=audiences)
    elif request.method == 'DELETE':
        if current_user.id == campaign.id_owner:
            db.session.delete(campaign)
            db.session.commit()
            return 'success', 200
        else:
            return abort(403)


def add(request):
    """
    handle add campaign requests
    :param request: http request
    :return: http response
    """
    form = CampaignForm(request.form)
    audiences = Audience().query.all()
    if request.method == 'GET':
        return render_template('frontend/campaign_add.html', form=form, audiences=audiences)
    elif request.method == 'POST':
        if form.validate_on_submit():
            campaign = Campaign()
            campaign.name = form.name.data
            campaign.description = form.description.data
            campaign.target_minutes = form.target_minutes.data
            campaign.id_audience = form.id_audience.data
            campaign.id_owner = current_user.id
            campaign.minutes_talked = 0
            db.session.add(campaign)

            db.session.commit()