-
Notifications
You must be signed in to change notification settings - Fork 4.3k
feat: add django admin page for survey report #31323
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
Merged
felipemontoya
merged 9 commits into
openedx:master
from
eduNEXT:survey_report_admin_site
Nov 30, 2022
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bc35762
feat: add django admin page for survey report
Alec4r 73ef70e
fix: solve quality test errors
Alec4r 01bc560
feat: remove delete buttons and delete actions
Alec4r eaf2203
docs: add help_text to fields
Alec4r 10f2e94
Merge branch 'master' into survey_report_admin_site
Alec4r 34598f7
test: fix quality test issues
Alec4r 1a38de1
Merge branch 'master' into survey_report_admin_site
Alec4r 058e2b1
docs: remove model form and add help_text in model
Alec4r bcf3dd7
feat: add migration to apply field changes
Alec4r File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| """ | ||
| Django Admin page for SurveyReport. | ||
| """ | ||
|
|
||
|
|
||
| from django.contrib import admin | ||
| from .models import SurveyReport | ||
|
|
||
|
|
||
| class SurveyReportAdmin(admin.ModelAdmin): | ||
| """ | ||
| Admin to manage survey reports. | ||
| """ | ||
| readonly_fields = ( | ||
| 'courses_offered', 'learners', 'registered_learners', | ||
| 'enrollments', 'generated_certificates', 'extra_data', | ||
| 'created_at' | ||
| ) | ||
|
|
||
| list_display = ( | ||
| 'id', 'summary', 'created_at' | ||
| ) | ||
|
|
||
| def summary(self, obj) -> str: | ||
| """ | ||
| Show a summary of the survey report. | ||
| info: | ||
| - Courses: Total number of active unique courses. | ||
| - Learners: Recently active users with login in some weeks. | ||
| - Enrollments: Total number of active enrollments in the platform. | ||
| """ | ||
| return f"Total Courses: {obj.courses_offered}," \ | ||
| f"Total Learners: {obj.learners}, Total Enrollments: {obj.enrollments}" | ||
|
|
||
| def has_add_permission(self, request): | ||
| """ | ||
| Removes the "add" button from admin. | ||
| """ | ||
| return False | ||
|
|
||
| def has_delete_permission(self, request, obj=None): | ||
| """ | ||
| Removes the "delete" options from admin. | ||
| """ | ||
| return False | ||
|
|
||
| def changeform_view(self, request, object_id=None, form_url='', extra_context=None): | ||
| """ | ||
| Removes the "save" buttons from admin change view. | ||
| """ | ||
| extra_context = extra_context or {} | ||
|
|
||
| extra_context['show_save'] = False | ||
| extra_context['show_save_and_continue'] = False | ||
| extra_context['show_save_and_add_another'] = False | ||
|
Alec4r marked this conversation as resolved.
|
||
|
|
||
| return super().changeform_view(request, object_id, form_url, extra_context) | ||
|
|
||
| def get_actions(self, request): | ||
| """ | ||
| Removes the default bulk delete option provided by Django, | ||
| it doesn't do what we need for this model. | ||
| """ | ||
| actions = super().get_actions(request) | ||
| if 'delete_selected' in actions: | ||
| del actions['delete_selected'] | ||
| return actions | ||
|
|
||
| admin.site.register(SurveyReport, SurveyReportAdmin) | ||
44 changes: 44 additions & 0 deletions
44
openedx/features/survey_report/migrations/0002_auto_20221130_1533.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # Generated by Django 3.2.16 on 2022-11-30 15:33 | ||
|
|
||
| from django.db import migrations, models | ||
| import jsonfield.fields | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('survey_report', '0001_initial'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AlterField( | ||
| model_name='surveyreport', | ||
| name='courses_offered', | ||
| field=models.BigIntegerField(help_text='Total number of active unique courses.'), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='surveyreport', | ||
| name='enrollments', | ||
| field=models.BigIntegerField(help_text='Total number of active enrollments in the platform.'), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='surveyreport', | ||
| name='extra_data', | ||
| field=jsonfield.fields.JSONField(blank=True, default=dict, help_text='Extra information that will be saved in the report, E.g: site_name, openedx-release.'), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='surveyreport', | ||
| name='generated_certificates', | ||
| field=models.BigIntegerField(help_text='Total number of generated certificates.'), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='surveyreport', | ||
| name='learners', | ||
| field=models.BigIntegerField(help_text='Total number of recently active users with login in some weeks.'), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='surveyreport', | ||
| name='registered_learners', | ||
| field=models.BigIntegerField(help_text='Total number of users ever registered in the platform.'), | ||
| ), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.