Exemplo n.º 1
0
def create_tag(originator_id, subject_id, text, publicity="public", types=[]):
    #should check if tag exists
    tag = Tag()
    tag.originator = originator_id
    tag.originator_slug = Person.query.filter(
        Person.id == originator_id)[0].slug
    tag.subject = subject_id
    tag.subject_slug = Person.query.filter(Person.id == subject_id)[0].slug
    tag.text = condition_label_text(text)
    tag.type = find_tag_type(text)
    for type in types:
        tag.type = ','.join([tag.type, type])
    tag.publicity = publicity
    tag = do_tag_logic(tag)
    labels = create_labels_from_tag(tag)
    if len(labels) > 0:
        #TODO: Return the label in the response as well.
        tag.label = labels[0]

    tag.slug = tag.create_slug()
    # check if tag exists
    existing_tags = Tag.query.filter(Tag.slug == tag.slug)
    if existing_tags.count() > 0:
        print("updating tag %s" % tag.slug)
        return update_tag(existing_tags[0].id, text, publicity=publicity)
    else:
        print("creating new tag %s" % tag.slug)
        db.session.add(tag)
        db.session.commit()
        return tag.id
Exemplo n.º 2
0
def create_tag_request():
    data = request.get_json() or {}
    (account_id, person_id) = get_account_and_person(data['token'])
    # Check if tag already exists - this check should be more elaborate
    tag = Tag()
    tag.originator = person_id
    tag.originator_slug = Person.query.filter(Person.id == person_id)[0].slug
    new = True
    # Update tag
    if 'id' in data:
        q = Tag.query.filter(Tag.slug == data['id'])
        if q.count() > 0:
            print("updating tag %s" % data['id'])
            tag = q[0]
            new = False
    # Someone is creating the same tag
    subject = -1
    if 'subject' in data:
        subject = Person.query.filter(Person.slug == data['subject'])[0]
        tag.subject = subject.id
        tag.subject_slug = subject.slug
    else:
        print("Error could not create tag becasue no subject")
        return -1
    text = ""
    if 'text' or 'label' in data:
        if 'label' in data:
            text = data['label']
        else:
            text = data['text']
        tag.text = condition_label_text(text)
        tag.type = find_tag_type(text)
    else:
        print("Error could not create tag becasue no text")
        return -1
    publicity = "public"
    if 'publicity' in data:
        publicity = data['publicity']
    tag.publicity = publicity
    tag = do_tag_logic(tag)
    labels = create_labels_from_tag(tag)
    if len(labels) > 0:
        #TODO: Return the label in the response as well.
        tag.label = labels[0]
    tag.slug = tag.create_slug()
    if ("repeatable" in decode_tag_types(tag.type)):
        tag.slug = tag.slug + "-".join(str(datetime.utcnow()).split(" "))
    if Tag.query.filter(Tag.slug == tag.slug).count() > 0:
        new = False
    if new:
        print("Created tag %s" % tag.slug)
        db.session.add(tag)
    else:
        print("Updated Tag %s" % tag.slug)
    response = jsonify(tag.to_deliverable())
    db.session.commit()
    return response
Exemplo n.º 3
0
def create_tag(subject_id, originator_id, text, publicity="public"):

    tag = Tag()
    tag.originator = originator_id
    tag.originator_slug = Person.query.filter(
        Person.id == originator_id)[0].slug
    tag.subject = subject_id
    tag.subject_slug = Person.query.filter(Person.id == subject_id)[0].slug
    tag.text = text
    label = create_label_from_tag(tag)
    db.session.add(label)
    tag.label = label.id
    tag.publicity = publicity
    tag.slug = tag.create_slug()
    return tag