
from flask import Flask, render_template
import jinja2

from .. import Directory, directory_list, str_size


# Init app

jinja2.filters.FILTERS['str_size'] = str_size

app = Flask(__name__)


# Pages

@app.route('/')
def dirlist():
    directories = [(d[0], Directory(d[1])) for d in directory_list()]
    directories.sort(key=lambda d: str(d[1]).lower())
    return render_template('dirlist.html', directories=directories)


# Run

def main():
    import sys
    from gunicorn.app.wsgiapp import run
    sys.argv = ['gunicorn',
                '--access-logfile=-',
                '--error-logfile=-',
                '-b', '127.0.0.1:5050',
                'deduplicated.web:app']
    run()


from flask import Flask, redirect, render_template, request
import jinja2

from .. import Directory, directory_list, str_size


# Init app

jinja2.filters.FILTERS['str_size'] = str_size

app = Flask(__name__)


# Pages

@app.route('/')
def dirlist():
    directories = [(d[0], Directory(d[1])) for d in directory_list()]
    directories.sort(key=lambda d: str(d[1]).lower())
    return render_template('dirlist.html', directories=directories)


@app.route('/dir/add', methods=['post'])
def diradd():
    dirname = request.form.get('directory', '')
    if dirname:
        Directory(dirname)
    return redirect('/')


# Run

def main():
    import sys
    from gunicorn.app.wsgiapp import run
    sys.argv = ['gunicorn',
                '--access-logfile=-',
                '--error-logfile=-',
                '-b', '127.0.0.1:5050',
                'deduplicated.web:app']
    run()

Add web function for add new directory
Add web function for add new directory

  
- from flask import Flask, render_template
+ from flask import Flask, redirect, render_template, request
  import jinja2
  
  from .. import Directory, directory_list, str_size
  
  
  # Init app
  
  jinja2.filters.FILTERS['str_size'] = str_size
  
  app = Flask(__name__)
  
  
  # Pages
  
  @app.route('/')
  def dirlist():
      directories = [(d[0], Directory(d[1])) for d in directory_list()]
      directories.sort(key=lambda d: str(d[1]).lower())
      return render_template('dirlist.html', directories=directories)
  
  
+ @app.route('/dir/add', methods=['post'])
+ def diradd():
+     dirname = request.form.get('directory', '')
+     if dirname:
+         Directory(dirname)
+     return redirect('/')
+ 
+ 
  # Run
  
  def main():
      import sys
      from gunicorn.app.wsgiapp import run
      sys.argv = ['gunicorn',
                  '--access-logfile=-',
                  '--error-logfile=-',
                  '-b', '127.0.0.1:5050',
                  'deduplicated.web:app']
      run()
  
Add web function for add new directory
## Code Before:

from flask import Flask, render_template
import jinja2

from .. import Directory, directory_list, str_size


# Init app

jinja2.filters.FILTERS['str_size'] = str_size

app = Flask(__name__)


# Pages

@app.route('/')
def dirlist():
    directories = [(d[0], Directory(d[1])) for d in directory_list()]
    directories.sort(key=lambda d: str(d[1]).lower())
    return render_template('dirlist.html', directories=directories)


# Run

def main():
    import sys
    from gunicorn.app.wsgiapp import run
    sys.argv = ['gunicorn',
                '--access-logfile=-',
                '--error-logfile=-',
                '-b', '127.0.0.1:5050',
                'deduplicated.web:app']
    run()

## Instruction:
Add web function for add new directory
## Code After:

from flask import Flask, redirect, render_template, request
import jinja2

from .. import Directory, directory_list, str_size


# Init app

jinja2.filters.FILTERS['str_size'] = str_size

app = Flask(__name__)


# Pages

@app.route('/')
def dirlist():
    directories = [(d[0], Directory(d[1])) for d in directory_list()]
    directories.sort(key=lambda d: str(d[1]).lower())
    return render_template('dirlist.html', directories=directories)


@app.route('/dir/add', methods=['post'])
def diradd():
    dirname = request.form.get('directory', '')
    if dirname:
        Directory(dirname)
    return redirect('/')


# Run

def main():
    import sys
    from gunicorn.app.wsgiapp import run
    sys.argv = ['gunicorn',
                '--access-logfile=-',
                '--error-logfile=-',
                '-b', '127.0.0.1:5050',
                'deduplicated.web:app']
    run()
