Permalink
Browse files

Issue #1

  • Loading branch information...
pastme committed Oct 28, 2015
1 parent 2d4690e commit 41d80131d3087ce9065417a0126503af705bac29
Showing with 72 additions and 13 deletions.
  1. +1 −1 coderbounty/settings.py
  2. +13 −7 coderbounty/templates/post.html
  3. +1 −1 coderbounty/urls.py
  4. +3 −3 website/models.py
  5. +0 −1 website/utils.py
  6. +54 −0 website/views.py
@@ -101,7 +101,7 @@
# Parse database configuration from $DATABASE_URL
DATABASES['default'] = dj_database_url.config()
#DATABASES['default'] = dj_database_url.config()
# Enable Connection Pooling (if desired)
DATABASES['default']['ENGINE'] = 'django_postgrespool'
@@ -19,10 +19,10 @@
url: data['url'],
csrfmiddlewaretoken: "{{ csrf_token }}"
}).done(function( data ) {
console.log(data)
var issue = jQuery.parseJSON(data)
$('#title').val(issue['title']);
$('#summary').val(issue['content']);
$('#content').val(issue['content']);
});
}
@@ -75,14 +75,16 @@
<span class="bugfix-top"></span>
<div class="frame-content">
<h1 class="titlebar-paper"><span>Po$t a Bounty</span></h1>
<form action="{% url 'paynow' %}" method="post">
<form action="{% url 'post' %}" method="post">
{% csrf_token %}
<div class="grid">
<!-- bounty-post -->
<div class="col-15 bounty-post form-layout form-layout-horizontal">
<!-- -->
<div class="form-item">
{% if message %}<p>&nbsp;&nbsp;&nbsp;<strong>{{ message }}</strong></p>{% endif %}
</div>
<!-- -->
<div class="form-item">
@@ -103,20 +105,23 @@ <h1 class="titlebar-paper"><span>Po$t a Bounty</span></h1>
<label class="label" for="issueUrl">Issue URL:</label>
<div class="value">
<input type="text" id="issueUrl" name="issueUrl"/>
</div>
</div>
<!-- -->
<div class="form-item">
<label class="label" for="title">Title:</label>
<div class="value">
<input type="text" id="title" name="title"/>
{% for error_field,error_value in errors.items %} {% if error_field == 'title' %} {{ error_value }} {% endif %} {% endfor %}
</div>
</div>
<!-- -->
<div class="form-item">
<label class="label" for="summary">Summary:</label>
<label class="label" for="content">Summary:</label>
<div class="vlaue">
<textarea id="summary" name="summary"></textarea>
<textarea id="content" name="content"></textarea>
{% for error_field,error_value in errors.items %} {% if error_field == 'content' %} {{ error_value }} {% endif %} {% endfor %}
</div>
</div>
<!-- -->
@@ -132,9 +137,10 @@ <h1 class="titlebar-paper"><span>Po$t a Bounty</span></h1>
</div>
<!-- -->
<div class="form-item form-short">
<label class="label" for="bounty">Bounty $:</label>
<label class="label" for="price">Bounty $:</label>
<div class="value">
<input type="text" id="bounty" name="bounty" pattern="^[0-9]*$" />
<input type="text" id="price" name="price" pattern="^[0-9]*$" />
{% for error_field,error_value in bounty_errors.items %} {{ error_value }} {% endfor %}
</div>
</div>
</div>
@@ -16,7 +16,7 @@
('^activity/', include('actstream.urls')),
url(r'^$', 'website.views.home', name='home'),
url(r'^post/$', 'website.views.post', name='post'),
url(r'^post/$', 'website.views.create_issue_and_bounty', name='post'),
url(r'^paynow/$', 'website.views.paynow', name='paynow'),
url(r'^list/$', 'website.views.list', name='list'),
url(r'^issue/$', 'website.views.issue', name='issue'),
@@ -72,7 +72,7 @@ class Issue(models.Model):
closed_by = models.CharField(max_length=255, null=True, blank=True)
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
notified_user = models.BooleanField(default=None)
notified_user = models.BooleanField(default=False)
def bounties(self):
if self.status == self.OPEN_STATUS:
@@ -111,13 +111,13 @@ class Meta:
def save(self, *args, **kwargs):
#add issue status to activity feed
super(Issue, self).save(*args, **kwargs)
if self.status == Issue.IN_REVIEW_STATUS:
action.send(self.user, verb="is in review now", target=self.number)
elif self.status == Issue.OPEN_STATUS:
action.send(self.user, verb="is open now", target=self.number)
action.send(self.user, verb="opened issue", target=self)
else:
action.send(self.user, verb="is closed", target=self.number)
super(Issue, self).save(*args, **kwargs)
@@ -60,7 +60,6 @@ def get_issue(request, url):
return False
data = r.groupdict()
req = urllib2.Request(replaced_url, None, {'Content-Type': 'application/' + service.type})
if service.name == "Bitbucket":
try:
result = json.load(urllib2.urlopen(req))
@@ -6,6 +6,7 @@
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.models import User
from models import Issue, Watcher, UserProfile, Service, UserService, Bounty
from .forms import IssueCreateForm, BountyCreateForm
from utils import get_issue, add_issue_to_database, get_twitter_count, get_facebook_count, create_comment, issue_counts, leaderboard, get_hexdigest
#from decorators import ajax_login_required
@@ -143,6 +144,59 @@ def home(request,
response = render_to_response(template, context, context_instance=RequestContext(request))
return response
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,
'error': '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:
return render(request, 'post.html', {
'languages': languages,
'message':'Please provide issue url',
})
issue_data = get_issue(request, url)
if issue_data:
instance = Issue(created = user,number = issue_data['number'],
project=issue_data['project'],user = user,)
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:
issue = form.save()
price = bounty_form.cleaned_data['price']
bounty_instance = Bounty(user = user,issue = issue,price = price)
bounty_instance.save()
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 post(request):
languages = []
for lang in Issue.LANGUAGES:

0 comments on commit 41d8013

Please sign in to comment.