def inbox(request): # offer messages my_pid = request.session['profile_id'] system_message = None if request.POST: offer_id = request.POST['offer_id'] cmd = request.POST['cmd'] if cmd == 'accept': is_accepted = True else: is_accepted = False i = Initiative_Service_Offer.objects.get(pk=offer_id) i.is_accepted = is_accepted i.save() system_message = "Updated" #initiative_list = Initiative.objects.all().filter(is_public=True) offer_list = inbox_dao.get_offer_list(my_pid) paginator = Paginator(offer_list, RECORDS_PER_PAGE) page = request.GET.get('page') try: offers = paginator.page(page) except PageNotAnInteger: offers = paginator.page(1) except EmptyPage: offers = paginator.page(paginator.num_pages) #service_selected = Service.objects.filter(initiative_service__initiative_id=initiative_id) #iso = Initiative_Service_Offer.objects.filter(initiative__profile_id=my_pid, service__service_id=initiative__).values('short_desc', 'milestones__is_completed') return render_to_response('inbox.html', { 'offer_list': offers, 'system_message': system_message }, RequestContext(request))
def initiative_contributors(request, uuid=None): system_message = None my_pid = request.session['profile_id'] if request.method == 'POST': # need security around this: check user owns initiative, and the # contrib is assocaited with this initiative contributor_id = request.POST['contributor_id'] uuid = request.POST['uuid'] try: initiative = Initiative.objects.get(uuid=uuid, profile_id=my_pid) except Initiative.DoesNotExist: return render_to_response('system.html', { 'system_message': 'Invalid data. Error code: D001', }, context_instance=RequestContext(request)) try: i = Initiative_Service_Offer.objects.get( id=contributor_id, initiative_id=initiative.id) i.is_accepted = False i.save() except Initiative_Service_Offer.DoesNotExist: return render_to_response('system.html', { 'system_message': 'Invalid data. Error code: D002', }, context_instance=RequestContext(request)) system_message = 'Update complete' else: try: initiative = Initiative.objects.get(uuid=uuid) except Initiative.DoesNotExist: return render_to_response('system.html', { 'system_message': 'Initiative Key not recognized.', }, context_instance=RequestContext(request)) initiative_id = initiative.id contributors = Initiative_Service_Offer.objects.filter( initiative_id=initiative_id, is_accepted=True).values( 'id', 'service__short_desc', 'profile__first_name', 'profile__last_name', 'profile__confirm_key') paginator = Paginator(contributors, RECORDS_PER_PAGE) page = request.GET.get('page') try: contributor_list = paginator.page(page) except PageNotAnInteger: contributor_list = paginator.page(1) except EmptyPage: contributor_list = paginator.page(paginator.num_pages) offer_list = inbox_dao.get_offer_list(my_pid) return render_to_response('initiative_contributor.html', { 'initiative': initiative, 'contributor_list': contributor_list, 'offer_list': offer_list, 'system_message': system_message }, RequestContext(request))