Skip to content

Commit

Permalink
Added Display Title
Browse files Browse the repository at this point in the history
  • Loading branch information
zserhan committed Mar 16, 2022
1 parent ae2efed commit 80bd3d6
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 7 deletions.
1 change: 1 addition & 0 deletions content_management/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def set_file_name(self, file_name):
filesize = models.FloatField(null=True, editable=True)
file_name = models.CharField(max_length=500, null=True)
title = models.CharField(max_length=300)
display_title = models.CharField(max_length=300, default="")
description = models.TextField(null=True)
modified_on = models.DateTimeField(default=datetime.now)
metadata = models.ManyToManyField(Metadata, blank=True)
Expand Down
2 changes: 1 addition & 1 deletion content_management/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class ContentSerializer(ModelSerializer):
class Meta:
model = Content
fields = ('id', 'file_name', 'content_file', 'title', 'description', 'modified_on', 'copyright_notes',
fields = ('id', 'file_name', 'content_file', 'title', 'display_title', 'description', 'modified_on', 'copyright_notes',
'rights_statement', 'published_date', 'active', 'metadata', 'additional_notes', 'metadata_info',
"published_year", "filesize", "reviewed_on", 'duplicatable')

Expand Down
13 changes: 11 additions & 2 deletions content_management/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def upload_sheet_contents(self, sheet_contents):
try:
content = Content()
content.title = each_content.get("Title")
if each_content.get("Display Title"):
content.display_title = each_content.get("Display Title")
else:
content.display_title = each_content.get("Title")
content.description = each_content.get("Description")
content.copyright_notes = each_content.get("Copyright Notes")
content.reviewed_on = datetime.datetime.now()
Expand Down Expand Up @@ -96,6 +100,10 @@ def upload_sheet_contents(self, sheet_contents):
else:
try:
content.description = each_content.get("Description")
if each_content.get("Display Title"):
content.display_title = each_content.get("Display Title")
else:
content.display_title = each_content.get("Title")
content.copyright_notes = each_content.get("Copyright Notes")
content.reviewed_on = datetime.datetime.now()
content.rights_statement = each_content.get("Rights Statement")
Expand Down Expand Up @@ -187,7 +195,8 @@ def build_library(self):
'logo_img__image_file'))

contents = self.add_keywords(
Content.objects.filter(libraryfolder__version_id=self.version.id).values('id', 'title',
Content.objects.filter(libraryfolder__version_id=self.version.id).values('id',
'display_title',
'description',
'file_name',
'published_date',
Expand All @@ -198,7 +207,7 @@ def build_library(self):
.filter(metadata_id__in=metadata.values_list('id')).values_list('content_id', 'metadata_id').distinct()
contents_folder = LibraryFolder.library_content.through.objects.filter(
libraryfolder__version_id=self.version.id) \
.values_list('content_id', 'libraryfolder_id', 'content__title', 'content__file_name',
.values_list('content_id', 'libraryfolder_id', 'content__display_title', 'content__file_name',
'content__filesize').distinct()
db_util = LibraryDbUtil(metadata_types, metadata, folders, modules, contents, contents_metadata,
contents_folder)
Expand Down
8 changes: 6 additions & 2 deletions content_management/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ def get_queryset(self):
title = self.request.GET.get("title", None)
if title != None:
queryset = queryset.filter(title__icontains=title)


display_title = self.request.GET.get("display_title", None)
if display_title != None:
queryset = queryset.filter(display_title__icontains=display_title)

file_name = self.request.GET.get("file_name", None)
if file_name != None:
queryset = queryset.filter(file_name__icontains=file_name)
Expand Down Expand Up @@ -195,7 +199,7 @@ def get_spreadsheet(self, request):
worksheet = workbook.add_worksheet()

content_fields = [
"title", "file_name", "description", "modified_on", "copyright_notes",
"title", "display_title", "file_name", "description", "modified_on", "copyright_notes",
"rights_statement", "additional_notes", "published_date", "reviewed_on", "active",
"duplicatable", "filesize"
]
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/js/content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export default class Content extends Component<ContentProps, ContentState> {
filesize: 0,
content_file: "",
title: "",
display_title: "",
description: null,
modified_on: "",
reviewed_on: "",
Expand Down Expand Up @@ -335,6 +336,7 @@ export default class Content extends Component<ContentProps, ContentState> {
validators={{
content_file: VALIDATORS.ADD_FILE,
title: VALIDATORS.TITLE,
display_title: VALIDATORS.DISPLAY_TITLE,
description: VALIDATORS.DESCRIPTION,
year: VALIDATORS.YEAR,
reviewed_on: VALIDATORS.REVIEWED_ON,
Expand Down Expand Up @@ -362,6 +364,7 @@ export default class Content extends Component<ContentProps, ContentState> {
validators={{
content_file: VALIDATORS.EDIT_FILE,
title: VALIDATORS.TITLE,
display_title: VALIDATORS.DISPLAY_TITLE,
description: VALIDATORS.DESCRIPTION,
year: VALIDATORS.YEAR,
reviewed_on: VALIDATORS.REVIEWED_ON,
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/js/context/global_state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default class GlobalState extends React.Component<GlobalStateProps, Globa
reviewed_from: null,
reviewed_to: null,
title: "",
display_title: "",
years_from: null,
years_to: null,
duplicatable: "all"
Expand Down Expand Up @@ -303,6 +304,7 @@ export default class GlobalState extends React.Component<GlobalStateProps, Globa
file_sizes,
reviewed_on,
title: search.title,
display_title: search.display_title,
copyright_notes: search.copyright_notes,
//Turn metadata_dict back to array of integers for search
metadata: Object.keys(search.metadata).reduce((prev, current) => {
Expand Down Expand Up @@ -375,7 +377,7 @@ export default class GlobalState extends React.Component<GlobalStateProps, Globa
async add_content(fields: content_fields) {
const form_data = new FormData()
form_data.append('title', fields.title)

form_data.append('display_title', fields.display_title)
if (!fields.content_file) {
Promise.reject("No Content File")
} else {
Expand Down Expand Up @@ -410,6 +412,7 @@ export default class GlobalState extends React.Component<GlobalStateProps, Globa
form_data.append("content_file", fields.content_file)
}
form_data.append('title', fields.title)
form_data.append('display_title', fields.display_title)
form_data.append('description', fields.description)
form_data.append('published_date', `${fields.year}-01-01`)
if (fields.reviewed_on) {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/js/libraries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export default class Libraries extends React.Component<LibrariesProps, Libraries
filesize: 0,
content_file: "",
title: "",
display_title: "",
description: null,
modified_on: "",
reviewed_on: "",
Expand Down
17 changes: 17 additions & 0 deletions frontend/src/js/reusable/content_modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default class ContentModal extends Component<ContentModalProps, ContentMo
this.default_fields = {
content_file: get_field_info_default<File|null>(null),
title: get_field_info_default(""),
display_title: get_field_info_default(""),
description: get_field_info_default(""),
year: get_field_info_default(""),
reviewed_on: get_field_info_default(null),
Expand Down Expand Up @@ -101,6 +102,8 @@ export default class ContentModal extends Component<ContentModalProps, ContentMo
row.additional_notes === null? "" : row.additional_notes)
draft.fields.title = get_field_info_default(
row.title === null ? "" : row.title)
draft.fields.display_title = get_field_info_default(
row.display_title === null ? "" : row.display_title)
draft.fields.year = get_field_info_default(
row.published_year === null ? "" : row.published_year)
draft.fields.duplicatable = get_field_info_default(row.duplicatable)
Expand Down Expand Up @@ -171,6 +174,7 @@ export default class ContentModal extends Component<ContentModalProps, ContentMo
}

formData.append('title', this.state.fields.title.value)
formData.append('display_title', this.state.fields.display_title.value)
formData.append('description', this.state.fields.description.value)
formData.append('duplicatable', this.state.fields.duplicatable.value ? "true" : "false")
formData.append('rights_statement', this.state.fields.rights_statement.value)
Expand Down Expand Up @@ -251,6 +255,19 @@ export default class ContentModal extends Component<ContentModalProps, ContentMo
})
}}
/>,
<TextField
fullWidth
error={this.state.fields.display_title.reason !== ""}
helperText={this.state.fields.display_title.reason}
label={"Display Title"}
value={this.state.fields.display_title.value}
onChange={(evt) => {
evt.persist()
this.update_state(draft => {
draft.fields.display_title.value = evt.target.value
})
}}
/>,
<TextField
fullWidth
error={this.state.fields.description.reason !== ""}
Expand Down
13 changes: 13 additions & 0 deletions frontend/src/js/reusable/content_search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,19 @@ export default class ContentSearch extends Component<ContentSearchProps, Content
}}
/>
</Grid>
<Grid item xs={4}>
<TextField
fullWidth
label={"Display Title"}
value={contents_api.state.search.display_title}
onChange={(evt) => {
evt.persist()
contents_api.update_search_state(draft => {
draft.display_title = evt.target.value
})
}}
/>
</Grid>
<Grid item xs={4}>
<TextField
fullWidth
Expand Down
1 change: 1 addition & 0 deletions frontend/src/js/reusable/view_content_modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const ViewContentModal = ({
<Grid item xs={4}>
{[
["Title", row.title],
["Display Title", row.display_title],
["Description", row.description],
["Filename", <a href={new URL(row.file_name, APP_URLS.CONTENT_FOLDER).href}>{row.file_name}</a>],
["Year of Publication", row.published_year],
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/js/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ interface SerializedMetadata {

type content_filters = {
title?: string
display_title?: string
years?: [number|null, number|null]
file_sizes?: [number|null, number|null]
reviewed_on?: [Date|null, Date|null]
Expand All @@ -46,6 +47,7 @@ interface SerializedContent {
filesize: number
content_file: string
title: string
display_title: string
description: string|null
modified_on: string
reviewed_on: string
Expand Down Expand Up @@ -286,6 +288,7 @@ type field_info<T> = {
type content_fields = {
content_file: File|null
title: string
display_title: string
description: string
year: string
reviewed_on: Date|null
Expand All @@ -299,6 +302,7 @@ type content_fields = {
type active_search_option = "active" | "inactive" | "all"
type search_state = {
title: string
display_title: string
copyright_notes: string
years_from: number | null
years_to: number | null
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/js/urls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ function url_with_params(urlstr: string, params:[string, any][]=[]) {
function get_filters_arr(page?: number, size?: number, filters?: content_filters, exclude_if_in_version?: LibraryVersion): [string, any][] {
const content_filter = filters || {}
const {
title, years, filename, copyright_notes, active, metadata, sort, file_sizes, reviewed_on, duplicatable
title, display_title, years, filename, copyright_notes, active, metadata, sort, file_sizes, reviewed_on, duplicatable
} = content_filter
const filters_arr: [string, any][] = page !== undefined ?
[["page", `${page}`], ["size", `${size}`]] :
[]

if (!isUndefined(title) && title !== "") filters_arr.push(["title", title])
if (!isUndefined(display_title) && display_title !== "") filters_arr.push(["display_title", display_title])
if (!isUndefined(years)) {
if(years[0] !== null) filters_arr.push(["published_year_from", `${years[0]}`])
if(years[1] !== null) filters_arr.push(["published_year_to", `${years[1]}`])
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/js/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ export default class VALIDATORS {
}
return ""
}
static DISPLAY_TITLE(display_title_str: any): string {
if (display_title_str === "") {
return "Field Required"
}
if (display_title_str.length > 300) {
return "Title must be less than 300 characters"
}
return ""
}
static DESCRIPTION(_description_str: any): string {
return ""
}
Expand Down

0 comments on commit 80bd3d6

Please sign in to comment.