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

#183 object compositions #194

Merged
merged 9 commits into from
Nov 4, 2018
Merged

#183 object compositions #194

merged 9 commits into from
Nov 4, 2018

Conversation

ArtemijRodionov
Copy link
Contributor

Closes #183

@ArtemijRodionov ArtemijRodionov self-assigned this Oct 8, 2018
@ArtemijRodionov ArtemijRodionov force-pushed the 183-object-compositions branch 5 times, most recently from cd9452d to 95f952d Compare October 8, 2018 17:35
@ArtemijRodionov ArtemijRodionov force-pushed the 183-object-compositions branch from 95f952d to 9e99cf1 Compare October 9, 2018 09:43
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.

some about naming and context concept

from .products import Products
from .tags import Tags

# @todo #183:60m Move context package to separate django app.
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think context should not be in separated django app. As we don't put all views or templates to separated apps


class Products(ModelContext):

def __init__(self, qs: QuerySet):
Copy link
Collaborator

Choose a reason for hiding this comment

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

every context should be able to receive another context

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The interface does not require it. A context implementation may have any constructor

Copy link
Collaborator

Choose a reason for hiding this comment

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

@artemiy312 , but we should be able to chain any context to any.
They may have no common methods, but theirs dicts should be merged.
There is initial idea: merge dicts with simple chaining

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@duker33 , a Contexts class suitable for this purpose

Copy link
Collaborator

Choose a reason for hiding this comment

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

@artemiy312 , y, it's much more good decision, then receiving contexts

}


class TagsByRaw(Tags):
Copy link
Collaborator

Choose a reason for hiding this comment

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

it's not clear what is raw. TagsDeserialised or docstring with comment like Deserialize tags from string

return self._qs.filter(slug__in=slugs)


class GroupTagsByProducts(Tags):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Group is verb, but we should start class name from noun (or create another convention about it).
So, i suggest TagsGroupedByProducts

class Checked404Tags(Tags):

def qs(self):
tags = self.qs()
Copy link
Collaborator

Choose a reason for hiding this comment

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

self.super.qs() or smth. Now it's infinity recursion

@@ -95,6 +95,7 @@ class ProductQuerySet(models.QuerySet):
def get_offset(self, start, step):
return self[start:start + step]

# @todo #183:60m Try to remove `ordering` arg from ProductQuerySet.get_by_category
Copy link
Collaborator

Choose a reason for hiding this comment

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

it's about 30 min i think. We should move it from model to context.
And use ready context arch for it

@duker33 duker33 added the discuss issue needs to finish discussion before start working label Oct 15, 2018
@ArtemijRodionov ArtemijRodionov force-pushed the 183-object-compositions branch 2 times, most recently from d0cb865 to e5e79aa Compare November 3, 2018 02:27
@ArtemijRodionov ArtemijRodionov force-pushed the 183-object-compositions branch 2 times, most recently from 71b896d to 9e48046 Compare November 3, 2018 03:17

def context(self):
return collections.ChainMap(
*[ctx.context() for ctx in self.contexts]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
*[ctx.context() for ctx in self.contexts]
iter(ctx.context() for ctx in self.contexts)

Copy link
Contributor Author

@ArtemijRodionov ArtemijRodionov Nov 4, 2018

Choose a reason for hiding this comment

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

I don't see the point. How iter can help here? ChainMap takes variadic dict as arguments, so i have to unpack contexts list


class Products(ModelContext):

def __init__(self, qs: QuerySet):
Copy link
Collaborator

Choose a reason for hiding this comment

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

@artemiy312 , y, it's much more good decision, then receiving contexts

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.

minor fix for Context class

@duker33 duker33 removed the discuss issue needs to finish discussion before start working label Nov 4, 2018
@ArtemijRodionov ArtemijRodionov force-pushed the 183-object-compositions branch from 9e48046 to a183f79 Compare November 4, 2018 14:46
@ArtemijRodionov ArtemijRodionov merged commit fb2fa2a into master Nov 4, 2018
@ArtemijRodionov ArtemijRodionov deleted the 183-object-compositions branch November 4, 2018 14:55
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