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

Refactor company app and updates throughout to make flake8/black pass #21

Merged
merged 3 commits into from
Jul 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Our stuff...

djangodenmark/settings/local.py
djangodenmark/media

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repos:
- id: end-of-file-fixer
exclude: "^(.tx/.*|.*\\.map)$"
- repo: https://github.com/psf/black
rev: 20.8b1
rev: 21.6b0
hooks:
- id: black
language_version: python3
Expand Down
10 changes: 10 additions & 0 deletions company/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.forms import ModelForm

from .models import Company


class CompanyForm(ModelForm):
class Meta:
model = Company
exclude = ("user", "created_at")
fields = "__all__"
38 changes: 21 additions & 17 deletions company/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# Generated by Django 3.2 on 2021-05-18 11:26
# Generated by Django 3.2.5 on 2021-07-10 21:44
import django.core.validators
import django.db.models.deletion
from django.conf import settings
from django.db import migrations
from django.db import models

import company.models


class Migration(migrations.Migration):

Expand All @@ -29,36 +27,42 @@ class Migration(migrations.Migration):
verbose_name="ID",
),
),
("logoImage", models.ImageField(null=True, upload_to="images/")),
("companyName", models.CharField(max_length=145)),
("description", models.TextField()),
(
"websiteURL",
"logo_image",
models.ImageField(
null=True, upload_to="images/", verbose_name="Company logo"
),
),
(
"company_name",
models.CharField(max_length=145, verbose_name="Company name"),
),
("description", models.TextField(verbose_name="Describe your company")),
(
"website_url",
models.URLField(
blank=True,
max_length=100,
validators=[
django.core.validators.RegexValidator(
code="invalid_url",
message="Website URL must include https:// or http://",
regex="[http]",
)
],
verbose_name="Link to your website",
),
),
("relationToDjango", models.TextField()),
(
"phoneNumber",
"relation_to_django",
models.TextField(verbose_name="Your relation to Django"),
),
("email", models.EmailField(max_length=100)),
(
"main_contact",
models.CharField(
max_length=15, validators=[company.models.only_int]
max_length=100, verbose_name="The main point of contact"
),
),
("email", models.EmailField(max_length=100)),
("mainContact", models.CharField(max_length=50)),
("streetName", models.CharField(max_length=45)),
("houseNumber", models.IntegerField()),
("postalCode", models.IntegerField()),
("region", models.CharField(max_length=45)),
("created_at", models.DateTimeField(auto_now_add=True)),
(
"user",
Expand Down
79 changes: 0 additions & 79 deletions company/migrations/0002_auto_20210506_1337.py

This file was deleted.

26 changes: 0 additions & 26 deletions company/migrations/0003_alter_company_phonenumber.py

This file was deleted.

18 changes: 0 additions & 18 deletions company/migrations/0004_alter_company_phonenumber.py

This file was deleted.

36 changes: 0 additions & 36 deletions company/migrations/0005_auto_20210518_1126.py

This file was deleted.

77 changes: 18 additions & 59 deletions company/models.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
from django.contrib.auth.models import User
from django.core.exceptions import ValidationError
from django.core.validators import RegexValidator
from django.db import models
from django.forms import ModelForm


def only_int(value):
"""function for valid phonenumber only contains numbers"""
if not value.isdigit():
raise ValidationError("Phone number must only contain numbers.")


class Company(models.Model):

user = models.ForeignKey(User, on_delete=models.CASCADE, default=None)
logoImage = models.ImageField(upload_to="images/", null=True)
companyName = models.CharField(max_length=145)
description = models.TextField()
websiteURL = models.URLField(
max_length=100,
logo_image = models.ImageField(
upload_to="images/",
null=True,
verbose_name="Company logo",
)
company_name = models.CharField(max_length=145, verbose_name="Company name")
description = models.TextField(verbose_name="Describe your company")
website_url = models.URLField(
max_length=200,
blank=True,
validators=[
RegexValidator(
Expand All @@ -27,54 +23,17 @@ class Company(models.Model):
code="invalid_url",
),
],
verbose_name="Link to your website",
)
relation_to_django = models.TextField(
verbose_name="Your relation to Django",
)
relationToDjango = models.TextField()
phoneNumber = models.CharField(max_length=15, blank=False, validators=[only_int])
email = models.EmailField(max_length=100)
mainContact = models.CharField(max_length=50)
streetName = models.CharField(max_length=45)
houseNumber = models.IntegerField()
postalCode = models.IntegerField()
region = models.CharField(max_length=45)
main_contact = models.CharField(
max_length=100,
verbose_name="The main point of contact",
)
created_at = models.DateTimeField(auto_now_add=True)

def __str__(self):
return "{} {} {} {} {} {} {} {} {} {} {} {} {}".format(
self.user,
self.companyName,
self.description,
self.websiteURL,
self.relationToDjango,
self.phoneNumber,
self.email,
self.mainContact,
self.streetName,
self.houseNumber,
self.postalCode,
self.region,
self.created_at,
)


class CompanyForm(ModelForm):
def init(self, args, **kwargs):
super(CompanyForm, self).__init__(args, **kwargs)

class Meta:
model = Company
exclude = ("user", "created_at")
fields = "__all__"
labels = {
"email": ("Email"),
"companyName": ("Company name"),
"logoImage": ("Company logo"),
"description": ("Describe your company"),
"websiteURL": ("Link to your website"),
"relationToDjango": ("Your relation to Django"),
"phoneNumber": ("Phone number"),
"mainContact": ("The main point of contact"),
"streetName": ("Street name"),
"houseNumber": ("House number"),
"postalCode": ("Postal code"),
"region": ("Region"),
}
return self.company_name
Loading