Repository: fossasia/open-event-server

Issue:
Example heroku deployment gives a 500
http://open-event.herokuapp.com/admin/ is a 500

`heroku logs` says:

```
2015-12-20T02:08:39.190175+00:00 app[web.1]:   File "/app/open_event/views/admin/home.py", line 23, in index
2015-12-20T02:08:39.190176+00:00 app[web.1]:     self._template_args['owner_events'] = DataGetter.get_all_owner_events()
2015-12-20T02:08:39.190176+00:00 app[web.1]:   File "/app/open_event/helpers/data_getter.py", line 26, in get_all_owner_events
2015-12-20T02:08:39.190177+00:00 app[web.1]:     return login.current_user.events_assocs
2015-12-20T02:08:39.190178+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/werkzeug/local.py", line 338, in __getattr__
2015-12-20T02:08:39.190178+00:00 app[web.1]:     return getattr(self._get_current_object(), name)
2015-12-20T02:08:39.190179+00:00 app[web.1]: AttributeError: 'AnonymousUserMixin' object has no attribute 'events_assocs'
```



Discussion:
 @leto IF you want an access to heroku i will give you, problem occurs in datatable relation

@rafalkowalski yeah I would like access. Do I need to send you an SSH key? We are telling GCI students to go look at it, so we should keep it stable and working. Did things get messed up because of database schema changes? 

@leto I've added you as a collborator, I suppose that maybe there is a problem 

I tried this:

```
-        return login.current_user.events_assocs
+        if login.current_user.is_authenticated:
+            return login.current_user.events_assocs
+        else:
+            return None
```

but the error still happens. I am still not sure why this only happens on Heroku and not in vagrant. @creativepsyco any ideas?

is it deployed to heroku?

Full error on heroku:

```
2015-12-20T17:34:03.411027+00:00 heroku[router]: at=info method=GET path="/admin/login/" host=open-event.herokuapp.com request_id=c318ef9a-0872-41d9-b1bc-c1535ea2dad5 fwd="116.89.39.53,218.186.13.13" dyno=web.1 connect=0ms service=5ms status=302 bytes=592
2015-12-20T17:34:03.954431+00:00 app[web.1]: Exception on /admin/ [GET]
2015-12-20T17:34:03.954435+00:00 app[web.1]: Traceback (most recent call last):
2015-12-20T17:34:03.954437+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
2015-12-20T17:34:03.954437+00:00 app[web.1]:     response = self.full_dispatch_request()
2015-12-20T17:34:03.954438+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
2015-12-20T17:34:03.954439+00:00 app[web.1]:     rv = self.handle_user_exception(e)
2015-12-20T17:34:03.954439+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/flask_cors/extension.py", line 110, in wrapped_function
2015-12-20T17:34:03.954440+00:00 app[web.1]:     return cors_after_request(app.make_response(f(*args, **kwargs)))
2015-12-20T17:34:03.954441+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
2015-12-20T17:34:03.954441+00:00 app[web.1]:     reraise(exc_type, exc_value, tb)
2015-12-20T17:34:03.954442+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
2015-12-20T17:34:03.954442+00:00 app[web.1]:     rv = self.dispatch_request()
2015-12-20T17:34:03.954443+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
2015-12-20T17:34:03.954444+00:00 app[web.1]:     return self.view_functions[rule.endpoint](**req.view_args)
2015-12-20T17:34:03.954444+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/flask_admin/base.py", line 68, in inner
2015-12-20T17:34:03.954445+00:00 app[web.1]:     return self._run_view(f, *args, **kwargs)
2015-12-20T17:34:03.954445+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/flask_admin/base.py", line 354, in _run_view
2015-12-20T17:34:03.954445+00:00 app[web.1]:     return fn(self, *args, **kwargs)
2015-12-20T17:34:03.954446+00:00 app[web.1]:   File "/app/open_event/views/admin/home.py", line 23, in index
2015-12-20T17:34:03.954446+00:00 app[web.1]:     self._template_args['owner_events'] = DataGetter.get_all_owner_events()
2015-12-20T17:34:03.954447+00:00 app[web.1]:   File "/app/open_event/helpers/data_getter.py", line 26, in get_all_owner_events
2015-12-20T17:34:03.954447+00:00 app[web.1]:     return login.current_user.events_assocs
2015-12-20T17:34:03.954448+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/werkzeug/local.py", line 338, in __getattr__
2015-12-20T17:34:03.954448+00:00 app[web.1]:     return getattr(self._get_current_object(), name)
2015-12-20T17:34:03.954448+00:00 app[web.1]: AttributeError: 'AnonymousUserMixin' object has no attribute 'events_assocs'
```

Its probably a flask login thing:  `AttributeError: 'AnonymousUserMixin' object has no attribute 'events_assocs'`

@creativepsyco yes, I deployed that if/else change to heroku master because I was unsure of how to test it otherwise. It can be reverted


Resolving patch:
diff --git a/open_event/views/admin/home.py b/open_event/views/admin/home.py
--- a/open_event/views/admin/home.py
+++ b/open_event/views/admin/home.py
@@ -18,10 +18,13 @@ def index(self):
         """Main page"""
         self._template = "admin/auth.html"
         if not login.current_user.is_authenticated:
+            print "Unauthenticated user"
             return redirect(url_for('.login_view'))
-        self._template_args['events'] = DataGetter.get_all_events()
-        self._template_args['owner_events'] = DataGetter.get_all_owner_events()
-        return super(MyHomeView, self).index()
+        else:
+            print "Authenticated user"
+            self._template_args['events'] = DataGetter.get_all_events()
+            self._template_args['owner_events'] = DataGetter.get_all_owner_events()
+            return super(MyHomeView, self).index()
 
     @expose('/login/', methods=('GET', 'POST'))
     def login_view(self):


Test patch: