def publish_new_manifesto(request): password = request.POST.get('password') return_data = {} if not request.user.check_password(password): return_data['STATUS'] = '0' return_data['MESSAGE'] = 'Wrong password' else: return_data['MESSAGE'] = [] manifesto_title = request.POST.get('manifestoTitle') manifesto_language = request.POST.get('manifestoLanguage') manifesto = Campaign() manifesto.title = manifesto_title manifesto.client = Client.objects.get(user=request.user) manifesto.language = Language.objects.get(id=manifesto_language) manifesto.date_created = datetime.datetime.now() manifesto.save() try: manifesto.save() return_data['MESSAGE'].append({ 'STATUS': '1', 'MESSAGE': 'Campaign has been created' }) manifesto = Campaign.objects.get( client=Client.objects.get(user=request.user), language=manifesto_language, title=manifesto_title) manifesto_content = json.loads( request.POST.get('manifestoContent')) for item in manifesto_content: try: manifesto_item = CampaignItems() manifesto_item.campaign = manifesto manifesto_item.title = item['contentTitle'] manifesto_item.content = item['content'] manifesto_item.save() return_data['MESSAGE'].append({ 'STATUS': '1', 'MESSAGE': '{} has been added to campaign.'.format( item['contentTitle']) }) except: return_data['MESSAGE'].append({ 'STATUS': '0', 'MESSAGE': '{} could not be added to the campaign.'.format( item['contentTitle']) }) except: return_data['MESSAGE'].append({ 'STATUS': '0', 'MESSAGE': 'Campaign failed to be published' }) return HttpResponse(json.dumps(return_data))