def add(request): message = '' url = '' error = '' checkout_uri = '' if not request.GET.get('bounty', None): error = "Please enter a bounty" if not request.GET.get('limit', None): error = "Please enter a time limit" if not request.GET.get('url', None): error = "Please enter a Github, Google Code or Bitbucket issue" if error: if request.is_ajax(): return HttpResponse(error) else: messages.error(request, error) return redirect('/') url = request.GET.get('url', None) issue = get_issue(request, url) if issue and issue['status'] == "open": issue['bounty'] = int(request.GET.get('bounty', 0)) issue['limit'] = request.GET.get('limit', 0) request.session['issue'] = issue if request.user.get_profile().balance and (int(request.user.get_profile().balance) > int(request.GET.get('bounty', 0))): if add_issue_to_database(request): user_profile = UserProfile.objects.get(user=request.user) user_profile.balance = int(user_profile.balance) - int(request.GET.get('bounty', 0)) request.user.get_profile().balance = user_profile.balance user_profile.save() message = "<span style='color: #8DC63F; font-weight:bold;'>$"\ + request.GET.get('bounty', 0) + " <span style='color:#4B4B4B'>bounty added to issue </span><strong>#"\ + str(issue['number']) + "</strong>" messages.add_message(request, messages.SUCCESS, message) else: try: wepay = WePay(production=settings.IN_PRODUCTION, access_token=settings.WEPAY_ACCESS_TOKEN) ctx = { 'account_id': settings.ACCOUNT_ID, 'short_description': '$' + request.GET.get('bounty', 0) + " bounty on " + issue['project'] + " issue #" + str(issue['number']), 'type': 'PERSONAL', 'amount': int(request.GET.get('bounty', 0)), 'mode': 'iframe' } wepay_call_return = wepay.call('/checkout/create', ctx) checkout_uri = wepay_call_return['checkout_uri'] message = "Adding bounty to issue #" + str(issue['number']) messages.add_message(request, messages.SUCCESS, message) except Exception, e: message = "%s" % e
def parse_url_ajax(request): url = request.POST.get('url', '') issue = get_issue(request, url) return HttpResponse(json.dumps(issue))
def add(request): message = '' url = '' error = '' checkout_uri = '' if not request.GET.get('bounty', None): error = "Please enter a bounty" if not request.GET.get('limit', None): error = "Please enter a time limit" if not request.GET.get('url', None): error = "Please enter a Github, Google Code or Bitbucket issue" if error: if request.is_ajax(): return HttpResponse(error) else: messages.error(request, error) return redirect('/') url = request.GET.get('url', None) issue = get_issue(request, url) if issue and issue['status'] == "open": issue['bounty'] = int(request.GET.get('bounty', 0)) issue['limit'] = request.GET.get('limit', 0) request.session['issue'] = issue if request.user.get_profile().balance and (int( request.user.get_profile().balance) > int( request.GET.get('bounty', 0))): if add_issue_to_database(request): user_profile = UserProfile.objects.get(user=request.user) user_profile.balance = int(user_profile.balance) - int( request.GET.get('bounty', 0)) request.user.get_profile().balance = user_profile.balance user_profile.save() message = "<span style='color: #8DC63F; font-weight:bold;'>$"\ + request.GET.get('bounty', 0) + " <span style='color:#4B4B4B'>bounty added to issue </span><strong>#"\ + str(issue['number']) + "</strong>" messages.add_message(request, messages.SUCCESS, message) else: try: wepay = WePay(production=settings.IN_PRODUCTION, access_token=settings.WEPAY_ACCESS_TOKEN) ctx = { 'account_id': settings.ACCOUNT_ID, 'short_description': '$' + request.GET.get('bounty', 0) + " bounty on " + issue['project'] + " issue #" + str(issue['number']), 'type': 'PERSONAL', 'amount': int(request.GET.get('bounty', 0)), 'mode': 'iframe' } wepay_call_return = wepay.call('/checkout/create', ctx) checkout_uri = wepay_call_return['checkout_uri'] message = "Adding bounty to issue #" + str(issue['number']) messages.add_message(request, messages.SUCCESS, message) except Exception, e: message = "%s" % e
def create_issue_and_bounty(request): languages = [] for lang in Issue.LANGUAGES: languages.append(lang[0]) user = request.user if not user.is_authenticated(): return render(request, 'post.html', { 'languages': languages, 'message': 'You need to be authenticated to post bounty' }) if request.method == 'GET': return render(request, 'post.html', { 'languages': languages, }) if request.method == 'POST': url = request.POST.get('issueUrl','') if not url: messages.error(request, 'Please provide an issue url') return render(request, 'post.html', { 'languages': languages }) issue_data = get_issue(request, url) if issue_data: service = Service.objects.get(name=issue_data['service']) instance = Issue(created = user,number = issue_data['number'], project=issue_data['project'],user = issue_data['user'],service=service) else: return render(request, 'post.html', { 'languages': languages, 'message':'Please provide a propper issue url', }) form = IssueCreateForm(request.POST, instance=instance) bounty_form = BountyCreateForm(request.POST) bounty_form_is_valid = bounty_form.is_valid() if form.is_valid() and bounty_form_is_valid: if not instance.pk: issue = form.save() else: issue = instance #issue already exists, post additional bounty #this doesn't seem to be working yet price = bounty_form.cleaned_data['price'] bounty_instance = Bounty(user = user,issue = issue,price = price) #save this data and post it with the return_uri from wepay data = serializers.serialize('xml', [ bounty_instance, ]) bounty_instance.save() wepay = WePay(settings.WEPAY_IN_PRODUCTION, settings.WEPAY_ACCESS_TOKEN) wepay_data = wepay.call('/checkout/create', { 'account_id': settings.WEPAY_ACCOUNT_ID, 'amount': request.POST.get('grand_total'), 'short_description': 'CoderBounty', 'long_description': data, 'type': 'service', 'currency': 'USD' }) print wepay_data #return redirect(wepay_data['checkout_uri']) return render(request, 'post.html', { 'languages': languages, 'message':'Successfully saved issue' }) else: return render(request, 'post.html', { 'languages': languages, 'message':'Error', 'errors': form.errors, 'bounty_errors':bounty_form.errors, })
def create_issue_and_bounty(request): languages = [] for lang in Issue.LANGUAGES: languages.append(lang[0]) user = request.user if request.method == 'GET': if request.GET.get('url'): issue_data = get_issue(request, request.GET.get('url')) if not issue_data: messages.error(request, 'Please provide an valid issue url') return redirect('/post') form = IssueCreateForm( initial={ 'issueUrl': request.GET.get('url'), 'title': issue_data['title'], 'content': issue_data['content'] or "Added from Github" }) else: form = IssueCreateForm() return render(request, 'post.html', { 'languages': languages, 'form': form, }) if request.method == 'POST': url = request.POST.get('issueUrl','') if not url: messages.error(request, 'Please provide an issue url') return render(request, 'post.html', { 'languages': languages }) issue_data = get_issue(request, url) if issue_data: service = Service.objects.get(name=issue_data['service']) instance = Issue(number = issue_data['number'], project=issue_data['project'],user = issue_data['user'],service=service) else: return render(request, 'post.html', { 'languages': languages, 'message':'Please provide a propper issue url', }) form = IssueCreateForm(request.POST, instance=instance) bounty_form = BountyCreateForm(request.POST) bounty_form_is_valid = bounty_form.is_valid() if form.is_valid() and bounty_form_is_valid: price = bounty_form.cleaned_data['price'] if int(price) < 5: return render(request, 'post.html', { 'languages': languages, 'message':'Bounty must be greater than $5', }) try: issue = form.save() except: issue = Issue.objects.get(number = issue_data['number'], project=issue_data['project'],user = issue_data['user'],service=service) #issue exists bounty_instance = Bounty(user = user,issue = issue,price = price) data = serializers.serialize('xml', [ bounty_instance, ]) wepay = WePay(settings.WEPAY_IN_PRODUCTION, settings.WEPAY_ACCESS_TOKEN) wepay_data = wepay.call('/checkout/create', { 'account_id': settings.WEPAY_ACCOUNT_ID, 'amount': request.POST.get('grand_total'), 'short_description': 'CoderBounty', 'long_description': data, 'type': 'service', 'redirect_uri': request.build_absolute_uri(issue.get_absolute_url()), 'currency': 'USD' }) if "error_code" in wepay_data: messages.error(request, wepay_data['error_description']) return render(request, 'post.html', { 'languages': languages }) return redirect(wepay_data['checkout_uri']) else: return render(request, 'post.html', { 'languages': languages, 'message':form.errors, 'errors': form.errors, 'form':form, 'bounty_errors':bounty_form.errors, })