Repository: CTFd/CTFd

Issue:
Importing an export generated prior to 1.1 (with configuration) breaks CTFd
**Environment**:

  - CTFd Version/Commit: 3af98b17d535b6b04aedc385c28771445dab3699
  - Operating System: Linux
  - Web Browser and Version: N/A

**What happened?**
Import an export containing configuration that was generated prior to  3af98b17d535b6b04aedc385c28771445dab3699 and CTFd will break because it will be looking for the `original` theme when the new one is called `core`.

**What did you expect to happen?**
It would not break - on import of the previous CTFd version if configured theme is called `original` don't import its value.

**How to reproduce your issue**

Do a full export from CTFd prior to 3af98b17d535b6b04aedc385c28771445dab3699 and then try again after / with 3af98b17d535b6b04aedc385c28771445dab3699 .

**Any associated stack traces or error logs**
```
[2017-12-12 09:50:46 +0000] [2767] [ERROR] Socket error processing request.
Traceback (most recent call last):
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 135, in handle
    self.handle_request(listener, req, client, addr)
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 191, in handle_request
    six.reraise(*sys.exc_info())
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 176, in handle_request
    respiter = self.wsgi(environ, resp.start_response)
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/flask/app.py", line 1997, in __call__
    return self.wsgi_app(environ, start_response)
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/flask/app.py", line 1985, in wsgi_app
    response = self.handle_exception(e)
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/flask/app.py", line 1547, in handle_exception
    return self.finalize_request(handler(e), from_error_handler=True)
  File "/home/user/hacking/github/CTFd/CTFd/utils.py", line 141, in general_error
    return render_template('errors/500.html'), 500
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/flask/templating.py", line 133, in render_template
    return _render(ctx.app.jinja_env.get_or_select_template(template_name_or_list),
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/jinja2/environment.py", line 869, in get_or_select_template
    return self.get_template(template_name_or_list, parent, globals)
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/jinja2/environment.py", line 830, in get_template
    return self._load_template(name, self.make_globals(globals))
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/jinja2/environment.py", line 804, in _load_template
    template = self.loader.load(self, name, globals)
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/jinja2/loaders.py", line 113, in load
    source, filename, uptodate = self.get_source(environment, name)
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/flask/templating.py", line 57, in get_source
    return self._get_source_fast(environment, template)
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/flask/templating.py", line 85, in _get_source_fast
    raise TemplateNotFound(template)
TemplateNotFound: errors/500.html
[2017-12-12 09:50:47 +0000] [2767] [DEBUG] GET /admin/config
[2017-12-12 09:50:47,174] ERROR in app: Exception on /admin/config [GET]
Traceback (most recent call last):
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/user/hacking/github/CTFd/CTFd/utils.py", line 289, in decorated_function
    return f(*args, **kwargs)
  File "/home/user/hacking/github/CTFd/CTFd/admin/__init__.py", line 214, in admin_config
    themes.remove(ctf_theme)
ValueError: list.remove(x): x not in list
[2017-12-12 09:50:47 +0000] [2767] [ERROR] Socket error processing request.
Traceback (most recent call last):
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 135, in handle
    self.handle_request(listener, req, client, addr)
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 191, in handle_request
    six.reraise(*sys.exc_info())
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 176, in handle_request
    respiter = self.wsgi(environ, resp.start_response)
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/flask/app.py", line 1997, in __call__
    return self.wsgi_app(environ, start_response)
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/flask/app.py", line 1985, in wsgi_app
    response = self.handle_exception(e)
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/flask/app.py", line 1547, in handle_exception
    return self.finalize_request(handler(e), from_error_handler=True)
  File "/home/user/hacking/github/CTFd/CTFd/utils.py", line 141, in general_error
    return render_template('errors/500.html'), 500
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/flask/templating.py", line 133, in render_template
    return _render(ctx.app.jinja_env.get_or_select_template(template_name_or_list),
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/jinja2/environment.py", line 869, in get_or_select_template
    return self.get_template(template_name_or_list, parent, globals)
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/jinja2/environment.py", line 830, in get_template
    return self._load_template(name, self.make_globals(globals))
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/jinja2/environment.py", line 804, in _load_template
    template = self.loader.load(self, name, globals)
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/jinja2/loaders.py", line 113, in load
    source, filename, uptodate = self.get_source(environment, name)
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/flask/templating.py", line 57, in get_source
    return self._get_source_fast(environment, template)
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/flask/templating.py", line 85, in _get_source_fast
    raise TemplateNotFound(template)
TemplateNotFound: errors/500.html
[2017-12-12 09:50:47 +0000] [2767] [DEBUG] GET /admin/config
[2017-12-12 09:50:47,681] ERROR in app: Exception on /admin/config [GET]
Traceback (most recent call last):
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/user/hacking/github/CTFd/CTFd/utils.py", line 289, in decorated_function
    return f(*args, **kwargs)
  File "/home/user/hacking/github/CTFd/CTFd/admin/__init__.py", line 214, in admin_config
    themes.remove(ctf_theme)
ValueError: list.remove(x): x not in list
[2017-12-12 09:50:47 +0000] [2767] [ERROR] Socket error processing request.
Traceback (most recent call last):
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 135, in handle
    self.handle_request(listener, req, client, addr)
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 191, in handle_request
    six.reraise(*sys.exc_info())
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 176, in handle_request
    respiter = self.wsgi(environ, resp.start_response)
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/flask/app.py", line 1997, in __call__
    return self.wsgi_app(environ, start_response)
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/flask/app.py", line 1985, in wsgi_app
    response = self.handle_exception(e)
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/flask/app.py", line 1547, in handle_exception
    return self.finalize_request(handler(e), from_error_handler=True)
  File "/home/user/hacking/github/CTFd/CTFd/utils.py", line 141, in general_error
    return render_template('errors/500.html'), 500
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/flask/templating.py", line 133, in render_template
    return _render(ctx.app.jinja_env.get_or_select_template(template_name_or_list),
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/jinja2/environment.py", line 869, in get_or_select_template
    return self.get_template(template_name_or_list, parent, globals)
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/jinja2/environment.py", line 830, in get_template
    return self._load_template(name, self.make_globals(globals))
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/jinja2/environment.py", line 804, in _load_template
    template = self.loader.load(self, name, globals)
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/jinja2/loaders.py", line 113, in load
    source, filename, uptodate = self.get_source(environment, name)
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/flask/templating.py", line 57, in get_source
    return self._get_source_fast(environment, template)
  File "/home/user/.virtualenvs/ctfd/local/lib/python2.7/site-packages/flask/templating.py", line 85, in _get_source_fast
    raise TemplateNotFound(template)
TemplateNotFound: errors/500.html
```



Discussion:

Resolving patch:
diff --git a/migrations/versions/d5a224bf5862_change_theme_from_original_to_core.py b/migrations/versions/d5a224bf5862_change_theme_from_original_to_core.py
new file mode 100644
--- /dev/null
+++ b/migrations/versions/d5a224bf5862_change_theme_from_original_to_core.py
@@ -0,0 +1,51 @@
+"""Change theme from original to core
+
+Revision ID: d5a224bf5862
+Revises: c12d2a1b0926
+Create Date: 2017-12-13 16:06:51.644187
+
+"""
+from CTFd.models import db
+from alembic import op
+import sqlalchemy as sa
+from sqlalchemy.dialects import mysql
+from sqlalchemy.sql import text, table, column, and_
+
+# revision identifiers, used by Alembic.
+revision = 'd5a224bf5862'
+down_revision = 'c12d2a1b0926'
+branch_labels = None
+depends_on = None
+
+
+config_table = table('config',
+    column('id', db.Integer),
+    column('key', db.Text),
+    column('value', db.Text)
+)
+
+
+def upgrade():
+    # ### commands auto generated by Alembic - please adjust! ###
+    connection = op.get_bind()
+    connection.execute(
+        config_table.update().where(
+            and_(config_table.c.key == 'ctf_theme', config_table.c.value == 'original')
+        ).values(
+            value='core'
+        )
+    )
+    # ### end Alembic commands ###
+
+
+def downgrade():
+    # ### commands auto generated by Alembic - please adjust! ###
+    connection = op.get_bind()
+    connection.execute(
+        config_table.update().where(
+            and_(config_table.c.key == 'ctf_theme', config_table.c.value == 'core')
+        ).values(
+            value='original'
+        )
+    )
+    # ### end Alembic commands ###


Test patch: