def unpublish_highlight(): #get user's role user_role = get_user_role() if user_role in video_permission_list: hl_id = request.json['hl_id'] if hl_id: old_obj = db.HighlightItem.get_by_id(hl_id) #used for logging #change publish to 0 result = db.HighlightItem.unpublish_highlight(hl_id) if not result: return jsonify( result=int(0), _id=hl_id, msg= "unpublish %s fail due to some error with executing db query" % hl_id) new_obj = db.HighlightItem.get_by_id(hl_id) #used for logging #logging log_activity(old_obj, new_obj, 'highlight', 'update', 'update highlight', 'unpublish highlight') return jsonify(result=int(1), _id=hl_id, msg="%s highlight is unpublished" % hl_id) return jsonify(result=int(0), _id=hl_id, msg="no highlight id") return 'permission denied', 403
def delete(): #get user's role user_role = get_user_role() if user_role in video_permission_list: highlight_id = request.json['highlight_id'] if not highlight_id: return 'no highlight_id' old_obj = db.HighlightItem.get_by_id(highlight_id) #use for logging #check priority video structure when delete for p in old_obj.priority: #decrease structure priority ralation db.HighlightItem.change_value_structure_in_priority( p, old_obj.priority[p], -1) #delete video object by id db.HighlightItem.remove_by_id(highlight_id) #logging log_activity(old_obj, old_obj, 'highlight', 'delete', 'delete highlight', 'delete highlight') return "Done" return 'permission denied', 403
def new(structure_id=None): #get user's role user_role = get_user_role() if user_role in video_permission_list: hl_obj = db.HighlightItem() hl_obj['_id'] = ObjectId() #set default for platforms and geoip attribute platforms = db.Platform.get_all() p_default = [] p_choices = [] for p in platforms: p_default.append(p.type) p_choices.append((p.type, p.type)) hl_obj.type = 'vod' #set default to vod hl_obj.platform = p_default hl_obj.GEOIP_COUNTRY_CODE_availability = ['VN', 'REST_OF_THE_WORLD'] #set default image_type hl_obj.image_type = 'standing_image' if structure_id=='55c42f6417dc1344d5012f5a' else 'small_image' hl_obj.publish = int(1) form = HighlightItemForm(request.form, obj=hl_obj) #init highlight form if request.method == 'POST': form.populate_obj(hl_obj) #Populates the attributes of the passed obj with data from the form’s fields #------------------manually validating fields------------------------ if len(hl_obj.structure_id) == 0: flash("You must select atleast 1 structure for this highlight!", "fail") return redirect(url_for("highlight_views.index")) #check available platform and GEOIP_COUNTRY_CODE_availability base on its parent structure check_platform_n_publish_country(hl_obj) #check priority highlight structure when save check_structure_and_priority_video(hl_obj) #-------------------------------------------------------------------- #check if the type is livetv, the highlight should auto turn off after the endtime of event. Call iapi to do the appointment check_set_appointment_tv_event(hl_obj) hl_obj.save() #logging log_activity(hl_obj, hl_obj, 'highlight', 'add', 'add highlight', 'add a highlight') flash("Highlight has been added!", "success") return redirect(url_for("highlight_views.index", structure_id=hl_obj.structure_id[0])) #get choices for structure select box set_structure_id_choice(form, [structure_id]) #get choices for platform select box form.platform.choices = p_choices return render_template('highlight/highlight_newedit.html',form=form, hl_obj=hl_obj, user_role=user_role, current_app=current_app) return 'permission denied', 403
def edit(highlight_id=None): #get user's role user_role = get_user_role() if user_role in video_permission_list: if not highlight_id: return redirect(url_for("highlight_views.index")) hl_obj = db.HighlightItem.get_by_id(highlight_id) old_obj = db.HighlightItem.get_by_id(highlight_id) #use for logging form = HighlightItemForm(request.form, obj=hl_obj) #init highlight form if request.method == 'POST': form.populate_obj(hl_obj) #Populates the attributes of the passed obj with data from the form’s fields #------------------manually validating fields------------------------ if len(hl_obj.structure_id) == 0: flash("You must select atleast 1 structure for this highlight!", "fail") return redirect(url_for("highlight_views.index")) #check available platform and GEOIP_COUNTRY_CODE_availability base on its parent structure check_platform_n_publish_country(hl_obj) #check priority highlight structure when save check_structure_and_priority_video(hl_obj) #-------------------------------------------------------------------- #check if the type is livetv, the highlight should auto turn off after the endtime of event. Call iapi to do the appointment if hl_obj.livetv_content.end_time!=old_obj.livetv_content.end_time or old_obj.type!='livetv': #revoke old task cancel_appointment_highlight_off_task(old_obj) #set new task check_set_appointment_tv_event(hl_obj) hl_obj.save() #logging log_activity(old_obj, hl_obj, 'highlight', 'update', 'update highlight', 'update a highlight') flash("Highlight has been edited!", "success") return redirect(url_for("highlight_views.index", structure_id=hl_obj.structure_id[0])) #get choices for structure select box set_structure_id_choice(form, hl_obj.structure_id) #get choices for platforms field platforms = db.Platform.get_all() form.platform.choices = [(p.type, p.type) for p in platforms] return render_template('highlight/highlight_newedit.html',form=form, hl_obj=hl_obj, highlight_id=highlight_id,\ user_role=user_role, current_app=current_app) return 'permission denied', 403
def upload_vod_img(): today = datetime.now().strftime("%d_%m_%Y") vid_savepath = os.path.join(app.config['UPLOAD_VIDEO_THUMBNAIL'], today) file1 = request.files['imgFile2'] if not os.path.exists(vid_savepath): os.mkdir(vid_savepath) #slugify filename now_time = datetime.now().strftime("%d-%m-%Y_%Hg%M-%S") safe_filename = slugify_filename(file1.filename, 'yes', 'yes') savepath = vid_savepath + '/' + safe_filename file1.save(savepath) status = 'DONE' img_link = today + '/' + safe_filename #logging log_activity(None, None, 'image', 'upload', 'upload image', 'upload highlight image %s' % savepath) #validate image dimension #im=Image.open(savepath) #if im.size!=(356,200): # status = 'fail' return jsonify(result=status, img_link=img_link)
def upload_event_img(): today = datetime.now().strftime("%d_%m_%Y") savepath = os.path.join(app.config['UPLOAD_EVENT_IMAGE_FOLDER'], today) file = request.files['imgFile'] if not os.path.exists(savepath): os.mkdir(savepath) #slugify filename safe_filename = slugify_filename(file.filename, 'yes', 'yes') savepath = savepath + '/' + safe_filename file.save(savepath) status = 'DONE' img_link = today + '/' + safe_filename #validate image dimension #im=Image.open(savepath) #if im.size!=(356,200): # status = 'fail' #logging log_activity(None, None, 'image', 'upload', 'upload image', 'upload highlight image %s' % savepath) return jsonify(result=status, img_link=img_link)
def reset_index(): #get user's role user_role = get_user_role() if user_role in video_permission_list: structure_id = request.json['structure_id'] if not structure_id: return jsonify(result=int(0), msg="No structure_id.") struc_obj = db.Structure.get_by_id(structure_id) if not struc_obj: return jsonify(result=int(0), msg="Found no structure with inputted id: %s" % structure_id) if struc_obj['children']: return jsonify( result=int(0), msg="Structure %s still got children structures, cannot reset." % struc_obj['name']) #the order will be vod on, tv, vod off with the sorting of startime for tv and old index for vod #so we will create 3 different array to satisfy above order vod_on_list = db.HighlightItem.get_all_by_type_struc_publish_and_sort( type='vod', structure_id=structure_id, publish=1, field_sort='priority.%s' % structure_id, sort_way=1) vod_off_list = db.HighlightItem.get_all_by_type_struc_publish_and_sort( type='vod', structure_id=structure_id, publish=0, field_sort='priority.%s' % structure_id, sort_way=1) tv_list = db.HighlightItem.get_all_by_type_struc_publish_and_sort( type='livetv', structure_id=structure_id, publish=None, field_sort='livetv_content.start_time', sort_way=1) #break tvlist into 2, 1 is not happening, one is the past now = datetime.now() tv1_list = [] tv2_list = [] for h in tv_list: if h['livetv_content']['end_time'] >= now: tv1_list.append(h) else: tv2_list.append(h) new_order = [h1 for h1 in vod_on_list] + [h2 for h2 in tv1_list] + [ h25 for h25 in tv2_list ] + [h3 for h3 in vod_off_list] index = int(1) for h in new_order: print 'hl_id:', str(h['_id']) print 'index:', index #set priority result = db.HighlightItem.hard_set_priority( structure_id, str(h['_id']), index) if not result: return jsonify(result=int(0), msg="Update highlight_id: %s to index %s fail" % (h['_id'], index)) index += int(1) #logging log_activity(None, None, 'highlight', 'reset index', 'reset highlight index', 'reset highlight index') return jsonify(result=int(1), msg="Highlight index reset success.") return jsonify(result=int(0), msg="no structure_id or highlight id or new_priority") return 'permission denied', 403