def remove_project(request, project_id): if request.method == 'DELETE': with connect() as conn: dbprojects = Projects(conn) dbprojects.remove(project_id) return HttpResponse(status=200) return HttpResponse(status=400)
def get_projects(request): if request.method == 'GET': with connect() as conn: dbprojects = Projects(conn) projects = dbprojects.readall() return JsonResponse(projects, safe=False, encoder=ModelsJSONEncoder, json_dumps_params={'indent': 2}) return HttpResponse(status=400)
def search_project(request): if request.method == 'GET': with connect() as conn: dbprojects = Projects(conn) descriptionlikesearch = request.GET.get('descr', None) projects = dbprojects.search(descriptionlikesearch) return JsonResponse(projects, safe=False, encoder=ModelsJSONEncoder) return HttpResponse(status=400)
def update_project(request, project_id): if request.method == 'PUT': try: project = _req_body_to_project(request) except (TypeError, KeyError) as e: print(e) return HttpResponse(status=400) with connect() as conn: dbprojects = Projects(conn) dbprojects.update(project, project_id) return HttpResponse(status=200) return HttpResponse(status=400)
def add_project(request): if request.method == 'POST': try: project = _req_body_to_project(request) except (TypeError, KeyError) as e: print(e) return HttpResponse(status=400) with connect() as conn: dbprojects = Projects(conn) dbprojects.add(project) return HttpResponse(status=200) return HttpResponse(status=400)
def import_projects(request): if request.method == 'POST': req_body = request.FILES['file'].read() projects_dict = simplexml.loads(req_body)['projects'] projects = [ Project(0, p['name'], p['description']) for p in projects_dict ] with connect() as conn: dbprojects = Projects(conn) dbprojects.importall(projects) return HttpResponse(status=200) return HttpResponse(status=400)
def export_projects(request): with connect() as conn: dbprojects = Projects(conn) projects = dbprojects.readall() return export(request, projects, 'projects')