Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @csrf_exempt
- def addCinemaFunction(request):
- if request.session["function"] == "admin" or request.session["function"] == "manager":
- with open('data_json.json', 'r', encoding='utf-8') as file:
- data_json = json.load(file)
- req = request.POST
- name = req.get('name')
- location = req.get('location')
- phone = req.get('phone')
- if name != None and location != None and phone != None and \
- name != "" and location != "" and phone != "":
- flag = False
- last_id = int(data_json['cinemas'][-1]['id']) + 1
- for cinema in data_json['cinemas']:
- if name == cinema['name']:
- flag = True
- break
- if flag == False:
- new_obj = {
- 'id': str(last_id),
- 'name': name,
- 'location': location,
- 'contacts': {
- 'phone': phone,
- },
- 'films': [],
- }
- data_json['cinemas'].append(new_obj)
- with open('data_json.json', 'w', encoding='utf-8') as file:
- file.write(json.dumps(data_json, ensure_ascii=False, separators=(',', ': '), indent=2))
- return redirect('guest')
- else:
- return render(request, 'json/addCinema.html', {})
- else:
- return render(request, 'json/addCinema.html', {})
- else:
- return redirect('/')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement