31
31
from ..extensions import db , csrf
32
32
from ..user .models import User , RootioUser
33
33
from ..utils import error_dict , fk_lookup_form_data , format_log_line , events_action_display_map
34
+ from rootio .user import ADMIN
34
35
35
36
radio = Blueprint ('radio' , __name__ , url_prefix = '/radio' )
36
37
39
40
@login_required
40
41
def index ():
41
42
# get all the user's networks and their stations
42
- networks = Network .query .outerjoin (Station ).join (User , Network .networkusers ).filter (User .id == current_user .id ).all ()
43
+ if current_user .role_code == ADMIN :
44
+ networks = Network .query .outerjoin (Station ).join (User , Network .networkusers ).all ()
45
+ else :
46
+ networks = Network .query .outerjoin (Station ).join (User , Network .networkusers ).filter (User .id == current_user .id ).all ()
43
47
return render_template ('radio/index.html' , networks = networks , userid = current_user .id , now = datetime .now )
44
48
45
49
@@ -83,7 +87,7 @@ def network_add():
83
87
@radio .route ('/station/' , methods = ['GET' ])
84
88
@login_required
85
89
def list_stations ():
86
- stations = Station .query . join ( Network ). join ( User , Network . networkusers ). filter ( User . id == current_user . id ). all ( )
90
+ stations = Station .get_stations ( current_user )
87
91
# stations = Station.query.join(Network).join(User).filter(User.id == current_user.id).all()
88
92
return render_template ('radio/stations.html' , stations = stations , active = 'stations' )
89
93
@@ -134,7 +138,10 @@ def station_add():
134
138
@radio .route ('/program/' , methods = ['GET' ])
135
139
@login_required
136
140
def programs ():
137
- programs = Program .query .join (Program , Network .programs ).join (User , Network .networkusers ).filter (
141
+ if current_user .role_code == ADMIN :
142
+ programs = Program .query .join (Program , Network .programs ).join (User , Network .networkusers ).filter (Program .program_type_id != 2 ).all ()
143
+ else :
144
+ programs = Program .query .join (Program , Network .programs ).join (User , Network .networkusers ).filter (
138
145
User .id == current_user .id ).filter (Program .program_type_id != 2 ).all ()
139
146
return render_template ('radio/programs.html' , programs = programs , active = 'programs' )
140
147
@@ -146,12 +153,22 @@ def program_definition(program_id):
146
153
# form = ProgramForm(obj=program, program_structure="test", next=request.args.get('next'))
147
154
148
155
# hosts in my network
149
- hosts = Person .query .join (Person , Network .people ).join (User , Network .networkusers ).filter (
156
+ if current_user .role_code == ADMIN :
157
+ hosts = Person .query .join (Person , Network .people ).join (User , Network .networkusers ).all ()
158
+ else :
159
+ hosts = Person .query .join (Person , Network .people ).join (User , Network .networkusers ).filter (
150
160
User .id == current_user .id ).all ()
151
161
news = ContentTrack .query .join (ContentType ).filter (ContentType .name == "News" ).all ()
152
162
ads = ContentTrack .query .join (ContentType ).filter (ContentType .name == "Advertisements" ).all ()
153
163
154
- medias = ContentTrack .query .join (User , Network .networkusers )\
164
+ if current_user .role_code == ADMIN :
165
+ medias = ContentTrack .query .join (User , Network .networkusers )\
166
+ .join (ContentTrack , ContentType )\
167
+ .filter (ContentType .name == "Media" )\
168
+ .filter (ContentTrack .deleted != True )\
169
+ .all ()
170
+ else :
171
+ medias = ContentTrack .query .join (User , Network .networkusers )\
155
172
.filter (User .id == current_user .id )\
156
173
.join (ContentTrack , ContentType )\
157
174
.filter (ContentType .name == "Media" )\
@@ -197,34 +214,59 @@ def program_add():
197
214
form = ProgramForm (request .form )
198
215
program = None
199
216
200
- # hosts in my network
201
- hosts = Person .query .join (Person , Network .people ).join (User , Network .networkusers )\
202
- .filter (User .id == current_user .id )\
203
- .all ()
204
- news = ContentTrack .query .join (User , Network .networkusers )\
205
- .filter (User .id == current_user .id )\
206
- .join (ContentTrack , ContentType )\
207
- .filter (ContentType .name == "News" )\
208
- .filter (ContentTrack .deleted != True )\
209
- .all ()
210
- ads = ContentTrack .query .join (User , Network .networkusers )\
211
- .filter (User .id == current_user .id )\
212
- .join (ContentTrack , ContentType )\
213
- .filter (ContentType .name == "Advertisements" )\
214
- .filter (ContentTrack .deleted != True )\
215
- .all ()
216
-
217
- medias = ContentTrack .query .join (User , Network .networkusers )\
218
- .filter (User .id == current_user .id )\
219
- .join (ContentTrack , ContentType )\
220
- .filter (ContentType .name == "Media" )\
221
- .filter (ContentTrack .deleted != True )\
222
- .all ()
223
-
224
-
225
- podcasts = ContentPodcast .query .join (User , Network .networkusers )\
226
- .filter (User .id == current_user .id )\
227
- .all ()
217
+ if current_user .role_code == ADMIN :
218
+ # hosts in my network
219
+ hosts = Person .query .join (Person , Network .people ).join (User , Network .networkusers )\
220
+ .all ()
221
+ news = ContentTrack .query .join (User , Network .networkusers )\
222
+ .join (ContentTrack , ContentType )\
223
+ .filter (ContentType .name == "News" )\
224
+ .filter (ContentTrack .deleted != True )\
225
+ .all ()
226
+ ads = ContentTrack .query .join (User , Network .networkusers )\
227
+ .join (ContentTrack , ContentType )\
228
+ .filter (ContentType .name == "Advertisements" )\
229
+ .filter (ContentTrack .deleted != True )\
230
+ .all ()
231
+
232
+ medias = ContentTrack .query .join (User , Network .networkusers )\
233
+ .join (ContentTrack , ContentType )\
234
+ .filter (ContentType .name == "Media" )\
235
+ .filter (ContentTrack .deleted != True )\
236
+ .all ()
237
+
238
+
239
+ podcasts = ContentPodcast .query .join (User , Network .networkusers )\
240
+ .all ()
241
+ else :
242
+ # hosts in my network
243
+ hosts = Person .query .join (Person , Network .people ).join (User , Network .networkusers )\
244
+ .filter (User .id == current_user .id )\
245
+ .all ()
246
+ news = ContentTrack .query .join (User , Network .networkusers )\
247
+ .filter (User .id == current_user .id )\
248
+ .join (ContentTrack , ContentType )\
249
+ .filter (ContentType .name == "News" )\
250
+ .filter (ContentTrack .deleted != True )\
251
+ .all ()
252
+ ads = ContentTrack .query .join (User , Network .networkusers )\
253
+ .filter (User .id == current_user .id )\
254
+ .join (ContentTrack , ContentType )\
255
+ .filter (ContentType .name == "Advertisements" )\
256
+ .filter (ContentTrack .deleted != True )\
257
+ .all ()
258
+
259
+ medias = ContentTrack .query .join (User , Network .networkusers )\
260
+ .filter (User .id == current_user .id )\
261
+ .join (ContentTrack , ContentType )\
262
+ .filter (ContentType .name == "Media" )\
263
+ .filter (ContentTrack .deleted != True )\
264
+ .all ()
265
+
266
+
267
+ podcasts = ContentPodcast .query .join (User , Network .networkusers )\
268
+ .filter (User .id == current_user .id )\
269
+ .all ()
228
270
community_contents = {"data" : [{"type" : "Ads" , "category_id" : "1" }, {"type" : "Announcements" , "category_id" : "2" },
229
271
{"type" : "Greetings" , "category_id" : "3" }]}
230
272
@@ -265,7 +307,10 @@ def program_delete(program_id):
265
307
@radio .route ('/music_program/' , methods = ['GET' ])
266
308
@login_required
267
309
def list_music_programs ():
268
- music_programs = Program .query .join (Program , Network .programs ).join (User , Network .networkusers ).filter (
310
+ if current_user .role_code == ADMIN :
311
+ music_programs = Program .query .join (Program , Network .programs ).join (User , Network .networkusers ).filter (Program .program_type_id == 2 ).all ()
312
+ else :
313
+ music_programs = Program .query .join (Program , Network .programs ).join (User , Network .networkusers ).filter (
269
314
User .id == current_user .id ).filter (Program .program_type_id == 2 ).all ()
270
315
return render_template ('radio/music_programs.html' , music_programs = music_programs , active = 'programs' )
271
316
@@ -276,11 +321,15 @@ def music_program_add():
276
321
form = ProgramForm (request .form )
277
322
program = None
278
323
279
- # Playlists and streams in my network
280
- playlists = ContentMusicPlaylist .query .join (Station ).join (Network ).join (User , Network .networkusers ).filter (
281
- User .id == current_user .id ).filter (ContentMusicPlaylist .deleted != True ).all () # Playlist->Station->Network->user
282
- streams = ContentStream .query .join (User , Network .networkusers ).filter (
283
- User .id == current_user .id ).all () # created by -> user -> Network
324
+ if current_user .role_code == ADMIN :
325
+ playlists = ContentMusicPlaylist .query .join (Station ).join (Network ).join (User , Network .networkusers ).filter (ContentMusicPlaylist .deleted != True ).all () # Playlist->Station->Network->user
326
+ streams = ContentStream .query .join (User , Network .networkusers ).filter (
327
+ User .id == current_user .id ).all () # created by -> user -> Network
328
+ else :
329
+ # Playlists and streams in my network
330
+ playlists = ContentMusicPlaylist .query .join (Station ).join (Network ).join (User , Network .networkusers ).filter (ContentMusicPlaylist .deleted != True ).all () # Playlist->Station->Network->user
331
+ streams = ContentStream .query .join (User , Network .networkusers ).filter (
332
+ User .id == current_user .id ).all () # created by -> user -> Network
284
333
285
334
if form .validate_on_submit ():
286
335
cleaned_data = form .data # make a copy
@@ -303,9 +352,13 @@ def music_program_add():
303
352
def music_program_definition (music_program_id ):
304
353
music_program = Program .query .filter_by (id = music_program_id ).first_or_404 ()
305
354
306
- # TODO: Filter these by network
307
- playlists = ContentMusicPlaylist .query .join (Station ).join (Network ).join (User , Network .networkusers ).filter (User .id == current_user .id ).all () #Playlist->Station->Network->user
308
- streams = ContentStream .query .join (User , Network .networkusers ).filter (User .id == current_user .id ).all () # created by -> user -> Network
355
+ if current_user .role_code == ADMIN :
356
+ playlists = ContentMusicPlaylist .query .join (Station ).join (Network ).join (User , Network .networkusers ).all () #Playlist->Station->Network->user
357
+ streams = ContentStream .query .join (User , Network .networkusers ).all () # created by -> user -> Network
358
+ else :
359
+ # TODO: Filter these by network
360
+ playlists = ContentMusicPlaylist .query .join (Station ).join (Network ).join (User , Network .networkusers ).filter (User .id == current_user .id ).all () #Playlist->Station->Network->user
361
+ streams = ContentStream .query .join (User , Network .networkusers ).filter (User .id == current_user .id ).all () # created by -> user -> Network
309
362
310
363
# render the program structure
311
364
action_names = []
@@ -692,7 +745,7 @@ def station_logs(station_id):
692
745
@login_required
693
746
def schedule ():
694
747
# TODO, if user is authorized to view only one station, redirect them there
695
- stations = Station .query . join ( Network ). join ( User , Network . networkusers ). filter ( User . id == current_user . id ). all ( )
748
+ stations = Station .get_stations ( current_user )
696
749
# stations = Station.query.order_by('name').all()
697
750
698
751
return render_template ('radio/schedules.html' ,
@@ -717,7 +770,10 @@ def schedule_station(station_id):
717
770
718
771
form = ScheduleProgramForm ()
719
772
720
- all_programs = Program .query .join (Program , Network .programs ).join (User , Network .networkusers ).filter (
773
+ if current_user .role_code == ADMIN :
774
+ all_programs = Program .query .join (Program , Network .programs ).join (User , Network .networkusers ).all ()
775
+ else :
776
+ all_programs = Program .query .join (Program , Network .programs ).join (User , Network .networkusers ).filter (
721
777
User .id == current_user .id ).all ()
722
778
# TODO: filter by language?
723
779
0 commit comments