Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Search-issue functionality #300

Merged
merged 2 commits into from
Jul 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bugheist/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@
url(r'^issue/comment/(?P<pk>\d+)/update/$',comments.views.EditComment, name='update_comment'),
url(r'^issue/comment/(?P<pk>\d+)/delete/$',comments.views.DeleteComment, name='delete_comment'),
url(r'^social/$', TemplateView.as_view(template_name="social.html")),
url(r'^search/$', website.views.search),

) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

7 changes: 0 additions & 7 deletions website/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class Domain(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)


def __unicode__(self):
return self.name

Expand Down Expand Up @@ -78,7 +77,6 @@ def get_logo(self):
favicon_url = self.url + '/favicon.ico'
return favicon_url


@property
def get_color(self):
if self.color:
Expand Down Expand Up @@ -183,23 +181,19 @@ def get_ocr(self):
except:
return "OCR not installed"


@property
def get_absolute_url(self):
return "/issue/" + str(self.id)

class Meta:
ordering = ['-created']


TWITTER_MAXLENGTH = getattr(settings, 'TWITTER_MAXLENGTH', 140)


def post_to_twitter(sender, instance, *args, **kwargs):

if not kwargs.get('created'):
return False

try:
consumer_key = os.environ['TWITTER_CONSUMER_KEY']
consumer_secret = os.environ['TWITTER_CONSUMER_SECRET']
Expand Down Expand Up @@ -318,4 +312,3 @@ def create_profile(sender, **kwargs):
profile.save()

post_save.connect(create_profile, sender=User)

1 change: 0 additions & 1 deletion website/static/vendor/bootstrap/css/bootstrap.css
Original file line number Diff line number Diff line change
Expand Up @@ -6755,4 +6755,3 @@ button.close {
display: none !important;
}
}
/*# sourceMappingURL=bootstrap.css.map */
6 changes: 4 additions & 2 deletions website/templates/_activity.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{% load gravatar %}
<div class="list-group-item activity-strip">
<div class="activity-strip-section">
<a class="comment_link" href="{{activity.target.get_absolute_url }}#comments_form">{{ activity.target.comments.all|length }} comments</a>
<a class="comment_link" href="{{activity.target.get_absolute_url }}#comments">
{{ activity.target.comments.all|length }} comments
</a>

{% if activity.actor.socialaccount_set.all.0.get_avatar_url %}
<img src="{{activity.actor.socialaccount_set.all.0.get_avatar_url}}" width="100" class="img-responsive img-rounded">
Expand Down Expand Up @@ -48,7 +50,7 @@
<a href="//{{ activity.target.domain_name }}">{{ activity.target.domain_name }}</a>
<span class="label label-info bug-type">{{activity.target.get_label_display}}</span>
</div>
<div class="more_info"><a>See More </a></div>
<div class="more_info"><a>See More</a></div>
</div>
</div>

Expand Down
3 changes: 3 additions & 0 deletions website/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@
<li style="float:left;">
<a href="#" id="startTour" class="start-tour">Tour</a>
</li>
<li style="float:left;">
<a href="/search" class="sponsor-hunt">Search</a>
</li>
</ul>
<div class="col-md-12">
<div class="col-md-4">
Expand Down
2 changes: 1 addition & 1 deletion website/templates/issue.html
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ <h4>OCR Results:</h4><hr>
{% endif %}
</div>

<form method="post" action="{% url 'comments.views.AddComment' pk=issue.pk %}" id="comments_form">
<form method="post" action="{% url 'comments.views.AddComment' pk=issue.pk %}" id="comments">
{% csrf_token %}
<div class="form-group">
<textarea placeholder="Comment" class="form-control" name="text_comment" required></textarea>
Expand Down
1 change: 0 additions & 1 deletion website/templates/issue_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
{% endblock %}

{% block content %}

<div id="fb-root"></div>
<script type="text/javascript" src="{% static "js/issue.js" %}"></script>
<div class="row">
Expand Down
98 changes: 98 additions & 0 deletions website/templates/search.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{% extends "base.html" %}
{% load gravatar %}
{% load staticfiles %}
{% load humanize %}

{% block content %}
<div class="row">
<hr>
<div class="col-md-4 col-md-offset-4">
<h3 class="text-center">Search for Bugs & Issues</h3><hr>
<form method="GET" action=".">
<div class="input-group">
<input type="text" class="form-control" name="query" value="{{query}}" placeholder="Search for issues...">
<span class="input-group-btn">
<select class="form-control" name="type">
<option value="issue" selected="selected">Issue</option>
<option value="domain">Domain</option>
<option value="user">User</option>
</select>
<button class="btn btn-default" type="submit">Search</button>
</span>
</div>
</form>
</div>
</div>
{% if query %}
{% if issues %}
{% for issue in issues %}
<div class="list-group-item activity-strip">
<div class="activity-strip-section">
<a class="comment_link" href="{{issue.get_absolute_url }}#comments">
{{ issue.comments.all|length }} comments
</a>

{% if issue.user.socialaccount_set.all.0.get_avatar_url %}
<img src="{{issue.user.socialaccount_set.all.0.get_avatar_url}}" width="100" class="img-responsive img-rounded">
{% else %}
<img src="{% gravatar_url issue.user.email 100 %}" width="100" class="img-responsive img-rounded">
{% endif %}

<div class="info">
<a href="/domain/{{ issue.domain_name }}">
<img src="http://www.{{issue.domain_name}}/favicon.ico" height="25" onerror="this.onerror=null; this.style.display='none';">
</a>
<a href="{{ issue.get_absolute_url }}">{{ issue.description|truncatechars:100 }}</a>
{% if issue.status == "open" %}
<span class="label label-success text-capitalize">{{issue.status}}</span>
{% else %}
<span class="label label-danger text-capitalize">{{issue.status}}</span>
{% endif %}
<div class="small">
<a href="{{ issue.user.get_absolute_url }}" class="text-capitalize">
{{ issue.user }}
</a>
found a bug on <a href="/domain/{{ issue.domain_name }}">{{ issue.domain_title }}</a> {{ issue.timestamp|timesince }} ago |
<a href="//{{ issue.domain_name }}">{{ issue.domain_name }}</a>
<span class="label label-info bug-type">{{issue.get_label_display}}</span>
</div>
</div>
</div>
<div class="activity-screenshot">
{% if issue.screenshot %}
<a href="{{ issue.get_absolute_url }}">
<img src="{{ issue.screenshot.url }}">
</a>
{% endif %}
</div>
</div>
{% endfor %}
{% elif domains %}
<div class="list-group">
{% for domain in domains %}
<div class="list-group-item">
<a href="{{ domain.get_absolute_url }}">
<img src="{{domain.get_logo}}" height="100" onerror="this.onerror=null; this.style.display ='none';">
<strong>{{ domain.name }}</strong>
</a>
</div>
{% endfor %}
</div>
{% elif users %}
<div class="list-group">
{% for user in users %}
<div class="list-group-item">
{% if user.socialaccount_set.all.0.get_avatar_url %}
<img src="{{user.socialaccount_set.all.0.get_avatar_url}}">
{% else %}
<img src="{% gravatar_url user.email 50 %}">
{% endif %}
<a href="/profile/{{user.username}}">{{user.username}}</a>
</div>
{% endfor %}
</div>
{% else %}
<div class="alert alert-danger" role="alert">Nothing Found!</div>
{% endif %}
{% endif %}
{% endblock %}
33 changes: 26 additions & 7 deletions website/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from website.models import Issue, Points, Hunt, Domain, InviteFriend
from django.core.files import File
from django.core.urlresolvers import reverse, reverse_lazy
from django.db.models import Sum, Count
from django.db.models import Sum, Count, Q
from django.core.urlresolvers import reverse
from django.core.files.storage import default_storage
from django.views.generic import View
Expand Down Expand Up @@ -88,7 +88,6 @@ def find_key(request, token):

class IssueBaseCreate(object):


def form_valid(self, form):
score = 3
obj = form.save(commit=False)
Expand All @@ -109,7 +108,6 @@ def process_issue(self, user, obj, created, domain, score=3):
action.send(user, verb='found a bug on website', target=obj)
messages.success(self.request, 'Bug added! +'+ str(score))


if created:
try:
email_to = get_email_from_domain(domain)
Expand Down Expand Up @@ -164,7 +162,6 @@ def process_issue(self, user, obj, created, domain, score=3):
return HttpResponseRedirect("/")



class IssueCreate(IssueBaseCreate, CreateView):
model = Issue
fields = ['url','description','screenshot','domain', 'label']
Expand Down Expand Up @@ -391,6 +388,31 @@ def get_context_data(self, *args, **kwargs):
context['scoreboard'] = Domain.objects.all().order_by('-modified')
return context

def search(request, template="search.html"):
query = request.GET.get('query')
stype = request.GET.get('type')
if query is None:
return render_to_response(template, context_instance=RequestContext(request))

if stype == "issue":
context = {
'query' : query,
'type' : stype,
'issues' : Issue.objects.filter(Q(description__icontains=query))
}
elif stype == "domain":
context = {
'query' : query,
'type' : stype,
'domains' : Domain.objects.filter(Q(url__icontains=query))
}
elif stype == "user":
context = {
'query' : query,
'type' : stype,
'users' : User.objects.filter(Q(username__icontains=query))
}
return render_to_response(template, context, context_instance=RequestContext(request))

class HuntCreate(CreateView):
model = Hunt
Expand Down Expand Up @@ -483,7 +505,6 @@ def get_context_data(self, *args, **kwargs):
context['emails'] = get_email_from_domain(self.kwargs['slug'])
return context


def get_email_from_domain(domain_name):
new_urls = deque(['http://'+domain_name])
processed_urls = set()
Expand Down Expand Up @@ -610,7 +631,6 @@ def assign_issue_to_user(request, user, **kwargs):
assigner.request = request
assigner.process_issue(user, issue, created, domain)


class CreateInviteFriend(CreateView):
template_name = 'invite_friend.html'
model = InviteFriend
Expand Down Expand Up @@ -647,4 +667,3 @@ def form_valid(self, form):
messages.success(self.request, 'An email has been sent to your friend. Keep inviting your friends and get points!')

return HttpResponseRedirect(self.success_url)