Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bitpoll/poll/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from bitpoll.base.models import BitpollUser
from bitpoll.base.validators import validate_timezone
from bitpoll.poll.util import DateTimePart, PartialDateTime
from bitpoll.poll.util import DateTimePart, PartialDateTime, split_unescape
from django.utils import translation

POLL_TYPES = (
Expand Down Expand Up @@ -239,7 +239,7 @@ def get_hierarchy(self, tz):
if self.date:
return [PartialDateTime(self.date, DateTimePart.date, tz),
PartialDateTime(self.date, DateTimePart.time, tz)]
return [part.strip() for part in self.text.split("/") if part]
return [part.strip() for part in split_unescape(self.text, "/") if part]

def votechoice_count(self):
return self.votechoice_set.filter(value__isnull=False).count()
Expand Down
1 change: 1 addition & 0 deletions bitpoll/poll/templates/poll/universal_choice_creation.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ <h4>{% trans 'Grouping' %}</h4>
<li>{% trans 'Some-Group/Another-Choice' %}</li>
<li>{% trans 'Some-Group/Third-Choice' %}</li>
</ul>
<p>{% blocktrans %}If you want to have a '/' in the choice escape it with '\': '\/'.{% endblocktrans %}</p>
</div>
</div>
</div>
Expand Down
37 changes: 37 additions & 0 deletions bitpoll/poll/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,40 @@ def format(self):
return date_format(self.datetime, format='H:i')
elif self.part == DateTimePart.datetime:
return date_format(self.datetime, format='D, j. N Y H:i')


#From: https://stackoverflow.com/questions/18092354/python-split-string-without-splitting-escaped-character
def split_unescape(s, delim, escape='\\', unescape=True):
"""
>>> split_unescape('foo,bar', ',')
['foo', 'bar']
>>> split_unescape('foo$,bar', ',', '$')
['foo,bar']
>>> split_unescape('foo$$,bar', ',', '$', unescape=True)
['foo$', 'bar']
>>> split_unescape('foo$$,bar', ',', '$', unescape=False)
['foo$$', 'bar']
>>> split_unescape('foo$', ',', '$', unescape=True)
['foo$']
"""
ret = []
current = []
itr = iter(s)
for ch in itr:
if ch == escape:
try:
# skip the next character; it has been escaped!
if not unescape:
current.append(escape)
current.append(next(itr))
except StopIteration:
if unescape:
current.append(escape)
elif ch == delim:
# split! (add current to the list and reset it)
ret.append(''.join(current))
current = []
else:
current.append(ch)
ret.append(''.join(current))
return ret