예제 #1
0
def gather_form_data():
    actor_dict = defaultdict(
        lambda: None,
        {value: field
         for value, field in request.form.iteritems()})
    organisation_ids = request.form.getlist('organisations')
    actor_dict['organisations'] = [
        get_name_from_id(x, organisation_factory()) for x in organisation_ids
    ]
    locations = request.form.getlist('locations')
    actor_dict['locations'] = [
        get_name_from_id(x, location_factory()) for x in locations
    ]
    professions = request.form.getlist('professions')
    actor_dict['professions'] = [
        get_name_from_id(x, profession_factory()) for x in professions
    ]
    actor_dict['gender'] = actor_dict['gender']
    actor_dict['is_activist'] = actor_dict['is_activist']
    actor_dict['birth_date'] = datetime.datetime.strptime(
        actor_dict['birth_date'], "%Y-%m-%d").date()
    actor_dict['owner_id'] = current_user.id

    actor_instance = Actor(**actor_dict)
    session.add(actor_instance)
    session.flush()

    return actor_instance
예제 #2
0
def gather_form_data():
    location_dict = defaultdict(lambda: None, {value: field for value, field in request.form.iteritems()})
    location_instance = Location(**location_dict)
    session.add(location_instance)
    session.commit()

    return location_instance
예제 #3
0
def gather_form_data():
    profession_dict = defaultdict(
        lambda: None,
        {value: field
         for value, field in request.form.iteritems()})
    profession_instance = Profession(**profession_dict)
    session.add(profession_instance)
    session.flush()

    return profession_instance
예제 #4
0
def gather_form_data():
    event_type_dict = defaultdict(
        lambda: None,
        {value: field
         for value, field in request.form.iteritems()})
    event_type_instance = EventType(**event_type_dict)
    session.add(event_type_instance)
    session.flush()

    return event_type_instance
예제 #5
0
def gather_form_data():
    release_type_dict = defaultdict(
        lambda: None,
        {value: field
         for value, field in request.form.iteritems()})
    release_type_instance = ReleaseType(**release_type_dict)
    session.add(release_type_instance)
    session.flush()

    return release_type_instance
예제 #6
0
def gather_form_data():
    prison_type_dict = defaultdict(
        lambda: None,
        {value: field
         for value, field in request.form.iteritems()})
    prison_type_instance = PrisonType(**prison_type_dict)
    session.add(prison_type_instance)
    session.commit()

    return prison_type_instance
예제 #7
0
def gather_form_data():
    international_authority_dict = defaultdict(
        lambda: None,
        {value: field
         for value, field in request.form.iteritems()})
    international_authority_instance = InternationalAuthority(
        **international_authority_dict)
    session.add(international_authority_instance)
    session.flush()

    return international_authority_instance
예제 #8
0
def gather_form_data():
    organisation_dict = defaultdict(lambda: None, {value: field for value, field in request.form.iteritems()})

    locations = request.form.getlist('locations')
    locs = location_factory()
    organisation_dict['locations'] = [get_name_from_id(x, locs) for x in locations]

    organisation_instance = Organisation(**organisation_dict)
    session.add(organisation_instance)
    session.flush()

    return organisation_instance
예제 #9
0
def gather_form_data():
    evidence_type_dict = defaultdict(lambda: None, {value: field for value, field in request.form.iteritems()})

    event = request.form.getlist('event')
    evs = event_factory()
    evidence_type_dict['event'] = get_name_from_id(event[0], evs)

    evidence_type_instance = EvidenceType(**evidence_type_dict)
    session.add(evidence_type_instance)
    session.commit()

    return evidence_type_instance
예제 #10
0
def gather_form_data():
    source_dict = defaultdict(
        lambda: None,
        {value: field
         for value, field in request.form.iteritems()})

    organisation_ids = request.form.getlist('organisations')
    source_dict['organisations'] = [
        get_name_from_id(x, organisation_factory()) for x in organisation_ids
    ]

    source_instance = Source(**source_dict)
    session.add(source_instance)
    session.flush()

    return source_instance
예제 #11
0
def gather_form_data():
    prison_dict = defaultdict(
        lambda: None,
        {value: field
         for value, field in request.form.iteritems()})

    locations = request.form.getlist('locations')
    locs = location_factory()
    prison_dict['locations'] = [get_name_from_id(x, locs) for x in locations]

    prison_types = request.form.getlist('prison_types')
    pt = prison_type_factory()
    prison_dict['prison_types'] = [
        get_name_from_id(x, pt) for x in prison_types
    ]

    prison_instance = Prison(**prison_dict)
    session.add(prison_instance)
    session.flush()

    return prison_instance
예제 #12
0
def gather_form_data():
    user_dict = defaultdict(
        lambda: None,
        {value: field
         for value, field in request.form.iteritems()})

    user_dict['password_salt'] = bcrypt.gensalt()
    user_dict['password'] = bcrypt.hashpw(str(request.form.get('password')),
                                          str(user_dict['password_salt']))

    organisation = request.form.getlist('organisation')
    if organisation:
        orgs = user_org_factory()
        user_dict['organisation'] = get_name_from_id(organisation[0], orgs)
    else:
        user_dict['organisation'] = None

    user_instance = User(**user_dict)
    session.add(user_instance)
    session.flush()

    return user_instance
예제 #13
0
def gather_form_data(event=None):
    event_dict = defaultdict(
        lambda: None, {
            value: field if field else None
            for value, field in request.form.iteritems()
        })

    uploaded_docs = request.files.getlist("documents")
    event_dict['documents'] = []
    if uploaded_docs:
        for uploaded_file in uploaded_docs:
            filename = secure_filename(uploaded_file.filename)
            if not filename == '':
                uploaded_file.save(os.path.join(DOC_FOLDER, filename))
                doc = Document()
                doc.filename = filename
                session.add(doc)
                session.commit()
                event_dict['documents'].append(doc)

    location_ids = request.form.getlist('locations')
    event_dict['locations'] = [
        get_name_from_id(x, location_factory()) for x in location_ids
    ]

    prison_ids = request.form.getlist('prisons')
    event_dict['prisons'] = [
        get_name_from_id(x, prison_factory()) for x in prison_ids
    ]

    release_types_ids = request.form.getlist('release_types')
    event_dict['release_types'] = [
        get_name_from_id(x, release_type_factory()) for x in release_types_ids
    ]

    sources = request.form.get('sources')
    sources_list = list(set([x.strip() for x in sources.split(",")]))
    event_dict['sources'] = find_things_by_name(sources_list, Source)

    witnesses = request.form.get('witnesses')
    witnesses_list = list(set([x.strip() for x in witnesses.split(",")]))
    event_dict['witnesses'] = find_things_by_name(witnesses_list, Actor)

    victims = request.form.get('victims')
    victims_list = list(set([x.strip() for x in victims.split(",")]))
    event_dict['victims'] = find_things_by_name(victims_list, Actor)

    perpetrators = request.form.get('perpetrators')
    perpetrators_list = list(set([x.strip() for x in perpetrators.split(",")]))
    event_dict['perpetrators'] = find_things_by_name(perpetrators_list, Actor)

    event_types = request.form.getlist('event_types')
    event_dict['event_types'] = [
        get_name_from_id(x, event_type_factory()) for x in event_types
    ]
    if event.report_id:
        report = session.query(Report).get(event.report_id)
        report.text = request.form.get('report')
        event_dict['report'] = report
    else:
        event_dict['report'] = Report(text=request.form.get('report'))

    event_dict['owner_id'] = current_user.id
    #event_instance = Event(**event_dict)
    #event_instance.id = event.id if event else None

    if event is not None:
        for key, value in event_dict.iteritems():
            setattr(event, key, value)
        session.merge(event)
    else:
        session.add(event_instance)
    session.flush()

    return event