diff options
author | Akshen | 2017-07-26 14:23:08 +0530 |
---|---|---|
committer | Akshen | 2017-07-26 14:23:08 +0530 |
commit | e59227adeba86ddce5ac0d7e245a5f8dd088c2b2 (patch) | |
tree | e7d424834f5048e103b9d2b4b9156b6612e9c355 /workshop_app | |
parent | 91244eefb0fd0b7e30914cc5e06f890d58874d84 (diff) | |
download | workshop_booking-e59227adeba86ddce5ac0d7e245a5f8dd088c2b2.tar.gz workshop_booking-e59227adeba86ddce5ac0d7e245a5f8dd088c2b2.tar.bz2 workshop_booking-e59227adeba86ddce5ac0d7e245a5f8dd088c2b2.zip |
Updates Admin Interface
- Headers in Tables
- Download data in csv format from Table
Diffstat (limited to 'workshop_app')
-rw-r--r-- | workshop_app/admin.py | 202 | ||||
-rw-r--r-- | workshop_app/models.py | 9 |
2 files changed, 198 insertions, 13 deletions
diff --git a/workshop_app/admin.py b/workshop_app/admin.py index 1e2861b..11f7b6d 100644 --- a/workshop_app/admin.py +++ b/workshop_app/admin.py @@ -1,15 +1,199 @@ -from django.contrib import admin +import csv +from django.http import HttpResponse +from django.contrib import admin from .models import ( Profile, WorkshopType, Workshop, ProposeWorkshopDate, RequestedWorkshop, BookedWorkshop, - Testimonial) + Testimonial + ) +try: + from StringIO import StringIO as string_io +except ImportError: + from io import BytesIO as string_io + +#Custom Classes +class ProfileAdmin(admin.ModelAdmin): + list_display = ['user', 'institute','department','phone_number','position'] + list_filter = ['position', 'department'] + actions = ['download_csv'] + + def download_csv(self, request, queryset): + openfile = string_io() + response = HttpResponse(content_type='text/csv') + response['Content-Disposition'] = 'attachment;\ + filename=profile_data.csv' + + writer = csv.writer(response) + writer.writerow(['user', 'institute','department','phone_number', + 'position']) + + for q in queryset: + writer.writerow([q.user, q.institute, + q.department, q.phone_number, + q.position]) + + openfile.seek(0) + response.write(openfile.read()) + return response + + download_csv.short_description = "Download CSV file for selected stats." + + +class ProposeWorkshopDateAdmin(admin.ModelAdmin): + list_display = ['proposed_workshop_title', 'proposed_workshop_date', + 'proposed_workshop_coordinator', 'status', + 'proposed_workshop_instructor'] + list_filter = ['status'] + actions = ['download_csv'] + + def download_csv(self, request, queryset): + openfile = string_io() + response = HttpResponse(content_type='text/csv') + response['Content-Disposition'] = 'attachment;\ + filename=proposedworkshop_data.csv' + + writer = csv.writer(response) + writer.writerow(['proposed_workshop_title', 'proposed_workshop_date', + 'proposed_workshop_coordinator', 'status', + 'proposed_workshop_instructor']) + + for q in queryset: + writer.writerow([q.proposed_workshop_title, q.proposed_workshop_date, + q.proposed_workshop_coordinator, q.status, + q.proposed_workshop_instructor]) + + openfile.seek(0) + response.write(openfile.read()) + return response + + download_csv.short_description = "Download CSV file for selected stats." + + +class RequestedWorkshopAdmin(admin.ModelAdmin): + list_display = ['requested_workshop_title', + 'requested_workshop_date', + 'requested_workshop_coordinator', + 'requested_workshop_instructor', + 'status'] + + list_filter = ['status'] + actions = ['download_csv'] + + def download_csv(self, request, queryset): + openfile = string_io() + response = HttpResponse(content_type='text/csv') + response['Content-Disposition'] = 'attachment;\ + filename=requestedworkshop_data.csv' + + writer = csv.writer(response) + writer.writerow(['requested_workshop_title', + 'requested_workshop_date', + 'requested_workshop_coordinator', + 'requested_workshop_instructor', + 'status']) + + for q in queryset: + writer.writerow([q.requested_workshop_title, + q.requested_workshop_date, + q.requested_workshop_coordinator, + q.requested_workshop_instructor, + q.status]) + + openfile.seek(0) + response.write(openfile.read()) + return response + + download_csv.short_description = "Download CSV file for selected stats." + + +class WorkshopAdmin(admin.ModelAdmin): + list_display = ['workshop_title','workshop_instructor'] + list_filter = ['workshop_title'] + + +class WorkshopTypeAdmin(admin.ModelAdmin): + list_display = ['workshoptype_name', 'workshoptype_duration'] + list_filter = ['workshoptype_name'] + actions = ['download_csv'] + + def download_csv(self, request, queryset): + openfile = string_io() + response = HttpResponse(content_type='text/csv') + response['Content-Disposition'] = 'attachment;\ + filename=workshoptype_data.csv' + + writer = csv.writer(response) + writer.writerow(['workshoptype_name', 'workshoptype_duration']) + + for q in queryset: + writer.writerow([q.workshoptype_name, q.workshoptype_duration]) + + openfile.seek(0) + response.write(openfile.read()) + return response + + download_csv.short_description = "Download CSV file for selected stats." + + +class TestimonialAdmin(admin.ModelAdmin): + list_display = ['name', 'department', 'institute'] + list_filter = ['department'] + actions = ['download_csv'] + + def download_csv(self, request, queryset): + openfile = string_io() + response = HttpResponse(content_type='text/csv') + response['Content-Disposition'] = 'attachment;\ + filename=testimonials_data.csv' + + writer = csv.writer(response) + writer.writerow(['name', 'department', 'institute']) + + for q in queryset: + writer.writerow([q.name, + q.department, + q.institute + ]) + + openfile.seek(0) + response.write(openfile.read()) + return response + + download_csv.short_description = "Download CSV file for selected stats." + +class BookedWorkshopAdmin(admin.ModelAdmin): + list_display = ['booked_workshop_requested', + 'booked_workshop_proposed'] + actions = ['download_csv'] + + def download_csv(self, request, queryset): + openfile = string_io() + response = HttpResponse(content_type='text/csv') + response['Content-Disposition'] = 'attachment;\ + filename=bookedworkshops_data.csv' + + writer = csv.writer(response) + writer.writerow(['booked_workshop_requested', + 'booked_workshop_proposed']) + + for q in queryset: + writer.writerow([q.booked_workshop_requested, + q.booked_workshop_proposed + ]) + + openfile.seek(0) + response.write(openfile.read()) + return response + + download_csv.short_description = "Download CSV file for selected stats." + # Register your models here. -admin.site.register(Profile) -admin.site.register(WorkshopType) -admin.site.register(Workshop) -admin.site.register(ProposeWorkshopDate) -admin.site.register(RequestedWorkshop) -admin.site.register(BookedWorkshop) -admin.site.register(Testimonial) +admin.site.register(Profile, ProfileAdmin) +admin.site.register(WorkshopType, WorkshopTypeAdmin) +admin.site.register(Workshop, WorkshopAdmin) +admin.site.register(ProposeWorkshopDate, ProposeWorkshopDateAdmin) +admin.site.register(RequestedWorkshop, RequestedWorkshopAdmin) +admin.site.register(BookedWorkshop, BookedWorkshopAdmin) +admin.site.register(Testimonial, TestimonialAdmin) diff --git a/workshop_app/models.py b/workshop_app/models.py index 41a249e..b3ca1fc 100644 --- a/workshop_app/models.py +++ b/workshop_app/models.py @@ -129,10 +129,11 @@ class RequestedWorkshop(models.Model): ) def __str__(self): - return u"{0} | {1} | {2}".format( + return u"{0} | {1} | {2}| {3}".format( self.requested_workshop_date, self.requested_workshop_title, self.requested_workshop_coordinator, + self.status ) class ProposeWorkshopDate(models.Model): @@ -167,10 +168,11 @@ class ProposeWorkshopDate(models.Model): ) def __str__(self): - return u"{0} | {1} | {2}".format( + return u"{0} | {1} | {2}| {3}".format( self.proposed_workshop_date, self.proposed_workshop_title, self.proposed_workshop_coordinator, + self.status ) @@ -185,8 +187,7 @@ class BookedWorkshop(models.Model): def __str__(self): return u"{0} | {1} |".format( self.booked_workshop_requested, - self.booked_workshop_proposed, - + self.booked_workshop_proposed ) class Testimonial(models.Model): |