def initiative_edit_save(request): system_message = None if request.method == 'POST': uuid = request.POST['uuid'] initiative_id = initiative_dao.get_intitiative_id(uuid) form = InitiativeForm(request.POST) if form.is_valid(): is_public = form.cleaned_data['is_public'] initiative = Initiative.objects.get(pk=initiative_id) initiative.short_desc = form.cleaned_data['short_desc'] initiative.long_desc = form.cleaned_data['long_desc'] if is_public: if settings.INITIATIVE_LAUNCH_FEE == 0: initiative.is_public = is_public if initiative.publish_date is None: initiative.publish_date = datetime.now() else: initiative.is_public = is_public initiative.save() if settings.INITIATIVE_LAUNCH_FEE > 0 and is_public and initiative.publish_date is None: raw_fee = settings.INITIATIVE_LAUNCH_FEE display_fee = str(raw_fee)[:-2] + '.' + str(raw_fee)[-2:] return render_to_response('initiative_payment.html', { 'system_message': system_message, 'uuid': uuid, 'display_fee': display_fee, 'raw_fee': raw_fee, }, context_instance=RequestContext(request)) else: system_message = 'Initiative updated!' return render_to_response('initiative_edit.html', { 'system_message': system_message, 'form': None, 'uuid': uuid, }, context_instance=RequestContext(request)) else: system_message = 'Error' return render_to_response('initiative_edit.html', { 'system_message': system_message, 'uuid': uuid, 'form': form, }, context_instance=RequestContext(request)) else: system_message = 'Invalid request' return render_to_response('system.html', { 'system_message': system_message, }, context_instance=RequestContext(request))
def initiative_add(request): if request.method == 'POST': form = InitiativeForm(request.POST) if form.is_valid(): short_desc = form.cleaned_data['short_desc'] long_desc = form.cleaned_data['long_desc'] is_public = form.cleaned_data['is_public'] publish_date = None if is_public: if settings.INITIATIVE_LAUNCH_FEE == 0: is_public = is_public publish_date = datetime.now() else: is_public = False i = Initiative.objects.create( profile_id=request.session['profile_id'], short_desc=short_desc, long_desc=long_desc, is_public=is_public, publish_date=publish_date) if settings.INITIATIVE_LAUNCH_FEE > 0 and is_public: system_message = 'Initiative added, payment required.' raw_fee = settings.INITIATIVE_LAUNCH_FEE display_fee = raw_fee[-2:] + '.' + raw_fee[:-2] return render_to_response('initiative_payment.html', { 'system_message': system_message, 'uuid': i.uuid, 'display_fee': display_fee, 'raw_fee': raw_fee, }, context_instance=RequestContext(request)) # load data for next step #s = Service.objects.all().order_by('short_desc', ) return render_to_response('initiative_add.html', { 'system_message': 'Initiative created!.', 'return_code': '0', 'uuid': i.uuid }, RequestContext(request)) else: #form = InitiativeForm() return render_to_response('initiative_add.html', { 'form': form, }, RequestContext(request)) else: form = InitiativeForm() return render_to_response('initiative_add.html', { 'form': form, }, RequestContext(request))