Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
jackton1 authored Jun 2, 2021
2 parents aadcaa4 + 281dd8b commit b8ee3bc
Show file tree
Hide file tree
Showing 29 changed files with 117 additions and 92 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/auto-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ jobs:
github.actor == 'dependabot' ||
github.actor == 'dependabot-preview[bot]' ||
github.actor == 'dependabot-preview' ||
github.actor == 'pre-commit-ci' ||
github.actor == 'pre-commit-ci[bot]' ||
github.actor == 'renovate[bot]' ||
github.actor == 'renovate'
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/greetings.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Greetings

on: [pull_request, issues]
on: [pull_request_target, issues]

jobs:
greeting:
Expand Down
30 changes: 18 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@ repos:
- id: autoflake
args: ['--in-place', '--remove-all-unused-imports', '--remove-unused-variable']

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: trailing-whitespace
exclude: ^docs/.*|.*.md
- id: end-of-file-fixer
exclude: ^docs/.*|.*.md
- repo: https://github.com/pycqa/isort
rev: 5.8.0
hooks:
- id: isort
args: ["--profile", "black", "--filter-files"]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: trailing-whitespace
exclude: ^docs/.*|.*.md
- id: end-of-file-fixer
exclude: ^docs/.*|.*.md

- repo: https://github.com/psf/black
rev: 21.5b1
hooks:
- id: black
language_version: python3
- repo: https://github.com/psf/black
rev: 21.5b2
hooks:
- id: black
language_version: python3
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,5 @@ lint-fix: ## Run black with inplace for model_clone and sample/models.py.
# --------- Docs ---------------------------------------
# -----------------------------------------------------------
serve-docs:
@npm i -g docsify-cli
@npx docsify serve ./docs
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
## django-clone
| Python | Django | Downloads |
|:---------:|:-------:|:-----------:|
| [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/django_clone.svg)](https://pypi.org/project/django-clone) | [![PyPI - Django Version](https://img.shields.io/pypi/djversions/django_clone.svg)](https://docs.djangoproject.com/en/3.0/releases/) | [![Downloads](https://pepy.tech/badge/django-clone)](https://pepy.tech/project/django-clone) |

Create copies of a model instance with explicit control on how the instance should be duplicated (limiting fields or related objects) copied and unique field detection.
| PyPI | Test | Vulnerabilities | Coverage | Code Quality |
|:---------------:|:----:|:---------------:|:--------:|:-------------:|
| [![PyPI version](https://badge.fury.io/py/django-clone.svg)](https://badge.fury.io/py/django-clone) | [![Test](https://github.com/tj-django/django-clone/workflows/Test/badge.svg)](https://github.com/tj-django/django-clone/actions?query=workflow%3ATest) | [![Known Vulnerabilities](https://snyk.io/test/github/tj-django/django-clone/badge.svg?targetFile=requirements.txt)](https://snyk.io/test/github/tj-django/django-clone?targetFile=requirements.txt) | [![Codacy Badge](https://app.codacy.com/project/badge/Coverage/b33dd02dbb034d7fa9886a99f5383ea6)](https://www.codacy.com/gh/tj-django/django-clone?utm_source=github.com\&utm_medium=referral\&utm_content=tj-django/django-clone\&utm_campaign=Badge_Coverage) <br/> [![codecov](https://codecov.io/gh/tj-django/django-clone/branch/main/graph/badge.svg?token=2NE21Oe50Q)](https://codecov.io/gh/tj-django/django-clone)| [![Codacy Badge](https://app.codacy.com/project/badge/Grade/b33dd02dbb034d7fa9886a99f5383ea6)](https://www.codacy.com/gh/tj-django/django-clone?utm_source=github.com\&utm_medium=referral\&utm_content=tj-django/django-clone\&utm_campaign=Badge_Grade)

| PyPI | Python | Django | Downloads |
|:------------------------------:|:---------:|:-------:|:-----------:|
| [![PyPI version](https://badge.fury.io/py/django-clone.svg)](https://badge.fury.io/py/django-clone) | [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/django_clone.svg)](https://pypi.org/project/django-clone) | [![PyPI - Django Version](https://img.shields.io/pypi/djversions/django_clone.svg)](https://docs.djangoproject.com/en/3.0/releases/) | [![Downloads](https://pepy.tech/badge/django-clone)](https://pepy.tech/project/django-clone) |
| Dependencies | Code Style | Pre-Commit |
|:--------------:|:-------------:|:-----------:|
| [![Updates](https://pyup.io/repos/github/tj-django/django-clone/shield.svg)](https://pyup.io/repos/github/tj-django/django-clone/) | [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) | [![pre-commit.ci status](https://results.pre-commit.ci/badge/github/tj-django/django-clone/main.svg)](https://results.pre-commit.ci/latest/github/tj-django/django-clone/main) |

| Test | Vulnerabilities | Coverage | Code Quality | Dependencies | Code Style | Pre-Commit |
|:----:|:---------------:|:--------:|:-------------:| :---------------:|:-------------:|:-----------:|
| [![Test](https://github.com/tj-django/django-clone/workflows/Test/badge.svg)](https://github.com/tj-django/django-clone/actions?query=workflow%3ATest) | [![Known Vulnerabilities](https://snyk.io/test/github/tj-django/django-clone/badge.svg?targetFile=requirements.txt)](https://snyk.io/test/github/tj-django/django-clone?targetFile=requirements.txt) | [![Codacy Badge](https://app.codacy.com/project/badge/Coverage/b33dd02dbb034d7fa9886a99f5383ea6)](https://www.codacy.com/gh/tj-django/django-clone?utm_source=github.com\&utm_medium=referral\&utm_content=tj-django/django-clone\&utm_campaign=Badge_Coverage) <br/> [![codecov](https://codecov.io/gh/tj-django/django-clone/branch/main/graph/badge.svg?token=2NE21Oe50Q)](https://codecov.io/gh/tj-django/django-clone)| [![Codacy Badge](https://app.codacy.com/project/badge/Grade/b33dd02dbb034d7fa9886a99f5383ea6)](https://www.codacy.com/gh/tj-django/django-clone?utm_source=github.com\&utm_medium=referral\&utm_content=tj-django/django-clone\&utm_campaign=Badge_Grade) | [![Updates](https://pyup.io/repos/github/tj-django/django-clone/shield.svg)](https://pyup.io/repos/github/tj-django/django-clone/) | [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) | [![pre-commit.ci status](https://results.pre-commit.ci/badge/github/tj-django/django-clone/main.svg)](https://results.pre-commit.ci/latest/github/tj-django/django-clone/main) |
## django-clone

Create copies of a model instance with explicit control on how the instance should be duplicated (limiting fields or related objects) copied and unique field detection.

## Table of contents

Expand Down Expand Up @@ -303,7 +307,7 @@ INSTALLED_APPS = [

## Found a Bug?

To file a bug or submit a patch, please head over to [django-clone on github](https://github.com/jackton1/django-clone/issues).
To file a bug or submit a patch, please head over to [django-clone on github](https://github.com/tj-django/django-clone/issues).

## Contributors ✨

Expand Down
22 changes: 13 additions & 9 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
## django-clone
| Python | Django | Downloads |
|:---------:|:-------:|:-----------:|
| [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/django_clone.svg)](https://pypi.org/project/django-clone) | [![PyPI - Django Version](https://img.shields.io/pypi/djversions/django_clone.svg)](https://docs.djangoproject.com/en/3.0/releases/) | [![Downloads](https://pepy.tech/badge/django-clone)](https://pepy.tech/project/django-clone) |

Create copies of a model instance with explicit control on how the instance should be duplicated (limiting fields or related objects) copied and unique field detection.
| PyPI | Test | Vulnerabilities | Coverage | Code Quality |
|:---------------:|:----:|:---------------:|:--------:|:-------------:|
| [![PyPI version](https://badge.fury.io/py/django-clone.svg)](https://badge.fury.io/py/django-clone) | [![Test](https://github.com/tj-django/django-clone/workflows/Test/badge.svg)](https://github.com/tj-django/django-clone/actions?query=workflow%3ATest) | [![Known Vulnerabilities](https://snyk.io/test/github/tj-django/django-clone/badge.svg?targetFile=requirements.txt)](https://snyk.io/test/github/tj-django/django-clone?targetFile=requirements.txt) | [![Codacy Badge](https://app.codacy.com/project/badge/Coverage/b33dd02dbb034d7fa9886a99f5383ea6)](https://www.codacy.com/gh/tj-django/django-clone?utm_source=github.com\&utm_medium=referral\&utm_content=tj-django/django-clone\&utm_campaign=Badge_Coverage) <br/> [![codecov](https://codecov.io/gh/tj-django/django-clone/branch/main/graph/badge.svg?token=2NE21Oe50Q)](https://codecov.io/gh/tj-django/django-clone)| [![Codacy Badge](https://app.codacy.com/project/badge/Grade/b33dd02dbb034d7fa9886a99f5383ea6)](https://www.codacy.com/gh/tj-django/django-clone?utm_source=github.com\&utm_medium=referral\&utm_content=tj-django/django-clone\&utm_campaign=Badge_Grade)

| PyPI | Python | Django | Downloads |
|:------------------------------:|:---------:|:-------:|:-----------:|
| [![PyPI version](https://badge.fury.io/py/django-clone.svg)](https://badge.fury.io/py/django-clone) | [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/django_clone.svg)](https://pypi.org/project/django-clone) | [![PyPI - Django Version](https://img.shields.io/pypi/djversions/django_clone.svg)](https://docs.djangoproject.com/en/3.0/releases/) | [![Downloads](https://pepy.tech/badge/django-clone)](https://pepy.tech/project/django-clone) |
| Dependencies | Code Style | Pre-Commit |
|:--------------:|:-------------:|:-----------:|
| [![Updates](https://pyup.io/repos/github/tj-django/django-clone/shield.svg)](https://pyup.io/repos/github/tj-django/django-clone/) | [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) | [![pre-commit.ci status](https://results.pre-commit.ci/badge/github/tj-django/django-clone/main.svg)](https://results.pre-commit.ci/latest/github/tj-django/django-clone/main) |

| Test | Vulnerabilities | Coverage | Code Quality | Dependencies | Code Style | Pre-Commit |
|:----:|:---------------:|:--------:|:-------------:| :---------------:|:-------------:|:-----------:|
| [![Test](https://github.com/tj-django/django-clone/workflows/Test/badge.svg)](https://github.com/tj-django/django-clone/actions?query=workflow%3ATest) | [![Known Vulnerabilities](https://snyk.io/test/github/tj-django/django-clone/badge.svg?targetFile=requirements.txt)](https://snyk.io/test/github/tj-django/django-clone?targetFile=requirements.txt) | [![Codacy Badge](https://app.codacy.com/project/badge/Coverage/b33dd02dbb034d7fa9886a99f5383ea6)](https://www.codacy.com/gh/tj-django/django-clone?utm_source=github.com\&utm_medium=referral\&utm_content=tj-django/django-clone\&utm_campaign=Badge_Coverage) <br/> [![codecov](https://codecov.io/gh/tj-django/django-clone/branch/main/graph/badge.svg?token=2NE21Oe50Q)](https://codecov.io/gh/tj-django/django-clone)| [![Codacy Badge](https://app.codacy.com/project/badge/Grade/b33dd02dbb034d7fa9886a99f5383ea6)](https://www.codacy.com/gh/tj-django/django-clone?utm_source=github.com\&utm_medium=referral\&utm_content=tj-django/django-clone\&utm_campaign=Badge_Grade) | [![Updates](https://pyup.io/repos/github/tj-django/django-clone/shield.svg)](https://pyup.io/repos/github/tj-django/django-clone/) | [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) | [![pre-commit.ci status](https://results.pre-commit.ci/badge/github/tj-django/django-clone/main.svg)](https://results.pre-commit.ci/latest/github/tj-django/django-clone/main) |
## django-clone

Create copies of a model instance with explicit control on how the instance should be duplicated (limiting fields or related objects) copied and unique field detection.

## Table of contents

Expand Down Expand Up @@ -303,7 +307,7 @@ INSTALLED_APPS = [

## Found a Bug?

To file a bug or submit a patch, please head over to [django-clone on github](https://github.com/jackton1/django-clone/issues).
To file a bug or submit a patch, please head over to [django-clone on github](https://github.com/tj-django/django-clone/issues).

## Contributors ✨

Expand Down
35 changes: 17 additions & 18 deletions docs/_sidebar.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
- [Installation](#installation)
* [Installation](#installation)

- [Usage](#usage)
* [Usage](#usage)

- [Inheriting from `CloneModel` or `CloneMixin`](#inheriting-from-clonemodel-or-clonemixin)
* [Subclassing the `CloneModel`](#subclassing-the-clonemodel)

- [Subclassing the `CloneModel`](#subclassing-the-clonemodel)
- [Using the `CloneMixin`](#using-the-clonemixin)
* [Using the `CloneMixin`](#using-the-clonemixin)

- [Duplicating a model instance](#duplicating-a-model-instance)
* [Duplicating a model instance](#duplicating-a-model-instance)

- [Bulk cloning a model](#bulk-cloning-a-model)
* [Bulk cloning a model](#bulk-cloning-a-model)

- [CloneMixin attributes](#clonemixin-attributes)
* [CloneMixin attributes](#clonemixin-attributes)

- [Explicit](#explicit)
- [Implicit](#implicit)
* [Explicit](#explicit)
* [Implicit](#implicit)

- [Creating clones without subclassing `CloneMixin`.](#creating-clones-without-subclassing-clonemixin)
* [Creating clones without subclassing `CloneMixin`.](#creating-clones-without-subclassing-clonemixin)

- [Django Admin](#django-admin)
* [Django Admin](#django-admin)

- [Duplicating Models from the Django Admin view.](#duplicating-models-from-the-django-admin-view)
* [Duplicating Models from the Django Admin view.](#duplicating-models-from-the-django-admin-view)

- [List View](#list-view)
- [Change View](#change-view)
* [List View](#list-view)
* [Change View](#change-view)

- [CloneModelAdmin class attributes](#clonemodeladmin-class-attributes)
* [CloneModelAdmin class attributes](#clonemodeladmin-class-attributes)

- [Found a Bug?](#found-a-bug)
* [Found a Bug?](#found-a-bug)

- [Contributors ✨](#contributors-)
* [Contributors ✨](#contributors-)
14 changes: 7 additions & 7 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<script>
window.$docsify = {
name: 'django-clone',
repo: 'https://github.com/jackton1/django-clone',
repo: 'https://github.com/tj-django/django-clone',
themeColor: "#42b983",
loadNavbar: true,
loadSidebar: true,
Expand All @@ -26,22 +26,22 @@
sidebarDisplayLevel: 2, // set sidebar display level
share: {
reddit: {
url: "https://github.com/jackton1/django-clone",
url: "https://github.com/tj-django/django-clone",
},
linkedin: {
url: "https://github.com/jackton1/django-clone",
url: "https://github.com/tj-django/django-clone",
},
facebook: {
url: "https://github.com/jackton1/django-clone",
url: "https://github.com/tj-django/django-clone",
},
twitter: {
url: "https://github.com/jackton1/django-clone",
url: "https://github.com/tj-django/django-clone",
},
whatsapp: {
url: "https://github.com/jackton1/django-clone",
url: "https://github.com/tj-django/django-clone",
},
telegram: {
url: "https://github.com/jackton1/django-clone",
url: "https://github.com/tj-django/django-clone",
},
},
copyCode: {
Expand Down
16 changes: 8 additions & 8 deletions model_clone/mixins/clone.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
from itertools import repeat
from typing import List, Optional, Dict
from typing import Dict, List, Optional

from conditional import conditional
from django.core.checks import Error
from django.core.exceptions import ValidationError
from django.db import transaction, models, IntegrityError, connections
from django.db import IntegrityError, connections, models, transaction
from django.db.models import SlugField
from django.utils.text import slugify

from model_clone.apps import ModelCloneConfig
from model_clone.utils import (
clean_value,
transaction_autocommit,
get_unique_value,
context_mutable_attribute,
get_fields_and_unique_fields_from_cls,
get_unique_value,
transaction_autocommit,
)


Expand Down Expand Up @@ -250,11 +250,11 @@ def bulk_clone(self, count, attrs=None, batch_size=None, auto_commit=False):

def parallel_clone(self, count, attrs=None, batch_size=None, auto_commit=False):
# if this takes n time for t records
# t^n i.e 100 * 10ms = 1000ms to clone 100 objects.
# t^n i.e 100 ** 2ms = 10000ms (10s) to clone 100 objects.
# I'll like to reduce this down to max time to clone count/batch_size i.e
# If it take 100ms to clone 100 objects with a db of batch_size 100
# If it takes 10ms to clone 10 objects i'll like to keep this down to 10ms for
# max_num_of_threads i.e 10 threads for 100 objects.
# If it take 10000ms to clone 100 objects with a db of batch_size 100
# If it takes 20ms to clone 10 objects I'll like to keep this down to 20ms
# i.e max_num_of_threads 10 for 100 objects.
# This should run in parallel
# Testing jit and cpython if they offer better API's.
pass
Expand Down
24 changes: 12 additions & 12 deletions model_clone/tests/test_clone_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@
from django.contrib.auth import get_user_model
from django.core.exceptions import ValidationError
from django.db.transaction import TransactionManagementError
from django.db.utils import IntegrityError
from django.test import TestCase, TransactionTestCase
from django.utils.text import slugify
from django.db.utils import IntegrityError
from django.utils.timezone import make_naive
from mock import patch, PropertyMock
from mock import PropertyMock, patch

from sample.models import (
Author,
BackCover,
Book,
BookSaleTag,
BookTag,
Cover,
Edition,
Furniture,
House,
Library,
Book,
Author,
Page,
House,
Product,
Room,
Furniture,
Cover,
BackCover,
BookTag,
BookSaleTag,
Tag,
SaleTag,
Product,
Tag,
)

User = get_user_model()
Expand Down
2 changes: 1 addition & 1 deletion model_clone/tests/test_create_copy_of_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.utils.text import slugify

from model_clone import create_copy_of_instance
from sample.models import Library, Book
from sample.models import Book, Library

User = get_user_model()

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ asgiref==3.3.4
# via django
conditional==1.3
# via django-clone (setup.py)
django==3.2.3
django==3.2.4
# via django-clone (setup.py)
future==0.18.2
# via django-clone (setup.py)
Expand Down
2 changes: 1 addition & 1 deletion sample/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Register your models here.
from model_clone import CloneModelAdmin
from sample.models import Book, Author, Page, Library
from sample.models import Author, Book, Library, Page


class PageInline(admin.StackedInline):
Expand Down
1 change: 0 additions & 1 deletion sample/management/commands/create_default_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from django.contrib.auth import get_user_model
from django.core.management.base import BaseCommand


User = get_user_model()


Expand Down
2 changes: 1 addition & 1 deletion sample/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Generated by Django 2.2 on 2019-09-26 09:58

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
Expand Down
2 changes: 1 addition & 1 deletion sample/migrations/0003_book_created_at.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by Django 2.2 on 2019-11-21 23:37

from django.db import migrations, models
import django.utils.timezone
from django.db import migrations, models


class Migration(migrations.Migration):
Expand Down
3 changes: 2 additions & 1 deletion sample/migrations/0005_page.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Generated by Django 3.0 on 2019-12-03 09:47

from django.db import migrations, models
import django.db.models.deletion
from django.db import migrations, models

import model_clone.mixins.clone


Expand Down
3 changes: 2 additions & 1 deletion sample/migrations/0006_assignment.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Generated by Django 3.0.6 on 2020-05-16 17:33

from django.db import migrations, models
import django.db.models.deletion
from django.db import migrations, models

import model_clone.mixins.clone


Expand Down
2 changes: 1 addition & 1 deletion sample/migrations/0008_page_created_at.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by Django 3.1.7 on 2021-04-07 11:58

from django.db import migrations, models
import django.utils.timezone
from django.db import migrations, models


class Migration(migrations.Migration):
Expand Down
Loading

0 comments on commit b8ee3bc

Please sign in to comment.