summaryrefslogtreecommitdiff
path: root/workshop_app/admin.py
blob: 3eec8af4aba7629aeb518f7c18ecfcbef9e1f003 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import csv
from django.http import HttpResponse
from django.contrib import admin
from .models import (
				Profile, WorkshopType,
				Workshop, ProposeWorkshopDate,
				RequestedWorkshop, BookedWorkshop,
				Testimonial, ProfileComments, Banner
				)
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 = ['title','user', 'institute','location','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(['email_id', 'title','username', 'first_name', 'last_name', 
						'institute', 'location', 'department',
						'phone_number', 'position'])

		for q in queryset:
			writer.writerow([q.user.email, q.title, q.user, q.user.first_name,
							q.user.last_name, q.institute,
							q.location, 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."



class ProfileCommentAdmin(admin.ModelAdmin):
	list_display = ['comment', 'created_date', 'coordinator_profile', 'instructor_profile']


# Register your models here.
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)
admin.site.register(ProfileComments, ProfileCommentAdmin)
admin.site.register(Banner)