Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stb#537 Fix field types determination for Search class #315

Merged
merged 4 commits into from
Mar 29, 2019

Conversation

ArtemijRodionov
Copy link
Contributor

@ArtemijRodionov ArtemijRodionov self-assigned this Mar 28, 2019
@ArtemijRodionov ArtemijRodionov changed the title Stb#537 autocomplete Stb#537 Fix field types determination for Search class Mar 28, 2019
Copy link
Collaborator

@duker33 duker33 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proposal to redesign some code to OOP style

search/search.py Outdated
@@ -46,6 +46,20 @@ def trigram_search(query: str, queryset, fields: List[str]):
return queryset.annotate(similarity=trigram_query).order_by('-similarity')


def field_type(model, field):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

up to now we had convenient to use verbs as the first word of a function name.
So, let's call it get_field_type or change this convenient.
The both is ok for me, but convenient preserving should just cheaper.

Decide it plz

search/search.py Outdated
@@ -46,6 +46,20 @@ def trigram_search(query: str, queryset, fields: List[str]):
return queryset.annotate(similarity=trigram_query).order_by('-similarity')


def field_type(model, field):
"""Determine a type name of Django field."""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it'll be true OOP to create smth like this:

class FieldMeta:
	"""Django Model's field metadata."""
	
	TEXT_TYPES = ['CharField', 'TextField']
	
	def __init__(model, field: str):
		self.model = model
		self.field = field
		
	def type() -> str:
		# field_type() function code here
		...
		
	def is_text() -> bool:
		return self.type() in TEXT_TYPES

If you agree with it, pdd subtask would be good

@ArtemijRodionov ArtemijRodionov merged commit e49a28b into master Mar 29, 2019
@ArtemijRodionov ArtemijRodionov deleted the stb-537-autocomplete branch March 29, 2019 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants