def field_value(revision, field): value = getattr(revision, field) if field in ['script', 'pencils', 'inks', 'colors', 'letters', 'editing']: if type(revision).__name__ == 'IssueRevision': credits = revision.issue_credit_revisions.filter( credit_type__id=CREDIT_TYPES[field], deleted=False) else: credits = revision.story_credit_revisions.filter( credit_type__id=CREDIT_TYPES[field], deleted=False) if value and credits: value += '; ' for credit in credits: value += credit.creator.display_credit(credit, url=True) + '; ' if credits: value = value[:-2] return mark_safe(value) if field in [ 'is_surrogate', 'no_volume', 'display_volume_with_number', 'no_brand', 'page_count_uncertain', 'title_inferred', 'no_barcode', 'no_indicia_frequency', 'no_isbn', 'year_began_uncertain', 'year_overall_began_uncertain', 'year_ended_uncertain', 'year_overall_ended_uncertain', 'on_sale_date_uncertain', 'is_comics_publication', 'no_indicia_printer' ]: return yesno(value, 'Yes,No') elif field in ['is_current']: res_holder_display = '' if revision.previous(): reservation = revision.source.get_ongoing_reservation() if revision.previous().is_current and not value and reservation: res_holder = reservation.indexer res_holder_display = ' (ongoing reservation held by %s %s)' % \ (res_holder.first_name, res_holder.last_name) return yesno(value, 'Yes,No') + res_holder_display elif field in [ 'publisher', 'indicia_publisher', 'series', 'origin_issue', 'target_issue', 'award', 'from_feature', 'to_feature' ]: return absolute_url(value) elif field in ['origin', 'target']: return value.full_name_with_link() elif field == 'brand': if value and value.emblem: if settings.FAKE_IMAGES: return absolute_url(value) else: return mark_safe('<img src="' + value.emblem.icon.url + '"> ' + absolute_url(value)) return absolute_url(value) elif field in ['feature_object', 'feature_logo']: first = True features = '' for feature in value.all(): if first: first = False else: features += '; ' features += '<a href="%s">%s</a>' % (feature.get_absolute_url(), esc(feature.name)) return mark_safe(features) elif field in [ 'notes', 'tracking_notes', 'publication_notes', 'characters', 'synopsis' ]: return linebreaksbr(value) elif field == 'reprint_notes': reprint = '' if value.strip() != '': for string in split_reprint_string(value): string = string.strip() reprint += '<li> ' + esc(string) + ' </li>' if reprint != '': reprint = '<ul>' + reprint + '</ul>' return mark_safe(reprint) elif field in ['url']: return urlize(value) elif field in ['indicia_pub_not_printed']: return yesno(value, 'Not Printed,Printed') elif field == 'group': brand_groups = '' for brand in value.all(): brand_groups += absolute_url(brand) + '; ' if brand_groups: brand_groups = brand_groups[:-2] return mark_safe(brand_groups) elif field in [ 'no_editing', 'no_script', 'no_pencils', 'no_inks', 'no_colors', 'no_letters' ]: return yesno(value, 'X, ') elif field in ['page_count']: if revision.source_name == 'issue' and \ revision.changeset.storyrevisions.count(): # only calculate total sum for issue not sequences total_pages = sum_page_counts(revision.active_stories()) if revision.variant_of: if revision.changeset.issuerevisions.count() > 1: stories = revision.changeset.storyrevisions\ .exclude(issue=revision.issue) else: stories = revision.variant_of.active_stories() if revision.active_stories().count(): # variant has cover sequence, add page counts without cover stories = stories.exclude(sequence_number=0) total_pages += sum_page_counts(stories) else: # variant has no extra cover sequence total_pages = sum_page_counts(stories) sum_story_pages = format_page_count(total_pages) return '%s (note: total sum of story page counts is %s)' % \ (format_page_count(value), sum_story_pages) return format_page_count(value) elif field == 'isbn': if value: if validated_isbn(value): return '%s (note: valid ISBN)' % show_isbn(value) elif len(value.split(';')) > 1: return_val = show_isbn(value) + ' (note: ' for isbn in value.split(';'): return_val = return_val + '%s; ' % ("valid ISBN" if validated_isbn(isbn) else "invalid ISBN") return return_val + 'ISBNs are inequal)' elif value: return '%s (note: invalid ISBN)' % value elif field == 'barcode': if value: barcodes = value.split(';') return_val = show_barcode(value) + ' (note: ' for barcode in barcodes: return_val = return_val + '%s; ' % ( "valid UPC/EAN part" if valid_barcode(barcode) else "invalid UPC/EAN part or non-standard") return return_val[:-2] + ')' elif field == 'leading_article': if value is True: return 'Yes (sorted as: %s)' % remove_leading_article( revision.name) else: return 'No' elif field in [ 'has_barcode', 'has_isbn', 'has_issue_title', 'has_indicia_frequency', 'has_volume', 'has_rating' ]: if hasattr(revision, 'changed'): if revision.changed[field] and value is False: kwargs = {field[4:]: ''} if field[4:] == 'issue_title': kwargs = {'title': ''} if revision.series: value_count = revision.series.active_issues()\ .exclude(**kwargs).count() if value_count: return 'No (note: %d issues have a non-empty %s value)' % \ (value_count, field[4:]) return yesno(value, 'Yes,No') elif field == 'is_singleton': if hasattr(revision, 'changed'): if revision.changed[field] and value is True: if revision.series: value_count = revision.series.active_base_issues().count() if value_count != 1: return 'Yes (note: the series has %d issue%s)' % \ (value_count, pluralize(value_count)) elif revision.series.active_issues()\ .exclude(indicia_frequency='').count(): return 'Yes (note: the issue has an indicia frequency)' return yesno(value, 'Yes,No') elif field == 'after' and not hasattr(revision, 'changed'): # for previous revision (no attr changed) display empty string return '' elif field == 'cr_creator_names': creator_names = ", ".join(value.all().values_list('name', flat=True)) return creator_names elif field == 'creator_name': creator_names = "; ".join(value.all().values_list('name', flat=True)) return creator_names elif field == 'feature_object': features = "; ".join(value.all().values_list('name', flat=True)) return features elif field == 'feature_logo': features = "; ".join(value.all().values_list('name', flat=True)) return features elif field == 'indicia_printer': features = "; ".join(value.all().values_list('name', flat=True)) return features elif field == 'feature' and \ revision._meta.model_name == 'featurelogorevision': features = '' for feature in value.all(): features += absolute_url(feature) + '; ' if features: features = features[:-2] return mark_safe(features) return value
def field_value(revision, field): value = getattr(revision, field) if field in ['is_surrogate', 'no_volume', 'display_volume_with_number', 'no_brand', 'page_count_uncertain', 'title_inferred', 'no_barcode', 'no_indicia_frequency', 'no_isbn', 'year_began_uncertain', 'year_ended_uncertain', 'on_sale_date_uncertain', 'is_comics_publication']: return yesno(value, 'Yes,No') elif field in ['is_current']: res_holder_display = '' if revision.previous(): reservation = revision.source.get_ongoing_reservation() if revision.previous().is_current and not value and reservation: res_holder = reservation.indexer res_holder_display = ' (ongoing reservation held by %s %s)' % \ (res_holder.first_name, res_holder.last_name) return yesno(value, 'Yes,No') + res_holder_display elif field in ['publisher', 'indicia_publisher', 'series', 'origin_issue', 'target_issue']: return absolute_url(value) elif field in ['origin', 'target']: return value.full_name_with_link() elif field == 'brand': if value and value.emblem: return mark_safe('<img src="' + value.emblem.icon.url + '"> ' \ + absolute_url(value)) return absolute_url(value) elif field in ['notes', 'tracking_notes', 'publication_notes', 'characters', 'synopsis']: return linebreaksbr(value) elif field == 'reprint_notes': reprint = '' if value.strip() != '': for string in split_reprint_string(value): string = string.strip() reprint += '<li> ' + esc(string) + ' </li>' if reprint != '': reprint = '<ul>' + reprint + '</ul>' return mark_safe(reprint) elif field in ['url']: return urlize(value) elif field in ['indicia_pub_not_printed']: return yesno(value, 'Not Printed,Printed') elif field == 'group': brand_groups = '' for brand in value.all(): brand_groups += absolute_url(brand) + '; ' if brand_groups: brand_groups = brand_groups[:-2] return mark_safe(brand_groups) elif field in ['no_editing', 'no_script', 'no_pencils', 'no_inks', 'no_colors', 'no_letters']: return yesno(value, 'X, ') elif field in ['page_count']: if revision.source_name == 'issue' and \ revision.changeset.storyrevisions.count(): # only calculate total sum for issue not sequences total_pages = sum_page_counts(revision.active_stories()) if revision.variant_of: if revision.changeset.issuerevisions.count() > 1: stories = revision.changeset.storyrevisions\ .exclude(issue=revision.issue) else: stories = revision.variant_of.active_stories() if revision.active_stories().count(): # variant has cover sequence, add page counts without cover stories = stories.exclude(sequence_number=0) total_pages += sum_page_counts(stories) else: # variant has no extra cover sequence total_pages = sum_page_counts(stories) sum_story_pages = format_page_count(total_pages) return u'%s (note: total sum of story page counts is %s)' % \ (format_page_count(value), sum_story_pages) return format_page_count(value) elif field == 'isbn': if value: if validated_isbn(value): return u'%s (note: valid ISBN)' % show_isbn(value) elif len(value.split(';')) > 1: return_val = show_isbn(value) + ' (note: ' for isbn in value.split(';'): return_val = return_val + u'%s; ' % ("valid ISBN" \ if validated_isbn(isbn) else "invalid ISBN") return return_val + 'ISBNs are inequal)' elif value: return u'%s (note: invalid ISBN)' % value elif field == 'barcode': if value: barcodes = value.split(';') return_val = show_barcode(value) + ' (note: ' for barcode in barcodes: return_val = return_val + u'%s; ' % ("valid UPC/EAN part" \ if valid_barcode(barcode) \ else "invalid UPC/EAN part or non-standard") return return_val[:-2] + ')' elif field == 'leading_article': if value == True: return u'Yes (sorted as: %s)' % remove_leading_article(revision.name) else: return u'No' elif field in ['has_barcode', 'has_isbn', 'has_issue_title', 'has_indicia_frequency', 'has_volume', 'has_rating']: if hasattr(revision, 'changed'): if revision.changed[field] and value == False: kwargs = {field[4:]: ''} if field[4:] == 'issue_title': kwargs = {'title': ''} if revision.series: value_count = revision.series.active_issues()\ .exclude(**kwargs).count() if value_count: return 'No (note: %d issues have a non-empty %s value)' % \ (value_count, field[4:]) return yesno(value, 'Yes,No') elif field == 'is_singleton': if hasattr(revision, 'changed'): if revision.changed[field] and value == True: if revision.series: value_count = revision.series.active_base_issues().count() if value_count != 1: return 'Yes (note: the series has %d issue%s)' % \ (value_count, pluralize(value_count)) elif revision.series.active_issues()\ .exclude(indicia_frequency='').count(): return 'Yes (note: the issue has an indicia frequency)' return yesno(value, 'Yes,No') elif field == 'after' and not hasattr(revision, 'changed'): # for previous revision (no attr changed) display empty string return '' return value