def edit_tome_file_link(): tome_id = request.args[0] file_hash = request.args[1] tome = pdb.get_tome(tome_id) files = pdb.get_tome_files(tome_id, file_type=pydb.FileType.Content, include_local_file_info=True) tome_files = filter(lambda x: x['hash'] == file_hash, files) tome_file = tome_files[0] form = SQLFORM.factory(Field('file_extension', default=db_str_to_form(tome_file['file_extension'])), Field('fidelity', requires=FidelityValidator(), default=tome_file['fidelity']+0.1), submit_button='Save') title_text = title.coalesce_title(tome['title'], tome['subtitle']) response.title = u"Edit Files {} - Montag".format(title_text) field_names = ['file_extension', 'fidelity'] if form.process(keepvalues=True).accepted: doc = pdb.get_tome_document_by_guid(tome['guid'], hide_private_tags=False) other_files = filter(lambda x: x['hash'] != file_hash, doc['files']) tome_file_doc = filter(lambda x: x['hash'] == file_hash, doc['files'])[0] for f in field_names: tome_file_doc[f] = read_form_field(form, f) other_files.append(tome_file_doc) doc['files'] = other_files pdb.load_own_tome_document(doc) response.flash = 'Stored new values' redirect(URL('edit_tome', args=(tome['guid']), anchor='files')) elif form.errors: response.flash = 'form has errors' return dict(form=form, tome=tome, file=tome_file)
def edit_tome_file_link(): tome_id = request.args[0] file_hash = request.args[1] tome = pdb.get_tome(tome_id) files = pdb.get_tome_files(tome_id, file_type=pydb.FileType.Content, include_local_file_info=True) tome_files = filter(lambda x: x['hash'] == file_hash, files) tome_file = tome_files[0] form = SQLFORM.factory(Field('file_extension', default=db_str_to_form(tome_file['file_extension'])), Field('fidelity', requires=FidelityValidator(), default=tome_file['fidelity']+0.1), submit_button='Save') title_text = title.coalesce_title(tome['title'], tome['subtitle']) response.title = u"Edit Files {} - Montag".format(title_text) field_names = ['file_extension', 'fidelity'] if form.process(keepvalues=True).accepted: doc = pdb.get_tome_document_by_guid(tome['guid'], hide_private_tags=False) other_files = filter(lambda x: x['hash'] != file_hash, doc['files']) tome_file_doc = filter(lambda x: x['hash'] == file_hash, doc['files'])[0] for f in field_names: tome_file_doc[f] = read_form_field(form, f) other_files.append(tome_file_doc) doc['files'] = other_files pdb.load_own_tome_document(doc) response.flash = 'Stored new values' redirect(URL('edit_tome', args=(tome['guid']), anchor='files')) elif form.errors: response.flash = 'form has errors' return dict(form=form, tome=tome, file=tome_file)
def _select_author_merge_partner_form(first_author): form = SQLFORM.factory(Field('query', requires=IS_NOT_EMPTY(), default=db_str_to_form(first_author['name']), label="Search for"), submit_button='Search', _method='GET') return form
def _add_tome_from_file_form(metadata): def from_dict(the_dict, key, default_value=''): if key not in the_dict: return default_value else: return the_dict[key] form = SQLFORM.factory( Field( 'title', requires=IS_NOT_EMPTY(), default=db_str_to_form(from_dict(metadata, 'title')), comment=TOOLTIP( 'Please enter the title of the book like it is written on the cover.' )), Field('subtitle'), Field('edition'), Field( 'principal_language', default=db_str_to_form( from_dict(metadata, 'principal_language', 'en')), comment=TOOLTIP( 'Please use two letter ISO 639-1 codes (e.g. en for English).') ), Field('publication_year', default=db_str_to_form( from_dict(metadata, 'publication_year', ''))), Field('tome_type', default=TomeType.Fiction, widget=SQLFORM.widgets.radio.widget, requires=IS_IN_SET({ TomeType.Fiction: 'fiction', TomeType.NonFiction: 'non-fiction' })), Field('authors', 'text', requires=AuthorValidator(), default=[{ 'name': n } for n in metadata['author_names']]), Field('fidelity', requires=FidelityValidator(), default=DEFAULT_ADD_FIDELITY), submit_button='Add') return form
def _tome_edit_form(tome, required_tome_fidelity): form = SQLFORM.factory(Field('title', requires=IS_NOT_EMPTY(), default=db_str_to_form(tome['title']), comment=DIV( TOOLTIP('Please enter the title of the book like it is written on the cover.'), XML(r'<input type="button" value="Guess title case" onclick="title_case_field("no_table_title")">'), _class='nowrap')), Field('subtitle', default=db_str_to_form(tome['subtitle']), comment=XML(r'<input type="button" value="Guess subtitle case" onclick="title_case_field("no_table_subtitle")">')), Field('edition', default=db_str_to_form(tome['edition'])), Field('principal_language', default=db_str_to_form(tome['principal_language']), comment=TOOLTIP('Please use two letter ISO 639-1 codes (e.g. en for English).')), Field('publication_year', default=db_str_to_form(tome['publication_year'])), Field('tags', 'text', default=tome['tags'], requires=TagValidator(), comment=TOOLTIP('Use Syntax: FIDELITY TAG_VALUE. <BR> Prefix a TAG_VALUE with % to make it private. Private tags are not synchronized with friends.<br>' 'Prefix a TAG_VALUE with < to show it only on the tome detail page (it is still synchronized).')), Field('type', default=tome['type'], widget=SQLFORM.widgets.radio.widget, requires=IS_IN_SET({TomeType.Fiction: 'fiction', TomeType.NonFiction: 'non-fiction'})), Field('fidelity', requires=FidelityValidator(), default=required_tome_fidelity, comment='Current Value: {}'.format(tome['fidelity'])), submit_button='Save', name="edit_tome") return form
def _author_edit_form(author, required_fidelity): form = SQLFORM.factory(Field('name', requires=IS_NOT_EMPTY(), default=db_str_to_form(author['name']), comment=XML(r'<input type="button" value="Guess name case" ' r'onclick="title_case_field("no_table_name")">')), Field('date_of_birth', default=author['date_of_birth'], comment=TOOLTIP('Please enter the date in ISO 8601, ' 'e.g. 1920-08-22. If only the year is known, use that.')), Field('date_of_death', default=author['date_of_death'], comment=TOOLTIP('Please enter the date in ISO 8601, ' 'e.g. 1993-02-21. If only the year is known, use that.')), Field('fidelity', requires=FidelityValidator(), default=required_fidelity, comment='Current Value: {}'.format(author['fidelity'])), submit_button='Save') return form
def _tome_edit_form(tome, required_tome_fidelity): form = SQLFORM.factory(Field('title', requires=IS_NOT_EMPTY(), default=db_str_to_form(tome['title']), comment=DIV( TOOLTIP('Please enter the title of the book like it is written on the cover.'), XML(r'<input type="button" value="Guess title case" onclick="title_case_field("no_table_title")">'), _class='nowrap')), Field('subtitle', default=db_str_to_form(tome['subtitle']), comment=XML(r'<input type="button" value="Guess subtitle case" onclick="title_case_field("no_table_subtitle")">')), Field('edition', default=db_str_to_form(tome['edition'])), Field('principal_language', default=db_str_to_form(tome['principal_language']), comment=TOOLTIP('Please use two letter ISO 639-1 codes (e.g. en for English).')), Field('publication_year', default=db_str_to_form(tome['publication_year'])), Field('tags', 'text', default=tome['tags'], requires=TagValidator(), comment=TOOLTIP('Use Syntax: FIDELITY TAG_VALUE. <BR> Prefix a TAG_VALUE with % to make it private. Private tags are not synchronized with friends.<br>' 'Prefix a TAG_VALUE with < to show it only on the tome detail page (it is still synchronized).')), Field('type', default=tome['type'], widget=SQLFORM.widgets.radio.widget, requires=IS_IN_SET({TomeType.Fiction: 'fiction', TomeType.NonFiction: 'non-fiction'})), Field('fidelity', requires=FidelityValidator(), default=required_tome_fidelity, comment='Current Value: {}'.format(tome['fidelity'])), submit_button='Save', name="edit_tome") return form
def _author_edit_form(author, required_fidelity): form = SQLFORM.factory(Field('name', requires=IS_NOT_EMPTY(), default=db_str_to_form(author['name']), comment=XML(r'<input type="button" value="Guess name case" ' r'onclick="title_case_field("no_table_name")">')), Field('date_of_birth', default=author['date_of_birth'], comment=TOOLTIP('Please enter the date in ISO 8601, ' 'e.g. 1920-08-22. If only the year is known, use that.')), Field('date_of_death', default=author['date_of_death'], comment=TOOLTIP('Please enter the date in ISO 8601, ' 'e.g. 1993-02-21. If only the year is known, use that.')), Field('fidelity', requires=FidelityValidator(), default=required_fidelity, comment='Current Value: {}'.format(author['fidelity'])), submit_button='Save') return form
def _add_tome_from_file_form(metadata): def from_dict(the_dict, key, default_value=''): if key not in the_dict: return default_value else: return the_dict[key] form = SQLFORM.factory(Field('title', requires=IS_NOT_EMPTY(), default=db_str_to_form(from_dict(metadata, 'title')), comment=TOOLTIP('Please enter the title of the book like it is written on the cover.') ), Field('subtitle'), Field('edition'), Field('principal_language', default=db_str_to_form(from_dict(metadata, 'principal_language', 'en')), comment=TOOLTIP('Please use two letter ISO 639-1 codes (e.g. en for English).')), Field('publication_year', default=db_str_to_form(from_dict(metadata, 'publication_year', ''))), Field('tome_type', default=TomeType.Fiction, widget=SQLFORM.widgets.radio.widget, requires=IS_IN_SET({TomeType.Fiction: 'fiction', TomeType.NonFiction: 'non-fiction'})), Field('authors', 'text', requires=AuthorValidator(), default=[{'name': n} for n in metadata['author_names']]), Field('fidelity', requires=FidelityValidator(), default=DEFAULT_ADD_FIDELITY), submit_button='Add') return form
def _friend_edit_form(friend, comm_data): values = { 'hostname': '', 'port': '1234', 'secret': '*' * 6, 'confirm_secret': '-' * 6, 'type': 'tcp_aes', 'can_connect_to': friend['can_connect_to'] == 1 } if comm_data: for key, value in comm_data.iteritems(): if key != 'secret': values[key] = db_str_to_form(value) form = SQLFORM.factory( Field('name', requires=IS_NOT_EMPTY(), default=db_str_to_form(friend['name']), comment=TOOLTIP('Enter something to tell your friends apart.')), Field('secret', 'password', requires=IS_STRONG(min=8, special=0, upper=0), default='*'*6, comment=TOOLTIP('Please enter a reasonably long password (10+ characters) and share it ' 'with your friend. It will be used to identify each other and allow your ' 'friend to sync.')), Field('confirm_secret', 'password', requires=IS_EQUAL_TO(request.vars.secret, error_message='secrets do not match'), default='-'*6), Field('can_connect_to', type='boolean', default=values['can_connect_to'], comment=TOOLTIP('If you enable this, Montag will try to connect to this friend ' 'if you press the button "Update All".')), Field('hostname', requires=IS_NOT_EMPTY(), default=values['hostname'], comment=TOOLTIP('Please enter the IP-address or internet host name of your friend')), Field('port', requires=IS_INT_IN_RANGE(1024, 65535, error_message='invalid port'), default=values['port'], comment=TOOLTIP('Please enter the (TCP) port number your friend has made his/her Montag ' 'instance available under.')), Field('type', default=values['type'], comment=TOOLTIP('Connection type. Currently only "tcp_aes" is supported.')) ) return form
def _friend_edit_form(friend, comm_data): values = { 'hostname': '', 'port': '1234', 'secret': '*' * 6, 'confirm_secret': '-' * 6, 'type': 'tcp_aes', 'can_connect_to': friend['can_connect_to'] == 1 } if comm_data: for key, value in comm_data.iteritems(): if key != 'secret': values[key] = db_str_to_form(value) form = SQLFORM.factory( Field('name', requires=IS_NOT_EMPTY(), default=db_str_to_form(friend['name']), comment=TOOLTIP('Enter something to tell your friends apart.')), Field( 'secret', 'password', requires=IS_STRONG(min=8, special=0, upper=0), default='*' * 6, comment=TOOLTIP( 'Please enter a reasonably long password (10+ characters) and share it ' 'with your friend. It will be used to identify each other and allow your ' 'friend to sync.')), Field('confirm_secret', 'password', requires=IS_EQUAL_TO(request.vars.secret, error_message='secrets do not match'), default='-' * 6), Field( 'can_connect_to', type='boolean', default=values['can_connect_to'], comment=TOOLTIP( 'If you enable this, Montag will try to connect to this friend ' 'if you press the button "Update All".')), Field( 'hostname', requires=IS_NOT_EMPTY(), default=values['hostname'], comment=TOOLTIP( 'Please enter the IP-address or internet host name of your friend' )), Field( 'port', requires=IS_INT_IN_RANGE(1024, 65535, error_message='invalid port'), default=values['port'], comment=TOOLTIP( 'Please enter the (TCP) port number your friend has made his/her Montag ' 'instance available under.')), Field('type', default=values['type'], comment=TOOLTIP( 'Connection type. Currently only "tcp_aes" is supported.'))) return form
def formatter(self, value): authors = value return '\n'.join([db_str_to_form(author['name']) for author in authors])
def _tome_synopses_form(synopsis): form = SQLFORM.factory(Field('content', 'text', default=db_str_to_form(synopsis['content'])), Field('fidelity', requires=FidelityValidator(), default=synopsis['fidelity']+0.1), hidden={'guid': synopsis['guid'], '_formname': 'edit_synopsis_{}'.format(synopsis['guid'])}, submit_button='Save') return form
def formatter(self, value): tags = value return "\n".join([ "%.1f %s" % (tag['fidelity'], db_str_to_form(tag['tag_value'])) for tag in tags ])
def _tome_synopses_form(synopsis): form = SQLFORM.factory(Field('content', 'text', default=db_str_to_form(synopsis['content'])), Field('fidelity', requires=FidelityValidator(), default=synopsis['fidelity']+0.1), hidden={'guid': synopsis['guid'], '_formname': 'edit_synopsis_{}'.format(synopsis['guid'])}, submit_button='Save') return form
def formatter(self, value): authors = value return '\n'.join( [db_str_to_form(author['name']) for author in authors])
def formatter(self, value): tags = value return "\n".join(["%.1f %s" % (tag['fidelity'], db_str_to_form(tag['tag_value'])) for tag in tags])