Пример #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()
    })
Пример #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
Пример #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()
Пример #4
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 }")
Пример #5
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")
Пример #6
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")