# Path: core/models.py
# class Bridge(models.Model):
#     EVENT_CHOICES = (
#         # card
#         ("addAttachmentToCard", "addAttachmentToCard"),
#         ("addLabelToCard", "addLabelToCard"),
#         ("addMemberToCard", "addMemberToCard"),
#         ("commentCard", "commentCard"),
#         ("copyCard", "copyCard"),
#         ("createCard", "createCard"),
#         ("emailCard", "emailCard"),
#         ("moveCardFromBoard", "moveCardFromBoard"),
#         ("moveCardToBoard", "moveCardToBoard"),
#         ("removeLabelFromCard", "removeLabelFromCard"),
#         ("removeMemberFromCard", "removeMemberFromCard"),
#         (
#             "updateCard",
#             "updateCard (include moveCardToList, renameCard, renameCardDesc, updateCardDueDate, removeCardDueDate, archiveCard, unarchiveCard)",
#         ),
#         # checklist
#         ("addChecklistToCard", "addChecklistToCard"),
#         ("createCheckItem", "createCheckItem"),
#         ("updateCheckItemStateOnCard", "updateCheckItemStateOnCard"),
#         # list
#         ("archiveList", "archiveList"),
#         ("createList", "createList"),
#         ("moveListFromBoard", "moveCardFromBoard"),
#         ("moveListToBoard", "moveListToBoard"),
#         ("renameList", "renameList"),
#         ("updateList", "updateList"),
#     )
# 
#     webhook = models.ForeignKey(Webhook, on_delete=models.CASCADE)
#     board = models.ForeignKey(Board, on_delete=models.CASCADE)
# 
#     events = models.CharField(max_length=700)
# 
#     created_at = models.DateTimeField(auto_now_add=True)
#     updated_at = models.DateTimeField(auto_now=True)
# 
#     class Meta:
#         verbose_name_plural = "bridges"
# 
#     def __str__(self):
#         return "{}::{}".format(self.board, self.webhook)
# 
#     def __unicode__(self):
#         return "{}::{}".format(self.board, self.webhook)
# 
#     def events_as_list(self):
#         return literal_eval(self.events)
# 
# class Webhook(models.Model):
# 
#     name = models.CharField(max_length=50)
#     incoming_webhook_url = models.CharField(max_length=300, unique=True)
# 
#     icon_url = models.CharField(
#         max_length=250,
#         default="http://maffrigby.com/wp-content/uploads/2015/05/trello-icon.png",
#     )
#     username = models.CharField(max_length=30, default="Matterllo")
# 
#     board = models.ManyToManyField(Board)
# 
#     created_at = models.DateTimeField(auto_now_add=True)
#     updated_at = models.DateTimeField(auto_now=True)
# 
#     class Meta:
#         ordering = ["name"]
#         verbose_name_plural = "webhooks"
# 
#     def __str__(self):
#         return "{} :: {}".format(self.name, self.incoming_webhook_url)
# 
#     def __unicode__(self):
#         return "{} :: {}".format(self.name, self.incoming_webhook_url)


from crispy_forms.bootstrap import FormActions, Field
from crispy_forms.helper import FormHelper, Layout
from crispy_forms.layout import Submit, HTML
from django import forms
from core.models import Bridge, Webhook

    class Meta:
        model = Bridge
        fields = ["events"]
        help_texts = {
            "events": 'The generated key from <a href="https://docs.mattermost.com/developer/webhooks-incoming.html#setting-up-existing-integrations">Mattermost webhook</a>.',
        }


class WebhookCreateForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super(WebhookCreateForm, self).__init__(*args, **kwargs)
        helper = self.helper = FormHelper()

        layout = helper.layout = Layout()
        layout.append(Field("name", placeholder="webhook for town-square"))
        layout.append(
            Field(
                "incoming_webhook_url",
                placeholder="https://mattermost.gitlab.com/hooks/b5g6pyoqsjy88fa6kzn7xi1rzy",
            )
        )
        layout.append(FormActions(Submit("save", "Next")))

        helper.form_show_labels = False
        helper.form_class = "form-horizontal"
        helper.field_class = "col-lg-8"
        helper.help_text_inline = True

    class Meta:

# Path: core/models.py
# class Bridge(models.Model):
#     EVENT_CHOICES = (
#         # card
#         ("addAttachmentToCard", "addAttachmentToCard"),
#         ("addLabelToCard", "addLabelToCard"),
#         ("addMemberToCard", "addMemberToCard"),
#         ("commentCard", "commentCard"),
#         ("copyCard", "copyCard"),
#         ("createCard", "createCard"),
#         ("emailCard", "emailCard"),
#         ("moveCardFromBoard", "moveCardFromBoard"),
#         ("moveCardToBoard", "moveCardToBoard"),
#         ("removeLabelFromCard", "removeLabelFromCard"),
#         ("removeMemberFromCard", "removeMemberFromCard"),
#         (
#             "updateCard",
#             "updateCard (include moveCardToList, renameCard, renameCardDesc, updateCardDueDate, removeCardDueDate, archiveCard, unarchiveCard)",
#         ),
#         # checklist
#         ("addChecklistToCard", "addChecklistToCard"),
#         ("createCheckItem", "createCheckItem"),
#         ("updateCheckItemStateOnCard", "updateCheckItemStateOnCard"),
#         # list
#         ("archiveList", "archiveList"),
#         ("createList", "createList"),
#         ("moveListFromBoard", "moveCardFromBoard"),
#         ("moveListToBoard", "moveListToBoard"),
#         ("renameList", "renameList"),
#         ("updateList", "updateList"),
#     )
# 
#     webhook = models.ForeignKey(Webhook, on_delete=models.CASCADE)
#     board = models.ForeignKey(Board, on_delete=models.CASCADE)
# 
#     events = models.CharField(max_length=700)
# 
#     created_at = models.DateTimeField(auto_now_add=True)
#     updated_at = models.DateTimeField(auto_now=True)
# 
#     class Meta:
#         verbose_name_plural = "bridges"
# 
#     def __str__(self):
#         return "{}::{}".format(self.board, self.webhook)
# 
#     def __unicode__(self):
#         return "{}::{}".format(self.board, self.webhook)
# 
#     def events_as_list(self):
#         return literal_eval(self.events)
# 
# class Webhook(models.Model):
# 
#     name = models.CharField(max_length=50)
#     incoming_webhook_url = models.CharField(max_length=300, unique=True)
# 
#     icon_url = models.CharField(
#         max_length=250,
#         default="http://maffrigby.com/wp-content/uploads/2015/05/trello-icon.png",
#     )
#     username = models.CharField(max_length=30, default="Matterllo")
# 
#     board = models.ManyToManyField(Board)
# 
#     created_at = models.DateTimeField(auto_now_add=True)
#     updated_at = models.DateTimeField(auto_now=True)
# 
#     class Meta:
#         ordering = ["name"]
#         verbose_name_plural = "webhooks"
# 
#     def __str__(self):
#         return "{} :: {}".format(self.name, self.incoming_webhook_url)
# 
#     def __unicode__(self):
#         return "{} :: {}".format(self.name, self.incoming_webhook_url)


# Path: core/forms.py
from crispy_forms.bootstrap import FormActions, Field
from crispy_forms.helper import FormHelper, Layout
from crispy_forms.layout import Submit, HTML
from django import forms
from core.models import Bridge, Webhook


    class Meta:
        model = Bridge
        fields = ["events"]
        help_texts = {
            "events": 'The generated key from <a href="https://docs.mattermost.com/developer/webhooks-incoming.html#setting-up-existing-integrations">Mattermost webhook</a>.',
        }


class WebhookCreateForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super(WebhookCreateForm, self).__init__(*args, **kwargs)
        helper = self.helper = FormHelper()

        layout = helper.layout = Layout()
        layout.append(Field("name", placeholder="webhook for town-square"))
        layout.append(
            Field(
                "incoming_webhook_url",
                placeholder="https://mattermost.gitlab.com/hooks/b5g6pyoqsjy88fa6kzn7xi1rzy",
            )
        )
        layout.append(FormActions(Submit("save", "Next")))

        helper.form_show_labels = False
        helper.form_class = "form-horizontal"
        helper.field_class = "col-lg-8"
        helper.help_text_inline = True

    class Meta:

        model = Webhook