Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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: 5 additions & 0 deletions blt/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,11 @@
name="update_bch_address",
),
re_path(r"^contributor-stats/$", ContributorStatsView.as_view(), name="contributor-stats"),
re_path(
r"^contributor-stats/today$",
ContributorStatsView.as_view(today=True),
name="today-contributor-stats",
),
]

if settings.DEBUG:
Expand Down
2 changes: 1 addition & 1 deletion contributors.json
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@
"img":"https://avatars.githubusercontent.com/u/97744811?v=4",
"name":"Altafur Rahman",
"repository":"BLT | BLT-Flutter",
"short_description":"always want do something for the world☺",
"short_description":"always want to do something for the world☺",
"long_description":"Hi there, I'm Altafur Rahman Jisan! With a knack for Python and a dash of JavaScript, I turn code into comfort, crafting web experiences that feel like home. 🏡✨",
"location":"Chittagong, Bangladesh",
"twitter":"https://twitter.com/JisanAR03",
Expand Down
137 changes: 85 additions & 52 deletions website/templates/contributor_stats.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,60 +6,93 @@
{% endblock style %}
{% block content %}
{% include "includes/sidenav.html" %}
<div class="overflow-x-auto relative shadow-md sm:rounded-lg py-8 px-10 bg-white dark:bg-gray-800 my-20 mx-8">
<table class="w-full text-sm text-left text-gray-500 dark:text-gray-400 main_table"
id="userStatsTable">
<thead class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400 p-5 rounded border-b border-gray-200 dark:border-gray-700">
<tr>
<th scope="col" class="py-3 px-6">Username</th>
<th scope="col" class="py-3 px-6">Commits</th>
<th scope="col" class="py-3 px-6">Issues Opened</th>
<th scope="col" class="py-3 px-6">Issues Closed</th>
<th scope="col" class="py-3 px-6">Assigned Issues</th>
<th scope="col" class="py-3 px-6">Pull Requests</th>
<th scope="col" class="py-3 px-6">Comments</th>
</tr>
</thead>
<tbody>
{% for user, stats in user_stats.items %}
<tr class="bg-white border-b dark:bg-gray-800 dark:border-gray-700 hover:bg-gray-50 dark:hover:bg-gray-600">
<th scope="row"
class="py-4 px-6 font-semibold text-gray-900 whitespace-nowrap dark:text-white">
{{ user }}
</th>
<td class="py-4 px-6 font-medium text-gray-900 whitespace-nowrap dark:text-white">
<a href="https://github.com/{{ owner }}/{{ repo }}/commits?author={{ user }}&since={{ start_date }}&until={{ end_date }}"
target="_blank">{{ stats.commits }}</a>
</td>
<td class="py-4 px-6">
<a href="https://github.com/{{ owner }}/{{ repo }}/issues?q=is%3Aissue+is%3Aopen+author%3A{{ user }}+updated%3A>{{ start_date }}"
target="_blank">{{ stats.issues_opened }}</a>
</td>
<td class="py-4 px-6">
<a href="https://github.com/{{ owner }}/{{ repo }}/issues?q=is%3Aissue+is%3Aclosed+author%3A{{ user }}+updated%3A>{{ start_date }}"
target="_blank">{{ stats.issues_closed }}</a>
</td>
<td class="py-4 px-6">
<a href="https://github.com/{{ owner }}/{{ repo }}/issues?q=is%3Aissue+updated%3A%3E{{ start_date }}+assignee%3A{{ user }}"
target="_blank">{{ stats.assigned_issues }}</a>
</td>
<td class="py-4 px-6">
<a href="https://github.com/{{ owner }}/{{ repo }}/pulls?q=is%3Apr+author%3A{{ user }}+created%3A>{{ start_date }}"
target="_blank">{{ stats.prs }}</a>
</td>
<td class="py-4 px-6">
<a href="https://github.com/search?q=is%3Aissue+commenter%3A{{ user }}+repo%3A{{ owner }}%2F{{ repo }}+updated%3A%3E{{ start_date }}&type=issues&ref=advsearch"
target="_blank">{{ stats.comments }}</a>
</td>
{% if today %}
<!-- make same table just have username and Pull Requests -->
<div class="overflow-x-auto relative shadow-md sm:rounded-lg py-8 px-10 bg-white dark:bg-gray-800 my-20 mx-8">
<table class="w-full text-sm text-left text-gray-500 dark:text-gray-400 main_table"
id="userStatsTable">
<thead class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400 p-5 rounded border-b border-gray-200 dark:border-gray-700">
<tr>
<th scope="col" class="py-3 px-6">Username</th>
<th scope="col" class="py-3 px-6">Pull Requests</th>
</tr>
{% empty %}
<tr class="bg-white dark:bg-gray-800">
<td colspan="7" class="py-4 px-6 text-center">No activity found.</td>
</thead>
<tbody>
{% for username, prs in user_stats %}
<tr class="bg-white border-b dark:bg-gray-800 dark:border-gray-700 hover:bg-gray-50 dark:hover:bg-gray-600">
<th scope="row"
class="py-4 px-6 font-semibold text-gray-900 whitespace-nowrap dark:text-white">
{{ username }}
</th>
<td class="py-4 px-6">
<a href="https://github.com/{{ owner }}/{{ repo }}/pulls?q=is%3Apr+author%3A{{ username }}+created%3A{{ end_date }}"
target="_blank">{{ prs }}</a>
</td>
</tr>
{% empty %}
<tr class="bg-white dark:bg-gray-800">
<td colspan="2" class="py-4 px-6 text-center">No activity found.</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<div class="overflow-x-auto relative shadow-md sm:rounded-lg py-8 px-10 bg-white dark:bg-gray-800 my-20 mx-8">
<table class="w-full text-sm text-left text-gray-500 dark:text-gray-400 main_table"
id="userStatsTable">
<thead class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400 p-5 rounded border-b border-gray-200 dark:border-gray-700">
<tr>
<th scope="col" class="py-3 px-6">Username</th>
<th scope="col" class="py-3 px-6">Commits</th>
<th scope="col" class="py-3 px-6">Issues Opened</th>
<th scope="col" class="py-3 px-6">Issues Closed</th>
<th scope="col" class="py-3 px-6">Assigned Issues</th>
<th scope="col" class="py-3 px-6">Pull Requests</th>
<th scope="col" class="py-3 px-6">Comments</th>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</thead>
<tbody>
{% for user, stats in user_stats.items %}
<tr class="bg-white border-b dark:bg-gray-800 dark:border-gray-700 hover:bg-gray-50 dark:hover:bg-gray-600">
<th scope="row"
class="py-4 px-6 font-semibold text-gray-900 whitespace-nowrap dark:text-white">
{{ user }}
</th>
<td class="py-4 px-6 font-medium text-gray-900 whitespace-nowrap dark:text-white">
<a href="https://github.com/{{ owner }}/{{ repo }}/commits?author={{ user }}&since={{ start_date }}&until={{ end_date }}"
target="_blank">{{ stats.commits }}</a>
</td>
<td class="py-4 px-6">
<a href="https://github.com/{{ owner }}/{{ repo }}/issues?q=is%3Aissue+is%3Aopen+author%3A{{ user }}+updated%3A>{{ start_date }}"
target="_blank">{{ stats.issues_opened }}</a>
</td>
<td class="py-4 px-6">
<a href="https://github.com/{{ owner }}/{{ repo }}/issues?q=is%3Aissue+is%3Aclosed+author%3A{{ user }}+updated%3A>{{ start_date }}"
target="_blank">{{ stats.issues_closed }}</a>
</td>
<td class="py-4 px-6">
<a href="https://github.com/{{ owner }}/{{ repo }}/issues?q=is%3Aissue+updated%3A%3E{{ start_date }}+assignee%3A{{ user }}"
target="_blank">{{ stats.assigned_issues }}</a>
</td>
<td class="py-4 px-6">
<a href="https://github.com/{{ owner }}/{{ repo }}/pulls?q=is%3Apr+author%3A{{ user }}+created%3A>{{ start_date }}"
target="_blank">{{ stats.prs }}</a>
</td>
<td class="py-4 px-6">
<a href="https://github.com/search?q=is%3Aissue+commenter%3A{{ user }}+repo%3A{{ owner }}%2F{{ repo }}+updated%3A%3E{{ start_date }}&type=issues&ref=advsearch"
target="_blank">{{ stats.comments }}</a>
</td>
</tr>
{% empty %}
<tr class="bg-white dark:bg-gray-800">
<td colspan="7" class="py-4 px-6 text-center">No activity found.</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endif %}
{% endblock content %}
{% block scripts %}
<script src="https://code.jquery.com/jquery-3.7.1.min.js"
Expand Down
7 changes: 7 additions & 0 deletions website/templates/includes/sidenav.html
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@
</div>
<a href="{% url 'contributor-stats' %}" class="text"><span>Weekly Activity</span></a>
</li>
<!-- daily activity -->
<li class="flex items-center p-2">
<div class="w-8 mr-4">
<i class="fa fa-calendar-day" id="icon"></i>
</div>
<a href="{% url 'today-contributor-stats' %}" class="text"><span>Daily Activity</span></a>
</li>
<li class="flex items-center p-2">
<div class="w-8 mr-4">
<i class="fa fa-info" id="icon"></i>
Expand Down
34 changes: 21 additions & 13 deletions website/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4028,27 +4028,35 @@ def sitemap(request):

class ContributorStatsView(TemplateView):
template_name = "contributor_stats.html"
today = False

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

# Fetch all contributor stats records
stats = ContributorStats.objects.all()

# Convert the stats to a dictionary format expected by the template
user_stats = {
stat.username: {
"commits": stat.commits,
"issues_opened": stat.issues_opened,
"issues_closed": stat.issues_closed,
"assigned_issues": stat.assigned_issues,
"prs": stat.prs,
"comments": stat.comments,
if self.today:
# For "today" stats
user_stats = sorted(
([stat.username, stat.prs] for stat in stats if stat.prs > 0),
key=lambda x: x[1], # Sort by PRs value
reverse=True, # Descending order
)
else:
# Convert the stats to a dictionary format expected by the template
user_stats = {
stat.username: {
"commits": stat.commits,
"issues_opened": stat.issues_opened,
"issues_closed": stat.issues_closed,
"assigned_issues": stat.assigned_issues,
"prs": stat.prs,
"comments": stat.comments,
}
for stat in stats
}
for stat in stats
}

context["user_stats"] = user_stats
context["today"] = self.today
context["owner"] = "OWASP-BLT"
context["repo"] = "BLT"
context["start_date"] = (datetime.now().date() - timedelta(days=7)).isoformat()
Expand Down