<commit_before>#!/usr/bin/python

"""
created_by:         <NAME>
created_date:       3/2/2015
last_modified_by:   <NAME>
last_modified date: 3/2/2015
"""

# imports
import constants
import json

# classes
class Answer:
    'Question object to hold attributes and functions for a question'

    def __init__(self, id, created, created_by, question, score, answer_text):
        """
        self             - the answer in answer
        id               - the id number of the answer 'self' in the database
        created          - the date when the answer 'self' was created
        created_by       - the user that created the answer 'self'
        question_id      - the id number of the question the answer 'self' belongs to
        score            - the score of the answer
        answer_text      - the content of hte answer

        this function acts as the constructor to define a new answer object
        """
        self.id               = id
        self.created          = created
        self.created_by       = created_by
        self.question_id      = question
        self.score            = score
        self.answer_text      = answer_text

    @classmethod
    def noID(self, id, created, created_by, question, score, answer_text):
        """
        the parameters correspond with the parameters in the constructor above

        returns a new question with the id parameter set as None and the other
        parameters set as they are passed in

        this function acts as a second constructor where you have created a
        answer that has not yet been assigned an id from the database
        """
        return self(None, id, created, created_by, question, score, answer_text)

    def __eq__(self, other):
        """
        self  - the answer in answer
        other - another answer that you are comparing 'self' to

        return a boolean telling if the attributes of self and 'other'
        are the same

        this function overrides the way python compares two answers
        and decides if they are equal instead of checking if they are the
        exact same object
        """
        return (
        self.id               == other.id               and
        self.created          == other.created          and<commit_msg>answer.py updated<commit_after>#!/usr/bin/python

"""
created_by:         <NAME>
created_date:       3/2/2015
last_modified_by:   <NAME> (Bear)
last_modified date: 3/3/2015
"""

# imports
import constants
import json
import mysql.connector
from user import User
from mysql_connect_config import getConfig
# classes
class Answer:
    'Question object to hold attributes and functions for a question'

    def __init__(self, id, created, created_by, question, score, answer_text):
        """
        self             - the answer in answer
        id               - the id number of the answer 'self' in the database
        created          - the date when the answer 'self' was created
        created_by       - the user that created the answer 'self'
        question_id      - the id number of the question the answer 'self' belongs to
        score            - the score of the answer
        answer_text      - the content of hte answer

        this function acts as the constructor to define a new answer object
        """
        self.id               = id
        self.created          = created
        self.created_by       = created_by
        self.question_id      = question
        self.score            = score
        self.answer_text      = answer_text

    def add(self):
        if self.id is not None:
            return
        cnx = mysql.connector.connect(**getConfig())
        cursor = cnx.cursor()

        insert = ("INSERT INTO answer (id, created, created_by, question_id, score, content) VALUES (%s, '%s', %s, %s, %s, '%s', %s); SELECT LAST_INSET_ID();" % (self.id, self.created, self.created_by, self.question_id, self.score, self.content, self.active))
        cursor.execute(insert)
        for (id) in cursor:
            self.id=id

        cnx.commit()
        cursor.close()
        cnx.close

    def edit(self):
        cnx = mysql.connector.connect(**getConfig())
        cursor = cnx.cursor()

        if self.id is not None:
            update = ("UPDATE answer SET created '%s', created_by = %s, question_id = %s, score = %s, content = '%s' WHERE id = %s" % (self.created, self.created_by, self.question_id, self.score, self.content, self.id))
            cursor.execute(update)
        
        cnx.commit()
        cursor.close()
        cnx.close()
    def active(self, bool):
        cnx = mysql.connector.connecto(**getCongif())
        cursor = cnx.cursor()
        
        self.active = int(bool)
        active = ("UPDATE courses SET active = %s WHERE id = %s;" % (int(bool), self.id))
        
        cursor.execute(active)
        cnx.commit()
        cursor.close()
        cnx.close()

    @classmethod
    def get(self, id="all"):
        cnx = mysql.connector.connect(**getConfig())
        cursor = cnx.cursor()

        returnList = []
        query = ""
        if id == "all":
            query = "SELECT * FROM answer;"
        else:
            query = ("SELECT * FROM answer WHERE id=%s" % (id))
        cursor.execute(query)
        for (id, created, created_by, question_id, score, content, active) in cursor:
            user = User.get(created_by)[0]
            returnList.append(Answer(id, created, user, question_id, score, content, active ))
        
	    cnx.commit()
        cursor.close()
        cnx.close

        return returnList

    def noID(self, id, created, created_by, question, score, answer_text):
        """
        the parameters correspond with the parameters in the constructor above

        returns a new question with the id parameter set as None and the other
        parameters set as they are passed in

        this function acts as a second constructor where you have created a
        answer that has not yet been assigned an id from the database
        """
        return self(None, id, created, created_by, question, score, answer_text)

    def __eq__(self, other):
        """
        self  - the answer in answer
        other - another answer that you are comparing 'self' to

        return a boolean telling if the attributes of self and 'other'
        are the same

        this function overrides the way python compares two answers
        and decides if they are equal instead of checking if they are the
        exact same object
        """
        return (
        self.id               == other.id               and
        self.created          == other.created          and
{'fraction_non_alphanumeric': 0.07994011976047904, 'fraction_numerical': 0.0037425149700598802, 'mean_word_length': 1.9225721784776904, 'pattern_counts': {'":': 1, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '84253', 'n_tokens_mistral': 1760, 'n_tokens_neox': 1709, 'n_words': 674}