Skip to content

Microtask 1 #1

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

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d7b2d0e
files to be reviewed
yashasingh Oct 3, 2017
5ad9407
task 2 for review
yashasingh Oct 5, 2017
cc7ea89
Incomplete file deleted
yashasingh Oct 6, 2017
8133e9a
changes complete
yashasingh Oct 6, 2017
6dd4900
conflict resolved
yashasingh Oct 6, 2017
ef6bda9
conflict resolved
yashasingh Oct 6, 2017
8c861d6
review changes implemented
yashasingh Oct 6, 2017
7bbf540
Sanitized database query
yashasingh Oct 6, 2017
db47853
bug fixes done
yashasingh Oct 6, 2017
97357e5
minor bugs fixed
yashasingh Oct 6, 2017
3553348
minor bugs fixed
yashasingh Oct 6, 2017
863165f
minor fixes
yashasingh Oct 6, 2017
2f5e74d
issues fixed
yashasingh Oct 8, 2017
efcde18
issues fixed
yashasingh Oct 8, 2017
a613a35
issues fixed
yashasingh Oct 8, 2017
f5c41a7
issues resolved
yashasingh Oct 8, 2017
8969f0c
percentile issue resolved
yashasingh Oct 9, 2017
fee5636
merged code
yashasingh Oct 9, 2017
c9e8057
conflict resolved
yashasingh Oct 9, 2017
7659411
minor fixes
yashasingh Oct 9, 2017
66399e5
code cleaned
yashasingh Oct 9, 2017
1581136
merged task1
yashasingh Oct 9, 2017
8df73a2
Merge branch 'devtask2' into complete
yashasingh Oct 9, 2017
a8c655b
minor fixes
yashasingh Oct 9, 2017
4c4a59f
code made deployable
yashasingh Oct 9, 2017
a7fea46
UI updated
yashasingh Oct 11, 2017
f3d082f
minor fixes
yashasingh Oct 11, 2017
75a14b6
code updated
yashasingh Oct 11, 2017
0edfcac
pyc files ignored
yashasingh Oct 12, 2017
cb49836
merged master
yashasingh Oct 12, 2017
6e7a318
Merge branch 'complete' of https://github.com/yashasingh/Review into …
yashasingh Oct 12, 2017
7f5fbe8
minor fix
yashasingh Oct 12, 2017
81cd71a
Minor changes
yashasingh Nov 7, 2017
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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.pyc

Binary file removed App/__pycache__/__init__.cpython-34.pyc
Binary file not shown.
Binary file removed App/__pycache__/admin.cpython-34.pyc
Binary file not shown.
Binary file removed App/__pycache__/models.cpython-34.pyc
Binary file not shown.
Binary file removed App/__pycache__/urls.cpython-34.pyc
Binary file not shown.
Binary file removed App/__pycache__/views.cpython-34.pyc
Binary file not shown.
Binary file removed App/migrations/__pycache__/__init__.cpython-34.pyc
Binary file not shown.
43 changes: 43 additions & 0 deletions App/templates/App/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{% load static %}
<!DOCTYPE html>
<html>
<head>
<title>
Outreachy Tasks
</title>
<link type="text/css" rel="stylesheet" href="https://tools-static.wmflabs.org/cdnjs/ajax/libs/materialize/0.100.2/css/materialize.css" ></link>
<link href="https://tools-static.wmflabs.org/cdnjs/ajax/libs/font-awesome/4.7.0/css/font-awesome.css">
<link type="text/css" rel="stylesheet" href={% static "style.css" %} ></link>
</head>
<body>
<div class="row">
<h2 class="center"> Outreachy Microtasks </h2>
</div>
<div class="row">
<div class="col s12 m6">
<div class="card blue lighten-2">
<div class="card-content white-text">
<span class="card-title">User Contribution Summary</span>
<p>A simple tool that takes a username and lists the recent English Wikipedia edits of that user</p>
</div>
<div class="card-action">
<a class="pointer" href="https://github.com/yashasingh/Review/pull/1">Github</a>
<a class="pointer" href="{% url 'App:get_recent_english_edits' %}">Microtask1</a>
</div>
</div>
</div>
<div class="col s12 m6">
<div class="card blue lighten-2">
<div class="card-content white-text">
<span class="card-title">User Percentile</span>
<p>A simple tool that takes a username and tells what percentile the user is at by number of edits.</p>
</div>
<div class="card-action">
<a class="pointer" href="https://github.com/yashasingh/Review/pull/2">Github</a>
<a class="pointer" href="{% url 'App:get_the_user_percentile' %}">Microtask2</a>
</div>
</div>
</div>
</div>
</body>
</html>
80 changes: 80 additions & 0 deletions App/templates/App/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{% load static %}
<!DOCTYPE html>
<html>
<head>
<title>
Microtask 1
</title>
<link type="text/css" rel="stylesheet" href="https://tools-static.wmflabs.org/cdnjs/ajax/libs/materialize/0.100.2/css/materialize.css" ></link>
<link type="text/css" rel="stylesheet" href={% static "style.css" %} ></link>
</head>
<body>
<div class="row">
<nav>
<div class="nav-wrapper pd-left-20">
<a href="{% url 'App:get_recent_english_edits' %}" class="brand-logo">Microtask 1: Recent english edits</a>
<ul id="nav-mobile" class="right hide-on-med-and-down">
<li><a href="{% url 'App:get_the_user_percentile' %}">Microtask2</a></li>
<li><a href="{% url 'App:index' %}">Home</a></li>
</ul>
</div>
</nav>
</div>
<center><h4>Tool to display the recent English Wikipedia edits of that user</h4></center>
<div class="row">
<form class="col s12" method="post">
{% csrf_token %}
<div class="row">
<div class="input-field col s6 m6 offset-m3">
<input id="username" name="username" type="text">
<label for="username">Username</label>
</div>
</div>
<div class="row">
<div class="col s6 m6 offset-m3">
<button class="btn waves-effect waves-light blue-color" type="submit" name="action">Search
</button>
</div>
</div>
</form>
</div>
{% if error %}
<div class="row">
<div class="col s12 m6 offset-m3">
<div class="card blue lighten-2">
<div class="card-content white-text">
{{error}}
</div>
</div>
</div>
</div>
{% endif %}
<!-- loop -->
{% for x in contribution %}

<div class="row">
<div class="col s12 m6 offset-m3">
<div class="card blue lighten-2">
<div class="card-content white-text">
<span class="card-title"> User : {{x.user}}</span>
<ul>
<li>Title = {{x.title}} </li>
<li>PageID = {{x.pageid}} </li>
<li>RevisionID = {{x.revid}} </li>
<li>ParentID = {{x.parentid}} </li>
<li>ns = {{x.ns}}</li>
<li>Timestamp = {{x.timestamp}} </li>
<li>Size = {{x.size}} </li>
<li><a href="https://en.wikipedia.org/w/index.php?title=User:{{x.user}}&amp;diff=prev&amp;oldid={{x.revid}}">
Click here to view the edit.
</a> </li>
</ul>
</div>
</div>
</div>
</div>

{% endfor %}
</body>
</html>

9 changes: 9 additions & 0 deletions App/urls.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
from django.conf.urls import url

from . import views

app_name='App'
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^Microtask1/', views.get_recent_english_edits, name='get_recent_english_edits'),
url(r'^Microtask2/', views.get_the_user_percentile, name='get_the_user_percentile'),
]

66 changes: 66 additions & 0 deletions App/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import json
import requests
import urllib.parse

from django.http import HttpResponse
from django.shortcuts import render


def get_recent_english_edits(request):
"""
Display the recent english edits of the user.
"""

if request.method == 'POST':

# Here, we get the username
username = request.POST['username']
# if username is submitted blank
if not username:
return render(request, "App/index.html", {"error": "Please enter a username"})

# if username is not blank
params = {'action':'query',
'format':'json',
'list':'usercontribs',
'ucuser': username}


URL = "https://en.wikipedia.org/w/api.php?"

# Recieved data in json-format
response = requests.get(URL, params = params)

if response.status_code == 200:
lst = json.loads(response.text)
try:
# if username contains invalid value
if lst['error']:
return render(request,
'App/index.html',
{"error":lst['error']['info']}
)
except:
# Contribution data extracted
sub_lst = lst['query']['usercontribs']

# if user has no edits
if len(sub_lst) == 0:
return render(request,
'App/index.html',
{"error": "0 edits found for username {}".format(username)})

# Send contribution data for display
return render(request,
'App/index.html',
{"contribution": sub_lst, "username": username})
else:
return render(request,
'App/index.html',
{"error": 'Exit code {}'.format(str(response.status_code)),
}
)

if request.method == 'GET':
return render(request, 'App/index.html')

Binary file removed Project/__pycache__/__init__.cpython-34.pyc
Binary file not shown.
Binary file removed Project/__pycache__/settings.cpython-34.pyc
Binary file not shown.
Binary file removed Project/__pycache__/urls.cpython-34.pyc
Binary file not shown.
4 changes: 4 additions & 0 deletions Project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@
},
]

STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
]


# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/
Expand Down
1 change: 0 additions & 1 deletion app.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Project.settings")

app = get_wsgi_application()

35 changes: 35 additions & 0 deletions static/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.center {
text-align: center;
}
.pointer {
cursor: pointer;
}

.yellow {
color: yellow !important;
}

nav {
background-color: #64b5f6;
color: white;
}
input:active ~ label, input:valid ~ label {
top:-20px;
font-size:14px;
color:#5264AE;
}

.blue-color {
background-color: #64b5f6;
}

.pd-left-20 {
padding-left: 20px;
}
.btn:hover, .btn-large:hover {
background-color: #64b5f6;
}
.btn:focus, .btn-large:focus, .btn-floating:focus {
background-color: #64b5f6;

}