Repository: fossasia/open-event-server

Issue:
[Vintage] Error for Event: Cannot edit event on eventyay
- [X] bug report

**Current behavior:**
Cannot edit event. Difference to other events is: It does not use ticketing system. https://eventyay.com/events/303/edit/

Public Event: https://eventyay.com/e/565f0942/

Screenshot:
![screenshot from 2017-10-12 19-34-17](https://user-images.githubusercontent.com/1583873/31510229-62bcc03a-af84-11e7-9bb7-c838132b098b.png)



Discussion:
@mariobehling I'm tried to regenerate it, but not getting such error. It's working fine for me even if I don't use the Ticketing System.
```
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python2.7/site-packages/flask_restplus/api.py", line 557, in error_router
    return original_handler(e)
  File "/usr/local/lib/python2.7/site-packages/flask_cors/extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/opev/open_event/app/helpers/permission_decorators.py", line 172, in decorated_function
    return f(*args, **kwargs)
  File "/opev/open_event/app/views/users/events.py", line 333, in edit_view
    'tracks': get_tracks_json(event_id),
  File "/opev/open_event/app/helpers/wizard/sessions_speakers.py", line 19, in get_tracks_json
    data.append(track.serialize)
  File "/opev/open_event/app/models/track.py", line 52, in serialize
    'font_color': self.font_color
  File "/opev/open_event/app/models/track.py", line 43, in font_color
    a = 1 - (0.299 * int(h[0:2], 16) + 0.587 * int(h[2:4], 16) + 0.114 * int(h[4:6], 16))/255
ValueError: invalid literal for int() with base 16: 'rg'
```

@rahuldecoded the above is the stack trace. From what I can see it probably occurs due to an incorrect track color or the lack of it. 
@niranjan94 Working on it.
BTW did the error occur on choosing a specific track colour or for any colour.

Resolving patch:
diff --git a/app/models/track.py b/app/models/track.py
--- a/app/models/track.py
+++ b/app/models/track.py
@@ -34,8 +34,13 @@ def __unicode__(self):
 
     @property
     def font_color(self):
-        h = self.color.lstrip('#')
-        a = 1 - (0.299 * int(h[0:2], 16) + 0.587 * int(h[2:4], 16) + 0.114 * int(h[4:6], 16))/255
+        if self.color.startswith('#'):
+            h = self.color.lstrip('#')
+            a = 1 - (0.299 * int(h[0:2], 16) + 0.587 * int(h[2:4], 16) + 0.114 * int(h[4:6], 16))/255
+        elif self.color.startswith('rgba'):
+            h = self.color.lstrip('rgba').replace('(', '', 1).replace(')', '', 1)
+            h = h.split(',')
+            a = 1 - (0.299 * int(int(h[0]), 16) + 0.587 * int(int(h[1]), 16) + 0.114 * int(int(h[2]), 16)) / 255
         return '#000000' if (a < 0.5) else '#ffffff'
 
     @property


Test patch: