Ejemplo n.º 1
0
def csv_config(request):
    headers = None
    content = {}
    f = TextIOWrapper(request.FILES['config'].file, encoding='utf-8')
    reader = csv.reader(f.read().splitlines())
    # credits goes to http://www.eurion.net/python-snippets/snippet/CSV%20to%20Dictionary.html
    for row in reader:
        if reader.line_num == 1:
            headers = row[1:]
        else:
            content[row[0]] = dict(zip(headers, row[1:]))
    special_users = []
    projects = set()
    for username in content:
        user, created = User.objects.get_or_create(username=username)
        user.email = content[username]['Email']
        user.first_name = content[username]['First Name']
        user.last_name = content[username]['Last Name']
        user.profile.phone = content[username]['Phone']
        user.profile.skype = content[username]['Skype']
        user.profile.comment = content[username]['Comment']
        user.save()
        project = content[username]['Project']
        sub_project = content[username]['SubProject']
        if project != "*" and sub_project != "*":
            project, created = Project.objects.get_or_create(name=project + "-" + sub_project)
            project.created_by = request.user
            project.add_user(user, content[username]["Role"])
            project.save()
            projects.add(project)
        else:
            special_users.append(
                {"user": user, "role": content[username]["Role"], "project": project, "subproject": sub_project})
    for special_user in special_users:
        for project in projects:
            if (special_user['project'] == "*" and special_user['subproject'] == "*") \
                    or (special_user['project'] == "*" and project.name.endswith(special_user['subproject'])) \
                    or (special_user['subproject'] == "*" and project.name.startswith(special_user['project'])):
                project.add_user(special_user['user'], special_user['role'])
    for project in projects:
        ProjectAdmin.export_graph(project, request.user)
    return Response({"success": True})
Ejemplo n.º 2
0
def step_impl(context, username, project_name):
    p = Project.objects.get(name=project_name)
    u = User.objects.get(username=username)
    ProjectAdmin.export_graph(project=p, created_by_user=u)