Exemplo n.º 1
0
def add_tags(tags, objects, creator, section, action_type, action_context=None, comment=None):
    tag_set = TagSet(
        creator = creator,
        section = section,
        action_type = action_type,
        comment = comment,
    )
    if action_context:
        tag_set.action_context = action_context
    tag_set.save()

    for object in objects:
        for tag in tags:
            tagged = TaggedItem(
                tag_set = tag_set,
                tag = tag,
                active = True,
            )
            if object.__class__.__name__ == 'Voter':
                tagged.voter = object
            elif object.__class__.__name__ == 'Election':
                tagged.election = object
            elif object.__class__.__name__ == 'District':
                tagged.district = object
            elif object.__class__.__name__ == 'Supporter':
                tagged.supporter = object
            elif object.__class__.__name__ == 'Organization':
                tagged.organization = object
            elif object.__class__.__name__ == 'Donation':
                tagged.donation = object
            elif object.__class__.__name__ == 'Activity':
                tagged.activity = object
            elif object.__class__.__name__ == 'Team':
                tagged.team = object
            tagged.save()