def route_setup(): if g.auth['admin']: settings = Settings() ua = UserActivity() activity_log = ua.list_all_activity() context = { 'log': activity_log, 'auth': g.auth } return render_template('log.html', context=context) else: return redirect('/')
def route_selected_parcel(parcel_id): def float2datetime(epoc): import datetime result = '' dt = datetime.datetime.fromtimestamp(epoc) result = dt.strftime('%m/%d/%Y %H:%M:%S') return result def b2k(num): result = '0k' n = int(num) k = round(n / 1024, 2) result = str(k) + 'k' return result if not g.auth['user']: login_page = Settings().get('host-url') + '/auth/login' return redirect(login_page) file_list = FileList(parcel=parcel_id) for f in file_list.files: fpath = bytes(f['fullpath'], 'utf-8') f['encoded'] = '' f['encoded'] = base64.standard_b64encode(fpath).decode('utf-8') f['mtime'] = float2datetime(f['info'].st_mtime) f['filesize'] = b2k(f['info'].st_size) p = Parcels() p.load_one_parcel(parcel_id) details = p.parcel ua = UserActivity() activity = ua.list(parcel=p.parcel['parcel_id']) context = { 'title': 'parcel selected', 'showsearch': False, 'parcel': parcel_id, 'files': file_list.files, 'details': details, 'auth': g.auth, 'ua': activity } session['page'] = '/selected/%s' % parcel_id return render_template('selected_parcel.html', context=context)
def route_deletefile(encoded, parcel): filename = base64.standard_b64decode(encoded).decode('ascii') folder, file = os.path.split(filename) os.remove(filename) UserActivity().save(parcel=parcel, activity='deletefile', msg='delete file: %s' % file) redirect_to = Settings().get('host-url') + '/selected/%s' % parcel return redirect(redirect_to)
def end_session(self): self.tune_out = datetime.datetime.now() self.put() Stat.add_session(self) # Track user activity if self.sessionMedias.get() and self.channel.privacy != Privacy.PRIVATE: from useractivity import UserActivity broadcast.broadcastNewActivity(UserActivity.add_session(self.user, self))
def route_uploadfiles(): for item in request.files: f = request.files[item] parcel_id = request.form['parcel_id'] pf = ParcelFolder(parcel=parcel_id) filename_only = secure_filename(f.filename) fullpath = os.path.join(pf.path, filename_only) f.save(fullpath) UserActivity().save(parcel=parcel_id, activity='uploadfile', msg='%s' % filename_only) return jsonify({'status': 'ok'}), 200
def route_renamefile_post(): encoded = request.form['encoded'] parcel = request.form['parcel'] newfilename = request.form['newfilename'] # # Extract full path, and then split into path and name. fullpath = base64.standard_b64decode(encoded).decode('ascii') folder, file = os.path.split(fullpath) # # create new full path newfullpath = os.path.join(folder, newfilename) # # now rename the old file to new file. os.rename(fullpath, newfullpath) UserActivity().save(parcel=parcel, activity='renamefile', msg='%s to %s' % (file, newfilename)) redirect_to = Settings().get('host-url') + '/selected/%s' % parcel return redirect(redirect_to)
def add(cls, media, user, text, acl, parent_id=None, to_user=None): from notification import Notification c = Comment(media=media, user=user, text=text) c.mentions = [x[0] for x in re.findall(r"@\[(\d+):([a-zA-z\s]+)\]", text)] if parent_id: c.parent_comment = Comment.get_by_id(int(parent_id)) c.is_parent = False elif PRIVATE_COMMENTS: # ACL only needed on parent. Replies don't need ACLs. c.acl = acl c.put() media.comment_count += 1 media.put() for m in c.mentions: if not to_user or (to_user and m != to_user.id): mentioned_user = User.get_by_key_name(m) if not mentioned_user or True: # Send them notification on FB fetch = urlfetch.fetch(url='https://graph.facebook.com/%s/notifications' % m, payload='access_token=%s&template=%s&href=%s' % (constants.facebook_app()['APP_ACCESS_TOKEN'], '@[' + user.id + ']' + ' mentioned you in a comment on ' + media.name + '!', media.get_path()), method=urlfetch.POST) else: n = Notification.add(mentioned_user, constants.NotificationType.MENTION, c) broadcast.broadcastNotification(n) if c.is_parent: from useractivity import UserActivity broadcast.broadcastNewActivity(UserActivity.add_comment(c.user, c)) return c