# Path: recruit_app/user/models.py
# class EveCharacter(Model, TimeMixin):
#     __tablename__ = 'characters'
# 
#     character_id = Column(db.String(254), primary_key=True)
#     character_name = Column(db.String(254))
#     corporation_id = ReferenceCol('corporations', pk_name='corporation_id', nullable=True)
#     corporation = relationship('EveCorporationInfo', backref='characters', foreign_keys=[corporation_id])
# 
#     api_id = ReferenceCol('api_key_pairs', pk_name='api_id', nullable=True)
#     api = relationship('EveApiKeyPair', backref='characters', foreign_keys=[api_id])
# 
#     user_id = ReferenceCol('users', nullable=True)
#     user = relationship('User', backref='characters', foreign_keys=[user_id])
# 
#     skillpoints = Column(db.Integer, nullable=True)
#     previous_users = db.relationship('User', secondary=previous_chars, backref=db.backref('previous_chars', lazy='dynamic'), lazy='dynamic')
# 
#     def __str__(self):
#         return self.character_name
# 
# Path: recruit_app/recruit/models.py
# class HrApplication(SurrogatePK, TimeMixin, Model):
#     # query_class = HrApplicationQuery
#     __tablename__ = 'hr_applications'
# 
#     __searchable__ = ['thesis',
#                       'how_long',
#                       'notable_accomplishments',
#                       'corporation_history',
#                       'why_leaving',
#                       'what_know',
#                       'what_expect',
#                       'bought_characters',
#                       'why_interested',
#                       'find_out',
#                       'favorite_role',
#                       'main_character_name']
# 
#     main_character_name = Column(db.Unicode, nullable=True)
# 
#     alt_application = Column(db.Boolean, default=False)
# 
#     characters = relationship('EveCharacter', secondary=character_apps, backref=db.backref('hr_applications', lazy='dynamic'), lazy='dynamic')
# 
#     thesis = Column(db.UnicodeText, nullable=True)
#     how_long = Column(db.Text, nullable=True)
#     notable_accomplishments = Column(db.Text, nullable=True)
#     corporation_history = Column(db.Text, nullable=True)
#     why_leaving = Column(db.Text, nullable=True)
#     what_know = Column(db.Text, nullable=True)
#     what_expect = Column(db.Text, nullable=True)
#     bought_characters = Column(db.Text, nullable=True)
#     why_interested = Column(db.Text, nullable=True)
# 
#     goon_interaction = Column(db.Text, nullable=True)
#     friends = Column(db.Text, nullable=True)
# 
#     scale = Column(db.Text, nullable=True)
# 
#     find_out = Column(db.Text, nullable=True)
# 
#     favorite_role = Column(db.Text, nullable=True)
# 
#     user_id = ReferenceCol('users', nullable=True)
#     reviewer_user_id = ReferenceCol('users', nullable=True)
#     last_user_id = ReferenceCol('users', nullable=True)
# 
#     approved_denied = Column(db.Text, default="New")
# 
#     hidden = Column(db.Boolean, nullable=True, default=False)
# 
#     # search_vector = Column(TSVectorType('main_character_name', 'thesis'))
# 
#     user = relationship('User', foreign_keys=[user_id], backref='hr_applications')
#     reviewer_user = relationship('User', foreign_keys=[reviewer_user_id], backref='hr_applications_reviewed')
#     last_action_user = relationship('User', foreign_keys=[last_user_id], backref='hr_applications_touched')
#     
#     training = Column(db.Boolean, default=False)
# 
#     def __str__(self):
#         return '<Application %r>' % str(self.main_character_name)
# 
# class HrApplicationComment(SurrogatePK, TimeMixin, Model):
#     __tablename__ = 'hr_comments'
# 
#     comment = Column(db.Text, nullable=True)
# 
#     application_id = ReferenceCol('hr_applications')
#     user_id = ReferenceCol('users')
#     application = relationship('HrApplication', foreign_keys=[application_id], backref=backref('hr_comments', cascade="delete"))
#     user = relationship('User', backref='hr_comments', foreign_keys=[user_id])
# 
#     def __repr__(self):
#         return str(self.user) + " - Comment"
# 
# class HrApplicationCommentHistory(SurrogatePK, TimeMixin, Model):
#     __tablename__ = 'hr_comment_history'
#     
#     old_comment = Column(db.Text, nullable=True)
#     comment_id = ReferenceCol('hr_comments')
#     editor = ReferenceCol('users')
#     comment = relationship('HrApplicationComment', foreign_keys=[comment_id], backref=backref('hr_comment_history', cascade="delete"))
#     user = relationship('User', backref='hr_comment_history', foreign_keys=[editor])
#     
#     def __repr__(self):
#         return str(self.editor) + " - Edited comment"


from recruit_app.user.models import EveCharacter
from recruit_app.recruit.models import HrApplication, HrApplicationComment, HrApplicationCommentHistory
from flask import current_app, url_for
import datetime as dt
import requests
import re
        comment = HrApplicationComment()
        comment.application_id = application.id
        comment.comment = comment_data
        if user:
            comment.user_id = user.id
        comment.save()
        application.last_update_time = dt.datetime.utcnow()
        application.save()
        RecruitManager.comment_notify(comment)

    @staticmethod
    def edit_comment(comment, comment_data, user):
        # Save the previous version of the comment for possible future use / auditing
        comment_history = HrApplicationCommentHistory()
        comment_history.old_comment = comment.comment
        comment_history.comment_id = comment.id
        comment_history.editor = user
        comment_history.save()

        # Save the edit
        comment.comment = comment_data
        comment.last_update_time = dt.datetime.utcnow()
#        if not comment.user_id:
#            comment.user = user
        comment.application.last_update_time = dt.datetime.utcnow()
        comment.save()
        RecruitManager.comment_notify(comment)

    @staticmethod
    def create_application(form, user):

# Path: recruit_app/user/models.py
# class EveCharacter(Model, TimeMixin):
#     __tablename__ = 'characters'
# 
#     character_id = Column(db.String(254), primary_key=True)
#     character_name = Column(db.String(254))
#     corporation_id = ReferenceCol('corporations', pk_name='corporation_id', nullable=True)
#     corporation = relationship('EveCorporationInfo', backref='characters', foreign_keys=[corporation_id])
# 
#     api_id = ReferenceCol('api_key_pairs', pk_name='api_id', nullable=True)
#     api = relationship('EveApiKeyPair', backref='characters', foreign_keys=[api_id])
# 
#     user_id = ReferenceCol('users', nullable=True)
#     user = relationship('User', backref='characters', foreign_keys=[user_id])
# 
#     skillpoints = Column(db.Integer, nullable=True)
#     previous_users = db.relationship('User', secondary=previous_chars, backref=db.backref('previous_chars', lazy='dynamic'), lazy='dynamic')
# 
#     def __str__(self):
#         return self.character_name
# 
# Path: recruit_app/recruit/models.py
# class HrApplication(SurrogatePK, TimeMixin, Model):
#     # query_class = HrApplicationQuery
#     __tablename__ = 'hr_applications'
# 
#     __searchable__ = ['thesis',
#                       'how_long',
#                       'notable_accomplishments',
#                       'corporation_history',
#                       'why_leaving',
#                       'what_know',
#                       'what_expect',
#                       'bought_characters',
#                       'why_interested',
#                       'find_out',
#                       'favorite_role',
#                       'main_character_name']
# 
#     main_character_name = Column(db.Unicode, nullable=True)
# 
#     alt_application = Column(db.Boolean, default=False)
# 
#     characters = relationship('EveCharacter', secondary=character_apps, backref=db.backref('hr_applications', lazy='dynamic'), lazy='dynamic')
# 
#     thesis = Column(db.UnicodeText, nullable=True)
#     how_long = Column(db.Text, nullable=True)
#     notable_accomplishments = Column(db.Text, nullable=True)
#     corporation_history = Column(db.Text, nullable=True)
#     why_leaving = Column(db.Text, nullable=True)
#     what_know = Column(db.Text, nullable=True)
#     what_expect = Column(db.Text, nullable=True)
#     bought_characters = Column(db.Text, nullable=True)
#     why_interested = Column(db.Text, nullable=True)
# 
#     goon_interaction = Column(db.Text, nullable=True)
#     friends = Column(db.Text, nullable=True)
# 
#     scale = Column(db.Text, nullable=True)
# 
#     find_out = Column(db.Text, nullable=True)
# 
#     favorite_role = Column(db.Text, nullable=True)
# 
#     user_id = ReferenceCol('users', nullable=True)
#     reviewer_user_id = ReferenceCol('users', nullable=True)
#     last_user_id = ReferenceCol('users', nullable=True)
# 
#     approved_denied = Column(db.Text, default="New")
# 
#     hidden = Column(db.Boolean, nullable=True, default=False)
# 
#     # search_vector = Column(TSVectorType('main_character_name', 'thesis'))
# 
#     user = relationship('User', foreign_keys=[user_id], backref='hr_applications')
#     reviewer_user = relationship('User', foreign_keys=[reviewer_user_id], backref='hr_applications_reviewed')
#     last_action_user = relationship('User', foreign_keys=[last_user_id], backref='hr_applications_touched')
#     
#     training = Column(db.Boolean, default=False)
# 
#     def __str__(self):
#         return '<Application %r>' % str(self.main_character_name)
# 
# class HrApplicationComment(SurrogatePK, TimeMixin, Model):
#     __tablename__ = 'hr_comments'
# 
#     comment = Column(db.Text, nullable=True)
# 
#     application_id = ReferenceCol('hr_applications')
#     user_id = ReferenceCol('users')
#     application = relationship('HrApplication', foreign_keys=[application_id], backref=backref('hr_comments', cascade="delete"))
#     user = relationship('User', backref='hr_comments', foreign_keys=[user_id])
# 
#     def __repr__(self):
#         return str(self.user) + " - Comment"
# 
# class HrApplicationCommentHistory(SurrogatePK, TimeMixin, Model):
#     __tablename__ = 'hr_comment_history'
#     
#     old_comment = Column(db.Text, nullable=True)
#     comment_id = ReferenceCol('hr_comments')
#     editor = ReferenceCol('users')
#     comment = relationship('HrApplicationComment', foreign_keys=[comment_id], backref=backref('hr_comment_history', cascade="delete"))
#     user = relationship('User', backref='hr_comment_history', foreign_keys=[editor])
#     
#     def __repr__(self):
#         return str(self.editor) + " - Edited comment"


# Path: recruit_app/recruit/managers.py
from recruit_app.user.models import EveCharacter
from recruit_app.recruit.models import HrApplication, HrApplicationComment, HrApplicationCommentHistory
from flask import current_app, url_for
import datetime as dt
import requests
import re

        comment = HrApplicationComment()
        comment.application_id = application.id
        comment.comment = comment_data
        if user:
            comment.user_id = user.id
        comment.save()
        application.last_update_time = dt.datetime.utcnow()
        application.save()
        RecruitManager.comment_notify(comment)

    @staticmethod
    def edit_comment(comment, comment_data, user):
        # Save the previous version of the comment for possible future use / auditing
        comment_history = HrApplicationCommentHistory()
        comment_history.old_comment = comment.comment
        comment_history.comment_id = comment.id
        comment_history.editor = user
        comment_history.save()

        # Save the edit
        comment.comment = comment_data
        comment.last_update_time = dt.datetime.utcnow()
#        if not comment.user_id:
#            comment.user = user
        comment.application.last_update_time = dt.datetime.utcnow()
        comment.save()
        RecruitManager.comment_notify(comment)

    @staticmethod
    def create_application(form, user):

        application = HrApplication()