Esempio n. 1
0
File: tag.py Progetto: an/GTGOnline
def create_tag_objects(user, tag_list):
    '''
    It takes a user object and a tag_list containing tag names obtained from
    find_tags(), and returns a tuple of
    (list of new tags created and saved, list of existing tags)
    '''
    user = get_user_object(user)
    new_tags, existing_tags, new_tags_names = [], [], []
    for tag in tag_list:
        if does_tag_exist(user, tag):
            existing_tags.append(get_tag_object(user, tag_name = tag))
        else:
            created_tag = Tag(user = user, name = tag)
            new_tags.append(created_tag)
            new_tags_names.append(tag)
    
    if new_tags != []:
        create_bulk_tags(new_tags)
        # bulk_create does not return the ids of the objects saved. Hence, we
        # cannot use the new_tags list as it has not been updated. So, we have
        # to run another query which gets those same objects again from the
        # database.
        new_tags = Tag.objects.filter(user = user, name__in = new_tags_names)
        # For existing tags, we can simply give their list to the task object,
        # and it will add it to it's m2m field. Note that the following approach
        # only works because the existing tags HAVE ids.
        #task_object.tags.add(*existing_tags)
    return (list(new_tags), existing_tags)
Esempio n. 2
0
File: task.py Progetto: an/GTGOnline
def get_all_tasks_details(email):
    user = get_user_object(email)
    if user == None:
        return []
    all_tasks = []
    for task in user.task_set.all():
        all_tasks.append(get_task_details(user, task, include_subtasks = True))
    return all_tasks
Esempio n. 3
0
def remove_member_from_group(user, group_name, member_email):
    group = get_group_object(user, group_name)
    if group != None:
        member = get_user_object(member_email)
        group.members.remove(member)
Esempio n. 4
0
def add_member_to_group(user, group_name, member_email):
    group = get_group_object(user, group_name)
    if group != None:
        member = get_user_object(member_email)
        group.members.add(member)