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

Create form for create and update post #32

Merged
merged 1 commit into from
Jul 12, 2018
Merged

Conversation

serhii73
Copy link
Member

@serhii73 serhii73 commented Jun 1, 2018

No description provided.

@serhii73
Copy link
Member Author

serhii73 commented Jun 2, 2018

@webknjaz we can merge this Django project in master?

@webknjaz
Copy link
Member

webknjaz commented Jun 2, 2018

No

webknjaz
webknjaz previously approved these changes Jun 15, 2018
Copy link
Member

@webknjaz webknjaz left a comment

Choose a reason for hiding this comment

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

Let's do rebase and commits cleanup in each PR before merging from now on.

blog/forms.py Outdated
"""Create and edit form."""

class Meta:
"""Build form on the model and with the fields."""
Copy link
Member

Choose a reason for hiding this comment

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

It's not an action.

blog/forms.py Outdated


class PostForm(forms.ModelForm):
"""Create and edit form."""
Copy link
Member

Choose a reason for hiding this comment

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

It's not an action, but entity.

Copy link
Member Author

Choose a reason for hiding this comment

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

@webknjaz Creating and editing forms. ? Is good doc for this class?

href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet"
href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<link href='//fonts.googleapis.com/css?family=Lobster&subset=latin,latin-ext'
Copy link
Member

Choose a reason for hiding this comment

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

Don't mix different quotation styles.

{% endif %}
{% if user.is_authenticated %}
<a class="btn btn-default"
href="{% url 'post_edit' pk=post.pk %}"><span
Copy link
Member

Choose a reason for hiding this comment

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

Reformat this with the hierarchy in mind, not just do a new line on random space.

Copy link
Member Author

Choose a reason for hiding this comment

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

@webknjaz Sorry?

@serhii73
Copy link
Member Author

@webknjaz I fixed all problems.

@serhii73 serhii73 force-pushed the feature/6/django_forms branch 4 times, most recently from f05021a to ddb151f Compare June 17, 2018 09:21
blog/views.py Outdated
@@ -1,3 +1,50 @@
"""Views for the blog app."""
from django.shortcuts import render, get_object_or_404
from django.utils import timezone
from .models import Post
Copy link
Member

Choose a reason for hiding this comment

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

Don't mix app imports with framework imports.

blog/views.py Outdated

def post_list(request):
"""Show list posts on the page."""
posts = Post.objects.filter(published_date__lte=timezone.now()).order_by(
Copy link
Member

Choose a reason for hiding this comment

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

Better readable:

    posts = (
        Post.objects.
        filter(published_date__lte=timezone.now()).
        order_by('-published_date')
    )

{% for post in posts %}
<div class="post">
<div class="date">
<p>Опубликовано: {{ post.published_date }}</p>
Copy link
Member

Choose a reason for hiding this comment

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

Please replace all translatable strings with i18n ({% trans "Posted on:" %}).
This requires {% load i18n %}.

{% if user.is_authenticated %}
<a class="btn btn-default"
href="{% url 'post_edit' pk=post.pk %}"><span
class="glyphicon glyphicon-pencil"></span></a>
Copy link
Member

Choose a reason for hiding this comment

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

make this nicer

<div class="page-header">
{% if user.is_authenticated %}
<a href="{% url 'post_new' %}" class="top-menu"><span
class="glyphicon glyphicon-plus"></span></a>
Copy link
Member

Choose a reason for hiding this comment

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

this kind of nesting is unreadable

Copy link
Member

@webknjaz webknjaz left a comment

Choose a reason for hiding this comment

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

And add pyflakes to pre-commit.

@serhii73
Copy link
Member Author

@webknjaz Sorry,

pyflakes - This hook runs pyflakes. (This is deprecated, use flake8).

from pre-commit.com/hooks.html
If I right to understand it says here that I need to use flake8 and my code has it.

@webknjaz
Copy link
Member

It uses only a limited subset of pyflakes. try pylint then

Copy link
Member

@webknjaz webknjaz left a comment

Choose a reason for hiding this comment

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

use i18n in all other places.

@serhii73
Copy link
Member Author

@webknjaz

It uses only a limited subset of pyflakes. try pylint then

I need to create a new branch or add pylint to pre-commit here?

@webknjaz
Copy link
Member

Let's do it here

@@ -1,4 +1,7 @@
{% load staticfiles %}

{% load i18n %}
Copy link
Member

Choose a reason for hiding this comment

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

Wrap all strings.

@serhii73
Copy link
Member Author

************* Module blog.admin
E:  4, 0: Unable to import 'django.contrib' (import-error)
************* Module blog.apps
E:  2, 0: Unable to import 'django.apps' (import-error)
R:  5, 0: Too few public methods (0/2) (too-few-public-methods)
************* Module blog.forms
E:  2, 0: Unable to import 'django' (import-error)
R:  9, 4: Too few public methods (0/2) (too-few-public-methods)
R:  6, 0: Too few public methods (0/2) (too-few-public-methods)
************* Module blog.migrations.0001_initial
C: 30, 0: Wrong continued indentation (remove 3 spaces).
                    models.DateTimeField(blank=True, null=True)),
                 |  ^ (bad-continuation)
C:  1, 0: Module name "0001_initial" doesn't conform to snake_case naming style (invalid-name)
C:  1, 0: Missing module docstring (missing-docstring)
E:  3, 0: Unable to import 'django.conf' (import-error)
E:  4, 0: Unable to import 'django.db' (import-error)
E:  5, 0: Unable to import 'django.db.models.deletion' (import-error)
E:  6, 0: Unable to import 'django.utils.timezone' (import-error)
C:  9, 0: Missing class docstring (missing-docstring)
R:  9, 0: Too few public methods (0/2) (too-few-public-methods)
************* Module blog.models
C: 13, 0: Wrong hanging indentation (remove 4 spaces).
            default=timezone.now)
        |   ^ (bad-continuation)
C: 15, 0: Wrong hanging indentation (remove 4 spaces).
            blank=True, null=True)
        |   ^ (bad-continuation)
E:  2, 0: Unable to import 'django.db' (import-error)
E:  3, 0: Unable to import 'django.utils' (import-error)
************* Module blog.urls
E:  2, 0: Unable to import 'django.urls' (import-error)
C:  6, 0: Constant name "urlpatterns" doesn't conform to UPPER_CASE naming style (invalid-name)
************* Module blog.views
E:  2, 0: Unable to import 'django.shortcuts' (import-error)
E:  3, 0: Unable to import 'django.utils' (import-error)
C: 19, 0: Argument name "pk" doesn't conform to snake_case naming style (invalid-name)
C: 40, 0: Argument name "pk" doesn't conform to snake_case naming style (invalid-name)
************* Module mysite.urls
E:  2, 0: Unable to import 'django.contrib' (import-error)
E:  3, 0: Unable to import 'django.urls' (import-error)
C:  5, 0: Constant name "urlpatterns" doesn't conform to UPPER_CASE naming style (invalid-name)
************* Module mysite.wsgi
E: 12, 0: Unable to import 'django.core.wsgi' (import-error)
C: 16, 0: Constant name "application" doesn't conform to UPPER_CASE naming style (invalid-name)
-----------------------------------
Your code has been rated at 1.35/10
No config file found, using default configuration

pre-commit/pre-commit-hooks#157 - Do I need to use a local hook? - https://github.com/Yelp/venv-update/blob/de9e1befdecf448cf02ceb5c57a30bcc88a58c06/.pre-commit-config.yaml#L30-L36
Or maybe to add other hooks instead pylint? - https://pre-commit.com/hooks.html

@serhii73 serhii73 force-pushed the feature/6/django_forms branch 2 times, most recently from 7aab1c1 to 564a3b3 Compare June 19, 2018 11:40
@serhii73
Copy link
Member Author

@webknjaz Hi. What do you say about the code? Good now or still bad?
And what I need to do with pylint? Maybe add instead another checking instrument?
Because pylint not good working.

.travis.yml Outdated
before_install:
- pip install -U pre-commit
- pip install pylint-django==0.11.1
- pip install -r requirements.txt
Copy link
Member

Choose a reason for hiding this comment

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

Why did you split just one requirement into a file, while listing others outside of it? Be consistent.

@webknjaz
Copy link
Member

clean-up your commits

@serhii73
Copy link
Member Author

@webknjaz Now is good?

"".join([os.getenv("HOME"), "/virtualenv/python", platform.python_version(),
"/lib/python", ".".join(platform.python_version_tuple()[:2]), "/site-packages"])
if os.getenv("TRAVIS") else
"/home/sergey/.virtualenv/django_girls/lib/python3.6/site-packages".format(os.getcwd())
Copy link
Member

Choose a reason for hiding this comment

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

NEVER hardcode paths. Also, you inject current working directory from os.getcwd() to nowhere.

{% load i18n %}

{% block content %}
<h1>New post</h1>
Copy link
Member

Choose a reason for hiding this comment

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

i18n.

blog/views.py Outdated
from .models import Post


def post_list(request):
Copy link
Member

Choose a reason for hiding this comment

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

This is unrelated to the PR purpose. You need to merge #25/#24 first.
To simplify things, move pylint integration commit into a separate PR and let's merge it before other things.

@serhii73
Copy link
Member Author

@webknjaz done.

Copy link
Member

@webknjaz webknjaz left a comment

Choose a reason for hiding this comment

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

not done.

@serhii73 serhii73 force-pushed the feature/6/django_forms branch 2 times, most recently from 4b1a716 to 2eeb8fb Compare July 6, 2018 18:03
@serhii73
Copy link
Member Author

serhii73 commented Jul 6, 2018

@webknjaz Done.

Copy link
Member

@webknjaz webknjaz left a comment

Choose a reason for hiding this comment

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

fix docstrings

blog/forms.py Outdated
"""Class form based on the model."""

class Meta:
"""Description metadata."""
Copy link
Member

Choose a reason for hiding this comment

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

which description?

blog/forms.py Outdated


class PostForm(forms.ModelForm):
"""Class form based on the model."""
Copy link
Member

Choose a reason for hiding this comment

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

i see that it's a class, it's stated one line above. anything useful you want to tell me with this?

blog/forms.py Outdated
@@ -0,0 +1,14 @@
"""Creating and editing forms."""
Copy link
Member

Choose a reason for hiding this comment

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

Is it a prose or a module description? It's not an action, it's a module.

mysite/urls.py Outdated
@@ -4,5 +4,5 @@

urlpatterns = [
path('admin/', admin.site.urls),
path(r'', include('blog.urls')),
path('', include('blog.urls')),
Copy link
Member

Choose a reason for hiding this comment

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

How is this change related to this PR?

@serhii73
Copy link
Member Author

@webknjaz what do you think now about the code?

@webknjaz
Copy link
Member

I think that you need to read all comments, not just ones you like.

Copy link
Member

@webknjaz webknjaz left a comment

Choose a reason for hiding this comment

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

Fix comments

blog/forms.py Outdated
@@ -0,0 +1,14 @@
"""The module has forms who saved in DB and will be shown in HTML file."""
Copy link
Member

Choose a reason for hiding this comment

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

Mind your grammar

blog/forms.py Outdated


class PostForm(forms.ModelForm):
"""Form for our Post model."""
Copy link
Member

Choose a reason for hiding this comment

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

"our"? whose?

blog/forms.py Outdated
"""Form for our Post model."""

class Meta:
"""Description Post's metadata."""
Copy link
Member

Choose a reason for hiding this comment

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

Docstring is a description, it's obvious.

blog/forms.py Outdated
"""Form for Post model."""

class Meta:
"""Configuration for form."""
Copy link
Member

Choose a reason for hiding this comment

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

of

blog/forms.py Outdated


class PostForm(forms.ModelForm):
"""Form for Post model."""
Copy link
Member

Choose a reason for hiding this comment

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

Forget about model, it's about visual effect.

Copy link
Member

@webknjaz webknjaz left a comment

Choose a reason for hiding this comment

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

same

Copy link
Member

@webknjaz webknjaz left a comment

Choose a reason for hiding this comment

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

Now, fix the last comment left.

@serhii73 serhii73 force-pushed the feature/6/django_forms branch 2 times, most recently from 7c48045 to 74ea5eb Compare July 12, 2018 16:49
@webknjaz webknjaz merged commit 2370d29 into master Jul 12, 2018
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.

None yet

2 participants