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

filtering issues resolved #96

Merged
merged 9 commits into from
Oct 26, 2018
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
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"python.linting.enabled": false,
"python.pythonPath": "/usr/bin/python3"
"python.pythonPath": "/usr/bin/python3",
"files.associations": {
"iostream": "cpp"
}
}
40 changes: 20 additions & 20 deletions ContriHub/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@
else:
#this is for local you need not to make any changes here,
# it'll work unless you are sure about how to setup postgres/mysql etc
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
# }
# }
#An example how you can setup postgres sql in local, create a postgres db and provide relevant details in this format
# DB_PASS = os.environ.get('CONTRIHUB_PASS', "")
# DATABASES = {
Expand All @@ -140,20 +140,20 @@
# 'PORT': '',
# }
# }
# DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.mysql',
# 'OPTIONS': {
# # 'read_default_file': '/path/to/my.cnf',
# },
# # 'NAME': os.path.join(BASE_DIR, 'testdb'),
# 'NAME': 'contrihub_db',
# 'USER': 'user',
# 'PASSWORD': '1234',
# 'HOST': '127.0.0.1',
# 'PORT': '',
# }
# }
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'OPTIONS': {
# 'read_default_file': '/path/to/my.cnf',
},
# 'NAME': os.path.join(BASE_DIR, 'testdb'),
'NAME': 'contrihub_db',
'USER': 'user',
'PASSWORD': '1234',
'HOST': '127.0.0.1',
'PORT': '',
}
}


# Password validation
Expand Down
1 change: 1 addition & 0 deletions Projects/templates/Projects/contribution_user.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ <h2 style="text-align:center;">Solved Issues!!</h2>
</div>
</div>
</div>
<br>
{% endfor %}
</div>

Expand Down
32 changes: 26 additions & 6 deletions Projects/templates/Projects/leaderboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
<th scope="col"><strong>Score</strong><br> (click on score to see Contributions)</th>
</tr>
</thead>
<tbody>
<tbody class="infinite-container">

{% for user in users %}
<tr>
<th scope="row">{{forloop.counter}}</th>
<tr class="infinite-item">
<th scope="row">{{forloop.counter0|add:users.start_index}}</th>
<td><a href="https://github.com/{{user.username}}">{{user.username}}</a></td>
<td><a href="{%url 'contri_user' user.username %}" style="color:blue;">{{user.profile.points}}</a></td>
</tr>
Expand All @@ -37,10 +37,17 @@
</tbody>
</table>
</div>
<div class="card-footer">
<p class="text-muted">* Click on score to see contributions from user</p>
</div>

</div>

{% if users.has_next %}
<a class="infinite-more-link" href="?page={{users.next_page_number}}"></a>

<div class="loading">
<img src="{% static 'Projects/img/loader.gif' %}" alt="loading more issues" width="60px" style="display:block;margin-left:auto;margin-right:auto;">
</div>

{% endif %}
</div>


Expand All @@ -49,4 +56,17 @@


{% block js_extra %}
<script>
$(document).ready(function(){
var infiniteScroll = new Waypoint.Infinite({
element: $('.infinite-container')[0],
onBeforePageLoad: function () {
$('.loading').show();
},
onAfterPageLoad: function () {
$('.loading').hide();
}
});
});
</script>
{% endblock js_extra %}
1 change: 1 addition & 0 deletions Projects/templates/Projects/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
</div>
</div>
</div>
<br>
{% endfor %}
{% else %}
{% if page_user.profile.role == 'student' %}
Expand Down
89 changes: 52 additions & 37 deletions Projects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,64 @@
from django.contrib.auth.decorators import login_required
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator

from .models import Issues,Prs
from .models import Issues, Prs

import time


def home(request):
if request.method == 'GET':
print('home GET')
if request.method == 'GET':
print('home GET')
# Getting value of the clicked option
val=''
try:
val = request.GET['value'] #Now here you need to look for more attributes like
# title_project,title_issue,mentor_name etc
except Exception:
pass
print('val - ',val)
# First it checks for project name
if val and val != 'points': # here the issues after or should belike
# Issues.objects.filter( Q(title_project=val) & Q(mentor__username=mentor_name))
try:
project_filter = Issues.objects.filter(title_project=val)
mentor_filter = Issues.objects.filter(mentor__username=val)
level_filter = Issues.objects.filter(level=val)
issues = project_filter or mentor_filter or level_filter
except Exception:
issues = Issues.objects.all()
else: issues = Issues.objects.all()
issues = issues.order_by('points')
paginator = Paginator(issues, 15) # Show 15 issues per page
page = request.GET.get('page', 1)

try:
issues = paginator.get_page(page)
except PageNotAnInteger:
issues = paginator.get_page(1)
# issues = paginator.get_page(1)
except EmptyPage:
issues = paginator.get_page(paginator.num_pages)
issues = Issues.objects.none()
return render(request, 'Projects/home.html', {'issues': issues, 'val':val}) #this dic will have value of
val = ''
try:
val = request.GET['value']
except Exception:
pass
print('val - ', val)
# First it checks for project name
if val and val != 'points':
try:
print("in the try block")
val = int(val)
issues = Issues.objects.filter(level = val)
except Exception:
print("in the except block")
project_filter = Issues.objects.filter(title_project=str(val))
mentor_filter = Issues.objects.filter(mentor__username=str(val))
issues = project_filter or mentor_filter

else:
print("all issues|else block")
issues = Issues.objects.all()
issues = issues.order_by('points')
paginator = Paginator(issues, 15) # Show 15 issues per page
page = request.GET.get('page', 1)

try:
issues = paginator.get_page(page)
except PageNotAnInteger:
issues = paginator.get_page(1)
# issues = paginator.get_page(1)
except EmptyPage:
issues = paginator.get_page(paginator.num_pages)
issues = Issues.objects.none()
return render(request, 'Projects/home.html', {'issues': issues, 'val':val}) #this dic will have value of
#all filter attributes or you can also send a list of all such attrs

def leaderboard(request):
if request.method == 'GET':
users = User.objects.all().filter(profile__role='student').order_by('-profile__points')
return render(request, 'Projects/leaderboard.html', {'users': users})
if request.method == 'GET':
users = User.objects.all().filter(profile__role='student').order_by('-profile__points')
paginator = Paginator(users,5)
page = request.GET.get('page',1)
try:
users = paginator.get_page(page)
except PageNotAnInteger:
users = paginator.get_page(1)
except EmptyPage:
users = paginator.objects.none()
time.sleep(0.5)
return render(request, 'Projects/leaderboard.html', {'users': users})


@login_required(login_url='signin')
Expand Down