def new_project(request):
    user = request.user
    if request.method == 'POST':
        form = AddProjectForm(request.POST or None)
        if form.is_valid():
            tags = form.cleaned_data['_tags'].split()
            p = form.save()
            for i in tags:
                t = Tag.objects.get_or_create(text=i)[0]
                p.tags.add(t)
            p.admins.add(user)
            return redirect('/account/')
    else:
        form = AddProjectForm()
    return direct_to_template(request, 'add_project.html', locals())
def edit_project(request,project_id):
    user = request.user
    project = get_object_or_404(Project,pk=project_id)
    if request.method == 'POST':
        form = AddProjectForm(request.POST or None,instance=project)
        if form.is_valid() and project.is_admin(user):
            tags = form.cleaned_data['_tags'].split()
            form.save()
            project.tags.clear()
            for i in tags:
                t = Tag.objects.get_or_create(text=i)[0]
                project.tags.add(t)
            return redirect('/project/%s/'%(project_id))
    else:
        t = model_to_dict(project)
        t.update({'_tags':' '.join([i.text for i in project.tags.all()])})
        form = AddProjectForm(t)
    is_admin = project.is_admin(request.user)
    is_moder = project.is_moder(request.user)
    return direct_to_template(request, 'edit_project.html', locals())