Show More
@@ -400,14 +400,15 b' class MyAccountView(BaseAppView, DataGri' | |||
|
400 | 400 | c.active = 'bookmarks' |
|
401 | 401 | return self._get_template_context(c) |
|
402 | 402 | |
|
403 | def _process_entry(self, entry, user_id): | |
|
403 | def _process_bookmark_entry(self, entry, user_id): | |
|
404 | 404 | position = safe_int(entry.get('position')) |
|
405 | if position is None: | |
|
405 | cur_position = safe_int(entry.get('cur_position')) | |
|
406 | if position is None or cur_position is None: | |
|
406 | 407 | return |
|
407 | 408 | |
|
408 | 409 | # check if this is an existing entry |
|
409 | 410 | is_new = False |
|
410 | db_entry = UserBookmark().get_by_position_for_user(position, user_id) | |
|
411 | db_entry = UserBookmark().get_by_position_for_user(cur_position, user_id) | |
|
411 | 412 | |
|
412 | 413 | if db_entry and str2bool(entry.get('remove')): |
|
413 | 414 | log.debug('Marked bookmark %s for deletion', db_entry) |
@@ -446,12 +447,12 b' class MyAccountView(BaseAppView, DataGri' | |||
|
446 | 447 | should_save = True |
|
447 | 448 | |
|
448 | 449 | if should_save: |
|
449 | log.debug('Saving bookmark %s, new:%s', db_entry, is_new) | |
|
450 | 450 | # mark user and position |
|
451 | 451 | db_entry.user_id = user_id |
|
452 | 452 | db_entry.position = position |
|
453 | 453 | db_entry.title = entry.get('title') |
|
454 | 454 | db_entry.redirect_url = entry.get('redirect_url') or default_redirect_url |
|
455 | log.debug('Saving bookmark %s, new:%s', db_entry, is_new) | |
|
455 | 456 | |
|
456 | 457 | Session().add(db_entry) |
|
457 | 458 | |
@@ -468,15 +469,31 b' class MyAccountView(BaseAppView, DataGri' | |||
|
468 | 469 | controls = peppercorn.parse(self.request.POST.items()) |
|
469 | 470 | user_id = c.user.user_id |
|
470 | 471 | |
|
472 | # validate positions | |
|
473 | positions = {} | |
|
474 | for entry in controls.get('bookmarks', []): | |
|
475 | position = safe_int(entry['position']) | |
|
476 | if position is None: | |
|
477 | continue | |
|
478 | ||
|
479 | if position in positions: | |
|
480 | h.flash(_("Position {} is defined twice. " | |
|
481 | "Please correct this error.").format(position), category='error') | |
|
482 | return HTTPFound(h.route_path('my_account_bookmarks')) | |
|
483 | ||
|
484 | entry['position'] = position | |
|
485 | entry['cur_position'] = safe_int(entry.get('cur_position')) | |
|
486 | positions[position] = entry | |
|
487 | ||
|
471 | 488 | try: |
|
472 |
for entry in |
|
|
473 | self._process_entry(entry, user_id) | |
|
489 | for entry in positions.values(): | |
|
490 | self._process_bookmark_entry(entry, user_id) | |
|
474 | 491 | |
|
475 | 492 | Session().commit() |
|
476 | 493 | h.flash(_("Update Bookmarks"), category='success') |
|
477 | 494 | except IntegrityError: |
|
478 | 495 | h.flash(_("Failed to update bookmarks. " |
|
479 | "Make sure an unique position is used"), category='error') | |
|
496 | "Make sure an unique position is used."), category='error') | |
|
480 | 497 | |
|
481 | 498 | return HTTPFound(h.route_path('my_account_bookmarks')) |
|
482 | 499 |
@@ -5085,7 +5085,7 b' class UserBookmark(Base, BaseModel):' | |||
|
5085 | 5085 | .all() |
|
5086 | 5086 | |
|
5087 | 5087 | def __unicode__(self): |
|
5088 |
return u'<UserBookmark(% |
|
|
5088 | return u'<UserBookmark(%s @ %r)>' % (self.position, self.redirect_url) | |
|
5089 | 5089 | |
|
5090 | 5090 | |
|
5091 | 5091 | class FileStore(Base, BaseModel): |
@@ -1,13 +1,14 b'' | |||
|
1 | 1 | <%namespace name="dt" file="/data_table/_dt_elements.mako"/> |
|
2 | 2 | |
|
3 |
<%def name="form_item( |
|
|
3 | <%def name="form_item(position=None, title=None, redirect_url=None, repo=None, repo_group=None)"> | |
|
4 | 4 | <tr> |
|
5 | 5 | <td class="td-align-top" > |
|
6 | 6 | <div class="label"> |
|
7 | 7 | <label for="position">${_('Position')}:</label> |
|
8 | 8 | </div> |
|
9 | 9 | <div class="input"> |
|
10 |
<input type="text" name="position" value="${position |
|
|
10 | <input type="text" name="position" value="${position}" style="width: 40px"/> | |
|
11 | ${h.hidden('cur_position', position)} | |
|
11 | 12 | </div> |
|
12 | 13 | </td> |
|
13 | 14 | |
@@ -91,14 +92,14 b'' | |||
|
91 | 92 | <table class="rctable"> |
|
92 | 93 | ## generate always 10 entries |
|
93 | 94 | <input type="hidden" name="__start__" value="bookmarks:sequence"/> |
|
94 |
% for |
|
|
95 | % for item in (c.bookmark_items + [None for i in range(10)])[:10]: | |
|
95 | 96 | <input type="hidden" name="__start__" value="bookmark:mapping"/> |
|
96 | 97 | % if item is None: |
|
97 | 98 | ## empty placehodlder |
|
98 |
${form_item( |
|
|
99 | ${form_item()} | |
|
99 | 100 | % else: |
|
100 | 101 | ## actual entry |
|
101 |
${form_item( |
|
|
102 | ${form_item(position=item.position, title=item.title, redirect_url=item.redirect_url, repo=item.repository, repo_group=item.repository_group)} | |
|
102 | 103 | % endif |
|
103 | 104 | <input type="hidden" name="__end__" value="bookmark:mapping"/> |
|
104 | 105 | % endfor |
General Comments 0
You need to be logged in to leave comments.
Login now