Example #1
0
def add_interaction(user_id):
    body = request.get_json()
    print(f"\n\tbody: {body}")
    contact_name = body['contactName']
    method = body['contactMethod']
    duration = body['duration']
    notes = body['notes']
    success = False
    
    try:
        ## TODO: what if you know two people with same name??
        contact = Contact.query.filter_by(name=contact_name).one_or_none()
        if contact is None:
            abort(404)
        print(f"contact found: {contact}")
        interaction = Interaction(
            user_id=user_id, 
            contact_id=contact.id,
            method=method,
            duration=duration,
            notes=notes 
            )
        
        interaction.insert()
        contact.last_contacted = interaction.timestamp
        contact.update()

    except Exception as e:
        print(f"Exception in add_interactions: {e}")

    return jsonify({
        "success" : True,
        "newInteraction" : interaction.format()
    })
Example #2
0
def log_query(term, user, action):
    ''' Log a query into the interactions table
    '''
    try:
        db.session.add(Interaction(term=term, user=user, action=action))
        db.session.commit()
    except:
        pass
Example #3
0
    def setUp(self):
        """Make sure we start with a clean slate"""

        db.drop_all()
        db.create_all()

        Office.query.delete()
        District.query.delete() 
        Representative.query.delete()
        User.query.delete()
        Interaction.query.delete()
        UserRepresentative.query.delete()

        test_office = Office(phone='123-555-1234', address='123 Test St.', location='district')
        test_district = District(state='ny', district_num='123', house='lower')

        db.session.add(test_office)
        db.session.add(test_district)
        db.session.commit()

        office = Office.query.get(1)
        district = District.query.get(1)

        test_rep = Representative(first_name='Testy', last_name='McTestface', full_name='Testy McTestface', photo_url='https://mn315.net/wp-content/uploads/2018/06/cropped-Ugandan-Knuckles.jpg', email='*****@*****.**', serving=True, district=district, websites=[
                    {
                        "url": "http://www.google.com"
                    },
                    {
                        "url": "http://tesla.com"
                    }
                ])
        test_user = User.register(username='******', password='******', first_name='Some', last_name='User', email='*****@*****.**', address='123 Any St., Anytown NY 12345')
        # login_test = User.register(username='******', password='******', first_name='test', last_name='test', email='*****@*****.**', address='82 Kent Blvd., Salamanca NY 14779')
        db.session.add(test_rep)
        db.session.add(test_user)
        # db.session.add(login_test)
        db.session.commit()

        user = User.query.get(1)
        self.user = user
        # user2 = User.query.get(2)
        rep = Representative.query.get(1)


        user.representatives.append(rep)
        rep.offices.append(office)
        # user2.representatives.append(rep)
        db.session.commit()

        # import pdb
        # pdb.set_trace()

        test_interaction = Interaction(user=user, representative=rep, district=district, interaction_date='2020-07-15 10:00:00', medium='email', topic='stuff and junk', content='all the things')
        db.session.add(test_interaction)

        db.session.commit()
Example #4
0
def add_interaction():

    if not g.user:
        flash("Please sign up to access user functionality")
        return redirect("/signup")

    form = InteractionForm()
    reps = [(rep.id, rep.full_name) for rep in g.user.representatives]
    repid = request.args["repId"]
    form.representative.choices = reps
    form.representative.default = repid

    if form.validate_on_submit():

        interaction_date = form.interaction_date.data
        representative = form.representative.data
        medium = form.medium.data
        topic = form.topic.data
        content = form.content.data

        rep = Representative.query.get(representative)
        dist = District.query.get(rep.district.id)
        Interaction.add_intertaction(
            user=g.user,
            representative=rep,
            district=dist,
            interaction_date=interaction_date,
            medium=medium,
            topic=topic,
            content=content,
        )

        flash("Interaction sucessfully added")
        return redirect("/user/interactions")

    form.process()

    return render_template("add-interaction.html", form=form, user=g.user)
Example #5
0
def add_interaction(enrollmentID):
    """Add an interaction"""

    form = request.form

    interaction = Interaction(poster_id=g.user.id,
                              enrollment_id=enrollmentID,
                              content=form.get('text'),
                              time_stamp=datetime.now())

    db.session.add(interaction)
    db.session.commit()

    return redirect(f"/student_page/{ enrollmentID }")
    def test_add_interaction(self):
        interaction = Interaction.add_intertaction(self.user1, self.rep1,
                                                   self.rep1.district,
                                                   '2020-08-26', 'email',
                                                   'stuff', 'nonsense')

        testinteraction = Interaction.query.get(1)
        self.assertIsNotNone(testinteraction)
        self.assertEqual(testinteraction.user, self.user1)
        self.assertEqual(testinteraction.representative, self.rep1)
        self.assertEqual(testinteraction.district, self.rep1.district)
        # self.assertEqual(testinteraction.interaction_date, '2020-08-26')
        self.assertEqual(testinteraction.medium, 'email')
        self.assertEqual(testinteraction.topic, 'stuff')
        self.assertEqual(testinteraction.content, 'nonsense')
Example #7
0
 def mutate(self, info, **kwargs):
     if _validate_jwt(info.context['request'].headers):
         try:
             attrs = kwargs['new_interaction']
             ref_user_story = UseCase.objects.get(short_name=attrs['user_story_name'])
             new_interaction = Interaction(nature=attrs['nature'],
                                           data_flow=attrs['data_flow'], endpoint=attrs['endpoint'],
                                           project=ref_user_story.project).save()
             if attrs['nature'] == 'I':
                 ref_user_story.update(add_to_set__relations=new_interaction)
             elif attrs['nature'] == 'E':
                 ref_user_story.update(add_to_set__relations=new_interaction)
             else:
                 raise Exception("Invalid type of Interaction")
         except DoesNotExist:
             raise Exception("The User Story doesn't seem to exist")
     else:
         raise Exception("Unauthorized to perform task")
Example #8
0
db.session.add(test_user)
db.session.add(login_test)
db.session.commit()

user = User.query.get(1)
user2 = User.query.get(2)
rep = Representative.query.get(1)

user.representatives.append(rep)
rep.offices.append(office)
user2.representatives.append(rep)
db.session.commit()

# import pdb
# pdb.set_trace()

test_interaction = Interaction(
    user=user,
    representative=rep,
    district=district,
    interaction_date="2020-07-15 10:00:00",
    medium="email",
    topic="stuff and junk",
    content="all the things",
)
db.session.add(test_interaction)

db.session.commit()

print("If you made it this far, it seems to be working")