diff --git a/Dockerfile b/Dockerfile index 412a516e..33b08500 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,6 @@ FROM ubuntu:20.04 +# invalidate cache ARG APP_NAME # test arg diff --git a/Jenkinsfile b/Jenkinsfile index a5467bdf..295e2e03 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,7 +6,7 @@ pipeline { APP_NAME = "bottlecrm-api" DOCKERHUB = credentials("dockerhub") DOCKER_IMAGE_TAG = "build-${env.BUILD_NUMBER}-${env.GIT_COMMIT[0..7]}" - DOCKER_IMAGE = "ashwin31/bottlecrm-api:${env.DOCKER_IMAGE_TAG}" + DOCKER_IMAGE = "ashwin31/django-crm:${env.DOCKER_IMAGE_TAG}" DOCKER_CONFIG = "config.json" } @@ -26,7 +26,7 @@ pipeline { } stage('trigger deploy') { steps { - build job: 'bottlecrm-api-deploy', parameters: [ + build job: 'deploy', parameters: [ string( name: 'ENV_TYPE', value: "${env.ENV_TYPE}" diff --git a/README.md b/README.md index 0e3fea94..0035a24a 100644 --- a/README.md +++ b/README.md @@ -154,4 +154,3 @@ For commercial support [Contact us](https://micropyramid.com/contact-us/) # Trigger deploy - diff --git a/Steps b/Steps new file mode 100644 index 00000000..132657f2 --- /dev/null +++ b/Steps @@ -0,0 +1,20 @@ +Google Login +org + 1)List + 2)Create + 3)Update + 4)Add User to organisation + 5)Remove User from organisation + 6)Change user permission + +Leads + + 1)List + 2)Create + 3)Update + 4)LeadDetailView + 5)upload + 6)Lead comment + 7)Lead attachment + + diff --git a/accounts/migrations/0001_initial.py b/accounts/migrations/0001_initial.py index ee30193d..830bf379 100644 --- a/accounts/migrations/0001_initial.py +++ b/accounts/migrations/0001_initial.py @@ -1,93 +1,97 @@ -# Generated by Django 2.1.2 on 2019-01-28 07:07 +# Generated by Django 4.2.1 on 2023-06-19 13:08 -import phonenumber_field.modelfields from django.db import migrations, models +import phonenumber_field.modelfields +import uuid class Migration(migrations.Migration): initial = True - dependencies = [] + dependencies = [ + ] operations = [ migrations.CreateModel( - name="Account", + name='Account', fields=[ - ( - "id", - models.AutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("name", models.CharField(max_length=64, verbose_name="Name")), - ("email", models.EmailField(max_length=254)), - ( - "phone", - phonenumber_field.modelfields.PhoneNumberField( - max_length=128, null=True - ), - ), - ( - "industry", - models.CharField( - blank=True, - choices=[ - ("ADVERTISING", "ADVERTISING"), - ("AGRICULTURE", "AGRICULTURE"), - ("APPAREL & ACCESSORIES", "APPAREL & ACCESSORIES"), - ("AUTOMOTIVE", "AUTOMOTIVE"), - ("BANKING", "BANKING"), - ("BIOTECHNOLOGY", "BIOTECHNOLOGY"), - ( - "BUILDING MATERIALS & EQUIPMENT", - "BUILDING MATERIALS & EQUIPMENT", - ), - ("CHEMICAL", "CHEMICAL"), - ("COMPUTER", "COMPUTER"), - ("EDUCATION", "EDUCATION"), - ("ELECTRONICS", "ELECTRONICS"), - ("ENERGY", "ENERGY"), - ("ENTERTAINMENT & LEISURE", "ENTERTAINMENT & LEISURE"), - ("FINANCE", "FINANCE"), - ("FOOD & BEVERAGE", "FOOD & BEVERAGE"), - ("GROCERY", "GROCERY"), - ("HEALTHCARE", "HEALTHCARE"), - ("INSURANCE", "INSURANCE"), - ("LEGAL", "LEGAL"), - ("MANUFACTURING", "MANUFACTURING"), - ("PUBLISHING", "PUBLISHING"), - ("REAL ESTATE", "REAL ESTATE"), - ("SERVICE", "SERVICE"), - ("SOFTWARE", "SOFTWARE"), - ("SPORTS", "SPORTS"), - ("TECHNOLOGY", "TECHNOLOGY"), - ("TELECOMMUNICATIONS", "TELECOMMUNICATIONS"), - ("TELEVISION", "TELEVISION"), - ("TRANSPORTATION", "TRANSPORTATION"), - ("VENTURE CAPITAL", "VENTURE CAPITAL"), - ], - max_length=255, - null=True, - verbose_name="Industry Type", - ), - ), - ( - "website", - models.URLField(blank=True, null=True, verbose_name="Website"), - ), - ("description", models.TextField(blank=True, null=True)), - ( - "created_on", - models.DateTimeField(auto_now_add=True, verbose_name="Created on"), - ), - ("is_active", models.BooleanField(default=False)), + ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')), + ('updated_at', models.DateTimeField(auto_now=True, verbose_name='Last Modified At')), + ('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)), + ('name', models.CharField(max_length=64, verbose_name='Name')), + ('email', models.EmailField(max_length=254)), + ('phone', phonenumber_field.modelfields.PhoneNumberField(max_length=128, null=True, region=None)), + ('industry', models.CharField(blank=True, choices=[('ADVERTISING', 'ADVERTISING'), ('AGRICULTURE', 'AGRICULTURE'), ('APPAREL & ACCESSORIES', 'APPAREL & ACCESSORIES'), ('AUTOMOTIVE', 'AUTOMOTIVE'), ('BANKING', 'BANKING'), ('BIOTECHNOLOGY', 'BIOTECHNOLOGY'), ('BUILDING MATERIALS & EQUIPMENT', 'BUILDING MATERIALS & EQUIPMENT'), ('CHEMICAL', 'CHEMICAL'), ('COMPUTER', 'COMPUTER'), ('EDUCATION', 'EDUCATION'), ('ELECTRONICS', 'ELECTRONICS'), ('ENERGY', 'ENERGY'), ('ENTERTAINMENT & LEISURE', 'ENTERTAINMENT & LEISURE'), ('FINANCE', 'FINANCE'), ('FOOD & BEVERAGE', 'FOOD & BEVERAGE'), ('GROCERY', 'GROCERY'), ('HEALTHCARE', 'HEALTHCARE'), ('INSURANCE', 'INSURANCE'), ('LEGAL', 'LEGAL'), ('MANUFACTURING', 'MANUFACTURING'), ('PUBLISHING', 'PUBLISHING'), ('REAL ESTATE', 'REAL ESTATE'), ('SERVICE', 'SERVICE'), ('SOFTWARE', 'SOFTWARE'), ('SPORTS', 'SPORTS'), ('TECHNOLOGY', 'TECHNOLOGY'), ('TELECOMMUNICATIONS', 'TELECOMMUNICATIONS'), ('TELEVISION', 'TELEVISION'), ('TRANSPORTATION', 'TRANSPORTATION'), ('VENTURE CAPITAL', 'VENTURE CAPITAL')], max_length=255, null=True, verbose_name='Industry Type')), + ('billing_address_line', models.CharField(blank=True, max_length=255, null=True, verbose_name='Address')), + ('billing_street', models.CharField(blank=True, max_length=55, null=True, verbose_name='Street')), + ('billing_city', models.CharField(blank=True, max_length=255, null=True, verbose_name='City')), + ('billing_state', models.CharField(blank=True, max_length=255, null=True, verbose_name='State')), + ('billing_postcode', models.CharField(blank=True, max_length=64, null=True, verbose_name='Post/Zip-code')), + ('billing_country', models.CharField(blank=True, choices=[('GB', 'United Kingdom'), ('AF', 'Afghanistan'), ('AX', 'Aland Islands'), ('AL', 'Albania'), ('DZ', 'Algeria'), ('AS', 'American Samoa'), ('AD', 'Andorra'), ('AO', 'Angola'), ('AI', 'Anguilla'), ('AQ', 'Antarctica'), ('AG', 'Antigua and Barbuda'), ('AR', 'Argentina'), ('AM', 'Armenia'), ('AW', 'Aruba'), ('AU', 'Australia'), ('AT', 'Austria'), ('AZ', 'Azerbaijan'), ('BS', 'Bahamas'), ('BH', 'Bahrain'), ('BD', 'Bangladesh'), ('BB', 'Barbados'), ('BY', 'Belarus'), ('BE', 'Belgium'), ('BZ', 'Belize'), ('BJ', 'Benin'), ('BM', 'Bermuda'), ('BT', 'Bhutan'), ('BO', 'Bolivia'), ('BA', 'Bosnia and Herzegovina'), ('BW', 'Botswana'), ('BV', 'Bouvet Island'), ('BR', 'Brazil'), ('IO', 'British Indian Ocean Territory'), ('BN', 'Brunei Darussalam'), ('BG', 'Bulgaria'), ('BF', 'Burkina Faso'), ('BI', 'Burundi'), ('KH', 'Cambodia'), ('CM', 'Cameroon'), ('CA', 'Canada'), ('CV', 'Cape Verde'), ('KY', 'Cayman Islands'), ('CF', 'Central African Republic'), ('TD', 'Chad'), ('CL', 'Chile'), ('CN', 'China'), ('CX', 'Christmas Island'), ('CC', 'Cocos (Keeling) Islands'), ('CO', 'Colombia'), ('KM', 'Comoros'), ('CG', 'Congo'), ('CD', 'Congo, The Democratic Republic of the'), ('CK', 'Cook Islands'), ('CR', 'Costa Rica'), ('CI', "Cote d'Ivoire"), ('HR', 'Croatia'), ('CU', 'Cuba'), ('CY', 'Cyprus'), ('CZ', 'Czech Republic'), ('DK', 'Denmark'), ('DJ', 'Djibouti'), ('DM', 'Dominica'), ('DO', 'Dominican Republic'), ('EC', 'Ecuador'), ('EG', 'Egypt'), ('SV', 'El Salvador'), ('GQ', 'Equatorial Guinea'), ('ER', 'Eritrea'), ('EE', 'Estonia'), ('ET', 'Ethiopia'), ('FK', 'Falkland Islands (Malvinas)'), ('FO', 'Faroe Islands'), ('FJ', 'Fiji'), ('FI', 'Finland'), ('FR', 'France'), ('GF', 'French Guiana'), ('PF', 'French Polynesia'), ('TF', 'French Southern Territories'), ('GA', 'Gabon'), ('GM', 'Gambia'), ('GE', 'Georgia'), ('DE', 'Germany'), ('GH', 'Ghana'), ('GI', 'Gibraltar'), ('GR', 'Greece'), ('GL', 'Greenland'), ('GD', 'Grenada'), ('GP', 'Guadeloupe'), ('GU', 'Guam'), ('GT', 'Guatemala'), ('GG', 'Guernsey'), ('GN', 'Guinea'), ('GW', 'Guinea-Bissau'), ('GY', 'Guyana'), ('HT', 'Haiti'), ('HM', 'Heard Island and McDonald Islands'), ('VA', 'Holy See (Vatican City State)'), ('HN', 'Honduras'), ('HK', 'Hong Kong'), ('HU', 'Hungary'), ('IS', 'Iceland'), ('IN', 'India'), ('ID', 'Indonesia'), ('IR', 'Iran, Islamic Republic of'), ('IQ', 'Iraq'), ('IE', 'Ireland'), ('IM', 'Isle of Man'), ('IL', 'Israel'), ('IT', 'Italy'), ('JM', 'Jamaica'), ('JP', 'Japan'), ('JE', 'Jersey'), ('JO', 'Jordan'), ('KZ', 'Kazakhstan'), ('KE', 'Kenya'), ('KI', 'Kiribati'), ('KP', "Korea, Democratic People's Republic of"), ('KR', 'Korea, Republic of'), ('KW', 'Kuwait'), ('KG', 'Kyrgyzstan'), ('LA', "Lao People's Democratic Republic"), ('LV', 'Latvia'), ('LB', 'Lebanon'), ('LS', 'Lesotho'), ('LR', 'Liberia'), ('LY', 'Libyan Arab Jamahiriya'), ('LI', 'Liechtenstein'), ('LT', 'Lithuania'), ('LU', 'Luxembourg'), ('MO', 'Macao'), ('MK', 'Macedonia, The Former Yugoslav Republic of'), ('MG', 'Madagascar'), ('MW', 'Malawi'), ('MY', 'Malaysia'), ('MV', 'Maldives'), ('ML', 'Mali'), ('MT', 'Malta'), ('MH', 'Marshall Islands'), ('MQ', 'Martinique'), ('MR', 'Mauritania'), ('MU', 'Mauritius'), ('YT', 'Mayotte'), ('MX', 'Mexico'), ('FM', 'Micronesia, Federated States of'), ('MD', 'Moldova'), ('MC', 'Monaco'), ('MN', 'Mongolia'), ('ME', 'Montenegro'), ('MS', 'Montserrat'), ('MA', 'Morocco'), ('MZ', 'Mozambique'), ('MM', 'Myanmar'), ('NA', 'Namibia'), ('NR', 'Nauru'), ('NP', 'Nepal'), ('NL', 'Netherlands'), ('AN', 'Netherlands Antilles'), ('NC', 'New Caledonia'), ('NZ', 'New Zealand'), ('NI', 'Nicaragua'), ('NE', 'Niger'), ('NG', 'Nigeria'), ('NU', 'Niue'), ('NF', 'Norfolk Island'), ('MP', 'Northern Mariana Islands'), ('NO', 'Norway'), ('OM', 'Oman'), ('PK', 'Pakistan'), ('PW', 'Palau'), ('PS', 'Palestinian Territory, Occupied'), ('PA', 'Panama'), ('PG', 'Papua New Guinea'), ('PY', 'Paraguay'), ('PE', 'Peru'), ('PH', 'Philippines'), ('PN', 'Pitcairn'), ('PL', 'Poland'), ('PT', 'Portugal'), ('PR', 'Puerto Rico'), ('QA', 'Qatar'), ('RE', 'Reunion'), ('RO', 'Romania'), ('RU', 'Russian Federation'), ('RW', 'Rwanda'), ('BL', 'Saint Barthelemy'), ('SH', 'Saint Helena'), ('KN', 'Saint Kitts and Nevis'), ('LC', 'Saint Lucia'), ('MF', 'Saint Martin'), ('PM', 'Saint Pierre and Miquelon'), ('VC', 'Saint Vincent and the Grenadines'), ('WS', 'Samoa'), ('SM', 'San Marino'), ('ST', 'Sao Tome and Principe'), ('SA', 'Saudi Arabia'), ('SN', 'Senegal'), ('RS', 'Serbia'), ('SC', 'Seychelles'), ('SL', 'Sierra Leone'), ('SG', 'Singapore'), ('SK', 'Slovakia'), ('SI', 'Slovenia'), ('SB', 'Solomon Islands'), ('SO', 'Somalia'), ('ZA', 'South Africa'), ('GS', 'South Georgia and the South Sandwich Islands'), ('ES', 'Spain'), ('LK', 'Sri Lanka'), ('SD', 'Sudan'), ('SR', 'Suriname'), ('SJ', 'Svalbard and Jan Mayen'), ('SZ', 'Swaziland'), ('SE', 'Sweden'), ('CH', 'Switzerland'), ('SY', 'Syrian Arab Republic'), ('TW', 'Taiwan, Province of China'), ('TJ', 'Tajikistan'), ('TZ', 'Tanzania, United Republic of'), ('TH', 'Thailand'), ('TL', 'Timor-Leste'), ('TG', 'Togo'), ('TK', 'Tokelau'), ('TO', 'Tonga'), ('TT', 'Trinidad and Tobago'), ('TN', 'Tunisia'), ('TR', 'Turkey'), ('TM', 'Turkmenistan'), ('TC', 'Turks and Caicos Islands'), ('TV', 'Tuvalu'), ('UG', 'Uganda'), ('UA', 'Ukraine'), ('AE', 'United Arab Emirates'), ('US', 'United States'), ('UM', 'United States Minor Outlying Islands'), ('UY', 'Uruguay'), ('UZ', 'Uzbekistan'), ('VU', 'Vanuatu'), ('VE', 'Venezuela'), ('VN', 'Viet Nam'), ('VG', 'Virgin Islands, British'), ('VI', 'Virgin Islands, U.S.'), ('WF', 'Wallis and Futuna'), ('EH', 'Western Sahara'), ('YE', 'Yemen'), ('ZM', 'Zambia'), ('ZW', 'Zimbabwe')], max_length=3, null=True)), + ('website', models.URLField(blank=True, null=True, verbose_name='Website')), + ('description', models.TextField(blank=True, null=True)), + ('is_active', models.BooleanField(default=False)), + ('status', models.CharField(choices=[('open', 'Open'), ('close', 'Close')], default='open', max_length=64)), + ('contact_name', models.CharField(max_length=120, verbose_name='Contact Name')), ], options={ - "ordering": ["-created_on"], + 'verbose_name': 'Account', + 'verbose_name_plural': 'Accounts', + 'db_table': 'accounts', + 'ordering': ('-created_at',), + }, + ), + migrations.CreateModel( + name='AccountEmail', + fields=[ + ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')), + ('updated_at', models.DateTimeField(auto_now=True, verbose_name='Last Modified At')), + ('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)), + ('message_subject', models.TextField(null=True)), + ('message_body', models.TextField(null=True)), + ('timezone', models.CharField(default='UTC', max_length=100)), + ('scheduled_date_time', models.DateTimeField(null=True)), + ('scheduled_later', models.BooleanField(default=False)), + ('from_email', models.EmailField(max_length=254)), + ('rendered_message_body', models.TextField(null=True)), + ], + options={ + 'verbose_name': 'Account Email', + 'verbose_name_plural': 'Account Emails', + 'db_table': 'account_email', + 'ordering': ('-created_at',), + }, + ), + migrations.CreateModel( + name='AccountEmailLog', + fields=[ + ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')), + ('updated_at', models.DateTimeField(auto_now=True, verbose_name='Last Modified At')), + ('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)), + ('is_sent', models.BooleanField(default=False)), + ], + options={ + 'verbose_name': 'EmailLog', + 'verbose_name_plural': 'EmailLogs', + 'db_table': 'emailLogs', + 'ordering': ('-created_at',), + }, + ), + migrations.CreateModel( + name='Tags', + fields=[ + ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')), + ('updated_at', models.DateTimeField(auto_now=True, verbose_name='Last Modified At')), + ('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)), + ('name', models.CharField(max_length=20)), + ('slug', models.CharField(blank=True, max_length=20, unique=True)), + ], + options={ + 'verbose_name': 'Tag', + 'verbose_name_plural': 'Tags', + 'db_table': 'tags', + 'ordering': ('-created_at',), }, ), ] diff --git a/accounts/migrations/0002_auto_20190128_1237.py b/accounts/migrations/0002_auto_20190128_1237.py deleted file mode 100644 index 493678df..00000000 --- a/accounts/migrations/0002_auto_20190128_1237.py +++ /dev/null @@ -1,62 +0,0 @@ -# Generated by Django 2.1.2 on 2019-01-28 07:07 - -import django.db.models.deletion -from django.conf import settings -from django.db import migrations, models - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - ("accounts", "0001_initial"), - ("common", "0001_initial"), - migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ] - - operations = [ - migrations.AddField( - model_name="account", - name="assigned_to", - field=models.ManyToManyField( - related_name="account_assigned_to", to=settings.AUTH_USER_MODEL - ), - ), - migrations.AddField( - model_name="account", - name="billing_address", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - related_name="account_billing_address", - to="common.Address", - ), - ), - migrations.AddField( - model_name="account", - name="created_by", - field=models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - related_name="account_created_by", - to=settings.AUTH_USER_MODEL, - ), - ), - migrations.AddField( - model_name="account", - name="shipping_address", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - related_name="account_shipping_address", - to="common.Address", - ), - ), - migrations.AddField( - model_name="account", - name="teams", - field=models.ManyToManyField(to="common.Team"), - ), - ] diff --git a/accounts/migrations/0002_initial.py b/accounts/migrations/0002_initial.py new file mode 100644 index 00000000..580d3659 --- /dev/null +++ b/accounts/migrations/0002_initial.py @@ -0,0 +1,112 @@ +# Generated by Django 4.2.1 on 2023-06-19 13:08 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('leads', '0001_initial'), + ('teams', '0001_initial'), + ('accounts', '0001_initial'), + ('contacts', '0001_initial'), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('common', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='tags', + name='created_by', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_created_by', to=settings.AUTH_USER_MODEL, verbose_name='Created By'), + ), + migrations.AddField( + model_name='tags', + name='updated_by', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_updated_by', to=settings.AUTH_USER_MODEL, verbose_name='Last Modified By'), + ), + migrations.AddField( + model_name='accountemaillog', + name='contact', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='contact_email_log', to='contacts.contact'), + ), + migrations.AddField( + model_name='accountemaillog', + name='created_by', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_created_by', to=settings.AUTH_USER_MODEL, verbose_name='Created By'), + ), + migrations.AddField( + model_name='accountemaillog', + name='email', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='email_log', to='accounts.accountemail'), + ), + migrations.AddField( + model_name='accountemaillog', + name='updated_by', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_updated_by', to=settings.AUTH_USER_MODEL, verbose_name='Last Modified By'), + ), + migrations.AddField( + model_name='accountemail', + name='created_by', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_created_by', to=settings.AUTH_USER_MODEL, verbose_name='Created By'), + ), + migrations.AddField( + model_name='accountemail', + name='from_account', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='sent_email', to='accounts.account'), + ), + migrations.AddField( + model_name='accountemail', + name='recipients', + field=models.ManyToManyField(related_name='recieved_email', to='contacts.contact'), + ), + migrations.AddField( + model_name='accountemail', + name='updated_by', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_updated_by', to=settings.AUTH_USER_MODEL, verbose_name='Last Modified By'), + ), + migrations.AddField( + model_name='account', + name='assigned_to', + field=models.ManyToManyField(related_name='account_assigned_users', to='common.profile'), + ), + migrations.AddField( + model_name='account', + name='contacts', + field=models.ManyToManyField(related_name='account_contacts', to='contacts.contact'), + ), + migrations.AddField( + model_name='account', + name='created_by', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='account_created_by', to='common.profile'), + ), + migrations.AddField( + model_name='account', + name='lead', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='account_leads', to='leads.lead'), + ), + migrations.AddField( + model_name='account', + name='org', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='account_org', to='common.org'), + ), + migrations.AddField( + model_name='account', + name='tags', + field=models.ManyToManyField(blank=True, to='accounts.tags'), + ), + migrations.AddField( + model_name='account', + name='teams', + field=models.ManyToManyField(related_name='account_teams', to='teams.teams'), + ), + migrations.AddField( + model_name='account', + name='updated_by', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_updated_by', to=settings.AUTH_USER_MODEL, verbose_name='Last Modified By'), + ), + ] diff --git a/accounts/migrations/0003_auto_20190201_1840.py b/accounts/migrations/0003_auto_20190201_1840.py deleted file mode 100644 index 40b95382..00000000 --- a/accounts/migrations/0003_auto_20190201_1840.py +++ /dev/null @@ -1,34 +0,0 @@ -# Generated by Django 2.1.5 on 2019-02-01 13:10 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("accounts", "0002_auto_20190128_1237"), - ] - - operations = [ - migrations.CreateModel( - name="Tags", - fields=[ - ( - "id", - models.AutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("name", models.CharField(max_length=20)), - ("slug", models.CharField(blank=True, max_length=20, unique=True)), - ], - ), - migrations.AddField( - model_name="account", - name="tags", - field=models.ManyToManyField(blank=True, to="accounts.Tags"), - ), - ] diff --git a/accounts/migrations/0004_account_status.py b/accounts/migrations/0004_account_status.py deleted file mode 100644 index 096512a1..00000000 --- a/accounts/migrations/0004_account_status.py +++ /dev/null @@ -1,30 +0,0 @@ -# Generated by Django 2.1.5 on 2019-02-04 06:12 - -from django.db import migrations, models - - -def generate_status(apps, schema_editor): - Account = apps.get_model("accounts", "Account") - for account in Account.objects.all(): - account.status = "open" - account.save() - - -class Migration(migrations.Migration): - - dependencies = [ - ("accounts", "0003_auto_20190201_1840"), - ] - - operations = [ - migrations.AddField( - model_name="account", - name="status", - field=models.CharField( - choices=[("open", "Open"), ("close", "Close")], - default="open", - max_length=64, - ), - ), - migrations.RunPython(generate_status, migrations.RunPython.noop), - ] diff --git a/accounts/migrations/0005_auto_20190212_1334.py b/accounts/migrations/0005_auto_20190212_1334.py deleted file mode 100644 index 261d2b45..00000000 --- a/accounts/migrations/0005_auto_20190212_1334.py +++ /dev/null @@ -1,52 +0,0 @@ -# Generated by Django 2.1.5 on 2019-02-12 08:04 - -import django.db.models.deletion -from django.conf import settings -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("contacts", "0002_auto_20190212_1334"), - ("leads", "0004_auto_20190212_1334"), - ("accounts", "0004_account_status"), - ] - - operations = [ - migrations.RemoveField( - model_name="account", - name="assigned_to", - ), - migrations.RemoveField( - model_name="account", - name="teams", - ), - migrations.AddField( - model_name="account", - name="contacts", - field=models.ManyToManyField( - related_name="account_contacts", to="contacts.Contact" - ), - ), - migrations.AddField( - model_name="account", - name="leads", - field=models.ForeignKey( - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="account_leads", - to="leads.Lead", - ), - ), - migrations.AlterField( - model_name="account", - name="created_by", - field=models.ForeignKey( - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="account_created_by", - to=settings.AUTH_USER_MODEL, - ), - ), - ] diff --git a/accounts/migrations/0006_auto_20190212_1708.py b/accounts/migrations/0006_auto_20190212_1708.py deleted file mode 100644 index 1d4f032c..00000000 --- a/accounts/migrations/0006_auto_20190212_1708.py +++ /dev/null @@ -1,326 +0,0 @@ -# Generated by Django 2.1.5 on 2019-02-12 11:38 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("accounts", "0005_auto_20190212_1334"), - ] - - operations = [ - migrations.RenameField( - model_name="account", - old_name="leads", - new_name="lead", - ), - migrations.RemoveField( - model_name="account", - name="billing_address", - ), - migrations.RemoveField( - model_name="account", - name="shipping_address", - ), - migrations.AddField( - model_name="account", - name="billing_address_line", - field=models.CharField( - blank=True, max_length=255, null=True, verbose_name="Address" - ), - ), - migrations.AddField( - model_name="account", - name="billing_city", - field=models.CharField( - blank=True, max_length=255, null=True, verbose_name="City" - ), - ), - migrations.AddField( - model_name="account", - name="billing_country", - field=models.CharField( - blank=True, - choices=[ - ("GB", "United Kingdom"), - ("AF", "Afghanistan"), - ("AX", "Aland Islands"), - ("AL", "Albania"), - ("DZ", "Algeria"), - ("AS", "American Samoa"), - ("AD", "Andorra"), - ("AO", "Angola"), - ("AI", "Anguilla"), - ("AQ", "Antarctica"), - ("AG", "Antigua and Barbuda"), - ("AR", "Argentina"), - ("AM", "Armenia"), - ("AW", "Aruba"), - ("AU", "Australia"), - ("AT", "Austria"), - ("AZ", "Azerbaijan"), - ("BS", "Bahamas"), - ("BH", "Bahrain"), - ("BD", "Bangladesh"), - ("BB", "Barbados"), - ("BY", "Belarus"), - ("BE", "Belgium"), - ("BZ", "Belize"), - ("BJ", "Benin"), - ("BM", "Bermuda"), - ("BT", "Bhutan"), - ("BO", "Bolivia"), - ("BA", "Bosnia and Herzegovina"), - ("BW", "Botswana"), - ("BV", "Bouvet Island"), - ("BR", "Brazil"), - ("IO", "British Indian Ocean Territory"), - ("BN", "Brunei Darussalam"), - ("BG", "Bulgaria"), - ("BF", "Burkina Faso"), - ("BI", "Burundi"), - ("KH", "Cambodia"), - ("CM", "Cameroon"), - ("CA", "Canada"), - ("CV", "Cape Verde"), - ("KY", "Cayman Islands"), - ("CF", "Central African Republic"), - ("TD", "Chad"), - ("CL", "Chile"), - ("CN", "China"), - ("CX", "Christmas Island"), - ("CC", "Cocos (Keeling) Islands"), - ("CO", "Colombia"), - ("KM", "Comoros"), - ("CG", "Congo"), - ("CD", "Congo, The Democratic Republic of the"), - ("CK", "Cook Islands"), - ("CR", "Costa Rica"), - ("CI", "Cote d'Ivoire"), - ("HR", "Croatia"), - ("CU", "Cuba"), - ("CY", "Cyprus"), - ("CZ", "Czech Republic"), - ("DK", "Denmark"), - ("DJ", "Djibouti"), - ("DM", "Dominica"), - ("DO", "Dominican Republic"), - ("EC", "Ecuador"), - ("EG", "Egypt"), - ("SV", "El Salvador"), - ("GQ", "Equatorial Guinea"), - ("ER", "Eritrea"), - ("EE", "Estonia"), - ("ET", "Ethiopia"), - ("FK", "Falkland Islands (Malvinas)"), - ("FO", "Faroe Islands"), - ("FJ", "Fiji"), - ("FI", "Finland"), - ("FR", "France"), - ("GF", "French Guiana"), - ("PF", "French Polynesia"), - ("TF", "French Southern Territories"), - ("GA", "Gabon"), - ("GM", "Gambia"), - ("GE", "Georgia"), - ("DE", "Germany"), - ("GH", "Ghana"), - ("GI", "Gibraltar"), - ("GR", "Greece"), - ("GL", "Greenland"), - ("GD", "Grenada"), - ("GP", "Guadeloupe"), - ("GU", "Guam"), - ("GT", "Guatemala"), - ("GG", "Guernsey"), - ("GN", "Guinea"), - ("GW", "Guinea-Bissau"), - ("GY", "Guyana"), - ("HT", "Haiti"), - ("HM", "Heard Island and McDonald Islands"), - ("VA", "Holy See (Vatican City State)"), - ("HN", "Honduras"), - ("HK", "Hong Kong"), - ("HU", "Hungary"), - ("IS", "Iceland"), - ("IN", "India"), - ("ID", "Indonesia"), - ("IR", "Iran, Islamic Republic of"), - ("IQ", "Iraq"), - ("IE", "Ireland"), - ("IM", "Isle of Man"), - ("IL", "Israel"), - ("IT", "Italy"), - ("JM", "Jamaica"), - ("JP", "Japan"), - ("JE", "Jersey"), - ("JO", "Jordan"), - ("KZ", "Kazakhstan"), - ("KE", "Kenya"), - ("KI", "Kiribati"), - ("KP", "Korea, Democratic People's Republic of"), - ("KR", "Korea, Republic of"), - ("KW", "Kuwait"), - ("KG", "Kyrgyzstan"), - ("LA", "Lao People's Democratic Republic"), - ("LV", "Latvia"), - ("LB", "Lebanon"), - ("LS", "Lesotho"), - ("LR", "Liberia"), - ("LY", "Libyan Arab Jamahiriya"), - ("LI", "Liechtenstein"), - ("LT", "Lithuania"), - ("LU", "Luxembourg"), - ("MO", "Macao"), - ("MK", "Macedonia, The Former Yugoslav Republic of"), - ("MG", "Madagascar"), - ("MW", "Malawi"), - ("MY", "Malaysia"), - ("MV", "Maldives"), - ("ML", "Mali"), - ("MT", "Malta"), - ("MH", "Marshall Islands"), - ("MQ", "Martinique"), - ("MR", "Mauritania"), - ("MU", "Mauritius"), - ("YT", "Mayotte"), - ("MX", "Mexico"), - ("FM", "Micronesia, Federated States of"), - ("MD", "Moldova"), - ("MC", "Monaco"), - ("MN", "Mongolia"), - ("ME", "Montenegro"), - ("MS", "Montserrat"), - ("MA", "Morocco"), - ("MZ", "Mozambique"), - ("MM", "Myanmar"), - ("NA", "Namibia"), - ("NR", "Nauru"), - ("NP", "Nepal"), - ("NL", "Netherlands"), - ("AN", "Netherlands Antilles"), - ("NC", "New Caledonia"), - ("NZ", "New Zealand"), - ("NI", "Nicaragua"), - ("NE", "Niger"), - ("NG", "Nigeria"), - ("NU", "Niue"), - ("NF", "Norfolk Island"), - ("MP", "Northern Mariana Islands"), - ("NO", "Norway"), - ("OM", "Oman"), - ("PK", "Pakistan"), - ("PW", "Palau"), - ("PS", "Palestinian Territory, Occupied"), - ("PA", "Panama"), - ("PG", "Papua New Guinea"), - ("PY", "Paraguay"), - ("PE", "Peru"), - ("PH", "Philippines"), - ("PN", "Pitcairn"), - ("PL", "Poland"), - ("PT", "Portugal"), - ("PR", "Puerto Rico"), - ("QA", "Qatar"), - ("RE", "Reunion"), - ("RO", "Romania"), - ("RU", "Russian Federation"), - ("RW", "Rwanda"), - ("BL", "Saint Barthelemy"), - ("SH", "Saint Helena"), - ("KN", "Saint Kitts and Nevis"), - ("LC", "Saint Lucia"), - ("MF", "Saint Martin"), - ("PM", "Saint Pierre and Miquelon"), - ("VC", "Saint Vincent and the Grenadines"), - ("WS", "Samoa"), - ("SM", "San Marino"), - ("ST", "Sao Tome and Principe"), - ("SA", "Saudi Arabia"), - ("SN", "Senegal"), - ("RS", "Serbia"), - ("SC", "Seychelles"), - ("SL", "Sierra Leone"), - ("SG", "Singapore"), - ("SK", "Slovakia"), - ("SI", "Slovenia"), - ("SB", "Solomon Islands"), - ("SO", "Somalia"), - ("ZA", "South Africa"), - ("GS", "South Georgia and the South Sandwich Islands"), - ("ES", "Spain"), - ("LK", "Sri Lanka"), - ("SD", "Sudan"), - ("SR", "Suriname"), - ("SJ", "Svalbard and Jan Mayen"), - ("SZ", "Swaziland"), - ("SE", "Sweden"), - ("CH", "Switzerland"), - ("SY", "Syrian Arab Republic"), - ("TW", "Taiwan, Province of China"), - ("TJ", "Tajikistan"), - ("TZ", "Tanzania, United Republic of"), - ("TH", "Thailand"), - ("TL", "Timor-Leste"), - ("TG", "Togo"), - ("TK", "Tokelau"), - ("TO", "Tonga"), - ("TT", "Trinidad and Tobago"), - ("TN", "Tunisia"), - ("TR", "Turkey"), - ("TM", "Turkmenistan"), - ("TC", "Turks and Caicos Islands"), - ("TV", "Tuvalu"), - ("UG", "Uganda"), - ("UA", "Ukraine"), - ("AE", "United Arab Emirates"), - ("US", "United States"), - ("UM", "United States Minor Outlying Islands"), - ("UY", "Uruguay"), - ("UZ", "Uzbekistan"), - ("VU", "Vanuatu"), - ("VE", "Venezuela"), - ("VN", "Viet Nam"), - ("VG", "Virgin Islands, British"), - ("VI", "Virgin Islands, U.S."), - ("WF", "Wallis and Futuna"), - ("EH", "Western Sahara"), - ("YE", "Yemen"), - ("ZM", "Zambia"), - ("ZW", "Zimbabwe"), - ], - max_length=3, - null=True, - ), - ), - migrations.AddField( - model_name="account", - name="billing_postcode", - field=models.CharField( - blank=True, max_length=64, null=True, verbose_name="Post/Zip-code" - ), - ), - migrations.AddField( - model_name="account", - name="billing_state", - field=models.CharField( - blank=True, max_length=255, null=True, verbose_name="State" - ), - ), - migrations.AddField( - model_name="account", - name="billing_street", - field=models.CharField( - blank=True, max_length=55, null=True, verbose_name="Street" - ), - ), - migrations.AddField( - model_name="account", - name="contact_name", - field=models.CharField( - default=1, max_length=120, verbose_name="Contact Name" - ), - preserve_default=False, - ), - ] diff --git a/accounts/migrations/0007_email.py b/accounts/migrations/0007_email.py deleted file mode 100644 index 57b6146b..00000000 --- a/accounts/migrations/0007_email.py +++ /dev/null @@ -1,50 +0,0 @@ -# Generated by Django 2.1.7 on 2019-04-30 08:13 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("contacts", "0003_merge_20190214_1427"), - ("accounts", "0006_auto_20190212_1708"), - ] - - operations = [ - migrations.CreateModel( - name="Email", - fields=[ - ( - "id", - models.AutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("sent_at", models.DateTimeField(auto_now_add=True)), - ("message_subject", models.TextField(null=True)), - ("message_body", models.TextField(null=True)), - ( - "recipient", - models.ForeignKey( - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="recieved_email", - to="contacts.Contact", - ), - ), - ( - "sender", - models.ForeignKey( - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="sent_email", - to="accounts.Account", - ), - ), - ], - ), - ] diff --git a/accounts/migrations/0008_account_assigned_to.py b/accounts/migrations/0008_account_assigned_to.py deleted file mode 100644 index 0c14f301..00000000 --- a/accounts/migrations/0008_account_assigned_to.py +++ /dev/null @@ -1,22 +0,0 @@ -# Generated by Django 2.1.7 on 2019-05-17 09:14 - -from django.conf import settings -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ("accounts", "0007_email"), - ] - - operations = [ - migrations.AddField( - model_name="account", - name="assigned_to", - field=models.ManyToManyField( - related_name="account_assigned_users", to=settings.AUTH_USER_MODEL - ), - ), - ] diff --git a/accounts/migrations/0009_auto_20190809_1659.py b/accounts/migrations/0009_auto_20190809_1659.py deleted file mode 100644 index 37665349..00000000 --- a/accounts/migrations/0009_auto_20190809_1659.py +++ /dev/null @@ -1,96 +0,0 @@ -# Generated by Django 2.2.3 on 2019-08-09 11:29 - -import django.db.models.deletion -import django.utils.timezone -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("contacts", "0003_merge_20190214_1427"), - ("accounts", "0008_account_assigned_to"), - ] - - operations = [ - migrations.RenameField( - model_name="email", - old_name="sent_at", - new_name="created_on", - ), - migrations.RenameField( - model_name="email", - old_name="sender", - new_name="from_account", - ), - migrations.RemoveField( - model_name="email", - name="recipient", - ), - migrations.AddField( - model_name="email", - name="from_email", - field=models.EmailField(default=django.utils.timezone.now, max_length=254), - preserve_default=False, - ), - migrations.AddField( - model_name="email", - name="recipients", - field=models.ManyToManyField( - related_name="recieved_email", to="contacts.Contact" - ), - ), - migrations.AddField( - model_name="email", - name="rendered_message_body", - field=models.TextField(null=True), - ), - migrations.AddField( - model_name="email", - name="scheduled_date_time", - field=models.DateTimeField(null=True), - ), - migrations.AddField( - model_name="email", - name="scheduled_later", - field=models.BooleanField(default=False), - ), - migrations.AddField( - model_name="email", - name="timezone", - field=models.CharField(default="UTC", max_length=100), - ), - migrations.CreateModel( - name="EmailLog", - fields=[ - ( - "id", - models.AutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("is_sent", models.BooleanField(default=False)), - ( - "contact", - models.ForeignKey( - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="contact_email_log", - to="contacts.Contact", - ), - ), - ( - "email", - models.ForeignKey( - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="email_log", - to="accounts.Email", - ), - ), - ], - ), - ] diff --git a/accounts/migrations/0010_account_teams.py b/accounts/migrations/0010_account_teams.py deleted file mode 100644 index f3dee1b8..00000000 --- a/accounts/migrations/0010_account_teams.py +++ /dev/null @@ -1,21 +0,0 @@ -# Generated by Django 2.2.4 on 2019-09-17 05:46 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("teams", "0003_auto_20190909_1621"), - ("accounts", "0009_auto_20190809_1659"), - ] - - operations = [ - migrations.AddField( - model_name="account", - name="teams", - field=models.ManyToManyField( - related_name="account_teams", to="teams.Teams" - ), - ), - ] diff --git a/accounts/migrations/0011_account_company.py b/accounts/migrations/0011_account_company.py deleted file mode 100644 index 42012501..00000000 --- a/accounts/migrations/0011_account_company.py +++ /dev/null @@ -1,25 +0,0 @@ -# Generated by Django 2.2.10 on 2020-04-23 10:20 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0020_auto_20200409_1653"), - ("accounts", "0010_account_teams"), - ] - - operations = [ - migrations.AddField( - model_name="account", - name="company", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - to="common.Company", - ), - ), - ] diff --git a/accounts/migrations/0012_remove_account_company.py b/accounts/migrations/0012_remove_account_company.py deleted file mode 100644 index 94dc247c..00000000 --- a/accounts/migrations/0012_remove_account_company.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 3.1.7 on 2021-03-23 14:25 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ("accounts", "0011_account_company"), - ] - - operations = [ - migrations.RemoveField( - model_name="account", - name="company", - ), - ] diff --git a/accounts/migrations/0013_auto_20210913_1918.py b/accounts/migrations/0013_auto_20210913_1918.py deleted file mode 100644 index 3832eda1..00000000 --- a/accounts/migrations/0013_auto_20210913_1918.py +++ /dev/null @@ -1,42 +0,0 @@ -# Generated by Django 3.2 on 2021-09-13 13:48 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0034_auto_20210913_1918"), - ("accounts", "0012_remove_account_company"), - ] - - operations = [ - migrations.AddField( - model_name="account", - name="company", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - to="common.company", - ), - ), - migrations.AlterField( - model_name="account", - name="assigned_to", - field=models.ManyToManyField( - related_name="account_assigned_users", to="common.Profile" - ), - ), - migrations.AlterField( - model_name="account", - name="created_by", - field=models.ForeignKey( - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="account_created_by", - to="common.profile", - ), - ), - ] diff --git a/accounts/migrations/0014_rename_company_account_org.py b/accounts/migrations/0014_rename_company_account_org.py deleted file mode 100644 index 0633a379..00000000 --- a/accounts/migrations/0014_rename_company_account_org.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 3.2 on 2021-09-22 12:31 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ("accounts", "0013_auto_20210913_1918"), - ] - - operations = [ - migrations.RenameField( - model_name="account", - old_name="company", - new_name="org", - ), - ] diff --git a/accounts/migrations/0015_alter_account_org.py b/accounts/migrations/0015_alter_account_org.py deleted file mode 100644 index 8008c9d3..00000000 --- a/accounts/migrations/0015_alter_account_org.py +++ /dev/null @@ -1,26 +0,0 @@ -# Generated by Django 3.2.7 on 2021-10-06 07:21 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0037_alter_profile_org"), - ("accounts", "0014_rename_company_account_org"), - ] - - operations = [ - migrations.AlterField( - model_name="account", - name="org", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="account_org", - to="common.org", - ), - ), - ] diff --git a/accounts/models.py b/accounts/models.py index 13b57a2c..24856b73 100644 --- a/accounts/models.py +++ b/accounts/models.py @@ -10,18 +10,30 @@ from common.models import Org, Profile from common.utils import COUNTRIES, INDCHOICES from contacts.models import Contact from teams.models import Teams +from common.base import BaseModel -class Tags(models.Model): +class Tags(BaseModel): name = models.CharField(max_length=20) slug = models.CharField(max_length=20, unique=True, blank=True) + + class Meta: + verbose_name = "Tag" + verbose_name_plural = "Tags" + db_table = "tags" + ordering = ("-created_at",) + + def __str__(self): + return f"{self.name}" + + def save(self, *args, **kwargs): self.slug = slugify(self.name) super().save(*args, **kwargs) -class Account(models.Model): +class Account(BaseModel): ACCOUNT_STATUS_CHOICE = (("open", "Open"), ("close", "Close")) @@ -52,7 +64,6 @@ class Account(models.Model): created_by = models.ForeignKey( Profile, related_name="account_created_by", on_delete=models.SET_NULL, null=True ) - created_on = models.DateTimeField(_("Created on"), auto_now_add=True) is_active = models.BooleanField(default=False) tags = models.ManyToManyField(Tags, blank=True) status = models.CharField( @@ -78,10 +89,13 @@ class Account(models.Model): ) class Meta: - ordering = ["-created_on"] + verbose_name = "Account" + verbose_name_plural = "Accounts" + db_table = "accounts" + ordering = ("-created_at",) def __str__(self): - return self.name + return f"{self.name}" def get_complete_address(self): """Concatenates complete address.""" @@ -99,7 +113,7 @@ class Account(models.Model): @property def created_on_arrow(self): - return arrow.get(self.created_on).humanize() + return arrow.get(self.created_at).humanize() @property def contact_values(self): @@ -126,7 +140,7 @@ class Account(models.Model): return Profile.objects.filter(id__in=list(user_ids)) -class Email(models.Model): +class AccountEmail(BaseModel): from_account = models.ForeignKey( Account, related_name="sent_email", on_delete=models.SET_NULL, null=True ) @@ -136,21 +150,34 @@ class Email(models.Model): timezone = models.CharField(max_length=100, default="UTC") scheduled_date_time = models.DateTimeField(null=True) scheduled_later = models.BooleanField(default=False) - created_on = models.DateTimeField(auto_now_add=True) from_email = models.EmailField() rendered_message_body = models.TextField(null=True) + class Meta: + verbose_name = "Account Email" + verbose_name_plural = "Account Emails" + db_table = "account_email" + ordering = ("-created_at",) + def __str__(self): - return self.message_subject + return f"{self.message_subject}" - -class EmailLog(models.Model): +class AccountEmailLog(BaseModel): """this model is used to track if the email is sent or not""" email = models.ForeignKey( - Email, related_name="email_log", on_delete=models.SET_NULL, null=True + AccountEmail, related_name="email_log", on_delete=models.SET_NULL, null=True ) contact = models.ForeignKey( Contact, related_name="contact_email_log", on_delete=models.SET_NULL, null=True ) is_sent = models.BooleanField(default=False) + + class Meta: + verbose_name = "EmailLog" + verbose_name_plural = "EmailLogs" + db_table = "emailLogs" + ordering = ("-created_at",) + + def __str__(self): + return f"{self.email.message_subject}" diff --git a/accounts/serializer.py b/accounts/serializer.py index b7ca32c1..bb7972d2 100644 --- a/accounts/serializer.py +++ b/accounts/serializer.py @@ -1,8 +1,11 @@ from rest_framework import serializers -from accounts.models import Account, Email, Tags -from common.serializer import (AttachmentsSerializer, OrganizationSerializer, - ProfileSerializer) +from accounts.models import Account, AccountEmail, Tags, AccountEmailLog +from common.serializer import ( + AttachmentsSerializer, + OrganizationSerializer, + ProfileSerializer, +) from contacts.serializer import ContactSerializer from leads.serializer import LeadSerializer from teams.serializer import TeamsSerializer @@ -61,7 +64,7 @@ class EmailSerializer(serializers.ModelSerializer): super().__init__(*args, **kwargs) class Meta: - model = Email + model = AccountEmail fields = ( "message_subject", "message_body", @@ -95,10 +98,23 @@ class EmailLogSerializer(serializers.ModelSerializer): email = EmailSerializer() class Meta: - model = Email + model = AccountEmailLog fields = ["email", "contact", "is_sent"] +class AccountReadSerializer(serializers.ModelSerializer): + + class Meta: + model = Account + fields = ["name", "billing_city", "tags"] + +class AccountWriteSerializer(serializers.ModelSerializer): + + class Meta: + model = Account + fields = ["name","phone", "email", "billing_address_line","billing_street","billing_city", "billing_state", "billing_postcode","billing_country","contacts", "teams", "assigned_to","tags","account_attachment", "website", "status","lead"] + + class AccountCreateSerializer(serializers.ModelSerializer): def __init__(self, *args, **kwargs): account_view = kwargs.pop("account", False) @@ -150,3 +166,15 @@ class AccountCreateSerializer(serializers.ModelSerializer): "lead", "contact_name", ) + +class AccountDetailEditSwaggerSerializer(serializers.Serializer): + comment = serializers.CharField() + account_attachment = serializers.FileField() + +class AccountCommentEditSwaggerSerializer(serializers.Serializer): + comment = serializers.CharField() + +class EmailWriteSerializer(serializers.ModelSerializer): + class Meta: + model = AccountEmail + fields = ("from_email", "recipients", "message_subject","scheduled_later","timezone","scheduled_date_time","message_body") \ No newline at end of file diff --git a/accounts/swagger_params.py b/accounts/swagger_params.py deleted file mode 100644 index 2b8dba0f..00000000 --- a/accounts/swagger_params.py +++ /dev/null @@ -1,113 +0,0 @@ -from drf_yasg import openapi - -organization_params_in_header = openapi.Parameter( - "org", openapi.IN_HEADER, required=True, type=openapi.TYPE_INTEGER -) - -organization_params = [ - organization_params_in_header, -] - -account_get_params = [ - organization_params_in_header, - openapi.Parameter("name", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("city", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("tags", openapi.IN_QUERY, type=openapi.TYPE_STRING), -] - -account_post_params = [ - organization_params_in_header, - openapi.Parameter( - "name", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), - openapi.Parameter( - "phone", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), - openapi.Parameter( - "email", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), - openapi.Parameter( - "billing_address_line", - openapi.IN_QUERY, - required=True, - type=openapi.TYPE_STRING, - ), - openapi.Parameter( - "billing_street", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), - openapi.Parameter( - "billing_city", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), - openapi.Parameter( - "billing_state", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), - openapi.Parameter( - "billing_postcode", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), - openapi.Parameter( - "billing_country", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), - openapi.Parameter( - "contacts", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), - openapi.Parameter("teams", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("assigned_to", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter( - "tags", - openapi.IN_QUERY, - type=openapi.TYPE_STRING - # type=openapi.TYPE_ARRAY, items=openapi.Items(type=openapi.TYPE_STRING) - ), - openapi.Parameter("account_attachment", openapi.IN_QUERY, type=openapi.TYPE_FILE), - openapi.Parameter("website", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter( - "status", openapi.IN_QUERY, type=openapi.TYPE_STRING, enum=["open", "close"] - ), - openapi.Parameter("lead", openapi.IN_QUERY, type=openapi.TYPE_STRING), -] - -account_detail_get_params = [ - organization_params_in_header, - openapi.Parameter( - "account_attachment", - openapi.IN_QUERY, - type=openapi.TYPE_FILE, - ), - openapi.Parameter("comment", openapi.IN_QUERY, type=openapi.TYPE_STRING), -] - -account_comment_edit_params = [ - organization_params_in_header, - openapi.Parameter("comment", openapi.IN_QUERY, type=openapi.TYPE_STRING), -] - -account_detail_get_params = [ - organization_params_in_header, - openapi.Parameter( - "account_attachment", - openapi.IN_QUERY, - type=openapi.TYPE_FILE, - ), - openapi.Parameter("comment", openapi.IN_QUERY, type=openapi.TYPE_STRING), -] - -account_comment_edit_params = [ - organization_params_in_header, - openapi.Parameter("comment", openapi.IN_QUERY, type=openapi.TYPE_STRING), -] - -account_mail_params = [ - organization_params_in_header, - openapi.Parameter("from_email", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("recipients", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("message_subject", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("scheduled_later", openapi.IN_QUERY, type=openapi.TYPE_BOOLEAN), - openapi.Parameter("timezone", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter( - "scheduled_date_time", - openapi.IN_QUERY, - type=openapi.FORMAT_DATETIME, - example="2021-01-01 00:00", - ), - openapi.Parameter("message_body", openapi.IN_QUERY, type=openapi.TYPE_STRING), -] diff --git a/accounts/swagger_params1.py b/accounts/swagger_params1.py new file mode 100644 index 00000000..297e81dd --- /dev/null +++ b/accounts/swagger_params1.py @@ -0,0 +1,19 @@ +from drf_spectacular.types import OpenApiTypes +from drf_spectacular.utils import OpenApiParameter + +organization_params_in_header = organization_params_in_header = OpenApiParameter( + "org", OpenApiTypes.STR, OpenApiParameter.HEADER +) + +organization_params = [ + organization_params_in_header, +] + +account_get_params = [ + organization_params_in_header, + OpenApiParameter("name", OpenApiTypes.STR, OpenApiParameter.QUERY), + OpenApiParameter("city", OpenApiTypes.STR, OpenApiParameter.QUERY), + OpenApiParameter("tags", OpenApiTypes.STR, OpenApiParameter.QUERY), +] + + diff --git a/accounts/tasks.py b/accounts/tasks.py index 8a92be27..8834beb5 100644 --- a/accounts/tasks.py +++ b/accounts/tasks.py @@ -7,7 +7,7 @@ from django.core.mail import EmailMessage from django.template import Context, Template from django.template.loader import render_to_string -from accounts.models import Account, Email, EmailLog +from accounts.models import Account, AccountEmail, AccountEmailLog from common.models import Profile from common.utils import convert_to_custom_timezone diff --git a/accounts/tests_celery_tasks.py b/accounts/tests_celery_tasks.py index c1b17af5..4185e141 100644 --- a/accounts/tests_celery_tasks.py +++ b/accounts/tests_celery_tasks.py @@ -4,8 +4,11 @@ from django.test import TestCase from django.test.utils import override_settings from accounts.models import Email -from accounts.tasks import (send_email, send_email_to_assigned_user, - send_scheduled_emails) +from accounts.tasks import ( + send_email, + send_email_to_assigned_user, + send_scheduled_emails, +) from accounts.tests import AccountCreateTest diff --git a/accounts/views.py b/accounts/views.py index 6261d764..9ddb619e 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -2,20 +2,29 @@ import json from django.db.models import Q from django.shortcuts import get_object_or_404 -from drf_yasg.utils import swagger_auto_schema + +from drf_rw_serializers import generics + +from drf_spectacular.utils import OpenApiExample, OpenApiParameter, extend_schema from rest_framework import status from rest_framework.pagination import LimitOffsetPagination from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView +from rest_framework.generics import GenericAPIView -from accounts import swagger_params +from accounts import swagger_params1 from accounts.models import Account, Tags from accounts.serializer import ( AccountCreateSerializer, AccountSerializer, EmailSerializer, TagsSerailizer, + AccountReadSerializer, + AccountWriteSerializer, + AccountDetailEditSwaggerSerializer, + AccountCommentEditSwaggerSerializer, + EmailWriteSerializer ) from accounts.tasks import send_email, send_email_to_assigned_user from cases.serializer import CaseSerializer @@ -48,10 +57,11 @@ class AccountsListView(APIView, LimitOffsetPagination): # authentication_classes = (JSONWebTokenAuthentication,) permission_classes = (IsAuthenticated,) model = Account + serializer_class = AccountReadSerializer def get_context_data(self, **kwargs): - params = self.request.post_data - queryset = self.model.objects.filter(org=self.request.org).order_by("-id") + params = self.request.query_params + queryset = self.model.objects.filter(org=self.request.profile.org).order_by("-id") if self.request.profile.role != "ADMIN" and not self.request.profile.is_admin: queryset = queryset.filter( Q(created_by=self.request.profile) | Q(assigned_to=self.request.profile) @@ -116,33 +126,29 @@ class AccountsListView(APIView, LimitOffsetPagination): return context - @swagger_auto_schema( - tags=["Accounts"], manual_parameters=swagger_params.account_get_params - ) + @extend_schema(tags=["Accounts"], parameters=swagger_params1.account_get_params) def get(self, request, *args, **kwargs): context = self.get_context_data(**kwargs) return Response(context) - @swagger_auto_schema( - tags=["Accounts"], manual_parameters=swagger_params.account_post_params - ) + @extend_schema(tags=["Accounts"], parameters=swagger_params1.organization_params,request=AccountWriteSerializer) def post(self, request, *args, **kwargs): - params = request.post_data + data = request.data serializer = AccountCreateSerializer( - data=params, request_obj=request, account=True + data=data, request_obj=request, account=True ) # Save Account if serializer.is_valid(): account_object = serializer.save( - created_by=request.profile, org=request.org + created_by=request.profile, org=request.profile.org ) - if params.get("contacts"): - contacts_list = json.loads(params.get("contacts")) - contacts = Contact.objects.filter(id__in=contacts_list, org=request.org) + if data.get("contacts"): + contacts_list = json.loads(data.get("contacts")) + contacts = Contact.objects.filter(id__in=contacts_list, org=request.profile.org) if contacts: account_object.contacts.add(*contacts) - if params.get("tags"): - tags = json.loads(params.get("tags")) + if data.get("tags"): + tags = json.loads(data.get("tags")) for tag in tags: tag_obj = Tags.objects.filter(slug=tag.lower()) if tag_obj.exists(): @@ -150,15 +156,15 @@ class AccountsListView(APIView, LimitOffsetPagination): else: tag_obj = Tags.objects.create(name=tag) account_object.tags.add(tag_obj) - if params.get("teams"): - teams_list = json.loads(params.get("teams")) - teams = Teams.objects.filter(id__in=teams_list, org=request.org) + if data.get("teams"): + teams_list = json.loads(data.get("teams")) + teams = Teams.objects.filter(id__in=teams_list, org=request.profile.org) if teams: account_object.teams.add(*teams) - if params.get("assigned_to"): - assigned_to_list = json.loads(params.get("assigned_to")) + if data.get("assigned_to"): + assigned_to_list = json.loads(data.get("assigned_to")) profiles = Profile.objects.filter( - id__in=assigned_to_list, org=request.org, is_active=True + id__in=assigned_to_list, org=request.profile.org, is_active=True ) if profiles: account_object.assigned_to.add(*profiles) @@ -191,24 +197,24 @@ class AccountsListView(APIView, LimitOffsetPagination): class AccountDetailView(APIView): # authentication_classes = (JSONWebTokenAuthentication,) permission_classes = (IsAuthenticated,) + serializer_class = AccountReadSerializer def get_object(self, pk): return get_object_or_404(Account, id=pk) - @swagger_auto_schema( - tags=["Accounts"], manual_parameters=swagger_params.account_post_params - ) + @extend_schema(tags=["Accounts"], parameters=swagger_params1.organization_params,request=AccountWriteSerializer) def put(self, request, pk, format=None): - params = request.post_data + data = request.data account_object = self.get_object(pk=pk) - if account_object.org != request.org: + if account_object.org != request.profile.org: return Response( {"error": True, "errors": "User company doesnot match with header...."}, status=status.HTTP_403_FORBIDDEN, ) serializer = AccountCreateSerializer( - account_object, data=params, request_obj=request, account=True + account_object, data=data, request_obj=request, account=True ) + serializer.data['org'] = request.profile.org if serializer.is_valid(): if ( @@ -232,15 +238,15 @@ class AccountDetailView(APIView): ) account_object.contacts.clear() - if params.get("contacts"): - contacts_list = json.loads(params.get("contacts")) - contacts = Contact.objects.filter(id__in=contacts_list, org=request.org) + if data.get("contacts"): + contacts_list = json.loads(data.get("contacts")) + contacts = Contact.objects.filter(id__in=contacts_list, org=request.profile.org) if contacts: account_object.contacts.add(*contacts) account_object.tags.clear() - if params.get("tags"): - tags = json.loads(params.get("tags")) + if data.get("tags"): + tags = json.loads(data.get("tags")) for tag in tags: tag_obj = Tags.objects.filter(slug=tag.lower()) if tag_obj.exists(): @@ -250,17 +256,17 @@ class AccountDetailView(APIView): account_object.tags.add(tag_obj) account_object.teams.clear() - if params.get("teams"): - teams_list = json.loads(params.get("teams")) - teams = Teams.objects.filter(id__in=teams_list, org=request.org) + if data.get("teams"): + teams_list = json.loads(data.get("teams")) + teams = Teams.objects.filter(id__in=teams_list, org=request.profile.org) if teams: account_object.teams.add(*teams) account_object.assigned_to.clear() - if params.get("assigned_to"): - assigned_to_list = json.loads(params.get("assigned_to")) + if data.get("assigned_to"): + assigned_to_list = json.loads(data.get("assigned_to")) profiles = Profile.objects.filter( - id__in=assigned_to_list, org=request.org, is_active=True + id__in=assigned_to_list, org=request.profile.org, is_active=True ) if profiles: account_object.assigned_to.add(*profiles) @@ -290,12 +296,10 @@ class AccountDetailView(APIView): status=status.HTTP_400_BAD_REQUEST, ) - @swagger_auto_schema( - tags=["Accounts"], manual_parameters=swagger_params.organization_params - ) + @extend_schema(tags=["Accounts"], parameters=swagger_params1.organization_params) def delete(self, request, pk, format=None): self.object = self.get_object(pk) - if self.object.org != request.org: + if self.object.org != request.profile.org: return Response( {"error": True, "errors": "User company doesnot match with header...."}, status=status.HTTP_403_FORBIDDEN, @@ -315,12 +319,10 @@ class AccountDetailView(APIView): status=status.HTTP_200_OK, ) - @swagger_auto_schema( - tags=["Accounts"], manual_parameters=swagger_params.organization_params - ) + @extend_schema(tags=["Accounts"], parameters=swagger_params1.organization_params) def get(self, request, pk, format=None): self.account = self.get_object(pk=pk) - if self.account.org != request.org: + if self.account.org != request.profile.org: return Response( {"error": True, "errors": "User company doesnot match with header...."}, status=status.HTTP_404_NOT_FOUND, @@ -350,13 +352,13 @@ class AccountDetailView(APIView): if self.request.profile.is_admin or self.request.profile.role == "ADMIN": users_mention = list( - Profile.objects.filter(is_active=True, org=self.request.org).values( - "user__username" + Profile.objects.filter(is_active=True, org=self.request.profile.org).values( + "user__email" ) ) elif self.request.profile != self.account.created_by: if self.account.created_by: - users_mention = [{"username": self.account.created_by.user.username}] + users_mention = [{"username": self.account.created_by.user.email}] else: users_mention = [] else: @@ -377,7 +379,7 @@ class AccountDetailView(APIView): ).data, "users": ProfileSerializer( Profile.objects.filter( - is_active=True, org=self.request.org + is_active=True, org=self.request.profile.org ).order_by("user__email"), many=True, ).data, @@ -406,14 +408,14 @@ class AccountDetailView(APIView): ) return Response(context) - @swagger_auto_schema( - tags=["Accounts"], manual_parameters=swagger_params.account_detail_get_params + @extend_schema( + tags=["Accounts"], parameters=swagger_params1.organization_params,request=AccountDetailEditSwaggerSerializer ) def post(self, request, pk, **kwargs): - params = request.post_data + data = request.data context = {} self.account_obj = Account.objects.get(pk=pk) - if self.account_obj.org != request.org: + if self.account_obj.org != request.profile.org: return Response( { "error": True, @@ -433,9 +435,9 @@ class AccountDetailView(APIView): }, status=status.HTTP_403_FORBIDDEN, ) - comment_serializer = CommentSerializer(data=params) + comment_serializer = CommentSerializer(data=data) if comment_serializer.is_valid(): - if params.get("comment"): + if data.get("comment"): comment_serializer.save( account_id=self.account_obj.id, commented_by=self.request.profile, @@ -469,23 +471,24 @@ class AccountCommentView(APIView): model = Comment # authentication_classes = (JSONWebTokenAuthentication,) permission_classes = (IsAuthenticated,) + serializer_class = AccountCommentEditSwaggerSerializer def get_object(self, pk): return self.model.objects.get(pk=pk) - @swagger_auto_schema( - tags=["Accounts"], manual_parameters=swagger_params.account_comment_edit_params + @extend_schema( + tags=["Accounts"], parameters=swagger_params1.organization_params,request=AccountCommentEditSwaggerSerializer ) def put(self, request, pk, format=None): - params = request.post_data + data = request.data obj = self.get_object(pk) if ( request.profile.role == "ADMIN" or request.profile.is_admin or request.profile == obj.commented_by ): - serializer = CommentSerializer(obj, data=params) - if params.get("comment"): + serializer = CommentSerializer(obj, data=data) + if data.get("comment"): if serializer.is_valid(): serializer.save() return Response( @@ -504,9 +507,7 @@ class AccountCommentView(APIView): status=status.HTTP_403_FORBIDDEN, ) - @swagger_auto_schema( - tags=["Accounts"], manual_parameters=swagger_params.organization_params - ) + @extend_schema(tags=["Accounts"], parameters=swagger_params1.organization_params) def delete(self, request, pk, format=None): self.object = self.get_object(pk) if ( @@ -532,10 +533,9 @@ class AccountAttachmentView(APIView): model = Attachments # authentication_classes = (JSONWebTokenAuthentication,) permission_classes = (IsAuthenticated,) + serializer_class = AccountDetailEditSwaggerSerializer - @swagger_auto_schema( - tags=["Accounts"], manual_parameters=swagger_params.organization_params - ) + @extend_schema(tags=["Accounts"], parameters=swagger_params1.organization_params) def delete(self, request, pk, format=None): self.object = self.model.objects.get(pk=pk) if ( @@ -561,17 +561,16 @@ class AccountCreateMailView(APIView): # authentication_classes = (JSONWebTokenAuthentication,) permission_classes = (IsAuthenticated,) model = Account + serializer_class = EmailWriteSerializer - @swagger_auto_schema( - tags=["Accounts"], manual_parameters=swagger_params.account_mail_params - ) + @extend_schema(tags=["Accounts"], parameters=swagger_params1.organization_params,request=EmailWriteSerializer) def post(self, request, pk, *args, **kwargs): - params = request.post_data - scheduled_later = params.get("scheduled_later") - scheduled_date_time = params.get("scheduled_date_time") + data = request.data + scheduled_later = data.get("scheduled_later") + scheduled_date_time = data.get("scheduled_date_time") account = Account.objects.filter(id=pk).first() serializer = EmailSerializer( - data=params, + data=data, request_obj=request, # account=account, ) @@ -585,17 +584,17 @@ class AccountCreateMailView(APIView): status=status.HTTP_400_BAD_REQUEST, ) - if params.get("recipients"): - contacts = json.loads(params.get("recipients")) + if data.get("recipients"): + contacts = json.loads(data.get("recipients")) for contact in contacts: - obj_contact = Contact.objects.filter(id=contact, org=request.org) + obj_contact = Contact.objects.filter(id=contact, org=request.profile.org) if obj_contact.exists(): email_obj.recipients.add(contact) else: email_obj.delete() data["recipients"] = "Please enter valid recipient" return Response({"error": True, "errors": data}) - if params.get("scheduled_later") != "true": + if data.get("scheduled_later") != "true": send_email.delay(email_obj.id) else: email_obj.scheduled_later = True diff --git a/cases/migrations/0001_initial.py b/cases/migrations/0001_initial.py index 80a5a53c..accb8d22 100644 --- a/cases/migrations/0001_initial.py +++ b/cases/migrations/0001_initial.py @@ -1,7 +1,8 @@ -# Generated by Django 2.1.2 on 2019-01-28 07:07 +# Generated by Django 4.2.1 on 2023-06-19 13:08 -import django.db.models.deletion from django.db import migrations, models +import django.db.models.deletion +import uuid class Migration(migrations.Migration): @@ -9,82 +10,30 @@ class Migration(migrations.Migration): initial = True dependencies = [ - ("accounts", "0001_initial"), + ('accounts', '0001_initial'), ] operations = [ migrations.CreateModel( - name="Case", + name='Case', fields=[ - ( - "id", - models.AutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("name", models.CharField(max_length=64, verbose_name="Name")), - ( - "status", - models.CharField( - choices=[ - ("New", "New"), - ("Assigned", "Assigned"), - ("Pending", "Pending"), - ("Closed", "Closed"), - ("Rejected", "Rejected"), - ("Duplicate", "Duplicate"), - ], - max_length=64, - ), - ), - ( - "priority", - models.CharField( - choices=[ - ("Low", "Low"), - ("Normal", "Normal"), - ("High", "High"), - ("Urgent", "Urgent"), - ], - max_length=64, - ), - ), - ( - "case_type", - models.CharField( - blank=True, - choices=[ - ("Question", "Question"), - ("Incident", "Incident"), - ("Problem", "Problem"), - ], - default="", - max_length=255, - null=True, - ), - ), - ("closed_on", models.DateField()), - ("description", models.TextField(blank=True, null=True)), - ( - "created_on", - models.DateTimeField(auto_now_add=True, verbose_name="Created on"), - ), - ("is_active", models.BooleanField(default=False)), - ( - "account", - models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - to="accounts.Account", - ), - ), + ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')), + ('updated_at', models.DateTimeField(auto_now=True, verbose_name='Last Modified At')), + ('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)), + ('name', models.CharField(max_length=64, verbose_name='Name')), + ('status', models.CharField(choices=[('New', 'New'), ('Assigned', 'Assigned'), ('Pending', 'Pending'), ('Closed', 'Closed'), ('Rejected', 'Rejected'), ('Duplicate', 'Duplicate')], max_length=64)), + ('priority', models.CharField(choices=[('Low', 'Low'), ('Normal', 'Normal'), ('High', 'High'), ('Urgent', 'Urgent')], max_length=64)), + ('case_type', models.CharField(blank=True, choices=[('Question', 'Question'), ('Incident', 'Incident'), ('Problem', 'Problem')], default='', max_length=255, null=True)), + ('closed_on', models.DateField()), + ('description', models.TextField(blank=True, null=True)), + ('is_active', models.BooleanField(default=False)), + ('account', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='accounts_cases', to='accounts.account')), ], options={ - "ordering": ["-created_on"], + 'verbose_name': 'Case', + 'verbose_name_plural': 'Cases', + 'db_table': 'case', + 'ordering': ('-created_at',), }, ), ] diff --git a/cases/migrations/0002_auto_20190128_1237.py b/cases/migrations/0002_auto_20190128_1237.py deleted file mode 100644 index b4c389d2..00000000 --- a/cases/migrations/0002_auto_20190128_1237.py +++ /dev/null @@ -1,46 +0,0 @@ -# Generated by Django 2.1.2 on 2019-01-28 07:07 - -import django.db.models.deletion -from django.conf import settings -from django.db import migrations, models - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - ("common", "0001_initial"), - ("cases", "0001_initial"), - ("contacts", "0001_initial"), - migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ] - - operations = [ - migrations.AddField( - model_name="case", - name="assigned_to", - field=models.ManyToManyField( - related_name="case_assigned_users", to=settings.AUTH_USER_MODEL - ), - ), - migrations.AddField( - model_name="case", - name="contacts", - field=models.ManyToManyField(to="contacts.Contact"), - ), - migrations.AddField( - model_name="case", - name="created_by", - field=models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - related_name="case_created_by", - to=settings.AUTH_USER_MODEL, - ), - ), - migrations.AddField( - model_name="case", - name="teams", - field=models.ManyToManyField(to="common.Team"), - ), - ] diff --git a/cases/migrations/0002_initial.py b/cases/migrations/0002_initial.py new file mode 100644 index 00000000..36256f5a --- /dev/null +++ b/cases/migrations/0002_initial.py @@ -0,0 +1,51 @@ +# Generated by Django 4.2.1 on 2023-06-19 13:08 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('teams', '0001_initial'), + ('contacts', '0001_initial'), + ('common', '0001_initial'), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('cases', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='case', + name='assigned_to', + field=models.ManyToManyField(related_name='case_assigned_users', to='common.profile'), + ), + migrations.AddField( + model_name='case', + name='contacts', + field=models.ManyToManyField(to='contacts.contact'), + ), + migrations.AddField( + model_name='case', + name='created_by', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='case_created_by', to='common.profile'), + ), + migrations.AddField( + model_name='case', + name='org', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='case_org', to='common.org'), + ), + migrations.AddField( + model_name='case', + name='teams', + field=models.ManyToManyField(related_name='cases_teams', to='teams.teams'), + ), + migrations.AddField( + model_name='case', + name='updated_by', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_updated_by', to=settings.AUTH_USER_MODEL, verbose_name='Last Modified By'), + ), + ] diff --git a/cases/migrations/0003_auto_20190212_1334.py b/cases/migrations/0003_auto_20190212_1334.py deleted file mode 100644 index a6ff26a8..00000000 --- a/cases/migrations/0003_auto_20190212_1334.py +++ /dev/null @@ -1,29 +0,0 @@ -# Generated by Django 2.1.5 on 2019-02-12 08:04 - -import django.db.models.deletion -from django.conf import settings -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("cases", "0002_auto_20190128_1237"), - ] - - operations = [ - migrations.RemoveField( - model_name="case", - name="teams", - ), - migrations.AlterField( - model_name="case", - name="created_by", - field=models.ForeignKey( - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="case_created_by", - to=settings.AUTH_USER_MODEL, - ), - ), - ] diff --git a/cases/migrations/0004_case_teams.py b/cases/migrations/0004_case_teams.py deleted file mode 100644 index 0b632224..00000000 --- a/cases/migrations/0004_case_teams.py +++ /dev/null @@ -1,19 +0,0 @@ -# Generated by Django 2.2.4 on 2019-09-17 05:46 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("teams", "0003_auto_20190909_1621"), - ("cases", "0003_auto_20190212_1334"), - ] - - operations = [ - migrations.AddField( - model_name="case", - name="teams", - field=models.ManyToManyField(related_name="cases_teams", to="teams.Teams"), - ), - ] diff --git a/cases/migrations/0005_case_company.py b/cases/migrations/0005_case_company.py deleted file mode 100644 index ef226470..00000000 --- a/cases/migrations/0005_case_company.py +++ /dev/null @@ -1,25 +0,0 @@ -# Generated by Django 2.2.10 on 2020-04-27 12:13 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0021_document_company"), - ("cases", "0004_case_teams"), - ] - - operations = [ - migrations.AddField( - model_name="case", - name="company", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - to="common.Company", - ), - ), - ] diff --git a/cases/migrations/0006_auto_20210323_1747.py b/cases/migrations/0006_auto_20210323_1747.py deleted file mode 100644 index 3c6fce55..00000000 --- a/cases/migrations/0006_auto_20210323_1747.py +++ /dev/null @@ -1,26 +0,0 @@ -# Generated by Django 3.1.7 on 2021-03-23 12:17 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("accounts", "0011_account_company"), - ("cases", "0005_case_company"), - ] - - operations = [ - migrations.AlterField( - model_name="case", - name="account", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - related_name="accounts_cases", - to="accounts.account", - ), - ), - ] diff --git a/cases/migrations/0007_remove_case_company.py b/cases/migrations/0007_remove_case_company.py deleted file mode 100644 index 793a5ca6..00000000 --- a/cases/migrations/0007_remove_case_company.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 3.1.7 on 2021-03-24 04:51 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ("cases", "0006_auto_20210323_1747"), - ] - - operations = [ - migrations.RemoveField( - model_name="case", - name="company", - ), - ] diff --git a/cases/migrations/0008_auto_20210913_1918.py b/cases/migrations/0008_auto_20210913_1918.py deleted file mode 100644 index 6147e5ae..00000000 --- a/cases/migrations/0008_auto_20210913_1918.py +++ /dev/null @@ -1,42 +0,0 @@ -# Generated by Django 3.2 on 2021-09-13 13:48 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0034_auto_20210913_1918"), - ("cases", "0007_remove_case_company"), - ] - - operations = [ - migrations.AddField( - model_name="case", - name="company", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - to="common.company", - ), - ), - migrations.AlterField( - model_name="case", - name="assigned_to", - field=models.ManyToManyField( - related_name="case_assigned_users", to="common.Profile" - ), - ), - migrations.AlterField( - model_name="case", - name="created_by", - field=models.ForeignKey( - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="case_created_by", - to="common.profile", - ), - ), - ] diff --git a/cases/migrations/0009_rename_company_case_org.py b/cases/migrations/0009_rename_company_case_org.py deleted file mode 100644 index 64bcfe72..00000000 --- a/cases/migrations/0009_rename_company_case_org.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 3.2 on 2021-09-22 12:31 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ("cases", "0008_auto_20210913_1918"), - ] - - operations = [ - migrations.RenameField( - model_name="case", - old_name="company", - new_name="org", - ), - ] diff --git a/cases/migrations/0010_alter_case_org.py b/cases/migrations/0010_alter_case_org.py deleted file mode 100644 index c7471c02..00000000 --- a/cases/migrations/0010_alter_case_org.py +++ /dev/null @@ -1,26 +0,0 @@ -# Generated by Django 3.2.7 on 2021-10-06 07:21 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0037_alter_profile_org"), - ("cases", "0009_rename_company_case_org"), - ] - - operations = [ - migrations.AlterField( - model_name="case", - name="org", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="case_org", - to="common.org", - ), - ), - ] diff --git a/cases/models.py b/cases/models.py index 4b54ccfd..1ea4ede4 100644 --- a/cases/models.py +++ b/cases/models.py @@ -6,13 +6,14 @@ from django.utils.translation import pgettext_lazy from accounts.models import Account from common.models import Org, Profile +from common.base import BaseModel from common.utils import CASE_TYPE, PRIORITY_CHOICE, STATUS_CHOICE from contacts.models import Contact -from planner.models import Event +from planner.models import PlannerEvent as Event from teams.models import Teams -class Case(models.Model): +class Case(BaseModel): name = models.CharField(pgettext_lazy("Name of the case", "Name"), max_length=64) status = models.CharField(choices=STATUS_CHOICE, max_length=64) priority = models.CharField(choices=PRIORITY_CHOICE, max_length=64) @@ -34,7 +35,6 @@ class Case(models.Model): created_by = models.ForeignKey( Profile, related_name="case_created_by", on_delete=models.SET_NULL, null=True ) - created_on = models.DateTimeField(_("Created on"), auto_now_add=True) is_active = models.BooleanField(default=False) teams = models.ManyToManyField(Teams, related_name="cases_teams") org = models.ForeignKey( @@ -42,10 +42,13 @@ class Case(models.Model): ) class Meta: - ordering = ["-created_on"] + verbose_name = "Case" + verbose_name_plural = "Cases" + db_table = "case" + ordering = ("-created_at",) def __str__(self): - return self.name + return f"{self.name}" @property def get_team_users(self): @@ -116,4 +119,4 @@ class Case(models.Model): @property def created_on_arrow(self): - return arrow.get(self.created_on).humanize() + return arrow.get(self.created_at).humanize() diff --git a/cases/serializer.py b/cases/serializer.py index 08e57483..96c11738 100644 --- a/cases/serializer.py +++ b/cases/serializer.py @@ -73,3 +73,28 @@ class CaseCreateSerializer(serializers.ModelSerializer): "org", "created_on_arrow", ) + +class CaseCreateSwaggerSerializer(serializers.ModelSerializer): + class Meta: + model = Case + fields = ( + "name", + "status", + "priority", + "case_type", + "closed_on", + "teams", + "assigned_to", + "account", + "case_attachment", + "contacts", + "description", + ) + +class CaseDetailEditSwaggerSerializer(serializers.Serializer): + comment = serializers.CharField() + case_attachment = serializers.FileField() + +class CaseCommentEditSwaggerSerializer(serializers.Serializer): + comment = serializers.CharField() + diff --git a/cases/swagger_params.py b/cases/swagger_params.py deleted file mode 100644 index ad368944..00000000 --- a/cases/swagger_params.py +++ /dev/null @@ -1,63 +0,0 @@ -from drf_yasg import openapi - -organization_params_in_header = openapi.Parameter( - "org", openapi.IN_HEADER, required=True, type=openapi.TYPE_INTEGER -) - -organization_params = [ - organization_params_in_header, -] - -cases_list_get_params = [ - organization_params_in_header, - openapi.Parameter("name", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("status", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("priority", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("account", openapi.IN_QUERY, type=openapi.TYPE_STRING), -] - -cases_detail_get_params = [ - organization_params_in_header, - openapi.Parameter( - "case_attachment", - openapi.IN_QUERY, - type=openapi.TYPE_FILE, - ), - openapi.Parameter("comment", openapi.IN_QUERY, type=openapi.TYPE_STRING), -] - -cases_create_post_params = [ - organization_params_in_header, - openapi.Parameter( - "name", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), - openapi.Parameter( - "status", openapi.IN_QUERY, type=openapi.TYPE_STRING, required=True - ), - openapi.Parameter( - "priority", openapi.IN_QUERY, type=openapi.TYPE_STRING, required=True - ), - openapi.Parameter("type_of_case", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter( - "closed_on", - openapi.IN_QUERY, - type=openapi.TYPE_STRING, - format="date", - required=True, - ), - openapi.Parameter("teams", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("assigned_to", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("account", openapi.IN_QUERY, type=openapi.TYPE_INTEGER), - openapi.Parameter( - "case_attachment", - openapi.IN_QUERY, - type=openapi.TYPE_FILE, - ), - openapi.Parameter("contacts", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("description", openapi.IN_QUERY, type=openapi.TYPE_STRING), -] - -cases_comment_edit_params = [ - organization_params_in_header, - openapi.Parameter("comment", openapi.IN_QUERY, type=openapi.TYPE_STRING), -] diff --git a/cases/swagger_params1.py b/cases/swagger_params1.py new file mode 100644 index 00000000..13b1dc67 --- /dev/null +++ b/cases/swagger_params1.py @@ -0,0 +1,18 @@ +from drf_spectacular.types import OpenApiTypes +from drf_spectacular.utils import OpenApiParameter + +organization_params_in_header = organization_params_in_header = OpenApiParameter( + "org", OpenApiTypes.STR, OpenApiParameter.HEADER +) + +organization_params = [ + organization_params_in_header, +] + +cases_list_get_params = [ + organization_params_in_header, + OpenApiParameter("name", OpenApiTypes.STR,OpenApiParameter.QUERY), + OpenApiParameter("status", OpenApiTypes.STR,OpenApiParameter.QUERY), + OpenApiParameter("priority", OpenApiTypes.STR,OpenApiParameter.QUERY), + OpenApiParameter("account", OpenApiTypes.STR,OpenApiParameter.QUERY), +] diff --git a/cases/views.py b/cases/views.py index 6ebf64e1..00a9c935 100644 --- a/cases/views.py +++ b/cases/views.py @@ -1,7 +1,7 @@ import json from django.db.models import Q -from drf_yasg.utils import swagger_auto_schema +from drf_spectacular.utils import OpenApiExample, OpenApiParameter, extend_schema from rest_framework import status from rest_framework.pagination import LimitOffsetPagination from rest_framework.permissions import IsAuthenticated @@ -10,9 +10,9 @@ from rest_framework.views import APIView from accounts.models import Account from accounts.serializer import AccountSerializer -from cases import swagger_params +from cases import swagger_params1 from cases.models import Case -from cases.serializer import CaseCreateSerializer, CaseSerializer +from cases.serializer import CaseCreateSerializer, CaseSerializer,CaseCreateSwaggerSerializer,CaseDetailEditSwaggerSerializer,CaseCommentEditSwaggerSerializer from cases.tasks import send_email_to_assigned_user from common.models import Attachments, Comment, Profile @@ -30,11 +30,11 @@ class CaseListView(APIView, LimitOffsetPagination): model = Case def get_context_data(self, **kwargs): - params = self.request.post_data - queryset = self.model.objects.filter(org=self.request.org).order_by("-id") - accounts = Account.objects.filter(org=self.request.org).order_by("-id") - contacts = Contact.objects.filter(org=self.request.org).order_by("-id") - profiles = Profile.objects.filter(is_active=True, org=self.request.org) + params = self.request.query_params + queryset = self.model.objects.filter(org=self.request.profile.org).order_by("-id") + accounts = Account.objects.filter(org=self.request.profile.org).order_by("-id") + contacts = Contact.objects.filter(org=self.request.profile.org).order_by("-id") + profiles = Profile.objects.filter(is_active=True, org=self.request.profile.org) if self.request.profile.role != "ADMIN" and not self.request.profile.is_admin: queryset = queryset.filter( Q(created_by=self.request.profile) | Q(assigned_to=self.request.profile) @@ -82,43 +82,43 @@ class CaseListView(APIView, LimitOffsetPagination): context["contacts_list"] = ContactSerializer(contacts, many=True).data return context - @swagger_auto_schema( - tags=["Cases"], manual_parameters=swagger_params.cases_list_get_params + @extend_schema( + tags=["Cases"], parameters=swagger_params1.cases_list_get_params ) def get(self, request, *args, **kwargs): context = self.get_context_data(**kwargs) return Response(context) - @swagger_auto_schema( - tags=["Cases"], manual_parameters=swagger_params.cases_create_post_params + @extend_schema( + tags=["Cases"], parameters=swagger_params1.organization_params,request=CaseCreateSwaggerSerializer ) def post(self, request, *args, **kwargs): - params = request.post_data + params = request.data serializer = CaseCreateSerializer(data=params, request_obj=request) if serializer.is_valid(): cases_obj = serializer.save( created_by=request.profile, - org=request.org, + org=request.profile.org, closed_on=params.get("closed_on"), - case_type=params.get("type_of_case"), + case_type=params.get("case_type"), ) if params.get("contacts"): contacts_list = json.loads(params.get("contacts")) - contacts = Contact.objects.filter(id__in=contacts_list, org=request.org) + contacts = Contact.objects.filter(id__in=contacts_list, org=request.profile.org) if contacts: cases_obj.contacts.add(*contacts) if params.get("teams"): teams_list = json.loads(params.get("teams")) - teams = Teams.objects.filter(id__in=teams_list, org=request.org) + teams = Teams.objects.filter(id__in=teams_list, org=request.profile.org) if teams.exists(): cases_obj.teams.add(*teams) if params.get("assigned_to"): assinged_to_list = json.loads(params.get("assigned_to")) profiles = Profile.objects.filter( - id__in=assinged_to_list, org=request.org, is_active=True + id__in=assinged_to_list, org=request.profile.org, is_active=True ) if profiles: cases_obj.assigned_to.add(*profiles) @@ -155,13 +155,13 @@ class CaseDetailView(APIView): def get_object(self, pk): return self.model.objects.filter(id=pk).first() - @swagger_auto_schema( - tags=["Cases"], manual_parameters=swagger_params.cases_create_post_params + @extend_schema( + tags=["Cases"], parameters=swagger_params1.organization_params,request=CaseCreateSwaggerSerializer ) def put(self, request, pk, format=None): - params = request.post_data + params = request.data cases_object = self.get_object(pk=pk) - if cases_object.org != request.org: + if cases_object.org != request.profile.org: return Response( {"error": True, "errors": "User company doesnot match with header...."}, status=status.HTTP_403_FORBIDDEN, @@ -187,7 +187,7 @@ class CaseDetailView(APIView): if serializer.is_valid(): cases_object = serializer.save( - closed_on=params.get("closed_on"), case_type=params.get("type_of_case") + closed_on=params.get("closed_on"), case_type=params.get("case_type") ) previous_assigned_to_users = list( cases_object.assigned_to.all().values_list("id", flat=True) @@ -195,14 +195,14 @@ class CaseDetailView(APIView): cases_object.contacts.clear() if params.get("contacts"): contacts_list = json.loads(params.get("contacts")) - contacts = Contact.objects.filter(id__in=contacts_list, org=request.org) + contacts = Contact.objects.filter(id__in=contacts_list, org=request.profile.org) if contacts: cases_object.contacts.add(*contacts) cases_object.teams.clear() if params.get("teams"): teams_list = json.loads(params.get("teams")) - teams = Teams.objects.filter(id__in=teams_list, org=request.org) + teams = Teams.objects.filter(id__in=teams_list, org=request.profile.org) if teams.exists(): cases_object.teams.add(*teams) @@ -210,7 +210,7 @@ class CaseDetailView(APIView): if params.get("assigned_to"): assinged_to_list = json.loads(params.get("assigned_to")) profiles = Profile.objects.filter( - id__in=assinged_to_list, org=request.org, is_active=True + id__in=assinged_to_list, org=request.profile.org, is_active=True ) if profiles: cases_object.assigned_to.add(*profiles) @@ -240,12 +240,12 @@ class CaseDetailView(APIView): status=status.HTTP_400_BAD_REQUEST, ) - @swagger_auto_schema( - tags=["Cases"], manual_parameters=swagger_params.organization_params + @extend_schema( + tags=["Cases"], parameters=swagger_params1.organization_params ) def delete(self, request, pk, format=None): self.object = self.get_object(pk) - if self.object.org != request.org: + if self.object.org != request.profile.org: return Response( {"error": True, "errors": "User company doesnot match with header...."}, status=status.HTTP_403_FORBIDDEN, @@ -265,12 +265,12 @@ class CaseDetailView(APIView): status=status.HTTP_200_OK, ) - @swagger_auto_schema( - tags=["Cases"], manual_parameters=swagger_params.organization_params + @extend_schema( + tags=["Cases"], parameters=swagger_params1.organization_params ) def get(self, request, pk, format=None): self.cases = self.get_object(pk=pk) - if self.cases.org != request.org: + if self.cases.org != request.profile.org: return Response( {"error": True, "errors": "User company doesnot match with header...."}, status=status.HTTP_403_FORBIDDEN, @@ -301,13 +301,13 @@ class CaseDetailView(APIView): if self.request.profile.is_admin or self.request.profile.role == "ADMIN": users_mention = list( - Profile.objects.filter(is_active=True, org=self.request.org).values( - "user__username" + Profile.objects.filter(is_active=True, org=self.request.profile.org).values( + "user__email" ) ) elif self.request.profile != self.cases.created_by: if self.cases.created_by: - users_mention = [{"username": self.cases.created_by.user.username}] + users_mention = [{"username": self.cases.created_by.user.email}] else: users_mention = [] else: @@ -332,13 +332,13 @@ class CaseDetailView(APIView): ) return Response(context) - @swagger_auto_schema( - tags=["Cases"], manual_parameters=swagger_params.cases_detail_get_params + @extend_schema( + tags=["Cases"], parameters=swagger_params1.organization_params,request=CaseDetailEditSwaggerSerializer ) def post(self, request, pk, **kwargs): - params = request.post_data + params = request.data self.cases_obj = Case.objects.get(pk=pk) - if self.cases_obj.org != request.org: + if self.cases_obj.org != request.profile.org: return Response( {"error": True, "errors": "User company doesnot match with header...."}, status=status.HTTP_403_FORBIDDEN, @@ -393,11 +393,11 @@ class CaseCommentView(APIView): def get_object(self, pk): return self.model.objects.get(pk=pk) - @swagger_auto_schema( - tags=["Cases"], manual_parameters=swagger_params.cases_comment_edit_params + @extend_schema( + tags=["Cases"], parameters=swagger_params1.organization_params,request=CaseCommentEditSwaggerSerializer ) def put(self, request, pk, format=None): - params = request.post_data + params = request.data obj = self.get_object(pk) if ( request.profile.role == "ADMIN" @@ -424,8 +424,8 @@ class CaseCommentView(APIView): status=status.HTTP_403_FORBIDDEN, ) - @swagger_auto_schema( - tags=["Cases"], manual_parameters=swagger_params.organization_params + @extend_schema( + tags=["Cases"], parameters=swagger_params1.organization_params ) def delete(self, request, pk, format=None): self.object = self.get_object(pk) @@ -453,8 +453,8 @@ class CaseAttachmentView(APIView): # authentication_classes = (JSONWebTokenAuthentication,) permission_classes = (IsAuthenticated,) - @swagger_auto_schema( - tags=["Cases"], manual_parameters=swagger_params.organization_params + @extend_schema( + tags=["Cases"], parameters=swagger_params1.organization_params ) def delete(self, request, pk, format=None): self.object = self.model.objects.get(pk=pk) diff --git a/cms/apps.py b/cms/apps.py index a3f8532e..80bf9e5c 100644 --- a/cms/apps.py +++ b/cms/apps.py @@ -2,5 +2,5 @@ from django.apps import AppConfig class CmsConfig(AppConfig): - default_auto_field = 'django.db.models.BigAutoField' - name = 'cms' + default_auto_field = "django.db.models.BigAutoField" + name = "cms" diff --git a/cms/blocks.py b/cms/blocks.py index 0e90ed68..d4051818 100644 --- a/cms/blocks.py +++ b/cms/blocks.py @@ -1,9 +1,9 @@ from django.db import models from modelcluster.models import ClusterableModel from wagtail.blocks import CharBlock, ListBlock, RichTextBlock, TextBlock -from wagtail.core import blocks -from wagtail.core.blocks import StructBlock -from wagtail.core.models import Orderable +from wagtail import blocks +from wagtail.blocks import StructBlock +from wagtail.models import Orderable from wagtail.fields import RichTextField from wagtail.images.blocks import ImageChooserBlock from wagtail.snippets.blocks import SnippetChooserBlock diff --git a/cms/migrations/0001_initial.py b/cms/migrations/0001_initial.py index f83f0e22..4d054cb5 100644 --- a/cms/migrations/0001_initial.py +++ b/cms/migrations/0001_initial.py @@ -1,12 +1,14 @@ -# Generated by Django 4.1.1 on 2022-10-11 12:11 +# Generated by Django 4.2.1 on 2023-06-19 13:08 +import cms.blocks +from django.db import migrations, models import django.db.models.deletion import django_extensions.db.fields import modelcluster.fields import wagtail.blocks +import wagtail.contrib.routable_page.models import wagtail.fields import wagtail.images.blocks -from django.db import migrations, models class Migration(migrations.Migration): @@ -14,11 +16,34 @@ class Migration(migrations.Migration): initial = True dependencies = [ - ('wagtailcore', '0077_alter_revision_user'), - ('wagtailimages', '0024_index_image_file_hash'), + ('wagtailcore', '0083_workflowcontenttype'), + ('wagtailimages', '0025_alter_image_file_alter_rendition_file'), ] operations = [ + migrations.CreateModel( + name='BlogDetailPage', + fields=[ + ('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.page')), + ('excerpt', wagtail.fields.RichTextField()), + ('content', wagtail.fields.StreamField([('content_title', cms.blocks.BlogContentTitleBlock()), ('code', cms.blocks.BlogCodeBlock()), ('rich_text', cms.blocks.BlogRichTextBlock()), ('image', cms.blocks.BlogImageBlock())], null=True, use_json_field=True)), + ], + options={ + 'abstract': False, + }, + bases=('wagtailcore.page',), + ), + migrations.CreateModel( + name='BlogListPage', + fields=[ + ('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.page')), + ('intro', wagtail.fields.RichTextField(blank=True)), + ], + options={ + 'abstract': False, + }, + bases=(wagtail.contrib.routable_page.models.RoutablePageMixin, 'wagtailcore.page'), + ), migrations.CreateModel( name='HomePage', fields=[ diff --git a/cms/migrations/0002_blogdetailpage_bloglistpage.py b/cms/migrations/0002_blogdetailpage_bloglistpage.py deleted file mode 100644 index 89868d49..00000000 --- a/cms/migrations/0002_blogdetailpage_bloglistpage.py +++ /dev/null @@ -1,41 +0,0 @@ -# Generated by Django 4.1.1 on 2022-10-31 06:50 - -from django.db import migrations, models -import django.db.models.deletion -import wagtail.contrib.routable_page.models -import wagtail.fields - - -class Migration(migrations.Migration): - - dependencies = [ - ('wagtailcore', '0077_alter_revision_user'), - ('cms', '0001_initial'), - ] - - operations = [ - migrations.CreateModel( - name='BlogDetailPage', - fields=[ - ('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.page')), - ('excerpt', wagtail.fields.RichTextField()), - ('show_legend', models.BooleanField(default=False)), - ('content', wagtail.fields.StreamField([], use_json_field=None)), - ], - options={ - 'abstract': False, - }, - bases=('wagtailcore.page',), - ), - migrations.CreateModel( - name='BlogListPage', - fields=[ - ('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.page')), - ('intro', wagtail.fields.RichTextField(blank=True)), - ], - options={ - 'abstract': False, - }, - bases=(wagtail.contrib.routable_page.models.RoutablePageMixin, 'wagtailcore.page'), - ), - ] diff --git a/cms/migrations/0003_remove_blogdetailpage_show_legend_and_more.py b/cms/migrations/0003_remove_blogdetailpage_show_legend_and_more.py deleted file mode 100644 index afe82cd5..00000000 --- a/cms/migrations/0003_remove_blogdetailpage_show_legend_and_more.py +++ /dev/null @@ -1,24 +0,0 @@ -# Generated by Django 4.1.1 on 2022-10-31 09:01 - -import cms.blocks -from django.db import migrations -import wagtail.fields - - -class Migration(migrations.Migration): - - dependencies = [ - ('cms', '0002_blogdetailpage_bloglistpage'), - ] - - operations = [ - migrations.RemoveField( - model_name='blogdetailpage', - name='show_legend', - ), - migrations.AlterField( - model_name='blogdetailpage', - name='content', - field=wagtail.fields.StreamField([('content_title', cms.blocks.BlogContentTitleBlock()), ('code', cms.blocks.BlogCodeBlock()), ('rich_text', cms.blocks.BlogRichTextBlock()), ('image', cms.blocks.BlogImageBlock())], use_json_field=None), - ), - ] diff --git a/cms/models.py b/cms/models.py index 49b1b229..334c097f 100644 --- a/cms/models.py +++ b/cms/models.py @@ -1,20 +1,24 @@ from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator from django.db import models +from django.shortcuts import render from django.utils.translation import gettext_lazy as _ from django_extensions.db.fields import AutoSlugField from modelcluster.fields import ParentalKey from modelcluster.models import ClusterableModel -from wagtail.admin.edit_handlers import (FieldPanel, InlinePanel, - MultiFieldPanel, PageChooserPanel) -from wagtail.contrib.settings.models import BaseSiteSetting, register_setting -from wagtail.core import blocks -from wagtail.core.fields import StreamField -from wagtail.core.models import Orderable, Page -from wagtail.images.edit_handlers import ImageChooserPanel -from wagtail.snippets.models import register_snippet +from wagtail.admin.panels import ( + FieldPanel, + InlinePanel, + MultiFieldPanel, + PageChooserPanel, +) from wagtail.contrib.routable_page.models import RoutablePageMixin, route +from wagtail.contrib.settings.models import BaseSiteSetting, register_setting +from wagtail import blocks +from wagtail.fields import StreamField +from wagtail.models import Orderable, Page from wagtail.fields import RichTextField -from django.shortcuts import render +# from wagtail.images. import ImageChooserPanel +from wagtail.snippets.models import register_snippet from cms import blocks diff --git a/common/admin.py b/common/admin.py index 9604d04b..f4fd4389 100644 --- a/common/admin.py +++ b/common/admin.py @@ -1,10 +1,10 @@ from django.contrib import admin -from common.models import Address, Comment, Comment_Files, User +from common.models import Address, Comment, CommentFiles, User # Register your models here. admin.site.register(User) admin.site.register(Address) admin.site.register(Comment) -admin.site.register(Comment_Files) +admin.site.register(CommentFiles) diff --git a/common/base.py b/common/base.py new file mode 100644 index 00000000..6930f8f0 --- /dev/null +++ b/common/base.py @@ -0,0 +1,38 @@ +import uuid + +# Django imports +from django.db import models + +# Third party imports +from crum import get_current_user + +# Module imports +from common.mixins import AuditModel + + +class BaseModel(AuditModel): + id = models.UUIDField( + default=uuid.uuid4, unique=True, editable=False, db_index=True, primary_key=True + ) + + class Meta: + abstract = True + + def save(self, *args, **kwargs): + user = get_current_user() + if user is None or user.is_anonymous: + self.created_by = None + self.updated_by = None + super(BaseModel, self).save(*args, **kwargs) + else: + # Check if the model is being created or updated + if self._state.adding: + # If created only set created_by value: set updated_by to None + self.created_by = user + self.updated_by = None + # If updated only set updated_by value don't touch created_by + self.updated_by = user + super(BaseModel, self).save(*args, **kwargs) + + def __str__(self): + return str(self.id) \ No newline at end of file diff --git a/common/custom_openapi.py b/common/custom_openapi.py new file mode 100644 index 00000000..8cef92a0 --- /dev/null +++ b/common/custom_openapi.py @@ -0,0 +1,7 @@ +def preprocessing_filter_spec(endpoints): + filtered = [] + for (path, path_regex, method, callback) in endpoints: + # Remove all but DRF API endpoints + if path.startswith("/api/"): + filtered.append((path, path_regex, method, callback)) + return filtered diff --git a/common/middleware/get_company.py b/common/middleware/get_company.py index 31f93e1a..ba66ea10 100644 --- a/common/middleware/get_company.py +++ b/common/middleware/get_company.py @@ -4,29 +4,36 @@ from django.contrib.auth import logout from django.core.exceptions import ValidationError from rest_framework import status from rest_framework.response import Response +from crum import get_current_user +from django.utils.functional import SimpleLazyObject from common.models import Org, Profile, User -def set_profile_request(request, org, token): - # we are decoding the token - decoded = jwt.decode(token, (settings.SECRET_KEY), algorithms=[settings.JWT_ALGO]) +# def set_profile_request(request, org, token): +# # we are decoding the token +# decoded = jwt.decode(token, (settings.SECRET_KEY), algorithms=[settings.JWT_ALGO]) - request.user = User.objects.get(id=decoded["user_id"]) +# request.user = User.objects.get(id=decoded["user_id"]) - if request.user: - request.profile = Profile.objects.get( - user=request.user, org=org, is_active=True - ) - request.profile.role = "ADMIN" - request.profile.save() - if request.profile is None: - logout(request) - return Response( - {"error": False}, - status=status.HTTP_200_OK, - ) +# if request.user: +# request.profile = Profile.objects.get( +# user=request.user, org=org, is_active=True +# ) +# request.profile.role = "ADMIN" +# request.profile.save() +# if request.profile is None: +# logout(request) +# return Response( +# {"error": False}, +# status=status.HTTP_200_OK, + # ) +def get_actual_value(request): + if request.user is None: + return None + + return request.user #here should have value, so any code using request.user will work class GetProfileAndOrg(object): def __init__(self, get_response): @@ -38,18 +45,18 @@ class GetProfileAndOrg(object): def process_request(self, request): + request.profile = None + user_id = None # here I am getting the the jwt token passing in header if request.headers.get("Authorization"): token1 = request.headers.get("Authorization") - token = token1.split(" ")[1] # getting the token value + decoded = jwt.decode(token, (settings.SECRET_KEY), algorithms=[settings.JWT_ALGO]) + user_id = decoded['user_id'] + if user_id is not None: if request.headers.get("org"): - org_id = request.headers.get("org") - org = Org.objects.get(id=org_id) - if org: - request.org = org - set_profile_request(request, org, token) - else: - request.org = None - else: - request.org = None + profile = Profile.objects.get( + user_id=user_id, org=request.headers.get("org"), is_active=True + ) + if profile: + request.profile = profile diff --git a/common/middleware/swagger_post.py b/common/middleware/swagger_post.py deleted file mode 100644 index e62cf3ab..00000000 --- a/common/middleware/swagger_post.py +++ /dev/null @@ -1,19 +0,0 @@ -import json - - -class SwaggerMiddleware: - def __init__(self, get_response): - self.get_response = get_response - - def __call__(self, request, *args, **kwargs): - request.body # just add this line BEFORE get_response - - request.post_data = ( - request.GET if len(request.POST) == 0 else request.POST - ) # for swagger - - if request.post_data == {} and request.body: # <--- for raw data (import) - request.post_data = json.loads(request.body) - - response = self.get_response(request) - return response diff --git a/common/migrations/0001_initial.py b/common/migrations/0001_initial.py index f7f26010..15f3db3e 100644 --- a/common/migrations/0001_initial.py +++ b/common/migrations/0001_initial.py @@ -1,11 +1,12 @@ -# Generated by Django 2.1.2 on 2019-01-28 07:07 - -import django.contrib.auth.models -import django.db.models.deletion -from django.conf import settings -from django.db import migrations, models +# Generated by Django 4.2.1 on 2023-06-19 13:08 import common.models +from django.conf import settings +import django.contrib.auth.models +from django.db import migrations, models +import django.db.models.deletion +import phonenumber_field.modelfields +import uuid class Migration(migrations.Migration): @@ -13,484 +14,179 @@ class Migration(migrations.Migration): initial = True dependencies = [ - ("accounts", "0001_initial"), - ("cases", "0001_initial"), ] operations = [ migrations.CreateModel( - name="User", + name='User', fields=[ - ( - "id", - models.AutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("password", models.CharField(max_length=128, verbose_name="password")), - ( - "last_login", - models.DateTimeField( - blank=True, null=True, verbose_name="last login" - ), - ), - ( - "is_superuser", - models.BooleanField( - default=False, - help_text="Designates that this user has all permissions without explicitly assigning them.", - verbose_name="superuser status", - ), - ), - ("username", models.CharField(max_length=100, unique=True)), - ("first_name", models.CharField(blank=True, max_length=150)), - ("last_name", models.CharField(blank=True, max_length=150)), - ("email", models.EmailField(max_length=255, unique=True)), - ("is_active", models.BooleanField(default=True)), - ("is_admin", models.BooleanField(default=False)), - ("is_staff", models.BooleanField(default=False)), - ( - "date_joined", - models.DateTimeField(auto_now_add=True, verbose_name="date joined"), - ), - ( - "role", - models.CharField( - choices=[("ADMIN", "ADMIN"), ("USER", "USER")], max_length=50 - ), - ), - ( - "profile_pic", - models.FileField( - blank=True, - max_length=1000, - null=True, - upload_to=common.models.img_url, - ), - ), + ('password', models.CharField(max_length=128, verbose_name='password')), + ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')), + ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')), + ('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)), + ('email', models.EmailField(blank=True, max_length=254, unique=True, verbose_name='email address')), + ('profile_pic', models.FileField(blank=True, max_length=1000, null=True, upload_to=common.models.img_url)), + ('activation_key', models.CharField(blank=True, max_length=150, null=True)), + ('key_expires', models.DateTimeField(blank=True, null=True)), + ('is_active', models.BooleanField(default=True)), ], options={ - "abstract": False, + 'verbose_name': 'User', + 'verbose_name_plural': 'Users', + 'db_table': 'users', + 'ordering': ('-is_active',), }, managers=[ - ("objects", django.contrib.auth.models.UserManager()), + ('objects', django.contrib.auth.models.UserManager()), ], ), migrations.CreateModel( - name="Address", + name='Address', fields=[ - ( - "id", - models.AutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ( - "address_line", - models.CharField( - blank=True, max_length=255, null=True, verbose_name="Address" - ), - ), - ( - "street", - models.CharField( - blank=True, max_length=55, null=True, verbose_name="Street" - ), - ), - ( - "city", - models.CharField( - blank=True, max_length=255, null=True, verbose_name="City" - ), - ), - ( - "state", - models.CharField( - blank=True, max_length=255, null=True, verbose_name="State" - ), - ), - ( - "postcode", - models.CharField( - blank=True, - max_length=64, - null=True, - verbose_name="Post/Zip-code", - ), - ), - ( - "country", - models.CharField( - blank=True, - choices=[ - ("GB", "United Kingdom"), - ("AF", "Afghanistan"), - ("AX", "Aland Islands"), - ("AL", "Albania"), - ("DZ", "Algeria"), - ("AS", "American Samoa"), - ("AD", "Andorra"), - ("AO", "Angola"), - ("AI", "Anguilla"), - ("AQ", "Antarctica"), - ("AG", "Antigua and Barbuda"), - ("AR", "Argentina"), - ("AM", "Armenia"), - ("AW", "Aruba"), - ("AU", "Australia"), - ("AT", "Austria"), - ("AZ", "Azerbaijan"), - ("BS", "Bahamas"), - ("BH", "Bahrain"), - ("BD", "Bangladesh"), - ("BB", "Barbados"), - ("BY", "Belarus"), - ("BE", "Belgium"), - ("BZ", "Belize"), - ("BJ", "Benin"), - ("BM", "Bermuda"), - ("BT", "Bhutan"), - ("BO", "Bolivia"), - ("BA", "Bosnia and Herzegovina"), - ("BW", "Botswana"), - ("BV", "Bouvet Island"), - ("BR", "Brazil"), - ("IO", "British Indian Ocean Territory"), - ("BN", "Brunei Darussalam"), - ("BG", "Bulgaria"), - ("BF", "Burkina Faso"), - ("BI", "Burundi"), - ("KH", "Cambodia"), - ("CM", "Cameroon"), - ("CA", "Canada"), - ("CV", "Cape Verde"), - ("KY", "Cayman Islands"), - ("CF", "Central African Republic"), - ("TD", "Chad"), - ("CL", "Chile"), - ("CN", "China"), - ("CX", "Christmas Island"), - ("CC", "Cocos (Keeling) Islands"), - ("CO", "Colombia"), - ("KM", "Comoros"), - ("CG", "Congo"), - ("CD", "Congo, The Democratic Republic of the"), - ("CK", "Cook Islands"), - ("CR", "Costa Rica"), - ("CI", "Cote d'Ivoire"), - ("HR", "Croatia"), - ("CU", "Cuba"), - ("CY", "Cyprus"), - ("CZ", "Czech Republic"), - ("DK", "Denmark"), - ("DJ", "Djibouti"), - ("DM", "Dominica"), - ("DO", "Dominican Republic"), - ("EC", "Ecuador"), - ("EG", "Egypt"), - ("SV", "El Salvador"), - ("GQ", "Equatorial Guinea"), - ("ER", "Eritrea"), - ("EE", "Estonia"), - ("ET", "Ethiopia"), - ("FK", "Falkland Islands (Malvinas)"), - ("FO", "Faroe Islands"), - ("FJ", "Fiji"), - ("FI", "Finland"), - ("FR", "France"), - ("GF", "French Guiana"), - ("PF", "French Polynesia"), - ("TF", "French Southern Territories"), - ("GA", "Gabon"), - ("GM", "Gambia"), - ("GE", "Georgia"), - ("DE", "Germany"), - ("GH", "Ghana"), - ("GI", "Gibraltar"), - ("GR", "Greece"), - ("GL", "Greenland"), - ("GD", "Grenada"), - ("GP", "Guadeloupe"), - ("GU", "Guam"), - ("GT", "Guatemala"), - ("GG", "Guernsey"), - ("GN", "Guinea"), - ("GW", "Guinea-Bissau"), - ("GY", "Guyana"), - ("HT", "Haiti"), - ("HM", "Heard Island and McDonald Islands"), - ("VA", "Holy See (Vatican City State)"), - ("HN", "Honduras"), - ("HK", "Hong Kong"), - ("HU", "Hungary"), - ("IS", "Iceland"), - ("IN", "India"), - ("ID", "Indonesia"), - ("IR", "Iran, Islamic Republic of"), - ("IQ", "Iraq"), - ("IE", "Ireland"), - ("IM", "Isle of Man"), - ("IL", "Israel"), - ("IT", "Italy"), - ("JM", "Jamaica"), - ("JP", "Japan"), - ("JE", "Jersey"), - ("JO", "Jordan"), - ("KZ", "Kazakhstan"), - ("KE", "Kenya"), - ("KI", "Kiribati"), - ("KP", "Korea, Democratic People's Republic of"), - ("KR", "Korea, Republic of"), - ("KW", "Kuwait"), - ("KG", "Kyrgyzstan"), - ("LA", "Lao People's Democratic Republic"), - ("LV", "Latvia"), - ("LB", "Lebanon"), - ("LS", "Lesotho"), - ("LR", "Liberia"), - ("LY", "Libyan Arab Jamahiriya"), - ("LI", "Liechtenstein"), - ("LT", "Lithuania"), - ("LU", "Luxembourg"), - ("MO", "Macao"), - ("MK", "Macedonia, The Former Yugoslav Republic of"), - ("MG", "Madagascar"), - ("MW", "Malawi"), - ("MY", "Malaysia"), - ("MV", "Maldives"), - ("ML", "Mali"), - ("MT", "Malta"), - ("MH", "Marshall Islands"), - ("MQ", "Martinique"), - ("MR", "Mauritania"), - ("MU", "Mauritius"), - ("YT", "Mayotte"), - ("MX", "Mexico"), - ("FM", "Micronesia, Federated States of"), - ("MD", "Moldova"), - ("MC", "Monaco"), - ("MN", "Mongolia"), - ("ME", "Montenegro"), - ("MS", "Montserrat"), - ("MA", "Morocco"), - ("MZ", "Mozambique"), - ("MM", "Myanmar"), - ("NA", "Namibia"), - ("NR", "Nauru"), - ("NP", "Nepal"), - ("NL", "Netherlands"), - ("AN", "Netherlands Antilles"), - ("NC", "New Caledonia"), - ("NZ", "New Zealand"), - ("NI", "Nicaragua"), - ("NE", "Niger"), - ("NG", "Nigeria"), - ("NU", "Niue"), - ("NF", "Norfolk Island"), - ("MP", "Northern Mariana Islands"), - ("NO", "Norway"), - ("OM", "Oman"), - ("PK", "Pakistan"), - ("PW", "Palau"), - ("PS", "Palestinian Territory, Occupied"), - ("PA", "Panama"), - ("PG", "Papua New Guinea"), - ("PY", "Paraguay"), - ("PE", "Peru"), - ("PH", "Philippines"), - ("PN", "Pitcairn"), - ("PL", "Poland"), - ("PT", "Portugal"), - ("PR", "Puerto Rico"), - ("QA", "Qatar"), - ("RE", "Reunion"), - ("RO", "Romania"), - ("RU", "Russian Federation"), - ("RW", "Rwanda"), - ("BL", "Saint Barthelemy"), - ("SH", "Saint Helena"), - ("KN", "Saint Kitts and Nevis"), - ("LC", "Saint Lucia"), - ("MF", "Saint Martin"), - ("PM", "Saint Pierre and Miquelon"), - ("VC", "Saint Vincent and the Grenadines"), - ("WS", "Samoa"), - ("SM", "San Marino"), - ("ST", "Sao Tome and Principe"), - ("SA", "Saudi Arabia"), - ("SN", "Senegal"), - ("RS", "Serbia"), - ("SC", "Seychelles"), - ("SL", "Sierra Leone"), - ("SG", "Singapore"), - ("SK", "Slovakia"), - ("SI", "Slovenia"), - ("SB", "Solomon Islands"), - ("SO", "Somalia"), - ("ZA", "South Africa"), - ("GS", "South Georgia and the South Sandwich Islands"), - ("ES", "Spain"), - ("LK", "Sri Lanka"), - ("SD", "Sudan"), - ("SR", "Suriname"), - ("SJ", "Svalbard and Jan Mayen"), - ("SZ", "Swaziland"), - ("SE", "Sweden"), - ("CH", "Switzerland"), - ("SY", "Syrian Arab Republic"), - ("TW", "Taiwan, Province of China"), - ("TJ", "Tajikistan"), - ("TZ", "Tanzania, United Republic of"), - ("TH", "Thailand"), - ("TL", "Timor-Leste"), - ("TG", "Togo"), - ("TK", "Tokelau"), - ("TO", "Tonga"), - ("TT", "Trinidad and Tobago"), - ("TN", "Tunisia"), - ("TR", "Turkey"), - ("TM", "Turkmenistan"), - ("TC", "Turks and Caicos Islands"), - ("TV", "Tuvalu"), - ("UG", "Uganda"), - ("UA", "Ukraine"), - ("AE", "United Arab Emirates"), - ("US", "United States"), - ("UM", "United States Minor Outlying Islands"), - ("UY", "Uruguay"), - ("UZ", "Uzbekistan"), - ("VU", "Vanuatu"), - ("VE", "Venezuela"), - ("VN", "Viet Nam"), - ("VG", "Virgin Islands, British"), - ("VI", "Virgin Islands, U.S."), - ("WF", "Wallis and Futuna"), - ("EH", "Western Sahara"), - ("YE", "Yemen"), - ("ZM", "Zambia"), - ("ZW", "Zimbabwe"), - ], - max_length=3, - null=True, - ), - ), + ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')), + ('updated_at', models.DateTimeField(auto_now=True, verbose_name='Last Modified At')), + ('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)), + ('address_line', models.CharField(blank=True, default='', max_length=255, verbose_name='Address')), + ('street', models.CharField(blank=True, default='', max_length=55, verbose_name='Street')), + ('city', models.CharField(blank=True, default='', max_length=255, verbose_name='City')), + ('state', models.CharField(blank=True, default='', max_length=255, verbose_name='State')), + ('postcode', models.CharField(blank=True, default='', max_length=64, verbose_name='Post/Zip-code')), + ('country', models.CharField(blank=True, choices=[('GB', 'United Kingdom'), ('AF', 'Afghanistan'), ('AX', 'Aland Islands'), ('AL', 'Albania'), ('DZ', 'Algeria'), ('AS', 'American Samoa'), ('AD', 'Andorra'), ('AO', 'Angola'), ('AI', 'Anguilla'), ('AQ', 'Antarctica'), ('AG', 'Antigua and Barbuda'), ('AR', 'Argentina'), ('AM', 'Armenia'), ('AW', 'Aruba'), ('AU', 'Australia'), ('AT', 'Austria'), ('AZ', 'Azerbaijan'), ('BS', 'Bahamas'), ('BH', 'Bahrain'), ('BD', 'Bangladesh'), ('BB', 'Barbados'), ('BY', 'Belarus'), ('BE', 'Belgium'), ('BZ', 'Belize'), ('BJ', 'Benin'), ('BM', 'Bermuda'), ('BT', 'Bhutan'), ('BO', 'Bolivia'), ('BA', 'Bosnia and Herzegovina'), ('BW', 'Botswana'), ('BV', 'Bouvet Island'), ('BR', 'Brazil'), ('IO', 'British Indian Ocean Territory'), ('BN', 'Brunei Darussalam'), ('BG', 'Bulgaria'), ('BF', 'Burkina Faso'), ('BI', 'Burundi'), ('KH', 'Cambodia'), ('CM', 'Cameroon'), ('CA', 'Canada'), ('CV', 'Cape Verde'), ('KY', 'Cayman Islands'), ('CF', 'Central African Republic'), ('TD', 'Chad'), ('CL', 'Chile'), ('CN', 'China'), ('CX', 'Christmas Island'), ('CC', 'Cocos (Keeling) Islands'), ('CO', 'Colombia'), ('KM', 'Comoros'), ('CG', 'Congo'), ('CD', 'Congo, The Democratic Republic of the'), ('CK', 'Cook Islands'), ('CR', 'Costa Rica'), ('CI', "Cote d'Ivoire"), ('HR', 'Croatia'), ('CU', 'Cuba'), ('CY', 'Cyprus'), ('CZ', 'Czech Republic'), ('DK', 'Denmark'), ('DJ', 'Djibouti'), ('DM', 'Dominica'), ('DO', 'Dominican Republic'), ('EC', 'Ecuador'), ('EG', 'Egypt'), ('SV', 'El Salvador'), ('GQ', 'Equatorial Guinea'), ('ER', 'Eritrea'), ('EE', 'Estonia'), ('ET', 'Ethiopia'), ('FK', 'Falkland Islands (Malvinas)'), ('FO', 'Faroe Islands'), ('FJ', 'Fiji'), ('FI', 'Finland'), ('FR', 'France'), ('GF', 'French Guiana'), ('PF', 'French Polynesia'), ('TF', 'French Southern Territories'), ('GA', 'Gabon'), ('GM', 'Gambia'), ('GE', 'Georgia'), ('DE', 'Germany'), ('GH', 'Ghana'), ('GI', 'Gibraltar'), ('GR', 'Greece'), ('GL', 'Greenland'), ('GD', 'Grenada'), ('GP', 'Guadeloupe'), ('GU', 'Guam'), ('GT', 'Guatemala'), ('GG', 'Guernsey'), ('GN', 'Guinea'), ('GW', 'Guinea-Bissau'), ('GY', 'Guyana'), ('HT', 'Haiti'), ('HM', 'Heard Island and McDonald Islands'), ('VA', 'Holy See (Vatican City State)'), ('HN', 'Honduras'), ('HK', 'Hong Kong'), ('HU', 'Hungary'), ('IS', 'Iceland'), ('IN', 'India'), ('ID', 'Indonesia'), ('IR', 'Iran, Islamic Republic of'), ('IQ', 'Iraq'), ('IE', 'Ireland'), ('IM', 'Isle of Man'), ('IL', 'Israel'), ('IT', 'Italy'), ('JM', 'Jamaica'), ('JP', 'Japan'), ('JE', 'Jersey'), ('JO', 'Jordan'), ('KZ', 'Kazakhstan'), ('KE', 'Kenya'), ('KI', 'Kiribati'), ('KP', "Korea, Democratic People's Republic of"), ('KR', 'Korea, Republic of'), ('KW', 'Kuwait'), ('KG', 'Kyrgyzstan'), ('LA', "Lao People's Democratic Republic"), ('LV', 'Latvia'), ('LB', 'Lebanon'), ('LS', 'Lesotho'), ('LR', 'Liberia'), ('LY', 'Libyan Arab Jamahiriya'), ('LI', 'Liechtenstein'), ('LT', 'Lithuania'), ('LU', 'Luxembourg'), ('MO', 'Macao'), ('MK', 'Macedonia, The Former Yugoslav Republic of'), ('MG', 'Madagascar'), ('MW', 'Malawi'), ('MY', 'Malaysia'), ('MV', 'Maldives'), ('ML', 'Mali'), ('MT', 'Malta'), ('MH', 'Marshall Islands'), ('MQ', 'Martinique'), ('MR', 'Mauritania'), ('MU', 'Mauritius'), ('YT', 'Mayotte'), ('MX', 'Mexico'), ('FM', 'Micronesia, Federated States of'), ('MD', 'Moldova'), ('MC', 'Monaco'), ('MN', 'Mongolia'), ('ME', 'Montenegro'), ('MS', 'Montserrat'), ('MA', 'Morocco'), ('MZ', 'Mozambique'), ('MM', 'Myanmar'), ('NA', 'Namibia'), ('NR', 'Nauru'), ('NP', 'Nepal'), ('NL', 'Netherlands'), ('AN', 'Netherlands Antilles'), ('NC', 'New Caledonia'), ('NZ', 'New Zealand'), ('NI', 'Nicaragua'), ('NE', 'Niger'), ('NG', 'Nigeria'), ('NU', 'Niue'), ('NF', 'Norfolk Island'), ('MP', 'Northern Mariana Islands'), ('NO', 'Norway'), ('OM', 'Oman'), ('PK', 'Pakistan'), ('PW', 'Palau'), ('PS', 'Palestinian Territory, Occupied'), ('PA', 'Panama'), ('PG', 'Papua New Guinea'), ('PY', 'Paraguay'), ('PE', 'Peru'), ('PH', 'Philippines'), ('PN', 'Pitcairn'), ('PL', 'Poland'), ('PT', 'Portugal'), ('PR', 'Puerto Rico'), ('QA', 'Qatar'), ('RE', 'Reunion'), ('RO', 'Romania'), ('RU', 'Russian Federation'), ('RW', 'Rwanda'), ('BL', 'Saint Barthelemy'), ('SH', 'Saint Helena'), ('KN', 'Saint Kitts and Nevis'), ('LC', 'Saint Lucia'), ('MF', 'Saint Martin'), ('PM', 'Saint Pierre and Miquelon'), ('VC', 'Saint Vincent and the Grenadines'), ('WS', 'Samoa'), ('SM', 'San Marino'), ('ST', 'Sao Tome and Principe'), ('SA', 'Saudi Arabia'), ('SN', 'Senegal'), ('RS', 'Serbia'), ('SC', 'Seychelles'), ('SL', 'Sierra Leone'), ('SG', 'Singapore'), ('SK', 'Slovakia'), ('SI', 'Slovenia'), ('SB', 'Solomon Islands'), ('SO', 'Somalia'), ('ZA', 'South Africa'), ('GS', 'South Georgia and the South Sandwich Islands'), ('ES', 'Spain'), ('LK', 'Sri Lanka'), ('SD', 'Sudan'), ('SR', 'Suriname'), ('SJ', 'Svalbard and Jan Mayen'), ('SZ', 'Swaziland'), ('SE', 'Sweden'), ('CH', 'Switzerland'), ('SY', 'Syrian Arab Republic'), ('TW', 'Taiwan, Province of China'), ('TJ', 'Tajikistan'), ('TZ', 'Tanzania, United Republic of'), ('TH', 'Thailand'), ('TL', 'Timor-Leste'), ('TG', 'Togo'), ('TK', 'Tokelau'), ('TO', 'Tonga'), ('TT', 'Trinidad and Tobago'), ('TN', 'Tunisia'), ('TR', 'Turkey'), ('TM', 'Turkmenistan'), ('TC', 'Turks and Caicos Islands'), ('TV', 'Tuvalu'), ('UG', 'Uganda'), ('UA', 'Ukraine'), ('AE', 'United Arab Emirates'), ('US', 'United States'), ('UM', 'United States Minor Outlying Islands'), ('UY', 'Uruguay'), ('UZ', 'Uzbekistan'), ('VU', 'Vanuatu'), ('VE', 'Venezuela'), ('VN', 'Viet Nam'), ('VG', 'Virgin Islands, British'), ('VI', 'Virgin Islands, U.S.'), ('WF', 'Wallis and Futuna'), ('EH', 'Western Sahara'), ('YE', 'Yemen'), ('ZM', 'Zambia'), ('ZW', 'Zimbabwe')], default='', max_length=3)), ], + options={ + 'verbose_name': 'Address', + 'verbose_name_plural': 'Addresses', + 'db_table': 'address', + 'ordering': ('-created_at',), + }, ), migrations.CreateModel( - name="Attachments", + name='APISettings', fields=[ - ( - "id", - models.AutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("file_name", models.CharField(max_length=60)), - ( - "created_on", - models.DateTimeField(auto_now_add=True, verbose_name="Created on"), - ), - ( - "attachment", - models.FileField(max_length=1001, upload_to="attachments/%Y/%m/"), - ), + ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')), + ('updated_at', models.DateTimeField(auto_now=True, verbose_name='Last Modified At')), + ('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)), + ('title', models.TextField()), + ('apikey', models.CharField(blank=True, max_length=16)), + ('website', models.URLField(max_length=255, null=True)), ], + options={ + 'verbose_name': 'APISetting', + 'verbose_name_plural': 'APISettings', + 'db_table': 'apiSettings', + 'ordering': ('-created_at',), + }, ), migrations.CreateModel( - name="Comment", + name='Attachments', fields=[ - ( - "id", - models.AutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("comment", models.CharField(max_length=255)), - ("commented_on", models.DateTimeField(auto_now_add=True)), - ( - "account", - models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - related_name="accounts_comments", - to="accounts.Account", - ), - ), - ( - "case", - models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - related_name="cases", - to="cases.Case", - ), - ), - ( - "commented_by", - models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - to=settings.AUTH_USER_MODEL, - ), - ), + ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')), + ('updated_at', models.DateTimeField(auto_now=True, verbose_name='Last Modified At')), + ('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)), + ('file_name', models.CharField(max_length=60)), + ('attachment', models.FileField(max_length=1001, upload_to='attachments/%Y/%m/')), ], + options={ + 'verbose_name': 'Attachment', + 'verbose_name_plural': 'Attachments', + 'db_table': 'attachments', + 'ordering': ('-created_at',), + }, ), migrations.CreateModel( - name="Comment_Files", + name='Comment', fields=[ - ( - "id", - models.AutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("updated_on", models.DateTimeField(auto_now_add=True)), - ( - "comment_file", - models.FileField( - default="", upload_to="comment_files", verbose_name="File" - ), - ), - ( - "comment", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, to="common.Comment" - ), - ), + ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')), + ('updated_at', models.DateTimeField(auto_now=True, verbose_name='Last Modified At')), + ('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)), + ('comment', models.CharField(max_length=255)), + ('commented_on', models.DateTimeField(auto_now_add=True)), ], + options={ + 'verbose_name': 'Comment', + 'verbose_name_plural': 'Comments', + 'db_table': 'comment', + 'ordering': ('-created_at',), + }, ), migrations.CreateModel( - name="Team", + name='CommentFiles', fields=[ - ( - "id", - models.AutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("name", models.CharField(max_length=55)), - ("members", models.ManyToManyField(to=settings.AUTH_USER_MODEL)), + ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')), + ('updated_at', models.DateTimeField(auto_now=True, verbose_name='Last Modified At')), + ('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)), + ('updated_on', models.DateTimeField(auto_now_add=True)), + ('comment_file', models.FileField(blank=True, null=True, upload_to='CommentFiles', verbose_name='File')), ], + options={ + 'verbose_name': 'CommentFile', + 'verbose_name_plural': 'CommentFiles', + 'db_table': 'commentFiles', + 'ordering': ('-created_at',), + }, + ), + migrations.CreateModel( + name='Org', + fields=[ + ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')), + ('updated_at', models.DateTimeField(auto_now=True, verbose_name='Last Modified At')), + ('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)), + ('name', models.CharField(blank=True, max_length=100, null=True)), + ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_created_by', to=settings.AUTH_USER_MODEL, verbose_name='Created By')), + ('updated_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_updated_by', to=settings.AUTH_USER_MODEL, verbose_name='Last Modified By')), + ], + options={ + 'verbose_name': 'Organization', + 'verbose_name_plural': 'Organizations', + 'db_table': 'organization', + 'ordering': ('-created_at',), + }, + ), + migrations.CreateModel( + name='Profile', + fields=[ + ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')), + ('updated_at', models.DateTimeField(auto_now=True, verbose_name='Last Modified At')), + ('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)), + ('phone', phonenumber_field.modelfields.PhoneNumberField(max_length=128, null=True, region=None, unique=True)), + ('alternate_phone', phonenumber_field.modelfields.PhoneNumberField(max_length=128, null=True, region=None)), + ('role', models.CharField(choices=[('ADMIN', 'ADMIN'), ('USER', 'USER')], default='USER', max_length=50)), + ('has_sales_access', models.BooleanField(default=False)), + ('has_marketing_access', models.BooleanField(default=False)), + ('is_active', models.BooleanField(default=True)), + ('is_organization_admin', models.BooleanField(default=False)), + ('date_of_joining', models.DateField(blank=True, null=True)), + ('address', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='adress_users', to='common.address')), + ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_created_by', to=settings.AUTH_USER_MODEL, verbose_name='Created By')), + ('org', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='user_org', to='common.org')), + ('updated_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_updated_by', to=settings.AUTH_USER_MODEL, verbose_name='Last Modified By')), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + options={ + 'verbose_name': 'Profile', + 'verbose_name_plural': 'Profiles', + 'db_table': 'profile', + 'ordering': ('-created_at',), + }, + ), + migrations.CreateModel( + name='Document', + fields=[ + ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')), + ('updated_at', models.DateTimeField(auto_now=True, verbose_name='Last Modified At')), + ('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)), + ('title', models.TextField(blank=True, null=True)), + ('document_file', models.FileField(max_length=5000, upload_to=common.models.document_path)), + ('status', models.CharField(choices=[('active', 'active'), ('inactive', 'inactive')], default='active', max_length=64)), + ('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='document_uploaded', to='common.profile')), + ('org', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='document_org', to='common.org')), + ('shared_to', models.ManyToManyField(related_name='document_shared_to', to='common.profile')), + ], + options={ + 'verbose_name': 'Document', + 'verbose_name_plural': 'Documents', + 'db_table': 'document', + 'ordering': ('-created_at',), + }, ), ] diff --git a/common/migrations/0002_auto_20190128_1237.py b/common/migrations/0002_auto_20190128_1237.py deleted file mode 100644 index 5fde899a..00000000 --- a/common/migrations/0002_auto_20190128_1237.py +++ /dev/null @@ -1,132 +0,0 @@ -# Generated by Django 2.1.2 on 2019-01-28 07:07 - -import django.db.models.deletion -from django.conf import settings -from django.db import migrations, models - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - ("contacts", "0001_initial"), - ("common", "0001_initial"), - ("opportunity", "0001_initial"), - ("auth", "0009_alter_user_last_name_max_length"), - ("leads", "0001_initial"), - ("accounts", "0002_auto_20190128_1237"), - ] - - operations = [ - migrations.AddField( - model_name="comment", - name="contact", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - related_name="contact_comments", - to="contacts.Contact", - ), - ), - migrations.AddField( - model_name="comment", - name="lead", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - related_name="leads", - to="leads.Lead", - ), - ), - migrations.AddField( - model_name="comment", - name="opportunity", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - related_name="opportunity_comments", - to="opportunity.Opportunity", - ), - ), - migrations.AddField( - model_name="attachments", - name="account", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - related_name="account_attachment", - to="accounts.Account", - ), - ), - migrations.AddField( - model_name="attachments", - name="contact", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - related_name="contact_attachment", - to="contacts.Contact", - ), - ), - migrations.AddField( - model_name="attachments", - name="created_by", - field=models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - related_name="attachment_created_by", - to=settings.AUTH_USER_MODEL, - ), - ), - migrations.AddField( - model_name="attachments", - name="lead", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - related_name="lead_attachment", - to="leads.Lead", - ), - ), - migrations.AddField( - model_name="attachments", - name="opportunity", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - related_name="opportunity_attachment", - to="opportunity.Opportunity", - ), - ), - migrations.AddField( - model_name="user", - name="groups", - field=models.ManyToManyField( - blank=True, - help_text="The groups this user belongs to. A user will get all permissions granted to each of their groups.", - related_name="user_set", - related_query_name="user", - to="auth.Group", - verbose_name="groups", - ), - ), - migrations.AddField( - model_name="user", - name="user_permissions", - field=models.ManyToManyField( - blank=True, - help_text="Specific permissions for this user.", - related_name="user_set", - related_query_name="user", - to="auth.Permission", - verbose_name="user permissions", - ), - ), - ] diff --git a/common/migrations/0002_initial.py b/common/migrations/0002_initial.py new file mode 100644 index 00000000..aa21817c --- /dev/null +++ b/common/migrations/0002_initial.py @@ -0,0 +1,211 @@ +# Generated by Django 4.2.1 on 2023-06-19 13:08 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('leads', '0001_initial'), + ('invoices', '0001_initial'), + ('teams', '0001_initial'), + ('auth', '0012_alter_user_first_name_max_length'), + ('accounts', '0002_initial'), + ('opportunity', '0001_initial'), + ('contacts', '0001_initial'), + ('common', '0001_initial'), + ('tasks', '0001_initial'), + ('cases', '0002_initial'), + ('events', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='document', + name='teams', + field=models.ManyToManyField(related_name='document_teams', to='teams.teams'), + ), + migrations.AddField( + model_name='document', + name='updated_by', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_updated_by', to=settings.AUTH_USER_MODEL, verbose_name='Last Modified By'), + ), + migrations.AddField( + model_name='commentfiles', + name='comment', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='common.comment'), + ), + migrations.AddField( + model_name='commentfiles', + name='created_by', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_created_by', to=settings.AUTH_USER_MODEL, verbose_name='Created By'), + ), + migrations.AddField( + model_name='commentfiles', + name='updated_by', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_updated_by', to=settings.AUTH_USER_MODEL, verbose_name='Last Modified By'), + ), + migrations.AddField( + model_name='comment', + name='account', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='accounts_comments', to='accounts.account'), + ), + migrations.AddField( + model_name='comment', + name='case', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='cases', to='cases.case'), + ), + migrations.AddField( + model_name='comment', + name='commented_by', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='common.profile'), + ), + migrations.AddField( + model_name='comment', + name='contact', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='contact_comments', to='contacts.contact'), + ), + migrations.AddField( + model_name='comment', + name='created_by', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_created_by', to=settings.AUTH_USER_MODEL, verbose_name='Created By'), + ), + migrations.AddField( + model_name='comment', + name='event', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='events_comments', to='events.event'), + ), + migrations.AddField( + model_name='comment', + name='invoice', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='invoice_comments', to='invoices.invoice'), + ), + migrations.AddField( + model_name='comment', + name='lead', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='leads_comments', to='leads.lead'), + ), + migrations.AddField( + model_name='comment', + name='opportunity', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='opportunity_comments', to='opportunity.opportunity'), + ), + migrations.AddField( + model_name='comment', + name='profile', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='user_comments', to='common.profile'), + ), + migrations.AddField( + model_name='comment', + name='task', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='tasks_comments', to='tasks.task'), + ), + migrations.AddField( + model_name='comment', + name='updated_by', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_updated_by', to=settings.AUTH_USER_MODEL, verbose_name='Last Modified By'), + ), + migrations.AddField( + model_name='attachments', + name='account', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='account_attachment', to='accounts.account'), + ), + migrations.AddField( + model_name='attachments', + name='case', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='case_attachment', to='cases.case'), + ), + migrations.AddField( + model_name='attachments', + name='contact', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='contact_attachment', to='contacts.contact'), + ), + migrations.AddField( + model_name='attachments', + name='created_by', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='attachment_created_by', to='common.profile'), + ), + migrations.AddField( + model_name='attachments', + name='event', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='events_attachment', to='events.event'), + ), + migrations.AddField( + model_name='attachments', + name='invoice', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='invoice_attachment', to='invoices.invoice'), + ), + migrations.AddField( + model_name='attachments', + name='lead', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='lead_attachment', to='leads.lead'), + ), + migrations.AddField( + model_name='attachments', + name='opportunity', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='opportunity_attachment', to='opportunity.opportunity'), + ), + migrations.AddField( + model_name='attachments', + name='task', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='tasks_attachment', to='tasks.task'), + ), + migrations.AddField( + model_name='attachments', + name='updated_by', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_updated_by', to=settings.AUTH_USER_MODEL, verbose_name='Last Modified By'), + ), + migrations.AddField( + model_name='apisettings', + name='created_by', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='settings_created_by', to='common.profile'), + ), + migrations.AddField( + model_name='apisettings', + name='lead_assigned_to', + field=models.ManyToManyField(related_name='lead_assignee_users', to='common.profile'), + ), + migrations.AddField( + model_name='apisettings', + name='org', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='org_api_settings', to='common.org'), + ), + migrations.AddField( + model_name='apisettings', + name='tags', + field=models.ManyToManyField(blank=True, to='accounts.tags'), + ), + migrations.AddField( + model_name='apisettings', + name='updated_by', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_updated_by', to=settings.AUTH_USER_MODEL, verbose_name='Last Modified By'), + ), + migrations.AddField( + model_name='address', + name='created_by', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_created_by', to=settings.AUTH_USER_MODEL, verbose_name='Created By'), + ), + migrations.AddField( + model_name='address', + name='updated_by', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_updated_by', to=settings.AUTH_USER_MODEL, verbose_name='Last Modified By'), + ), + migrations.AddField( + model_name='user', + name='groups', + field=models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups'), + ), + migrations.AddField( + model_name='user', + name='user_permissions', + field=models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions'), + ), + migrations.AlterUniqueTogether( + name='profile', + unique_together={('user', 'org')}, + ), + ] diff --git a/common/migrations/0003_alter_user_profile_pic.py b/common/migrations/0003_alter_user_profile_pic.py new file mode 100644 index 00000000..c6fa937f --- /dev/null +++ b/common/migrations/0003_alter_user_profile_pic.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.1 on 2023-07-12 09:52 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('common', '0002_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='user', + name='profile_pic', + field=models.CharField(blank=True, max_length=1000, null=True), + ), + ] diff --git a/common/migrations/0003_document.py b/common/migrations/0003_document.py deleted file mode 100644 index 0603c223..00000000 --- a/common/migrations/0003_document.py +++ /dev/null @@ -1,47 +0,0 @@ -# Generated by Django 2.1.5 on 2019-01-28 07:28 - -import django.db.models.deletion -from django.conf import settings -from django.db import migrations, models - -import common.models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0002_auto_20190128_1237"), - ] - - operations = [ - migrations.CreateModel( - name="Document", - fields=[ - ( - "id", - models.AutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("title", models.CharField(blank=True, max_length=1000, null=True)), - ( - "document_file", - models.FileField( - max_length=5000, upload_to=common.models.document_path - ), - ), - ("created_on", models.DateTimeField(auto_now_add=True)), - ( - "created_by", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - related_name="document_uploaded", - to=settings.AUTH_USER_MODEL, - ), - ), - ], - ), - ] diff --git a/common/migrations/0004_alter_profile_alternate_phone.py b/common/migrations/0004_alter_profile_alternate_phone.py new file mode 100644 index 00000000..7a83303a --- /dev/null +++ b/common/migrations/0004_alter_profile_alternate_phone.py @@ -0,0 +1,19 @@ +# Generated by Django 4.2.1 on 2023-07-21 11:23 + +from django.db import migrations +import phonenumber_field.modelfields + + +class Migration(migrations.Migration): + + dependencies = [ + ('common', '0003_alter_user_profile_pic'), + ] + + operations = [ + migrations.AlterField( + model_name='profile', + name='alternate_phone', + field=phonenumber_field.modelfields.PhoneNumberField(blank=True, max_length=128, null=True, region=None), + ), + ] diff --git a/common/migrations/0004_attachments_case.py b/common/migrations/0004_attachments_case.py deleted file mode 100644 index d8540037..00000000 --- a/common/migrations/0004_attachments_case.py +++ /dev/null @@ -1,26 +0,0 @@ -# Generated by Django 2.1.5 on 2019-01-29 08:02 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("cases", "0002_auto_20190128_1237"), - ("common", "0003_document"), - ] - - operations = [ - migrations.AddField( - model_name="attachments", - name="case", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - related_name="case_attachment", - to="cases.Case", - ), - ), - ] diff --git a/common/migrations/0005_auto_20190204_1400.py b/common/migrations/0005_auto_20190204_1400.py deleted file mode 100644 index a2023c7e..00000000 --- a/common/migrations/0005_auto_20190204_1400.py +++ /dev/null @@ -1,34 +0,0 @@ -# Generated by Django 2.1.5 on 2019-02-04 08:30 - -from django.db import migrations, models - - -def generate_document_status(apps, schema_editor): - Document = apps.get_model("common", "Document") - for document in Document.objects.all(): - document.status = "active" - document.save() - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0004_attachments_case"), - ] - - operations = [ - migrations.AlterModelOptions( - name="user", - options={"ordering": ["-is_active"]}, - ), - migrations.AddField( - model_name="document", - name="status", - field=models.CharField( - choices=[("active", "active"), ("inactive", "inactive")], - default="active", - max_length=64, - ), - ), - migrations.RunPython(generate_document_status), - ] diff --git a/common/migrations/0006_comment_user.py b/common/migrations/0006_comment_user.py deleted file mode 100644 index a518ed1a..00000000 --- a/common/migrations/0006_comment_user.py +++ /dev/null @@ -1,26 +0,0 @@ -# Generated by Django 2.1.5 on 2019-02-08 07:09 - -import django.db.models.deletion -from django.conf import settings -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0005_auto_20190204_1400"), - ] - - operations = [ - migrations.AddField( - model_name="comment", - name="user", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - related_name="user_comments", - to=settings.AUTH_USER_MODEL, - ), - ), - ] diff --git a/common/migrations/0007_auto_20190212_1334.py b/common/migrations/0007_auto_20190212_1334.py deleted file mode 100644 index 62308d85..00000000 --- a/common/migrations/0007_auto_20190212_1334.py +++ /dev/null @@ -1,48 +0,0 @@ -# Generated by Django 2.1.5 on 2019-02-12 08:04 - -import django.db.models.deletion -from django.conf import settings -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("contacts", "0002_auto_20190212_1334"), - ("planner", "0002_auto_20190212_1334"), - ("cases", "0003_auto_20190212_1334"), - ("opportunity", "0003_auto_20190212_1334"), - ("leads", "0004_auto_20190212_1334"), - ("accounts", "0005_auto_20190212_1334"), - ("common", "0006_comment_user"), - ] - - operations = [ - migrations.RemoveField( - model_name="team", - name="members", - ), - migrations.AlterField( - model_name="attachments", - name="created_by", - field=models.ForeignKey( - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="attachment_created_by", - to=settings.AUTH_USER_MODEL, - ), - ), - migrations.AlterField( - model_name="document", - name="created_by", - field=models.ForeignKey( - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="document_uploaded", - to=settings.AUTH_USER_MODEL, - ), - ), - migrations.DeleteModel( - name="Team", - ), - ] diff --git a/common/migrations/0008_google.py b/common/migrations/0008_google.py deleted file mode 100644 index 4a836713..00000000 --- a/common/migrations/0008_google.py +++ /dev/null @@ -1,46 +0,0 @@ -# Generated by Django 2.1.7 on 2019-02-14 05:51 - -import django.db.models.deletion -from django.conf import settings -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0007_auto_20190212_1334"), - ] - - operations = [ - migrations.CreateModel( - name="Google", - fields=[ - ( - "id", - models.AutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("google_id", models.CharField(default="", max_length=200)), - ("google_url", models.CharField(default="", max_length=1000)), - ("verified_email", models.CharField(default="", max_length=200)), - ("family_name", models.CharField(default="", max_length=200)), - ("name", models.CharField(default="", max_length=200)), - ("gender", models.CharField(default="", max_length=10)), - ("dob", models.CharField(default="", max_length=50)), - ("given_name", models.CharField(default="", max_length=200)), - ("email", models.CharField(db_index=True, default="", max_length=200)), - ( - "user", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - related_name="google", - to=settings.AUTH_USER_MODEL, - ), - ), - ], - ), - ] diff --git a/common/migrations/0009_document_shared_to.py b/common/migrations/0009_document_shared_to.py deleted file mode 100644 index b1c8e325..00000000 --- a/common/migrations/0009_document_shared_to.py +++ /dev/null @@ -1,21 +0,0 @@ -# Generated by Django 2.1.7 on 2019-02-14 06:42 - -from django.conf import settings -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0008_google"), - ] - - operations = [ - migrations.AddField( - model_name="document", - name="shared_to", - field=models.ManyToManyField( - related_name="document_shared_to", to=settings.AUTH_USER_MODEL - ), - ), - ] diff --git a/common/migrations/0010_apisettings.py b/common/migrations/0010_apisettings.py deleted file mode 100644 index efd668e7..00000000 --- a/common/migrations/0010_apisettings.py +++ /dev/null @@ -1,54 +0,0 @@ -# Generated by Django 2.1.5 on 2019-02-13 13:09 - -import django.db.models.deletion -from django.conf import settings -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("accounts", "0006_auto_20190212_1708"), - ("common", "0009_document_shared_to"), - ] - - operations = [ - migrations.CreateModel( - name="APISettings", - fields=[ - ( - "id", - models.AutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("title", models.CharField(max_length=1000)), - ( - "apikey", - models.CharField( - default="a223998f39691c748515bca13519b7b3", max_length=16 - ), - ), - ("created_on", models.DateTimeField(auto_now_add=True)), - ( - "created_by", - models.ForeignKey( - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="settings_created_by", - to=settings.AUTH_USER_MODEL, - ), - ), - ( - "lead_assigned_to", - models.ManyToManyField( - related_name="lead_assignee_users", to=settings.AUTH_USER_MODEL - ), - ), - ("tags", models.ManyToManyField(blank=True, to="accounts.Tags")), - ], - ), - ] diff --git a/common/migrations/0011_auto_20190218_1230.py b/common/migrations/0011_auto_20190218_1230.py deleted file mode 100644 index 731e5e5c..00000000 --- a/common/migrations/0011_auto_20190218_1230.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 2.1.7 on 2019-02-18 07:00 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0010_apisettings"), - ] - - operations = [ - migrations.AlterField( - model_name="apisettings", - name="apikey", - field=models.CharField(blank=True, max_length=16), - ), - ] diff --git a/common/migrations/0012_apisettings_website.py b/common/migrations/0012_apisettings_website.py deleted file mode 100644 index 78f656dc..00000000 --- a/common/migrations/0012_apisettings_website.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 2.1.7 on 2019-02-19 10:53 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0011_auto_20190218_1230"), - ] - - operations = [ - migrations.AddField( - model_name="apisettings", - name="website", - field=models.URLField(default="", max_length=255), - ), - ] diff --git a/common/migrations/0013_auto_20190508_1540.py b/common/migrations/0013_auto_20190508_1540.py deleted file mode 100644 index 6163b023..00000000 --- a/common/migrations/0013_auto_20190508_1540.py +++ /dev/null @@ -1,37 +0,0 @@ -# Generated by Django 2.1.7 on 2019-05-08 10:10 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("tasks", "0002_task_created_by"), - ("common", "0012_apisettings_website"), - ] - - operations = [ - migrations.AddField( - model_name="attachments", - name="task", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - related_name="tasks_attachment", - to="tasks.Task", - ), - ), - migrations.AddField( - model_name="comment", - name="task", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - related_name="tasks_comments", - to="tasks.Task", - ), - ), - ] diff --git a/common/migrations/0014_auto_20190524_1113.py b/common/migrations/0014_auto_20190524_1113.py deleted file mode 100644 index e24aeaf9..00000000 --- a/common/migrations/0014_auto_20190524_1113.py +++ /dev/null @@ -1,37 +0,0 @@ -# Generated by Django 2.1.7 on 2019-05-24 05:43 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("invoices", "0002_auto_20190524_1113"), - ("common", "0013_auto_20190508_1540"), - ] - - operations = [ - migrations.AddField( - model_name="attachments", - name="invoice", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - related_name="invoice_attachment", - to="invoices.Invoice", - ), - ), - migrations.AddField( - model_name="comment", - name="invoice", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - related_name="invoice_comments", - to="invoices.Invoice", - ), - ), - ] diff --git a/common/migrations/0015_auto_20190604_1830.py b/common/migrations/0015_auto_20190604_1830.py deleted file mode 100644 index b7a49377..00000000 --- a/common/migrations/0015_auto_20190604_1830.py +++ /dev/null @@ -1,37 +0,0 @@ -# Generated by Django 2.1.7 on 2019-06-04 13:00 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("events", "0002_event_date_of_meeting"), - ("common", "0014_auto_20190524_1113"), - ] - - operations = [ - migrations.AddField( - model_name="attachments", - name="event", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - related_name="events_attachment", - to="events.Event", - ), - ), - migrations.AddField( - model_name="comment", - name="event", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - related_name="events_comments", - to="events.Event", - ), - ), - ] diff --git a/common/migrations/0016_auto_20190624_1816.py b/common/migrations/0016_auto_20190624_1816.py deleted file mode 100644 index 00b7eb33..00000000 --- a/common/migrations/0016_auto_20190624_1816.py +++ /dev/null @@ -1,35 +0,0 @@ -# Generated by Django 2.2.2 on 2019-06-24 12:46 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0015_auto_20190604_1830"), - ] - - operations = [ - migrations.AddField( - model_name="user", - name="has_marketing_access", - field=models.BooleanField(default=False), - ), - migrations.AddField( - model_name="user", - name="has_sales_access", - field=models.BooleanField(default=False), - ), - migrations.AlterField( - model_name="comment", - name="lead", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - related_name="leads_comments", - to="leads.Lead", - ), - ), - ] diff --git a/common/migrations/0017_auto_20190722_1443.py b/common/migrations/0017_auto_20190722_1443.py deleted file mode 100644 index a1e17c02..00000000 --- a/common/migrations/0017_auto_20190722_1443.py +++ /dev/null @@ -1,47 +0,0 @@ -# Generated by Django 2.2.2 on 2019-07-22 09:13 - -import django.db.models.deletion -from django.conf import settings -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0016_auto_20190624_1816"), - ] - - operations = [ - migrations.AlterModelOptions( - name="apisettings", - options={"ordering": ("-created_on",)}, - ), - migrations.AlterModelOptions( - name="document", - options={"ordering": ("-created_on",)}, - ), - migrations.CreateModel( - name="Profile", - fields=[ - ( - "id", - models.AutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("activation_key", models.CharField(max_length=50)), - ("key_expires", models.DateTimeField()), - ( - "user", - models.OneToOneField( - on_delete=django.db.models.deletion.CASCADE, - related_name="profile", - to=settings.AUTH_USER_MODEL, - ), - ), - ], - ), - ] diff --git a/common/migrations/0018_document_teams.py b/common/migrations/0018_document_teams.py deleted file mode 100644 index 3996234a..00000000 --- a/common/migrations/0018_document_teams.py +++ /dev/null @@ -1,21 +0,0 @@ -# Generated by Django 2.2.4 on 2019-09-17 05:46 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("teams", "0003_auto_20190909_1621"), - ("common", "0017_auto_20190722_1443"), - ] - - operations = [ - migrations.AddField( - model_name="document", - name="teams", - field=models.ManyToManyField( - related_name="document_teams", to="teams.Teams" - ), - ), - ] diff --git a/common/migrations/0019_auto_20200401_0941.py b/common/migrations/0019_auto_20200401_0941.py deleted file mode 100644 index b7fd5001..00000000 --- a/common/migrations/0019_auto_20200401_0941.py +++ /dev/null @@ -1,298 +0,0 @@ -# Generated by Django 2.2.10 on 2020-04-01 04:11 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0018_document_teams"), - ] - - operations = [ - migrations.CreateModel( - name="Company", - fields=[ - ( - "id", - models.AutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("name", models.CharField(max_length=100)), - ("address", models.CharField(max_length=2000)), - ("sub_domain", models.CharField(max_length=30)), - ("user_limit", models.IntegerField(default=5)), - ( - "country", - models.CharField( - blank=True, - choices=[ - ("GB", "United Kingdom"), - ("AF", "Afghanistan"), - ("AX", "Aland Islands"), - ("AL", "Albania"), - ("DZ", "Algeria"), - ("AS", "American Samoa"), - ("AD", "Andorra"), - ("AO", "Angola"), - ("AI", "Anguilla"), - ("AQ", "Antarctica"), - ("AG", "Antigua and Barbuda"), - ("AR", "Argentina"), - ("AM", "Armenia"), - ("AW", "Aruba"), - ("AU", "Australia"), - ("AT", "Austria"), - ("AZ", "Azerbaijan"), - ("BS", "Bahamas"), - ("BH", "Bahrain"), - ("BD", "Bangladesh"), - ("BB", "Barbados"), - ("BY", "Belarus"), - ("BE", "Belgium"), - ("BZ", "Belize"), - ("BJ", "Benin"), - ("BM", "Bermuda"), - ("BT", "Bhutan"), - ("BO", "Bolivia"), - ("BA", "Bosnia and Herzegovina"), - ("BW", "Botswana"), - ("BV", "Bouvet Island"), - ("BR", "Brazil"), - ("IO", "British Indian Ocean Territory"), - ("BN", "Brunei Darussalam"), - ("BG", "Bulgaria"), - ("BF", "Burkina Faso"), - ("BI", "Burundi"), - ("KH", "Cambodia"), - ("CM", "Cameroon"), - ("CA", "Canada"), - ("CV", "Cape Verde"), - ("KY", "Cayman Islands"), - ("CF", "Central African Republic"), - ("TD", "Chad"), - ("CL", "Chile"), - ("CN", "China"), - ("CX", "Christmas Island"), - ("CC", "Cocos (Keeling) Islands"), - ("CO", "Colombia"), - ("KM", "Comoros"), - ("CG", "Congo"), - ("CD", "Congo, The Democratic Republic of the"), - ("CK", "Cook Islands"), - ("CR", "Costa Rica"), - ("CI", "Cote d'Ivoire"), - ("HR", "Croatia"), - ("CU", "Cuba"), - ("CY", "Cyprus"), - ("CZ", "Czech Republic"), - ("DK", "Denmark"), - ("DJ", "Djibouti"), - ("DM", "Dominica"), - ("DO", "Dominican Republic"), - ("EC", "Ecuador"), - ("EG", "Egypt"), - ("SV", "El Salvador"), - ("GQ", "Equatorial Guinea"), - ("ER", "Eritrea"), - ("EE", "Estonia"), - ("ET", "Ethiopia"), - ("FK", "Falkland Islands (Malvinas)"), - ("FO", "Faroe Islands"), - ("FJ", "Fiji"), - ("FI", "Finland"), - ("FR", "France"), - ("GF", "French Guiana"), - ("PF", "French Polynesia"), - ("TF", "French Southern Territories"), - ("GA", "Gabon"), - ("GM", "Gambia"), - ("GE", "Georgia"), - ("DE", "Germany"), - ("GH", "Ghana"), - ("GI", "Gibraltar"), - ("GR", "Greece"), - ("GL", "Greenland"), - ("GD", "Grenada"), - ("GP", "Guadeloupe"), - ("GU", "Guam"), - ("GT", "Guatemala"), - ("GG", "Guernsey"), - ("GN", "Guinea"), - ("GW", "Guinea-Bissau"), - ("GY", "Guyana"), - ("HT", "Haiti"), - ("HM", "Heard Island and McDonald Islands"), - ("VA", "Holy See (Vatican City State)"), - ("HN", "Honduras"), - ("HK", "Hong Kong"), - ("HU", "Hungary"), - ("IS", "Iceland"), - ("IN", "India"), - ("ID", "Indonesia"), - ("IR", "Iran, Islamic Republic of"), - ("IQ", "Iraq"), - ("IE", "Ireland"), - ("IM", "Isle of Man"), - ("IL", "Israel"), - ("IT", "Italy"), - ("JM", "Jamaica"), - ("JP", "Japan"), - ("JE", "Jersey"), - ("JO", "Jordan"), - ("KZ", "Kazakhstan"), - ("KE", "Kenya"), - ("KI", "Kiribati"), - ("KP", "Korea, Democratic People's Republic of"), - ("KR", "Korea, Republic of"), - ("KW", "Kuwait"), - ("KG", "Kyrgyzstan"), - ("LA", "Lao People's Democratic Republic"), - ("LV", "Latvia"), - ("LB", "Lebanon"), - ("LS", "Lesotho"), - ("LR", "Liberia"), - ("LY", "Libyan Arab Jamahiriya"), - ("LI", "Liechtenstein"), - ("LT", "Lithuania"), - ("LU", "Luxembourg"), - ("MO", "Macao"), - ("MK", "Macedonia, The Former Yugoslav Republic of"), - ("MG", "Madagascar"), - ("MW", "Malawi"), - ("MY", "Malaysia"), - ("MV", "Maldives"), - ("ML", "Mali"), - ("MT", "Malta"), - ("MH", "Marshall Islands"), - ("MQ", "Martinique"), - ("MR", "Mauritania"), - ("MU", "Mauritius"), - ("YT", "Mayotte"), - ("MX", "Mexico"), - ("FM", "Micronesia, Federated States of"), - ("MD", "Moldova"), - ("MC", "Monaco"), - ("MN", "Mongolia"), - ("ME", "Montenegro"), - ("MS", "Montserrat"), - ("MA", "Morocco"), - ("MZ", "Mozambique"), - ("MM", "Myanmar"), - ("NA", "Namibia"), - ("NR", "Nauru"), - ("NP", "Nepal"), - ("NL", "Netherlands"), - ("AN", "Netherlands Antilles"), - ("NC", "New Caledonia"), - ("NZ", "New Zealand"), - ("NI", "Nicaragua"), - ("NE", "Niger"), - ("NG", "Nigeria"), - ("NU", "Niue"), - ("NF", "Norfolk Island"), - ("MP", "Northern Mariana Islands"), - ("NO", "Norway"), - ("OM", "Oman"), - ("PK", "Pakistan"), - ("PW", "Palau"), - ("PS", "Palestinian Territory, Occupied"), - ("PA", "Panama"), - ("PG", "Papua New Guinea"), - ("PY", "Paraguay"), - ("PE", "Peru"), - ("PH", "Philippines"), - ("PN", "Pitcairn"), - ("PL", "Poland"), - ("PT", "Portugal"), - ("PR", "Puerto Rico"), - ("QA", "Qatar"), - ("RE", "Reunion"), - ("RO", "Romania"), - ("RU", "Russian Federation"), - ("RW", "Rwanda"), - ("BL", "Saint Barthelemy"), - ("SH", "Saint Helena"), - ("KN", "Saint Kitts and Nevis"), - ("LC", "Saint Lucia"), - ("MF", "Saint Martin"), - ("PM", "Saint Pierre and Miquelon"), - ("VC", "Saint Vincent and the Grenadines"), - ("WS", "Samoa"), - ("SM", "San Marino"), - ("ST", "Sao Tome and Principe"), - ("SA", "Saudi Arabia"), - ("SN", "Senegal"), - ("RS", "Serbia"), - ("SC", "Seychelles"), - ("SL", "Sierra Leone"), - ("SG", "Singapore"), - ("SK", "Slovakia"), - ("SI", "Slovenia"), - ("SB", "Solomon Islands"), - ("SO", "Somalia"), - ("ZA", "South Africa"), - ("GS", "South Georgia and the South Sandwich Islands"), - ("ES", "Spain"), - ("LK", "Sri Lanka"), - ("SD", "Sudan"), - ("SR", "Suriname"), - ("SJ", "Svalbard and Jan Mayen"), - ("SZ", "Swaziland"), - ("SE", "Sweden"), - ("CH", "Switzerland"), - ("SY", "Syrian Arab Republic"), - ("TW", "Taiwan, Province of China"), - ("TJ", "Tajikistan"), - ("TZ", "Tanzania, United Republic of"), - ("TH", "Thailand"), - ("TL", "Timor-Leste"), - ("TG", "Togo"), - ("TK", "Tokelau"), - ("TO", "Tonga"), - ("TT", "Trinidad and Tobago"), - ("TN", "Tunisia"), - ("TR", "Turkey"), - ("TM", "Turkmenistan"), - ("TC", "Turks and Caicos Islands"), - ("TV", "Tuvalu"), - ("UG", "Uganda"), - ("UA", "Ukraine"), - ("AE", "United Arab Emirates"), - ("US", "United States"), - ("UM", "United States Minor Outlying Islands"), - ("UY", "Uruguay"), - ("UZ", "Uzbekistan"), - ("VU", "Vanuatu"), - ("VE", "Venezuela"), - ("VN", "Viet Nam"), - ("VG", "Virgin Islands, British"), - ("VI", "Virgin Islands, U.S."), - ("WF", "Wallis and Futuna"), - ("EH", "Western Sahara"), - ("YE", "Yemen"), - ("ZM", "Zambia"), - ("ZW", "Zimbabwe"), - ], - max_length=3, - null=True, - ), - ), - ], - ), - migrations.AddField( - model_name="user", - name="company", - field=models.ForeignKey( - default=1, - on_delete=django.db.models.deletion.CASCADE, - to="common.Company", - ), - preserve_default=False, - ), - ] diff --git a/common/migrations/0020_auto_20200409_1653.py b/common/migrations/0020_auto_20200409_1653.py deleted file mode 100644 index 2ccc6f30..00000000 --- a/common/migrations/0020_auto_20200409_1653.py +++ /dev/null @@ -1,23 +0,0 @@ -# Generated by Django 2.2.10 on 2020-04-09 11:23 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0019_auto_20200401_0941"), - ] - - operations = [ - migrations.AlterField( - model_name="company", - name="address", - field=models.CharField(blank=True, max_length=2000, null=True), - ), - migrations.AlterField( - model_name="company", - name="name", - field=models.CharField(blank=True, max_length=100, null=True), - ), - ] diff --git a/common/migrations/0021_document_company.py b/common/migrations/0021_document_company.py deleted file mode 100644 index b3e805a0..00000000 --- a/common/migrations/0021_document_company.py +++ /dev/null @@ -1,24 +0,0 @@ -# Generated by Django 2.2.10 on 2020-04-27 11:40 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0020_auto_20200409_1653"), - ] - - operations = [ - migrations.AddField( - model_name="document", - name="company", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - to="common.Company", - ), - ), - ] diff --git a/common/migrations/0022_auto_20200609_1203.py b/common/migrations/0022_auto_20200609_1203.py deleted file mode 100644 index 0005fd27..00000000 --- a/common/migrations/0022_auto_20200609_1203.py +++ /dev/null @@ -1,24 +0,0 @@ -# Generated by Django 3.0.6 on 2020-06-09 06:33 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0021_document_company"), - ] - - operations = [ - migrations.AlterField( - model_name="user", - name="company", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - to="common.Company", - ), - ), - ] diff --git a/common/migrations/0023_apisettings_company.py b/common/migrations/0023_apisettings_company.py deleted file mode 100644 index d919c2ae..00000000 --- a/common/migrations/0023_apisettings_company.py +++ /dev/null @@ -1,24 +0,0 @@ -# Generated by Django 3.1 on 2021-01-13 11:24 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0022_auto_20200609_1203"), - ] - - operations = [ - migrations.AddField( - model_name="apisettings", - name="company", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - to="common.company", - ), - ), - ] diff --git a/common/migrations/0024_remove_user_company.py b/common/migrations/0024_remove_user_company.py deleted file mode 100644 index 7bb5ef65..00000000 --- a/common/migrations/0024_remove_user_company.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 3.1.7 on 2021-03-23 12:17 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0023_apisettings_company"), - ] - - operations = [ - migrations.RemoveField( - model_name="user", - name="company", - ), - ] diff --git a/common/migrations/0025_auto_20210324_1307.py b/common/migrations/0025_auto_20210324_1307.py deleted file mode 100644 index c4ae0c58..00000000 --- a/common/migrations/0025_auto_20210324_1307.py +++ /dev/null @@ -1,21 +0,0 @@ -# Generated by Django 3.1.7 on 2021-03-24 07:37 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0024_remove_user_company"), - ] - - operations = [ - migrations.RemoveField( - model_name="apisettings", - name="company", - ), - migrations.RemoveField( - model_name="document", - name="company", - ), - ] diff --git a/common/migrations/0026_auto_20210325_1923.py b/common/migrations/0026_auto_20210325_1923.py deleted file mode 100644 index b876414f..00000000 --- a/common/migrations/0026_auto_20210325_1923.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 3.1.7 on 2021-03-25 13:53 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0025_auto_20210324_1307"), - ] - - operations = [ - migrations.AlterField( - model_name="profile", - name="activation_key", - field=models.CharField(max_length=150), - ), - ] diff --git a/common/migrations/0027_auto_20210418_1112.py b/common/migrations/0027_auto_20210418_1112.py deleted file mode 100644 index ff983c1d..00000000 --- a/common/migrations/0027_auto_20210418_1112.py +++ /dev/null @@ -1,108 +0,0 @@ -# Generated by Django 3.2 on 2021-04-18 05:42 - -import django.db.models.deletion -from django.conf import settings -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0026_auto_20210325_1923"), - ] - - operations = [ - migrations.AlterField( - model_name="address", - name="address_line", - field=models.CharField( - blank=True, default="", max_length=255, verbose_name="Address" - ), - ), - migrations.AlterField( - model_name="address", - name="city", - field=models.CharField( - blank=True, default="", max_length=255, verbose_name="City" - ), - ), - migrations.AlterField( - model_name="address", - name="postcode", - field=models.CharField( - blank=True, default="", max_length=64, verbose_name="Post/Zip-code" - ), - ), - migrations.AlterField( - model_name="address", - name="state", - field=models.CharField( - blank=True, default="", max_length=255, verbose_name="State" - ), - ), - migrations.AlterField( - model_name="address", - name="street", - field=models.CharField( - blank=True, default="", max_length=55, verbose_name="Street" - ), - ), - migrations.AlterField( - model_name="apisettings", - name="created_by", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="settings_created_by", - to=settings.AUTH_USER_MODEL, - ), - ), - migrations.AlterField( - model_name="apisettings", - name="title", - field=models.TextField(), - ), - migrations.AlterField( - model_name="attachments", - name="created_by", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="attachment_created_by", - to=settings.AUTH_USER_MODEL, - ), - ), - migrations.AlterField( - model_name="company", - name="address", - field=models.TextField(blank=True, default=""), - ), - migrations.AlterField( - model_name="company", - name="name", - field=models.CharField(blank=True, default="", max_length=100), - ), - migrations.AlterField( - model_name="document", - name="created_by", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="document_uploaded", - to=settings.AUTH_USER_MODEL, - ), - ), - migrations.AlterField( - model_name="document", - name="title", - field=models.TextField(blank=True, default=""), - ), - migrations.AlterField( - model_name="google", - name="google_url", - field=models.TextField(default=""), - ), - ] diff --git a/common/migrations/0028_user_phone.py b/common/migrations/0028_user_phone.py deleted file mode 100644 index 93f029c3..00000000 --- a/common/migrations/0028_user_phone.py +++ /dev/null @@ -1,21 +0,0 @@ -# Generated by Django 3.2 on 2021-06-18 07:33 - -import phonenumber_field.modelfields -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0027_auto_20210418_1112"), - ] - - operations = [ - migrations.AddField( - model_name="user", - name="phone", - field=phonenumber_field.modelfields.PhoneNumberField( - max_length=128, null=True, region=None - ), - ), - ] diff --git a/common/migrations/0029_auto_20210730_1328.py b/common/migrations/0029_auto_20210730_1328.py deleted file mode 100644 index 2a7ec83d..00000000 --- a/common/migrations/0029_auto_20210730_1328.py +++ /dev/null @@ -1,68 +0,0 @@ -# Generated by Django 3.2.5 on 2021-07-30 07:58 - -import django.db.models.deletion -import phonenumber_field.modelfields -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0028_user_phone"), - ] - - operations = [ - migrations.AddField( - model_name="user", - name="address", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - related_name="adress_users", - to="common.address", - ), - ), - migrations.AddField( - model_name="user", - name="alternate_email", - field=models.EmailField(default="", max_length=255), - preserve_default=False, - ), - migrations.AddField( - model_name="user", - name="alternate_phone", - field=phonenumber_field.modelfields.PhoneNumberField( - max_length=128, null=True, region=None - ), - ), - migrations.AddField( - model_name="user", - name="description", - field=models.TextField(blank=True, null=True), - ), - migrations.AddField( - model_name="user", - name="skype_ID", - field=models.CharField(default="", max_length=50), - preserve_default=False, - ), - migrations.AddField( - model_name="user", - name="type", - field=models.CharField(default="", max_length=50), - preserve_default=False, - ), - migrations.AlterField( - model_name="user", - name="phone", - field=phonenumber_field.modelfields.PhoneNumberField( - max_length=128, null=True, region=None, unique=True - ), - ), - migrations.AlterField( - model_name="user", - name="role", - field=models.CharField(max_length=50), - ), - ] diff --git a/common/migrations/0030_alter_user_role.py b/common/migrations/0030_alter_user_role.py deleted file mode 100644 index c161f6e5..00000000 --- a/common/migrations/0030_alter_user_role.py +++ /dev/null @@ -1,20 +0,0 @@ -# Generated by Django 3.2.5 on 2021-07-30 08:30 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0029_auto_20210730_1328"), - ] - - operations = [ - migrations.AlterField( - model_name="user", - name="role", - field=models.CharField( - choices=[("ADMIN", "ADMIN"), ("USER", "USER")], max_length=50 - ), - ), - ] diff --git a/common/migrations/0031_auto_20210805_1214.py b/common/migrations/0031_auto_20210805_1214.py deleted file mode 100644 index f871dcea..00000000 --- a/common/migrations/0031_auto_20210805_1214.py +++ /dev/null @@ -1,125 +0,0 @@ -# Generated by Django 3.2.5 on 2021-08-05 06:44 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0030_alter_user_role"), - ] - - operations = [ - migrations.RenameField( - model_name="user", - old_name="type", - new_name="user_type", - ), - migrations.AlterField( - model_name="address", - name="address_line", - field=models.CharField( - blank=True, max_length=255, null=True, verbose_name="Address" - ), - ), - migrations.AlterField( - model_name="address", - name="city", - field=models.CharField( - blank=True, max_length=255, null=True, verbose_name="City" - ), - ), - migrations.AlterField( - model_name="address", - name="postcode", - field=models.CharField( - blank=True, max_length=64, null=True, verbose_name="Post/Zip-code" - ), - ), - migrations.AlterField( - model_name="address", - name="state", - field=models.CharField( - blank=True, max_length=255, null=True, verbose_name="State" - ), - ), - migrations.AlterField( - model_name="address", - name="street", - field=models.CharField( - blank=True, max_length=55, null=True, verbose_name="Street" - ), - ), - migrations.AlterField( - model_name="apisettings", - name="website", - field=models.URLField(max_length=255, null=True), - ), - migrations.AlterField( - model_name="comment_files", - name="comment_file", - field=models.FileField( - null=True, upload_to="comment_files", verbose_name="File" - ), - ), - migrations.AlterField( - model_name="company", - name="address", - field=models.TextField(blank=True, null=True), - ), - migrations.AlterField( - model_name="company", - name="name", - field=models.CharField(blank=True, max_length=100, null=True), - ), - migrations.AlterField( - model_name="document", - name="title", - field=models.TextField(blank=True, null=True), - ), - migrations.AlterField( - model_name="google", - name="dob", - field=models.CharField(max_length=50, null=True), - ), - migrations.AlterField( - model_name="google", - name="email", - field=models.CharField(db_index=True, max_length=200, null=True), - ), - migrations.AlterField( - model_name="google", - name="family_name", - field=models.CharField(max_length=200, null=True), - ), - migrations.AlterField( - model_name="google", - name="gender", - field=models.CharField(max_length=10, null=True), - ), - migrations.AlterField( - model_name="google", - name="given_name", - field=models.CharField(max_length=200, null=True), - ), - migrations.AlterField( - model_name="google", - name="google_id", - field=models.CharField(max_length=200, null=True), - ), - migrations.AlterField( - model_name="google", - name="google_url", - field=models.TextField(null=True), - ), - migrations.AlterField( - model_name="google", - name="name", - field=models.CharField(max_length=200, null=True), - ), - migrations.AlterField( - model_name="google", - name="verified_email", - field=models.CharField(max_length=200, null=True), - ), - ] diff --git a/common/migrations/0032_remove_user_user_type.py b/common/migrations/0032_remove_user_user_type.py deleted file mode 100644 index d0732205..00000000 --- a/common/migrations/0032_remove_user_user_type.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 3.2.5 on 2021-08-20 06:57 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0031_auto_20210805_1214"), - ] - - operations = [ - migrations.RemoveField( - model_name="user", - name="user_type", - ), - ] diff --git a/common/migrations/0033_alter_user_alternate_email.py b/common/migrations/0033_alter_user_alternate_email.py deleted file mode 100644 index 3b605867..00000000 --- a/common/migrations/0033_alter_user_alternate_email.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 3.2.5 on 2021-09-02 06:24 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0032_remove_user_user_type"), - ] - - operations = [ - migrations.AlterField( - model_name="user", - name="alternate_email", - field=models.EmailField(max_length=255, null=True), - ), - ] diff --git a/common/migrations/0034_auto_20210913_1918.py b/common/migrations/0034_auto_20210913_1918.py deleted file mode 100644 index c9b92d80..00000000 --- a/common/migrations/0034_auto_20210913_1918.py +++ /dev/null @@ -1,249 +0,0 @@ -# Generated by Django 3.2 on 2021-09-13 13:48 - -import django.db.models.deletion -import phonenumber_field.modelfields -from django.conf import settings -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0033_alter_user_alternate_email"), - ] - - operations = [ - migrations.RemoveField( - model_name="comment", - name="user", - ), - migrations.RemoveField( - model_name="google", - name="user", - ), - migrations.RemoveField( - model_name="user", - name="address", - ), - migrations.RemoveField( - model_name="user", - name="alternate_phone", - ), - migrations.RemoveField( - model_name="user", - name="has_marketing_access", - ), - migrations.RemoveField( - model_name="user", - name="has_sales_access", - ), - migrations.RemoveField( - model_name="user", - name="is_admin", - ), - migrations.RemoveField( - model_name="user", - name="phone", - ), - migrations.RemoveField( - model_name="user", - name="role", - ), - migrations.AddField( - model_name="apisettings", - name="company", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - to="common.company", - ), - ), - migrations.AddField( - model_name="comment", - name="profile", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - related_name="user_comments", - to="common.profile", - ), - ), - migrations.AddField( - model_name="document", - name="company", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - to="common.company", - ), - ), - migrations.AddField( - model_name="google", - name="profile", - field=models.ForeignKey( - null=True, - on_delete=django.db.models.deletion.CASCADE, - related_name="google", - to="common.profile", - ), - ), - migrations.AddField( - model_name="profile", - name="address", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - related_name="adress_users", - to="common.address", - ), - ), - migrations.AddField( - model_name="profile", - name="alternate_phone", - field=phonenumber_field.modelfields.PhoneNumberField( - max_length=128, null=True, region=None - ), - ), - migrations.AddField( - model_name="profile", - name="company", - field=models.ForeignKey( - null=True, - on_delete=django.db.models.deletion.CASCADE, - to="common.company", - ), - ), - migrations.AddField( - model_name="profile", - name="date_of_joining", - field=models.DateField(blank=True, null=True), - ), - migrations.AddField( - model_name="profile", - name="has_marketing_access", - field=models.BooleanField(default=False), - ), - migrations.AddField( - model_name="profile", - name="has_sales_access", - field=models.BooleanField(default=False), - ), - migrations.AddField( - model_name="profile", - name="is_active", - field=models.BooleanField(default=True), - ), - migrations.AddField( - model_name="profile", - name="is_organization_admin", - field=models.BooleanField(default=False), - ), - migrations.AddField( - model_name="profile", - name="phone", - field=phonenumber_field.modelfields.PhoneNumberField( - max_length=128, null=True, region=None, unique=True - ), - ), - migrations.AddField( - model_name="profile", - name="role", - field=models.CharField( - choices=[("ADMIN", "ADMIN"), ("USER", "USER")], - default="USER", - max_length=50, - ), - ), - migrations.AlterField( - model_name="apisettings", - name="created_by", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="settings_created_by", - to="common.profile", - ), - ), - migrations.AlterField( - model_name="apisettings", - name="lead_assigned_to", - field=models.ManyToManyField( - related_name="lead_assignee_users", to="common.Profile" - ), - ), - migrations.AlterField( - model_name="attachments", - name="created_by", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="attachment_created_by", - to="common.profile", - ), - ), - migrations.AlterField( - model_name="comment", - name="commented_by", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - to="common.profile", - ), - ), - migrations.AlterField( - model_name="company", - name="sub_domain", - field=models.CharField(blank=True, max_length=30, null=True), - ), - migrations.AlterField( - model_name="document", - name="created_by", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="document_uploaded", - to="common.profile", - ), - ), - migrations.AlterField( - model_name="document", - name="shared_to", - field=models.ManyToManyField( - related_name="document_shared_to", to="common.Profile" - ), - ), - migrations.AlterField( - model_name="profile", - name="activation_key", - field=models.CharField(blank=True, max_length=150, null=True), - ), - migrations.AlterField( - model_name="profile", - name="key_expires", - field=models.DateTimeField(blank=True, null=True), - ), - migrations.AlterField( - model_name="profile", - name="user", - field=models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL - ), - ), - migrations.AlterField( - model_name="user", - name="username", - field=models.CharField(blank=True, max_length=100, null=True), - ), - migrations.AlterUniqueTogether( - name="profile", - unique_together={("user", "company")}, - ), - ] diff --git a/common/migrations/0035_remove_company_sub_domain.py b/common/migrations/0035_remove_company_sub_domain.py deleted file mode 100644 index b527ccfc..00000000 --- a/common/migrations/0035_remove_company_sub_domain.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 3.2 on 2021-09-22 05:36 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0034_auto_20210913_1918"), - ] - - operations = [ - migrations.RemoveField( - model_name="company", - name="sub_domain", - ), - ] diff --git a/common/migrations/0036_auto_20210922_1801.py b/common/migrations/0036_auto_20210922_1801.py deleted file mode 100644 index 1b7d5f08..00000000 --- a/common/migrations/0036_auto_20210922_1801.py +++ /dev/null @@ -1,45 +0,0 @@ -# Generated by Django 3.2 on 2021-09-22 12:31 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ("events", "0007_rename_company_event_org"), - ("cases", "0009_rename_company_case_org"), - ("teams", "0007_rename_company_teams_org"), - ("leads", "0016_rename_company_lead_org"), - ("contacts", "0009_rename_company_contact_org"), - ("invoices", "0011_rename_company_invoice_org"), - ("tasks", "0008_rename_company_task_org"), - ("accounts", "0014_rename_company_account_org"), - ("opportunity", "0008_rename_company_opportunity_org"), - ("common", "0035_remove_company_sub_domain"), - ] - - operations = [ - migrations.RenameModel( - old_name="Company", - new_name="Org", - ), - migrations.RenameField( - model_name="apisettings", - old_name="company", - new_name="org", - ), - migrations.RenameField( - model_name="document", - old_name="company", - new_name="org", - ), - migrations.RenameField( - model_name="profile", - old_name="company", - new_name="org", - ), - migrations.AlterUniqueTogether( - name="profile", - unique_together={("user", "org")}, - ), - ] diff --git a/common/migrations/0037_alter_profile_org.py b/common/migrations/0037_alter_profile_org.py deleted file mode 100644 index cee7e0ae..00000000 --- a/common/migrations/0037_alter_profile_org.py +++ /dev/null @@ -1,24 +0,0 @@ -# Generated by Django 3.2.7 on 2021-10-06 07:21 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0036_auto_20210922_1801"), - ] - - operations = [ - migrations.AlterField( - model_name="profile", - name="org", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - to="common.org", - ), - ), - ] diff --git a/common/migrations/0038_auto_20220120_1318.py b/common/migrations/0038_auto_20220120_1318.py deleted file mode 100644 index c8fd0af0..00000000 --- a/common/migrations/0038_auto_20220120_1318.py +++ /dev/null @@ -1,74 +0,0 @@ -# Generated by Django 3.2.8 on 2022-01-20 07:48 - -import django.db.models.deletion -from django.conf import settings -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0037_alter_profile_org"), - ] - - operations = [ - migrations.RemoveField( - model_name="google", - name="profile", - ), - migrations.AddField( - model_name="google", - name="user", - field=models.ForeignKey( - null=True, - on_delete=django.db.models.deletion.CASCADE, - related_name="google_user", - to=settings.AUTH_USER_MODEL, - ), - ), - migrations.AlterField( - model_name="google", - name="dob", - field=models.CharField(default="", max_length=50), - ), - migrations.AlterField( - model_name="google", - name="email", - field=models.CharField(db_index=True, default="", max_length=200), - ), - migrations.AlterField( - model_name="google", - name="family_name", - field=models.CharField(default="", max_length=200), - ), - migrations.AlterField( - model_name="google", - name="gender", - field=models.CharField(default="", max_length=10), - ), - migrations.AlterField( - model_name="google", - name="given_name", - field=models.CharField(default="", max_length=200), - ), - migrations.AlterField( - model_name="google", - name="google_id", - field=models.CharField(default="", max_length=200), - ), - migrations.AlterField( - model_name="google", - name="google_url", - field=models.TextField(default=""), - ), - migrations.AlterField( - model_name="google", - name="name", - field=models.CharField(default="", max_length=200), - ), - migrations.AlterField( - model_name="google", - name="verified_email", - field=models.CharField(default="", max_length=200), - ), - ] diff --git a/common/migrations/0039_auto_20220202_2023.py b/common/migrations/0039_auto_20220202_2023.py deleted file mode 100644 index c62735c5..00000000 --- a/common/migrations/0039_auto_20220202_2023.py +++ /dev/null @@ -1,346 +0,0 @@ -# Generated by Django 3.2.11 on 2022-02-02 14:53 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0038_auto_20220120_1318"), - ] - - operations = [ - migrations.AlterField( - model_name="address", - name="address_line", - field=models.CharField( - blank=True, default="", max_length=255, verbose_name="Address" - ), - ), - migrations.AlterField( - model_name="address", - name="city", - field=models.CharField( - blank=True, default="", max_length=255, verbose_name="City" - ), - ), - migrations.AlterField( - model_name="address", - name="country", - field=models.CharField( - blank=True, - choices=[ - ("GB", "United Kingdom"), - ("AF", "Afghanistan"), - ("AX", "Aland Islands"), - ("AL", "Albania"), - ("DZ", "Algeria"), - ("AS", "American Samoa"), - ("AD", "Andorra"), - ("AO", "Angola"), - ("AI", "Anguilla"), - ("AQ", "Antarctica"), - ("AG", "Antigua and Barbuda"), - ("AR", "Argentina"), - ("AM", "Armenia"), - ("AW", "Aruba"), - ("AU", "Australia"), - ("AT", "Austria"), - ("AZ", "Azerbaijan"), - ("BS", "Bahamas"), - ("BH", "Bahrain"), - ("BD", "Bangladesh"), - ("BB", "Barbados"), - ("BY", "Belarus"), - ("BE", "Belgium"), - ("BZ", "Belize"), - ("BJ", "Benin"), - ("BM", "Bermuda"), - ("BT", "Bhutan"), - ("BO", "Bolivia"), - ("BA", "Bosnia and Herzegovina"), - ("BW", "Botswana"), - ("BV", "Bouvet Island"), - ("BR", "Brazil"), - ("IO", "British Indian Ocean Territory"), - ("BN", "Brunei Darussalam"), - ("BG", "Bulgaria"), - ("BF", "Burkina Faso"), - ("BI", "Burundi"), - ("KH", "Cambodia"), - ("CM", "Cameroon"), - ("CA", "Canada"), - ("CV", "Cape Verde"), - ("KY", "Cayman Islands"), - ("CF", "Central African Republic"), - ("TD", "Chad"), - ("CL", "Chile"), - ("CN", "China"), - ("CX", "Christmas Island"), - ("CC", "Cocos (Keeling) Islands"), - ("CO", "Colombia"), - ("KM", "Comoros"), - ("CG", "Congo"), - ("CD", "Congo, The Democratic Republic of the"), - ("CK", "Cook Islands"), - ("CR", "Costa Rica"), - ("CI", "Cote d'Ivoire"), - ("HR", "Croatia"), - ("CU", "Cuba"), - ("CY", "Cyprus"), - ("CZ", "Czech Republic"), - ("DK", "Denmark"), - ("DJ", "Djibouti"), - ("DM", "Dominica"), - ("DO", "Dominican Republic"), - ("EC", "Ecuador"), - ("EG", "Egypt"), - ("SV", "El Salvador"), - ("GQ", "Equatorial Guinea"), - ("ER", "Eritrea"), - ("EE", "Estonia"), - ("ET", "Ethiopia"), - ("FK", "Falkland Islands (Malvinas)"), - ("FO", "Faroe Islands"), - ("FJ", "Fiji"), - ("FI", "Finland"), - ("FR", "France"), - ("GF", "French Guiana"), - ("PF", "French Polynesia"), - ("TF", "French Southern Territories"), - ("GA", "Gabon"), - ("GM", "Gambia"), - ("GE", "Georgia"), - ("DE", "Germany"), - ("GH", "Ghana"), - ("GI", "Gibraltar"), - ("GR", "Greece"), - ("GL", "Greenland"), - ("GD", "Grenada"), - ("GP", "Guadeloupe"), - ("GU", "Guam"), - ("GT", "Guatemala"), - ("GG", "Guernsey"), - ("GN", "Guinea"), - ("GW", "Guinea-Bissau"), - ("GY", "Guyana"), - ("HT", "Haiti"), - ("HM", "Heard Island and McDonald Islands"), - ("VA", "Holy See (Vatican City State)"), - ("HN", "Honduras"), - ("HK", "Hong Kong"), - ("HU", "Hungary"), - ("IS", "Iceland"), - ("IN", "India"), - ("ID", "Indonesia"), - ("IR", "Iran, Islamic Republic of"), - ("IQ", "Iraq"), - ("IE", "Ireland"), - ("IM", "Isle of Man"), - ("IL", "Israel"), - ("IT", "Italy"), - ("JM", "Jamaica"), - ("JP", "Japan"), - ("JE", "Jersey"), - ("JO", "Jordan"), - ("KZ", "Kazakhstan"), - ("KE", "Kenya"), - ("KI", "Kiribati"), - ("KP", "Korea, Democratic People's Republic of"), - ("KR", "Korea, Republic of"), - ("KW", "Kuwait"), - ("KG", "Kyrgyzstan"), - ("LA", "Lao People's Democratic Republic"), - ("LV", "Latvia"), - ("LB", "Lebanon"), - ("LS", "Lesotho"), - ("LR", "Liberia"), - ("LY", "Libyan Arab Jamahiriya"), - ("LI", "Liechtenstein"), - ("LT", "Lithuania"), - ("LU", "Luxembourg"), - ("MO", "Macao"), - ("MK", "Macedonia, The Former Yugoslav Republic of"), - ("MG", "Madagascar"), - ("MW", "Malawi"), - ("MY", "Malaysia"), - ("MV", "Maldives"), - ("ML", "Mali"), - ("MT", "Malta"), - ("MH", "Marshall Islands"), - ("MQ", "Martinique"), - ("MR", "Mauritania"), - ("MU", "Mauritius"), - ("YT", "Mayotte"), - ("MX", "Mexico"), - ("FM", "Micronesia, Federated States of"), - ("MD", "Moldova"), - ("MC", "Monaco"), - ("MN", "Mongolia"), - ("ME", "Montenegro"), - ("MS", "Montserrat"), - ("MA", "Morocco"), - ("MZ", "Mozambique"), - ("MM", "Myanmar"), - ("NA", "Namibia"), - ("NR", "Nauru"), - ("NP", "Nepal"), - ("NL", "Netherlands"), - ("AN", "Netherlands Antilles"), - ("NC", "New Caledonia"), - ("NZ", "New Zealand"), - ("NI", "Nicaragua"), - ("NE", "Niger"), - ("NG", "Nigeria"), - ("NU", "Niue"), - ("NF", "Norfolk Island"), - ("MP", "Northern Mariana Islands"), - ("NO", "Norway"), - ("OM", "Oman"), - ("PK", "Pakistan"), - ("PW", "Palau"), - ("PS", "Palestinian Territory, Occupied"), - ("PA", "Panama"), - ("PG", "Papua New Guinea"), - ("PY", "Paraguay"), - ("PE", "Peru"), - ("PH", "Philippines"), - ("PN", "Pitcairn"), - ("PL", "Poland"), - ("PT", "Portugal"), - ("PR", "Puerto Rico"), - ("QA", "Qatar"), - ("RE", "Reunion"), - ("RO", "Romania"), - ("RU", "Russian Federation"), - ("RW", "Rwanda"), - ("BL", "Saint Barthelemy"), - ("SH", "Saint Helena"), - ("KN", "Saint Kitts and Nevis"), - ("LC", "Saint Lucia"), - ("MF", "Saint Martin"), - ("PM", "Saint Pierre and Miquelon"), - ("VC", "Saint Vincent and the Grenadines"), - ("WS", "Samoa"), - ("SM", "San Marino"), - ("ST", "Sao Tome and Principe"), - ("SA", "Saudi Arabia"), - ("SN", "Senegal"), - ("RS", "Serbia"), - ("SC", "Seychelles"), - ("SL", "Sierra Leone"), - ("SG", "Singapore"), - ("SK", "Slovakia"), - ("SI", "Slovenia"), - ("SB", "Solomon Islands"), - ("SO", "Somalia"), - ("ZA", "South Africa"), - ("GS", "South Georgia and the South Sandwich Islands"), - ("ES", "Spain"), - ("LK", "Sri Lanka"), - ("SD", "Sudan"), - ("SR", "Suriname"), - ("SJ", "Svalbard and Jan Mayen"), - ("SZ", "Swaziland"), - ("SE", "Sweden"), - ("CH", "Switzerland"), - ("SY", "Syrian Arab Republic"), - ("TW", "Taiwan, Province of China"), - ("TJ", "Tajikistan"), - ("TZ", "Tanzania, United Republic of"), - ("TH", "Thailand"), - ("TL", "Timor-Leste"), - ("TG", "Togo"), - ("TK", "Tokelau"), - ("TO", "Tonga"), - ("TT", "Trinidad and Tobago"), - ("TN", "Tunisia"), - ("TR", "Turkey"), - ("TM", "Turkmenistan"), - ("TC", "Turks and Caicos Islands"), - ("TV", "Tuvalu"), - ("UG", "Uganda"), - ("UA", "Ukraine"), - ("AE", "United Arab Emirates"), - ("US", "United States"), - ("UM", "United States Minor Outlying Islands"), - ("UY", "Uruguay"), - ("UZ", "Uzbekistan"), - ("VU", "Vanuatu"), - ("VE", "Venezuela"), - ("VN", "Viet Nam"), - ("VG", "Virgin Islands, British"), - ("VI", "Virgin Islands, U.S."), - ("WF", "Wallis and Futuna"), - ("EH", "Western Sahara"), - ("YE", "Yemen"), - ("ZM", "Zambia"), - ("ZW", "Zimbabwe"), - ], - default="", - max_length=3, - ), - ), - migrations.AlterField( - model_name="address", - name="postcode", - field=models.CharField( - blank=True, default="", max_length=64, verbose_name="Post/Zip-code" - ), - ), - migrations.AlterField( - model_name="address", - name="state", - field=models.CharField( - blank=True, default="", max_length=255, verbose_name="State" - ), - ), - migrations.AlterField( - model_name="address", - name="street", - field=models.CharField( - blank=True, default="", max_length=55, verbose_name="Street" - ), - ), - migrations.AlterField( - model_name="apisettings", - name="org", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="org_api_settings", - to="common.org", - ), - ), - migrations.AlterField( - model_name="comment_files", - name="comment_file", - field=models.FileField( - blank=True, null=True, upload_to="comment_files", verbose_name="File" - ), - ), - migrations.AlterField( - model_name="document", - name="org", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="document_org", - to="common.org", - ), - ), - migrations.AlterField( - model_name="profile", - name="org", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - related_name="user_org", - to="common.org", - ), - ), - ] diff --git a/common/migrations/0040_user_activation_key.py b/common/migrations/0040_user_activation_key.py deleted file mode 100644 index 0b8b926b..00000000 --- a/common/migrations/0040_user_activation_key.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 3.2 on 2022-08-19 10:05 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0039_auto_20220202_2023"), - ] - - operations = [ - migrations.AddField( - model_name="user", - name="activation_key", - field=models.CharField(blank=True, max_length=150, null=True), - ), - ] diff --git a/common/migrations/0041_user_key_expires.py b/common/migrations/0041_user_key_expires.py deleted file mode 100644 index b7c6c454..00000000 --- a/common/migrations/0041_user_key_expires.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 4.1 on 2022-09-05 10:41 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0040_user_activation_key"), - ] - - operations = [ - migrations.AddField( - model_name="user", - name="key_expires", - field=models.DateTimeField(blank=True, null=True), - ), - ] diff --git a/common/migrations/0042_remove_profile_activation_key_and_more.py b/common/migrations/0042_remove_profile_activation_key_and_more.py deleted file mode 100644 index df86667b..00000000 --- a/common/migrations/0042_remove_profile_activation_key_and_more.py +++ /dev/null @@ -1,21 +0,0 @@ -# Generated by Django 4.1 on 2022-09-05 10:51 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0041_user_key_expires"), - ] - - operations = [ - migrations.RemoveField( - model_name="profile", - name="activation_key", - ), - migrations.RemoveField( - model_name="profile", - name="key_expires", - ), - ] diff --git a/common/mixins.py b/common/mixins.py new file mode 100644 index 00000000..d99d997f --- /dev/null +++ b/common/mixins.py @@ -0,0 +1,50 @@ +# Python imports +import uuid + +# Django imports +from common.models import models + + +class TimeAuditModel(models.Model): + + """To path when the record was created and last modified""" + + created_at = models.DateTimeField( + auto_now_add=True, + verbose_name="Created At", + ) + updated_at = models.DateTimeField(auto_now=True, verbose_name="Last Modified At") + + class Meta: + abstract = True + + +class UserAuditModel(models.Model): + + """To path when the record was created and last modified""" + + created_by = models.ForeignKey( + "common.User", + on_delete=models.SET_NULL, + related_name="%(class)s_created_by", + verbose_name="Created By", + null=True, + ) + updated_by = models.ForeignKey( + "common.User", + on_delete=models.SET_NULL, + related_name="%(class)s_updated_by", + verbose_name="Last Modified By", + null=True, + ) + + class Meta: + abstract = True + + +class AuditModel(TimeAuditModel, UserAuditModel): + + """To path when the record was created and last modified""" + + class Meta: + abstract = True \ No newline at end of file diff --git a/common/models.py b/common/models.py index 2fcab04f..afa2ebb0 100644 --- a/common/models.py +++ b/common/models.py @@ -2,24 +2,28 @@ import binascii import datetime import os import time +import uuid import arrow -from django.contrib.auth.models import (AbstractBaseUser, PermissionsMixin, - UserManager) +from django.contrib.auth.models import AbstractUser +from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin, UserManager from django.db import models from django.utils import timezone from django.utils.translation import gettext_lazy as _ from phonenumber_field.modelfields import PhoneNumberField -from common.templatetags.common_tags import (is_document_file_audio, - is_document_file_code, - is_document_file_image, - is_document_file_pdf, - is_document_file_sheet, - is_document_file_text, - is_document_file_video, - is_document_file_zip) +from common.templatetags.common_tags import ( + is_document_file_audio, + is_document_file_code, + is_document_file_image, + is_document_file_pdf, + is_document_file_sheet, + is_document_file_text, + is_document_file_video, + is_document_file_zip, +) from common.utils import COUNTRIES, ROLES +from common.base import BaseModel def img_url(self, filename): @@ -27,7 +31,39 @@ def img_url(self, filename): return "%s/%s/%s" % ("profile_pics", hash_, filename) -class Address(models.Model): +class User(AbstractBaseUser, PermissionsMixin): + id = models.UUIDField( + default=uuid.uuid4, unique=True, editable=False, db_index=True, primary_key=True + ) + email = models.EmailField(_("email address"), blank=True, unique=True) + profile_pic = models.CharField( + max_length=1000, null=True, blank=True + ) + activation_key = models.CharField(max_length=150, null=True, blank=True) + key_expires = models.DateTimeField(null=True, blank=True) + is_active = models.BooleanField(default=True) + + USERNAME_FIELD = "email" + REQUIRED_FIELDS = ["username"] + + + objects = UserManager() + + class Meta: + verbose_name = "User" + verbose_name_plural = "Users" + db_table = "users" + ordering = ("-is_active",) + + def __str__(self): + return self.email + + # def save(self, *args, **kwargs): + # """by default the expiration time is set to 2 hours""" + # self.key_expires = timezone.now() + datetime.timedelta(hours=2) + # super().save(*args, **kwargs) + +class Address(BaseModel): address_line = models.CharField( _("Address"), max_length=255, blank=True, default="" ) @@ -39,6 +75,12 @@ class Address(models.Model): ) country = models.CharField(max_length=3, choices=COUNTRIES, blank=True, default="") + class Meta: + verbose_name = "Address" + verbose_name_plural = "Addresses" + db_table = "address" + ordering = ("-created_at",) + def __str__(self): return self.city if self.city else "" @@ -74,75 +116,77 @@ class Address(models.Model): return address -class Org(models.Model): +class Org(BaseModel): name = models.CharField(max_length=100, blank=True, null=True) - address = models.TextField(blank=True, null=True) - user_limit = models.IntegerField(default=5) - country = models.CharField(max_length=3, choices=COUNTRIES, blank=True, null=True) - - -class User(AbstractBaseUser, PermissionsMixin): - file_prepend = "users/profile_pics" - username = models.CharField(max_length=100, null=True, blank=True) - first_name = models.CharField(max_length=150, blank=True) - last_name = models.CharField(max_length=150, blank=True) - email = models.EmailField(max_length=255, unique=True) - alternate_email = models.EmailField(max_length=255, null=True) - is_active = models.BooleanField(default=True) - is_staff = models.BooleanField(default=False) - date_joined = models.DateTimeField(("date joined"), auto_now_add=True) - profile_pic = models.FileField( - max_length=1000, upload_to=img_url, null=True, blank=True - ) - activation_key = models.CharField(max_length=150, null=True, blank=True) - key_expires = models.DateTimeField(null=True, blank=True) - skype_ID = models.CharField(max_length=50) - description = models.TextField(blank=True, null=True) - - USERNAME_FIELD = "email" - REQUIRED_FIELDS = ["username"] - - objects = UserManager() - - def get_short_name(self): - return self.username - - def documents(self): - return self.document_uploaded.all() - - def get_full_name(self): - full_name = None - if self.first_name or self.last_name: - full_name = self.first_name + " " + self.last_name - elif self.username: - full_name = self.username - else: - full_name = self.email - return full_name - - @property - def created_on_arrow(self): - return arrow.get(self.date_joined).humanize() + # address = models.TextField(blank=True, null=True) + # user_limit = models.IntegerField(default=5) + # country = models.CharField(max_length=3, choices=COUNTRIES, blank=True, null=True) class Meta: - ordering = ["-is_active"] + verbose_name = "Organization" + verbose_name_plural = "Organizations" + db_table = "organization" + ordering = ("-created_at",) def __str__(self): - return self.email - - def save(self, *args, **kwargs): - """by default the expiration time is set to 2 hours""" - self.key_expires = timezone.now() + datetime.timedelta(hours=2) - super().save(*args, **kwargs) + return str(self.name) -class Profile(models.Model): +# class User(AbstractBaseUser, PermissionsMixin): +# email = models.EmailField(_("email address"), blank=True, unique=True) +# profile_pic = models.FileField( +# max_length=1000, upload_to=img_url, null=True, blank=True +# ) +# activation_key = models.CharField(max_length=150, null=True, blank=True) +# key_expires = models.DateTimeField(null=True, blank=True) + + +# USERNAME_FIELD = "email" +# REQUIRED_FIELDS = ["username"] + +# objects = UserManager() + +# def get_short_name(self): +# return self.username + +# def documents(self): +# return self.document_uploaded.all() + +# def get_full_name(self): +# full_name = None +# if self.first_name or self.last_name: +# full_name = self.first_name + " " + self.last_name +# elif self.username: +# full_name = self.username +# else: +# full_name = self.email +# return full_name + +# @property +# def created_on_arrow(self): +# return arrow.get(self.date_joined).humanize() + +# class Meta: +# ordering = ["-is_active"] + +# def __str__(self): +# return self.email + +# def save(self, *args, **kwargs): +# """by default the expiration time is set to 2 hours""" +# self.key_expires = timezone.now() + datetime.timedelta(hours=2) +# super().save(*args, **kwargs) + + + + +class Profile(BaseModel): user = models.ForeignKey(User, on_delete=models.CASCADE) org = models.ForeignKey( Org, null=True, on_delete=models.CASCADE, blank=True, related_name="user_org" ) phone = PhoneNumberField(null=True, unique=True) - alternate_phone = PhoneNumberField(null=True) + alternate_phone = PhoneNumberField(null=True,blank=True) address = models.ForeignKey( Address, related_name="adress_users", @@ -158,14 +202,30 @@ class Profile(models.Model): date_of_joining = models.DateField(null=True, blank=True) class Meta: - unique_together = (("user", "org"),) + verbose_name = "Profile" + verbose_name_plural = "Profiles" + db_table = "profile" + ordering = ("-created_at",) + unique_together = ["user", "org"] + + def __str__(self): + return f"{self.user.email} <{self.org.name}>" @property def is_admin(self): return self.is_organization_admin + @property + def user_details(self): + return { + 'email' : self.user.email, + 'id' : self.user.id, + 'is_active' : self.user.is_active, + 'profile_pic' : self.user.profile_pic + } -class Comment(models.Model): + +class Comment(BaseModel): case = models.ForeignKey( "cases.Case", blank=True, @@ -238,21 +298,39 @@ class Comment(models.Model): on_delete=models.CASCADE, ) + class Meta: + verbose_name = "Comment" + verbose_name_plural = "Comments" + db_table = "comment" + ordering = ("-created_at",) + + def __str__(self): + return f"{self.comment}" + def get_files(self): - return Comment_Files.objects.filter(comment_id=self) + return CommentFiles.objects.filter(comment_id=self) @property def commented_on_arrow(self): return arrow.get(self.commented_on).humanize() -class Comment_Files(models.Model): +class CommentFiles(BaseModel): comment = models.ForeignKey(Comment, on_delete=models.CASCADE) updated_on = models.DateTimeField(auto_now_add=True) comment_file = models.FileField( - "File", upload_to="comment_files", null=True, blank=True + "File", upload_to="CommentFiles", null=True, blank=True ) + class Meta: + verbose_name = "CommentFile" + verbose_name_plural = "CommentFiles" + db_table = "commentFiles" + ordering = ("-created_at",) + + def __str__(self): + return f"{self.comment.comment}" + def get_file_name(self): if self.comment_file: return self.comment_file.path.split("/")[-1] @@ -260,7 +338,7 @@ class Comment_Files(models.Model): return None -class Attachments(models.Model): +class Attachments(BaseModel): created_by = models.ForeignKey( Profile, related_name="attachment_created_by", @@ -269,7 +347,6 @@ class Attachments(models.Model): blank=True, ) file_name = models.CharField(max_length=60) - created_on = models.DateTimeField(_("Created on"), auto_now_add=True) attachment = models.FileField(max_length=1001, upload_to="attachments/%Y/%m/") lead = models.ForeignKey( "leads.Lead", @@ -330,6 +407,15 @@ class Attachments(models.Model): on_delete=models.CASCADE, ) + class Meta: + verbose_name = "Attachment" + verbose_name_plural = "Attachments" + db_table = "attachments" + ordering = ("-created_at",) + + def __str__(self): + return f"{self.file_name}" + def file_type(self): name_ext_list = self.attachment.url.split(".") if len(name_ext_list) > 1: @@ -360,7 +446,7 @@ class Attachments(models.Model): @property def created_on_arrow(self): - return arrow.get(self.created_on).humanize() + return arrow.get(self.created_at).humanize() def document_path(self, filename): @@ -368,7 +454,7 @@ def document_path(self, filename): return "%s/%s/%s" % ("docs", hash_, filename) -class Document(models.Model): +class Document(BaseModel): DOCUMENT_STATUS_CHOICE = (("active", "active"), ("inactive", "inactive")) @@ -381,7 +467,7 @@ class Document(models.Model): null=True, blank=True, ) - created_on = models.DateTimeField(auto_now_add=True) + status = models.CharField( choices=DOCUMENT_STATUS_CHOICE, max_length=64, default="active" ) @@ -396,11 +482,14 @@ class Document(models.Model): ) class Meta: - ordering = ("-created_on",) + verbose_name = "Document" + verbose_name_plural = "Documents" + db_table = "document" + ordering = ("-created_at",) def __str__(self): - return self.title - + return f"{self.title}" + def file_type(self): name_ext_list = self.document_file.url.split(".") if len(name_ext_list) > 1: @@ -445,14 +534,14 @@ class Document(models.Model): @property def created_on_arrow(self): - return arrow.get(self.created_on).humanize() + return arrow.get(self.created_at).humanize() def generate_key(): return binascii.hexlify(os.urandom(8)).decode() -class APISettings(models.Model): +class APISettings(BaseModel): title = models.TextField() apikey = models.CharField(max_length=16, blank=True) website = models.URLField(max_length=255, null=True) @@ -474,33 +563,19 @@ class APISettings(models.Model): null=True, related_name="org_api_settings", ) - created_on = models.DateTimeField(auto_now_add=True) + class Meta: - ordering = ("-created_on",) + verbose_name = "APISetting" + verbose_name_plural = "APISettings" + db_table = "apiSettings" + ordering = ("-created_at",) def __str__(self): - return self.title + return f"{self.title}" + def save(self, *args, **kwargs): if not self.apikey or self.apikey is None or self.apikey == "": self.apikey = generate_key() super().save(*args, **kwargs) - - -class Google(models.Model): - user = models.ForeignKey( - User, related_name="google_user", on_delete=models.CASCADE, null=True - ) - google_id = models.CharField(max_length=200, default="") - google_url = models.TextField(default="") - verified_email = models.CharField(max_length=200, default="") - family_name = models.CharField(max_length=200, default="") - name = models.CharField(max_length=200, default="") - gender = models.CharField(max_length=10, default="") - dob = models.CharField(max_length=50, default="") - given_name = models.CharField(max_length=200, default="") - email = models.CharField(max_length=200, default="", db_index=True) - - def __str__(self): - return self.email diff --git a/common/serializer.py b/common/serializer.py index 2d5ca4c7..fc4678da 100644 --- a/common/serializer.py +++ b/common/serializer.py @@ -7,34 +7,16 @@ from django.utils.http import urlsafe_base64_decode from rest_framework import serializers from rest_framework_simplejwt.tokens import AccessToken, RefreshToken -from common.models import (Address, APISettings, Attachments, Comment, - Document, Org, Profile, User) - - -class LoginSealizer(serializers.Serializer): - - email = serializers.CharField(max_length=255) - password = serializers.CharField(max_length=128, write_only=True) - access_token = serializers.CharField(max_length=None, read_only=True) - refresh_token = serializers.CharField(max_length=None, read_only=True) - - def validate(self, data): - email = data.get("email", None) - password = data.get("password", None) - user = authenticate(email=email, password=password) - if user: - - refresh = RefreshToken.for_user(user) - access = AccessToken.for_user(user) - return { - "access_token": str(access), - "refresh_token": str(refresh), - "user_id": str(user.id), - "error": False, - "email": user.email, - } - else: - raise serializers.ValidationError("Login Failed or Account is inactive.") +from common.models import ( + Address, + APISettings, + Attachments, + Comment, + Document, + Org, + Profile, + User, +) class OrganizationSerializer(serializers.ModelSerializer): @@ -44,7 +26,7 @@ class OrganizationSerializer(serializers.ModelSerializer): class SocialLoginSerializer(serializers.Serializer): - accessToken = serializers.CharField() + token = serializers.CharField() class CommentSerializer(serializers.ModelSerializer): @@ -79,34 +61,6 @@ class LeadCommentSerializer(serializers.ModelSerializer): ) -class RegisterOrganizationSerializer(serializers.ModelSerializer): - email = serializers.EmailField() - first_name = serializers.CharField(max_length=255) - password = serializers.CharField(max_length=100) - - class Meta: - model = User - fields = ("email", "first_name", "password") - extra_kwargs = { - "email": {"required": True}, - "first_name": {"required": True}, - "password": {"required": True}, - } - - def validate_password(self, password): - if password: - if len(password) < 4: - raise serializers.ValidationError( - "Password must be at least 4 characters long!" - ) - return password - - def validate_email(self, email): - - if User.objects.filter(email__iexact=email).exists(): - raise serializers.ValidationError("This email is already registered.") - return email - class OrgProfileCreateSerializer(serializers.ModelSerializer): """ @@ -114,18 +68,12 @@ class OrgProfileCreateSerializer(serializers.ModelSerializer): """ name = serializers.CharField(max_length=255) - address = serializers.CharField(max_length=255) - user_limit = serializers.CharField(max_length=255) - country = serializers.CharField(max_length=255) class Meta: model = Org - fields = "__all__" + fields = ["name"] extra_kwargs = { - "name": {"required": True}, - "address": {"required": True}, - "user_limit": {"required": True}, - "country": {"required": True}, + "name": {"required": True} } def validate_name(self, name): @@ -145,7 +93,7 @@ class ShowOrganizationListSerializer(serializers.ModelSerializer): we are using it for show orjanization list """ - org = OrgProfileCreateSerializer() + org = OrganizationSerializer() class Meta: model = Profile @@ -184,28 +132,18 @@ class BillingAddressSerializer(serializers.ModelSerializer): class CreateUserSerializer(serializers.ModelSerializer): - password = serializers.CharField() class Meta: model = User fields = ( - "first_name", - "last_name", "email", - "alternate_email", - "skype_ID", - "description", "profile_pic", - "password", ) def __init__(self, *args, **kwargs): self.org = kwargs.pop("org", None) super().__init__(*args, **kwargs) - self.fields["first_name"].required = True - self.fields["password"].required = False - self.fields["profile_pic"].required = False - self.fields["skype_ID"].required = False + self.fields["email"].required = True def validate_email(self, email): if self.instance: @@ -239,34 +177,15 @@ class CreateProfileSerializer(serializers.ModelSerializer): class UserSerializer(serializers.ModelSerializer): - profile_pic = serializers.SerializerMethodField() - - def get_profile_pic(self, obj): - if obj.profile_pic: - return obj.profile_pic.url - return None class Meta: model = User - fields = ( - "id", - "first_name", - "last_name", - "email", - "alternate_email", - "skype_ID", - "description", - "profile_pic", - ) + fields = ["id","email","profile_pic"] class ProfileSerializer(serializers.ModelSerializer): - user_details = serializers.SerializerMethodField() address = BillingAddressSerializer() - def get_user_details(self, obj): - return UserSerializer(obj.user).data - class Meta: model = Profile fields = ( @@ -282,55 +201,6 @@ class ProfileSerializer(serializers.ModelSerializer): ) -class ForgotPasswordSerializer(serializers.Serializer): - email = serializers.CharField(max_length=200) - - def validate(self, data): - email = data.get("email") - user = User.objects.filter(email__iexact=email).last() - if not user: - raise serializers.ValidationError( - "You don't have an account. Please create one." - ) - return data - - -class CheckTokenSerializer(serializers.Serializer): - uidb64_regex = r"[0-9A-Za-z_\-]+" - token_regex = r"[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20}" - uidb64 = serializers.RegexField(uidb64_regex) - token = serializers.RegexField(token_regex) - error_message = {"__all__": ("Invalid password reset token")} - - def get_user(self, uidb64): - try: - uid = urlsafe_base64_decode(uidb64).decode() - user = User._default_manager.get(pk=uid) - except (TypeError, ValueError, OverflowError, User.DoesNotExist): - user = None - return user - - -class ResetPasswordSerailizer(CheckTokenSerializer): - new_password1 = serializers.CharField() - new_password2 = serializers.CharField() - - def validate(self, data): - self.user = self.get_user(data.get("uid")) - if not self.user: - raise serializers.ValidationError(self.error_message) - is_valid_token = default_token_generator.check_token( - self.user, data.get("token") - ) - if not is_valid_token: - raise serializers.ValidationError(self.error_message) - new_password2 = data.get("new_password2") - new_password1 = data.get("new_password1") - if new_password1 != new_password2: - raise serializers.ValidationError("The two password fields didn't match.") - return new_password2 - - class AttachmentsSerializer(serializers.ModelSerializer): file_path = serializers.SerializerMethodField() @@ -450,31 +320,60 @@ class APISettingsListSerializer(serializers.ModelSerializer): "org", ] +class APISettingsSwaggerSerializer(serializers.ModelSerializer): + class Meta: + model = APISettings + fields = [ + "title", + "website", + "lead_assigned_to", + "tags", + ] -class PasswordChangeSerializer(serializers.Serializer): - old_password = serializers.CharField(max_length=100) - new_password = serializers.CharField(max_length=100) - retype_password = serializers.CharField(max_length=100) - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) +class DocumentCreateSwaggerSerializer(serializers.ModelSerializer): + class Meta: + model = Document + fields = [ + "title", + "document_file", + "teams", + "shared_to", + ] + +class DocumentEditSwaggerSerializer(serializers.ModelSerializer): + class Meta: + model = Document + fields = [ + "title", + "document_file", + "teams", + "shared_to", + "status" + ] + + +class UserCreateSwaggerSerializer(serializers.Serializer): + """ + It is swagger for creating or updating user + """ + ROLE_CHOICES = ["ADMIN", "USER"] + + email = serializers.CharField(max_length=1000,required=True) + role = serializers.ChoiceField(choices = ROLE_CHOICES,required=True) + phone = serializers.CharField(max_length=12) + alternate_phone = serializers.CharField(max_length=12) + address_line = serializers.CharField(max_length=10000,required=True) + street = serializers.CharField(max_length=1000) + city = serializers.CharField(max_length=1000) + state = serializers.CharField(max_length=1000) + pincode = serializers.CharField(max_length=1000) + country = serializers.CharField(max_length=1000) + +class UserUpdateStatusSwaggerSerializer(serializers.Serializer): + + STATUS_CHOICES = ["Active", "Inactive"] + + status = serializers.ChoiceField(choices = STATUS_CHOICES,required=True) - def validate_old_password(self, pwd): - if not check_password(pwd, self.context.get("user").password): - raise serializers.ValidationError("old password entered is incorrect.") - return pwd - def validate(self, data): - if len(data.get("new_password")) < 8: - raise serializers.ValidationError( - "Password must be at least 8 characters long!" - ) - if data.get("new_password") == data.get("old_password"): - raise serializers.ValidationError( - "New_password and old password should not be the same" - ) - if data.get("new_password") != data.get("retype_password"): - raise serializers.ValidationError( - "New_password and Retype_password did not match." - ) - return data diff --git a/common/swagger-ui.html b/common/swagger-ui.html new file mode 100644 index 00000000..18456413 --- /dev/null +++ b/common/swagger-ui.html @@ -0,0 +1,31 @@ + + + + + Swagger + + + + + + +
+ + + + + \ No newline at end of file diff --git a/common/swagger_params.py b/common/swagger_params.py deleted file mode 100644 index a05ab8b3..00000000 --- a/common/swagger_params.py +++ /dev/null @@ -1,258 +0,0 @@ -from drf_yasg import openapi - -organization_params_in_header = openapi.Parameter( - "org", openapi.IN_HEADER, required=True, type=openapi.TYPE_INTEGER -) - -organization_params = [ - organization_params_in_header, -] - -login_page_params = [ - openapi.Parameter( - "email", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), - openapi.Parameter( - "password", - openapi.IN_QUERY, - format="password", - required=True, - type=openapi.TYPE_STRING, - ), -] - -change_password_params = [ - organization_params_in_header, - openapi.Parameter( - "old_password", - openapi.IN_QUERY, - format="password", - required=True, - type=openapi.TYPE_STRING, - ), - openapi.Parameter( - "new_password", - openapi.IN_QUERY, - format="password", - required=True, - type=openapi.TYPE_STRING, - ), - openapi.Parameter( - "retype_password", - openapi.IN_QUERY, - format="password", - required=True, - type=openapi.TYPE_STRING, - ), -] - -user_update_params = [ - organization_params_in_header, - openapi.Parameter("first_name", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("last_name", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter( - "role", openapi.IN_QUERY, type=openapi.TYPE_STRING, enum=["ADMIN", "USER"] - ), - openapi.Parameter("email", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("alternate_email", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("phone", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("alternate_phone", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("skype_ID", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter( - "address_line", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), - openapi.Parameter("street", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("city", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("state", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("pincode", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("country", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("description", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("profile_pic", openapi.IN_QUERY, type=openapi.TYPE_FILE), - openapi.Parameter("has_sales_access", openapi.IN_QUERY, type=openapi.TYPE_BOOLEAN), - openapi.Parameter( - "has_marketing_access", openapi.IN_QUERY, type=openapi.TYPE_BOOLEAN - ), - openapi.Parameter( - "is_organization_admin", openapi.IN_QUERY, type=openapi.TYPE_BOOLEAN - ), - openapi.Parameter("teams", openapi.IN_QUERY, type=openapi.TYPE_STRING), -] - -user_delete_params = [ - organization_params_in_header, - openapi.Parameter( - "user_id", openapi.IN_QUERY, required=True, type=openapi.TYPE_NUMBER - ), -] - - -registration_page_params = [ - openapi.Parameter( - "first_name", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), - openapi.Parameter( - "email", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), - openapi.Parameter( - "password", - openapi.IN_QUERY, - format="password", - required=True, - type=openapi.TYPE_STRING, - ), -] - -post_org_creation_page_params = [ - openapi.Parameter( - "name", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), - openapi.Parameter( - "address", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), - openapi.Parameter( - "user_limit", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), - openapi.Parameter( - "country", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), -] - - -forgot_password_params = [ - openapi.Parameter( - "email", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), -] - -reset_password_params = [ - openapi.Parameter( - "new_password1", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), - openapi.Parameter( - "new_password2", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), -] - -user_list_params = [ - organization_params_in_header, - openapi.Parameter("username", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("email", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter( - "role", openapi.IN_QUERY, type=openapi.TYPE_STRING, enum=["ADMIN", "USER"] - ), - openapi.Parameter( - "status", - openapi.IN_QUERY, - type=openapi.TYPE_STRING, - enum=["Active", "In Active"], - ), -] - -user_create_params = [ - organization_params_in_header, - openapi.Parameter("first_name", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("last_name", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter( - "role", openapi.IN_QUERY, type=openapi.TYPE_STRING, enum=["ADMIN", "USER"] - ), - openapi.Parameter("email", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("alternate_email", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("phone", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("alternate_phone", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("skype_ID", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter( - "address_line", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), - openapi.Parameter("street", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("city", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("state", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("pincode", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("country", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("description", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("profile_pic", openapi.IN_QUERY, type=openapi.TYPE_FILE), - openapi.Parameter("has_sales_access", openapi.IN_QUERY, type=openapi.TYPE_BOOLEAN), - openapi.Parameter( - "has_marketing_access", openapi.IN_QUERY, type=openapi.TYPE_BOOLEAN - ), - openapi.Parameter( - "is_organization_admin", openapi.IN_QUERY, type=openapi.TYPE_BOOLEAN - ), - openapi.Parameter("status", openapi.IN_QUERY, type=openapi.TYPE_STRING), -] - -document_create_params = [ - organization_params_in_header, - openapi.Parameter( - "title", openapi.IN_QUERY, type=openapi.TYPE_STRING, required=True - ), - openapi.Parameter( - "document_file", openapi.IN_QUERY, type=openapi.TYPE_FILE, required=True - ), - openapi.Parameter("teams", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("shared_to", openapi.IN_QUERY, type=openapi.TYPE_STRING), -] - -document_get_params = [ - organization_params_in_header, - openapi.Parameter("title", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter( - "status", - openapi.IN_QUERY, - type=openapi.TYPE_STRING, - enum=["active", "inactive"], - ), - openapi.Parameter("shared_to", openapi.IN_QUERY, type=openapi.TYPE_STRING), -] - -document_update_params = [ - organization_params_in_header, - openapi.Parameter( - "title", openapi.IN_QUERY, type=openapi.TYPE_STRING, required=True - ), - openapi.Parameter( - "document_file", openapi.IN_QUERY, type=openapi.TYPE_FILE, required=True - ), - openapi.Parameter("teams", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("shared_to", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter( - "status", - openapi.IN_QUERY, - type=openapi.TYPE_STRING, - enum=["active", "inactive"], - ), -] - -users_status_params = [ - organization_params_in_header, - openapi.Parameter( - "status", - openapi.IN_QUERY, - type=openapi.TYPE_STRING, - enum=["Active", "Inactive"], - ), -] - -api_setting_create_params = [ - organization_params_in_header, - openapi.Parameter( - "title", openapi.IN_QUERY, type=openapi.TYPE_STRING, required=True - ), - openapi.Parameter( - "website", openapi.IN_QUERY, type=openapi.TYPE_STRING, required=True - ), - openapi.Parameter("lead_assigned_to", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter( - "tags", - openapi.IN_QUERY, - type=openapi.TYPE_STRING, - ), -] - -users_delete_params = [ - organization_params_in_header, - openapi.Parameter( - "users_list", - openapi.IN_QUERY, - type=openapi.TYPE_STRING, - ), -] diff --git a/common/swagger_params1.py b/common/swagger_params1.py new file mode 100644 index 00000000..4c41c3a4 --- /dev/null +++ b/common/swagger_params1.py @@ -0,0 +1,37 @@ +from drf_spectacular.types import OpenApiTypes +from drf_spectacular.utils import OpenApiParameter + +organization_params_in_header = OpenApiParameter( + "org", OpenApiTypes.STR, OpenApiParameter.HEADER +) + +organization_params = [ + organization_params_in_header, +] + +user_list_params = [ + organization_params_in_header, + OpenApiParameter("email", OpenApiTypes.STR,OpenApiParameter.QUERY), + OpenApiParameter( + "role", OpenApiTypes.STR, OpenApiParameter.QUERY,enum=["ADMIN", "USER"] + ), + OpenApiParameter( + "status", + OpenApiTypes.STR, + OpenApiParameter.QUERY, + enum=["Active", "In Active"], + ), +] + +document_get_params = [ + organization_params_in_header, + OpenApiParameter("title", OpenApiTypes.STR,OpenApiParameter.QUERY), + OpenApiParameter( + "status", + OpenApiTypes.STR, + OpenApiParameter.QUERY, + enum=["Active", "In Active"], + ), + OpenApiParameter("shared_to", OpenApiTypes.STR,OpenApiParameter.QUERY), +] + diff --git a/common/tests_celery_tasks.py b/common/tests_celery_tasks.py index 58fff6f3..c7dea2dd 100644 --- a/common/tests_celery_tasks.py +++ b/common/tests_celery_tasks.py @@ -6,9 +6,13 @@ from django.test.utils import override_settings from accounts.tests import AccountCreateTest from cases.tests import CaseCreation from common.models import Comment, User -from common.tasks import (resend_activation_link_to_user, - send_email_to_new_user, send_email_user_delete, - send_email_user_mentions, send_email_user_status) +from common.tasks import ( + resend_activation_link_to_user, + send_email_to_new_user, + send_email_user_delete, + send_email_user_mentions, + send_email_user_status, +) from common.tests import ObjectsCreation from contacts.tests import ContactObjectsCreation from events.tests import EventObjectTest diff --git a/common/urls.py b/common/urls.py index 68d8996b..7dcd5607 100644 --- a/common/urls.py +++ b/common/urls.py @@ -8,36 +8,21 @@ app_name = "api_common" urlpatterns = [ path("dashboard/", views.ApiHomeView.as_view()), - path("auth/register/", views.RegistrationView.as_view()), - path("auth/login/", views.LoginView.as_view()), path( - "auth/token/refresh/", + "auth/refresh-token/", jwt_views.TokenRefreshView.as_view(), name="token_refresh", ), # GoogleLoginView path("auth/google/", views.GoogleLoginView.as_view()), - path("auth/create-org/", views.OrgProfileCreateView.as_view()), - # path("auth/companies-list/", views.OrganizationListView.as_view()), + path("org/", views.OrgProfileCreateView.as_view()), path("profile/", views.ProfileView.as_view()), path("users/get-teams-and-users/", views.GetTeamsAndUsersView.as_view()), - path("profile/change-password/", views.ChangePasswordView.as_view()), - path("auth/forgot-password/", views.ForgotPasswordView.as_view()), - path( - "auth/reset-password///", - views.ResetPasswordView.as_view(), - ), - path( - "auth/activate-user////", - views.ActivateUserView.as_view(), - ), - path("auth/resend-activation-link/", views.ResendActivationLinkView.as_view()), path("users/", views.UsersListView.as_view()), - path("users//", views.UserDetailView.as_view()), + path("user//", views.UserDetailView.as_view()), path("documents/", views.DocumentListView.as_view()), - path("documents//", views.DocumentDetailView.as_view()), + path("documents//", views.DocumentDetailView.as_view()), path("api-settings/", views.DomainList.as_view()), - path("api-settings//", views.DomainDetailView.as_view()), - path("users//status/", views.UserStatusView.as_view()), - # path("delete_users/", views.UsersDelete.as_view()) + path("api-settings//", views.DomainDetailView.as_view()), + path("user//status/", views.UserStatusView.as_view()), ] diff --git a/common/utils.py b/common/utils.py index ba7a9ff0..908169c9 100644 --- a/common/utils.py +++ b/common/utils.py @@ -15,7 +15,7 @@ def jwt_payload_handler(user): # "has_sales_access": user.has_sales_access, # "has_marketing_access": user.has_marketing_access, "file_prepend": user.file_prepend, - "username": user.username, + "username": user.email, "first_name": user.first_name, "last_name": user.last_name, "is_active": user.is_active, diff --git a/common/views.py b/common/views.py index 5b309fb8..60e073f5 100644 --- a/common/views.py +++ b/common/views.py @@ -3,6 +3,10 @@ from multiprocessing import context from re import template import requests +from django.contrib.auth.base_user import BaseUserManager +from django.contrib.auth.hashers import make_password +from rest_framework_simplejwt.tokens import RefreshToken +from rest_framework.utils import json from django.conf import settings from django.contrib.auth import authenticate, login from django.contrib.auth.hashers import make_password @@ -17,7 +21,8 @@ from django.utils.translation import gettext as _ from django.views import View from django.views.decorators.csrf import csrf_exempt from django.views.decorators.http import require_http_methods -from drf_yasg.utils import swagger_auto_schema +from drf_spectacular.types import OpenApiTypes +from drf_spectacular.utils import OpenApiExample, OpenApiParameter, extend_schema from rest_framework import status from rest_framework.authtoken.models import Token from rest_framework.pagination import LimitOffsetPagination @@ -29,16 +34,24 @@ from accounts.models import Account, Contact, Tags from accounts.serializer import AccountSerializer from cases.models import Case from cases.serializer import CaseSerializer + ##from common.custom_auth import JSONWebTokenAuthentication -from common import serializer, swagger_params +from common import serializer, swagger_params1 from common.models import APISettings, Document, Org, Profile, User from common.serializer import * -from common.serializer import (CreateUserSerializer, PasswordChangeSerializer, - RegisterOrganizationSerializer) -from common.tasks import (resend_activation_link_to_user, - send_email_to_new_user, send_email_to_reset_password, - send_email_user_delete) +# from common.serializer import ( +# CreateUserSerializer, +# PasswordChangeSerializer, +# RegisterOrganizationSerializer, +# ) +from common.tasks import ( + resend_activation_link_to_user, + send_email_to_new_user, + send_email_to_reset_password, + send_email_user_delete, +) from common.token_generator import account_activation_token + # from rest_framework_jwt.serializers import jwt_encode_handler from common.utils import COUNTRIES, ROLES, jwt_payload_handler from contacts.serializer import ContactSerializer @@ -52,17 +65,14 @@ from teams.serializer import TeamsSerializer class GetTeamsAndUsersView(APIView): - ##authentication_classes = (JSONWebTokenAuthentication,) permission_classes = (IsAuthenticated,) - @swagger_auto_schema( - tags=["Users"], manual_parameters=swagger_params.organization_params - ) + @extend_schema(tags=["users"], parameters=swagger_params1.organization_params) def get(self, request, *args, **kwargs): data = {} - teams = Teams.objects.filter(org=request.org).order_by("-id") + teams = Teams.objects.filter(org=request.profile.org).order_by("-id") teams_data = TeamsSerializer(teams, many=True).data - profiles = Profile.objects.filter(is_active=True, org=request.org).order_by( + profiles = Profile.objects.filter(is_active=True, org=request.profile.org).order_by( "user__email" ) profiles_data = ProfileSerializer(profiles, many=True).data @@ -71,357 +81,21 @@ class GetTeamsAndUsersView(APIView): return Response(data) -class UserDetailView(APIView): - ##authentication_classes = (JSONWebTokenAuthentication,) - permission_classes = (IsAuthenticated,) - - def get_object(self, pk): - profile = get_object_or_404(Profile, pk=pk) - return profile - - @swagger_auto_schema( - tags=["Users"], manual_parameters=swagger_params.organization_params - ) - def get(self, request, pk, format=None): - profile_obj = self.get_object(pk) - if ( - self.request.profile.role != "ADMIN" - and not self.request.profile.is_admin - and self.request.profile.id != profile_obj.id - ): - return Response( - {"error": True, "errors": "Permission Denied"}, - status=status.HTTP_403_FORBIDDEN, - ) - if profile_obj.org != request.org: - return Response( - {"error": True, "errors": "User company doesnot match with header...."}, - status=status.HTTP_403_FORBIDDEN, - ) - assigned_data = Profile.objects.filter(org=request.org, is_active=True).values( - "id", "user__first_name" - ) - context = {} - context["profile_obj"] = ProfileSerializer(profile_obj).data - opportunity_list = Opportunity.objects.filter(assigned_to=profile_obj) - context["opportunity_list"] = OpportunitySerializer( - opportunity_list, many=True - ).data - contacts = Contact.objects.filter(assigned_to=profile_obj) - context["contacts"] = ContactSerializer(contacts, many=True).data - cases = Case.objects.filter(assigned_to=profile_obj) - context["cases"] = CaseSerializer(cases, many=True).data - context["assigned_data"] = assigned_data - comments = profile_obj.user_comments.all() - context["comments"] = CommentSerializer(comments, many=True).data - context["countries"] = COUNTRIES - return Response( - {"error": False, "data": context}, - status=status.HTTP_200_OK, - ) - - @swagger_auto_schema( - tags=["Users"], manual_parameters=swagger_params.user_update_params - ) - def put(self, request, pk, format=None): - params = request.post_data - profile = self.get_object(pk) - address_obj = profile.address - if ( - self.request.profile.role != "ADMIN" - and not self.request.user.is_superuser - and self.request.profile.id != profile.id - ): - return Response( - {"error": True, "errors": "Permission Denied"}, - status=status.HTTP_403_FORBIDDEN, - ) - - if profile.org != request.org: - return Response( - {"error": True, "errors": "User company doesnot match with header...."}, - status=status.HTTP_403_FORBIDDEN, - ) - serializer = CreateUserSerializer( - data=params, instance=profile.user, org=request.org - ) - address_serializer = BillingAddressSerializer(data=params, instance=address_obj) - profile_serializer = CreateProfileSerializer(data=params, instance=profile) - data = {} - if not serializer.is_valid(): - data["contact_errors"] = serializer.errors - if not address_serializer.is_valid(): - data["address_errors"] = (address_serializer.errors,) - if not profile_serializer.is_valid(): - data["profile_errors"] = (profile_serializer.errors,) - if data: - data["error"] = True - return Response( - data, - status=status.HTTP_400_BAD_REQUEST, - ) - if serializer.is_valid(): - address_obj = address_serializer.save() - user = serializer.save() - user.username = user.first_name - user.save() - profile = profile_serializer.save() - return Response( - {"error": False, "message": "User Updated Successfully"}, - status=status.HTTP_200_OK, - ) - return Response( - {"error": True, "errors": serializer.errors}, - status=status.HTTP_400_BAD_REQUEST, - ) - - @swagger_auto_schema( - tags=["Users"], manual_parameters=swagger_params.organization_params - ) - def delete(self, request, pk, format=None): - if self.request.profile.role != "ADMIN" and not self.request.profile.is_admin: - return Response( - {"error": True, "errors": "Permission Denied"}, - status=status.HTTP_403_FORBIDDEN, - ) - self.object = self.get_object(pk) - if self.object.id == request.profile.id: - return Response( - {"error": True, "errors": "Permission Denied"}, - status=status.HTTP_403_FORBIDDEN, - ) - deleted_by = self.request.profile.user.email - send_email_user_delete.delay( - self.object.user.email, - deleted_by=deleted_by, - ) - self.object.delete() - return Response({"status": "success"}, status=status.HTTP_200_OK) - - -class ChangePasswordView(APIView): - ##authentication_classes = (JSONWebTokenAuthentication,) - permission_classes = (IsAuthenticated,) - - @swagger_auto_schema( - tags=["Profile"], - operation_description="This is change password api", - manual_parameters=swagger_params.change_password_params, - ) - def post(self, request, format=None): - params = request.post_data - context = {"user": request.user} - serializer = PasswordChangeSerializer(data=params, context=context) - if serializer.is_valid(): - user = request.user - user.set_password(params.get("new_password")) - user.save() - return Response( - {"error": False, "message": "Password Changed Successfully"}, - status=status.HTTP_200_OK, - ) - return Response( - {"error": True, "errors": serializer.errors}, - status=status.HTTP_400_BAD_REQUEST, - ) - - -# check_header not working -class ApiHomeView(APIView): - - ##authentication_classes = (JSONWebTokenAuthentication,) - permission_classes = (IsAuthenticated,) - - @swagger_auto_schema( - tags=["dashboard"], manual_parameters=swagger_params.organization_params - ) - def get(self, request, format=None): - accounts = Account.objects.filter(status="open", org=request.org) - contacts = Contact.objects.filter(org=request.org) - leads = Lead.objects.filter(org=request.org).exclude( - Q(status="converted") | Q(status="closed") - ) - opportunities = Opportunity.objects.filter(org=request.org) - - if self.request.profile.role != "ADMIN" and not self.request.user.is_superuser: - accounts = accounts.filter( - Q(assigned_to=self.request.profile) | Q(created_by=self.request.profile) - ) - contacts = contacts.filter( - Q(assigned_to__id__in=self.request.profile) - | Q(created_by=self.request.profile) - ) - leads = leads.filter( - Q(assigned_to__id__in=self.request.profile) - | Q(created_by=self.request.profile) - ).exclude(status="closed") - opportunities = opportunities.filter( - Q(assigned_to__id__in=self.request.profile) - | Q(created_by=self.request.profile) - ) - context = {} - context["accounts_count"] = accounts.count() - context["contacts_count"] = contacts.count() - context["leads_count"] = leads.count() - context["opportunities_count"] = opportunities.count() - context["accounts"] = AccountSerializer(accounts, many=True).data - context["contacts"] = ContactSerializer(contacts, many=True).data - context["leads"] = LeadSerializer(leads, many=True).data - context["opportunities"] = OpportunitySerializer(opportunities, many=True).data - return Response(context, status=status.HTTP_200_OK) - - -class LoginView(APIView): - serializer_class = LoginSealizer - - @swagger_auto_schema( - tags=["Auth"], - operation_description="This is login api", - manual_parameters=swagger_params.login_page_params, - ) - def post(self, request): - serializer = self.serializer_class(data=request.post_data) #<------ - serializer.is_valid(raise_exception=True) - return Response( - { - "error": False, - "status": status.HTTP_200_OK, - "tokens": serializer.data, - } - ) - - -class RegistrationView(APIView): - model = User - serializer_class = RegisterOrganizationSerializer - - @swagger_auto_schema( - tags=["Auth"], - operation_description="This is registration api", - manual_parameters=swagger_params.registration_page_params, - ) - def post(self, request, format=None): - - serializer = self.serializer_class(data=request.post_data) - - if serializer.is_valid(): - user_obj = serializer.save() - password = request.post_data.get("password") - user_obj.password = make_password(password) - user_obj.save() - # sending mail for confirm password - send_email_to_new_user.delay( - user_obj.id, - ) - - return Response({"error": False, "status": status.HTTP_201_CREATED}) - else: - return Response( - { - "error": True, - "errors": serializer.errors, - "status": status.HTTP_400_BAD_REQUEST, - } - ) - - -class OrgProfileCreateView(APIView): - ##authentication_classes = (JSONWebTokenAuthentication,) - permission_classes = (IsAuthenticated,) - - model1 = Org - model2 = Profile - serializer_class = OrgProfileCreateSerializer - profile_serializer = CreateProfileSerializer - - @swagger_auto_schema( - tags=["Auth"], - operation_description="This is registration api", - manual_parameters=swagger_params.post_org_creation_page_params, - ) - def post(self, request, format=None): - params = request.post_data - - serializer = self.serializer_class(data=request.post_data) - if serializer.is_valid(): - org_obj = serializer.save() - - # now creating the profile - profile_obj = self.model2.objects.create(user=request.user, org=org_obj) - # now the current user is the admin of the newly created organisation - profile_obj.is_organization_admin = True - profile_obj.save() - - return Response( - { - "error": False, - "message": "New Org is Created.", - "org": self.serializer_class(org_obj).data, - "status": status.HTTP_201_CREATED, - } - ) - else: - return Response( - { - "error": True, - "errors": serializer.errors, - "status": status.HTTP_400_BAD_REQUEST, - } - ) - - @swagger_auto_schema( - tags=["Auth"], - operation_description="Just Pass the token, will return ORG list, associated with the user.", - # manual_parameters=swagger_params.organization_params, - ) - def get(self, request, format=None): - """ - here we are passing profile list of the user, where org details also included - """ - profile_list = Profile.objects.filter(user=request.user) - serializer = ShowOrganizationListSerializer(profile_list, many=True) - return Response( - { - "error": False, - "status": status.HTTP_200_OK, - "profile_org_list": serializer.data, - } - ) - - -class ProfileView(APIView): - # ##authentication_classes = (JSONWebTokenAuthentication,) - permission_classes = (IsAuthenticated,) - - @swagger_auto_schema( - tags=["Profile"], manual_parameters=swagger_params.organization_params - ) - def get(self, request, format=None): - # profile=Profile.objects.get(user=request.user) - context = {} - print("I am here") - context["user_obj"] = ProfileSerializer(self.request.profile).data - return Response(context, status=status.HTTP_200_OK) - - class UsersListView(APIView, LimitOffsetPagination): - ##authentication_classes = (JSONWebTokenAuthentication,) permission_classes = (IsAuthenticated,) - - @swagger_auto_schema( - tags=["Users"], manual_parameters=swagger_params.user_create_params - ) + @extend_schema(parameters=swagger_params1.organization_params,request=UserCreateSwaggerSerializer) def post(self, request, format=None): + print(request.profile.role, request.user.is_superuser) if self.request.profile.role != "ADMIN" and not self.request.user.is_superuser: return Response( {"error": True, "errors": "Permission Denied"}, status=status.HTTP_403_FORBIDDEN, ) else: - params = request.post_data + params = request.data if params: - user_serializer = CreateUserSerializer(data=params, org=request.org) + user_serializer = CreateUserSerializer(data=params, org=request.profile.org) address_serializer = BillingAddressSerializer(data=params) profile_serializer = CreateProfileSerializer(data=params) data = {} @@ -436,44 +110,43 @@ class UsersListView(APIView, LimitOffsetPagination): {"error": True, "errors": data}, status=status.HTTP_400_BAD_REQUEST, ) - if user_serializer.is_valid(): + if address_serializer.is_valid(): address_obj = address_serializer.save() user = user_serializer.save( - is_active=False, + is_active=True, ) - user.username = user.first_name + user.email = user.email user.save() - if params.get("password"): - user.set_password(params.get("password")) - user.save() + # if params.get("password"): + # user.set_password(params.get("password")) + # user.save() profile = Profile.objects.create( user=user, date_of_joining=timezone.now(), role=params.get("role"), address=address_obj, - org=request.org, + org=request.profile.org, ) - send_email_to_new_user.delay( - profile.id, - request.org.id, - ) + # send_email_to_new_user.delay( + # profile.id, + # request.profile.org.id, + # ) return Response( {"error": False, "message": "User Created Successfully"}, status=status.HTTP_201_CREATED, ) - @swagger_auto_schema( - tags=["Users"], manual_parameters=swagger_params.user_list_params - ) + + @extend_schema(parameters=swagger_params1.user_list_params) def get(self, request, format=None): if self.request.profile.role != "ADMIN" and not self.request.user.is_superuser: return Response( {"error": True, "errors": "Permission Denied"}, status=status.HTTP_403_FORBIDDEN, ) - queryset = Profile.objects.filter(org=request.org).order_by("-id") - params = request.post_data + queryset = Profile.objects.filter(org=request.profile.org).order_by("-id") + params = request.query_params if params: if params.get("email"): queryset = queryset.filter(user__email__icontains=params.get("email")) @@ -527,14 +200,253 @@ class UsersListView(APIView, LimitOffsetPagination): return Response(context) +class UserDetailView(APIView): + permission_classes = (IsAuthenticated,) + + def get_object(self, pk): + profile = get_object_or_404(Profile, pk=pk) + return profile + + @extend_schema(tags=["users"], parameters=swagger_params1.organization_params) + def get(self, request, pk, format=None): + profile_obj = self.get_object(pk) + if ( + self.request.profile.role != "ADMIN" + and not self.request.profile.is_admin + and self.request.profile.id != profile_obj.id + ): + return Response( + {"error": True, "errors": "Permission Denied"}, + status=status.HTTP_403_FORBIDDEN, + ) + if profile_obj.org != request.profile.org: + return Response( + {"error": True, "errors": "User company doesnot match with header...."}, + status=status.HTTP_403_FORBIDDEN, + ) + assigned_data = Profile.objects.filter(org=request.profile.org, is_active=True).values( + "id", "user__email" + ) + context = {} + context["profile_obj"] = ProfileSerializer(profile_obj).data + opportunity_list = Opportunity.objects.filter(assigned_to=profile_obj) + context["opportunity_list"] = OpportunitySerializer( + opportunity_list, many=True + ).data + contacts = Contact.objects.filter(assigned_to=profile_obj) + context["contacts"] = ContactSerializer(contacts, many=True).data + cases = Case.objects.filter(assigned_to=profile_obj) + context["cases"] = CaseSerializer(cases, many=True).data + context["assigned_data"] = assigned_data + comments = profile_obj.user_comments.all() + context["comments"] = CommentSerializer(comments, many=True).data + context["countries"] = COUNTRIES + return Response( + {"error": False, "data": context}, + status=status.HTTP_200_OK, + ) + + @extend_schema(tags=["users"],parameters=swagger_params1.organization_params, request=UserCreateSwaggerSerializer) + def put(self, request, pk, format=None): + params = request.data + profile = self.get_object(pk) + address_obj = profile.address + if ( + self.request.profile.role != "ADMIN" + and not self.request.user.is_superuser + and self.request.profile.id != profile.id + ): + return Response( + {"error": True, "errors": "Permission Denied"}, + status=status.HTTP_403_FORBIDDEN, + ) + + if profile.org != request.profile.org: + return Response( + {"error": True, "errors": "User company doesnot match with header...."}, + status=status.HTTP_403_FORBIDDEN, + ) + serializer = CreateUserSerializer( + data=params, instance=profile.user, org=request.profile.org + ) + address_serializer = BillingAddressSerializer(data=params, instance=address_obj) + profile_serializer = CreateProfileSerializer(data=params, instance=profile) + data = {} + if not serializer.is_valid(): + data["contact_errors"] = serializer.errors + if not address_serializer.is_valid(): + data["address_errors"] = (address_serializer.errors,) + if not profile_serializer.is_valid(): + data["profile_errors"] = (profile_serializer.errors,) + if data: + data["error"] = True + return Response( + data, + status=status.HTTP_400_BAD_REQUEST, + ) + if address_serializer.is_valid(): + address_obj = address_serializer.save() + user = serializer.save() + user.email = user.email + user.save() + if profile_serializer.is_valid(): + profile = profile_serializer.save() + return Response( + {"error": False, "message": "User Updated Successfully"}, + status=status.HTTP_200_OK, + ) + return Response( + {"error": True, "errors": serializer.errors}, + status=status.HTTP_400_BAD_REQUEST, + ) + + @extend_schema( + tags=["users"],parameters=swagger_params1.organization_params + ) + def delete(self, request, pk, format=None): + if self.request.profile.role != "ADMIN" and not self.request.profile.is_admin: + return Response( + {"error": True, "errors": "Permission Denied"}, + status=status.HTTP_403_FORBIDDEN, + ) + self.object = self.get_object(pk) + if self.object.id == request.profile.id: + return Response( + {"error": True, "errors": "Permission Denied"}, + status=status.HTTP_403_FORBIDDEN, + ) + deleted_by = self.request.profile.user.email + send_email_user_delete.delay( + self.object.user.email, + deleted_by=deleted_by, + ) + self.object.delete() + return Response({"status": "success"}, status=status.HTTP_200_OK) + + +# check_header not working +class ApiHomeView(APIView): + + permission_classes = (IsAuthenticated,) + + @extend_schema(parameters=swagger_params1.organization_params) + def get(self, request, format=None): + accounts = Account.objects.filter(status="open", org=request.profile.org) + contacts = Contact.objects.filter(org=request.profile.org) + leads = Lead.objects.filter(org=request.profile.org).exclude( + Q(status="converted") | Q(status="closed") + ) + opportunities = Opportunity.objects.filter(org=request.profile.org) + + if self.request.profile.role != "ADMIN" and not self.request.user.is_superuser: + accounts = accounts.filter( + Q(assigned_to=self.request.profile) | Q(created_by=self.request.profile) + ) + contacts = contacts.filter( + Q(assigned_to__id__in=self.request.profile) + | Q(created_by=self.request.profile) + ) + leads = leads.filter( + Q(assigned_to__id__in=self.request.profile) + | Q(created_by=self.request.profile) + ).exclude(status="closed") + opportunities = opportunities.filter( + Q(assigned_to__id__in=self.request.profile) + | Q(created_by=self.request.profile) + ) + context = {} + context["accounts_count"] = accounts.count() + context["contacts_count"] = contacts.count() + context["leads_count"] = leads.count() + context["opportunities_count"] = opportunities.count() + context["accounts"] = AccountSerializer(accounts, many=True).data + context["contacts"] = ContactSerializer(contacts, many=True).data + context["leads"] = LeadSerializer(leads, many=True).data + context["opportunities"] = OpportunitySerializer(opportunities, many=True).data + return Response(context, status=status.HTTP_200_OK) + + +class OrgProfileCreateView(APIView): + ##authentication_classes = (JSONWebTokenAuthentication,) + permission_classes = (IsAuthenticated,) + + model1 = Org + model2 = Profile + serializer_class = OrgProfileCreateSerializer + profile_serializer = CreateProfileSerializer + + @extend_schema( + description="Organization and profile Creation api", + request=OrgProfileCreateSerializer + ) + def post(self, request, format=None): + params = request.data + serializer = self.serializer_class(data=params) + if serializer.is_valid(): + org_obj = serializer.save() + + # now creating the profile + profile_obj = self.model2.objects.create(user=request.user, org=org_obj) + # now the current user is the admin of the newly created organisation + profile_obj.is_organization_admin = True + profile_obj.role = 'ADMIN' + profile_obj.save() + + return Response( + { + "error": False, + "message": "New Org is Created.", + "org": self.serializer_class(org_obj).data, + "status": status.HTTP_201_CREATED, + } + ) + else: + return Response( + { + "error": True, + "errors": serializer.errors, + "status": status.HTTP_400_BAD_REQUEST, + } + ) + + @extend_schema( + description="Just Pass the token, will return ORG list, associated with user", + ) + def get(self, request, format=None): + """ + here we are passing profile list of the user, where org details also included + """ + profile_list = Profile.objects.filter(user=request.user) + serializer = ShowOrganizationListSerializer(profile_list, many=True) + return Response( + { + "error": False, + "status": status.HTTP_200_OK, + "profile_org_list": serializer.data, + } + ) + + +class ProfileView(APIView): + permission_classes = (IsAuthenticated,) + + @extend_schema(parameters=swagger_params1.organization_params) + def get(self, request, format=None): + # profile=Profile.objects.get(user=request.user) + context = {} + print("I am here") + print(self.request.profile) + context["user_obj"] = ProfileSerializer(self.request.profile).data + return Response(context, status=status.HTTP_200_OK) + class DocumentListView(APIView, LimitOffsetPagination): ##authentication_classes = (JSONWebTokenAuthentication,) permission_classes = (IsAuthenticated,) model = Document def get_context_data(self, **kwargs): - params = request.post_data - queryset = self.model.objects.filter(org=self.request.org).order_by("-id") + params = self.request.query_params + queryset = self.model.objects.filter(org=self.request.profile.org).order_by("-id") if self.request.user.is_superuser or self.request.profile.role == "ADMIN": queryset = queryset else: @@ -562,7 +474,7 @@ class DocumentListView(APIView, LimitOffsetPagination): ) context = {} - profile_list = Profile.objects.filter(is_active=True, org=self.request.org) + profile_list = Profile.objects.filter(is_active=True, org=self.request.profile.org) if self.request.profile.role == "ADMIN" or self.request.profile.is_admin: profiles = profile_list.order_by("user__email") else: @@ -620,35 +532,35 @@ class DocumentListView(APIView, LimitOffsetPagination): context["status_choices"] = Document.DOCUMENT_STATUS_CHOICE return context - @swagger_auto_schema( - tags=["documents"], manual_parameters=swagger_params.document_get_params + @extend_schema( + tags=["documents"], parameters=swagger_params1.document_get_params ) def get(self, request, *args, **kwargs): context = self.get_context_data(**kwargs) return Response(context) - @swagger_auto_schema( - tags=["documents"], manual_parameters=swagger_params.document_create_params + @extend_schema( + tags=["documents"], parameters=swagger_params1.organization_params,request=DocumentCreateSwaggerSerializer ) def post(self, request, *args, **kwargs): - params = request.post_data + params = request.data serializer = DocumentCreateSerializer(data=params, request_obj=request) if serializer.is_valid(): doc = serializer.save( created_by=request.profile, - org=request.org, + org=request.profile.org, document_file=request.FILES.get("document_file"), ) if params.get("shared_to"): assinged_to_list = json.loads(params.get("shared_to")) profiles = Profile.objects.filter( - id__in=assinged_to_list, org=request.org, is_active=True + id__in=assinged_to_list, org=request.profile.org, is_active=True ) if profiles: doc.shared_to.add(*profiles) if params.get("teams"): teams_list = json.loads(params.get("teams")) - teams = Teams.objects.filter(id__in=teams_list, org=request.org) + teams = Teams.objects.filter(id__in=teams_list, org=request.profile.org) if teams: doc.teams.add(*teams) @@ -669,8 +581,8 @@ class DocumentDetailView(APIView): def get_object(self, pk): return Document.objects.filter(id=pk).first() - @swagger_auto_schema( - tags=["documents"], manual_parameters=swagger_params.organization_params + @extend_schema( + tags=["documents"], parameters=swagger_params1.organization_params ) def get(self, request, pk, format=None): self.object = self.get_object(pk) @@ -679,7 +591,7 @@ class DocumentDetailView(APIView): {"error": True, "errors": "Document does not exist"}, status=status.HTTP_403_FORBIDDEN, ) - if self.object.org != self.request.org: + if self.object.org != self.request.profile.org: return Response( {"error": True, "errors": "User company doesnot match with header...."}, status=status.HTTP_403_FORBIDDEN, @@ -696,7 +608,7 @@ class DocumentDetailView(APIView): }, status=status.HTTP_403_FORBIDDEN, ) - profile_list = Profile.objects.filter(org=self.request.org) + profile_list = Profile.objects.filter(org=self.request.profile.org) if request.profile.role == "ADMIN" or request.user.is_superuser: profiles = profile_list.order_by("user__email") else: @@ -711,8 +623,8 @@ class DocumentDetailView(APIView): ) return Response(context, status=status.HTTP_200_OK) - @swagger_auto_schema( - tags=["documents"], manual_parameters=swagger_params.organization_params + @extend_schema( + tags=["documents"], parameters=swagger_params1.organization_params ) def delete(self, request, pk, format=None): document = self.get_object(pk) @@ -721,7 +633,7 @@ class DocumentDetailView(APIView): {"error": True, "errors": "Documdnt does not exist"}, status=status.HTTP_403_FORBIDDEN, ) - if document.org != self.request.org: + if document.org != self.request.profile.org: return Response( {"error": True, "errors": "User company doesnot match with header...."}, status=status.HTTP_403_FORBIDDEN, @@ -744,18 +656,19 @@ class DocumentDetailView(APIView): status=status.HTTP_200_OK, ) - @swagger_auto_schema( - tags=["documents"], manual_parameters=swagger_params.document_update_params + + @extend_schema( + tags=["documents"], parameters=swagger_params1.organization_params,request=DocumentEditSwaggerSerializer ) def put(self, request, pk, format=None): self.object = self.get_object(pk) - params = request.post_data + params = request.data if not self.object: return Response( {"error": True, "errors": "Document does not exist"}, status=status.HTTP_403_FORBIDDEN, ) - if self.object.org != self.request.org: + if self.object.org != self.request.profile.org: return Response( {"error": True, "errors": "User company doesnot match with header...."}, status=status.HTTP_403_FORBIDDEN, @@ -779,13 +692,13 @@ class DocumentDetailView(APIView): doc = serializer.save( document_file=request.FILES.get("document_file"), status=params.get("status"), - org=request.org, + org=request.profile.org, ) doc.shared_to.clear() if params.get("shared_to"): assinged_to_list = json.loads(params.get("shared_to")) profiles = Profile.objects.filter( - id__in=assinged_to_list, org=request.org, is_active=True + id__in=assinged_to_list, org=request.profile.org, is_active=True ) if profiles: doc.shared_to.add(*profiles) @@ -793,7 +706,7 @@ class DocumentDetailView(APIView): doc.teams.clear() if params.get("teams"): teams_list = json.loads(params.get("teams")) - teams = Teams.objects.filter(id__in=teams_list, org=request.org) + teams = Teams.objects.filter(id__in=teams_list, org=request.profile.org) if teams: doc.teams.add(*teams) return Response( @@ -806,78 +719,11 @@ class DocumentDetailView(APIView): ) -class ForgotPasswordView(APIView): - @swagger_auto_schema( - tags=["Auth"], manual_parameters=swagger_params.forgot_password_params - ) - def post(self, request, format=None): - params = request.post_data - serializer = ForgotPasswordSerializer(data=params) - if serializer.is_valid(): - user = get_object_or_404(User, email=params.get("email")) - if not user.is_active: - return Response( - {"error": True, "errors": "Please activate account to proceed."}, - status=status.HTTP_406_NOT_ACCEPTABLE, - ) - send_email_to_reset_password.delay(user.email) - data = { - "error": False, - "message": "We have sent you an email. please reset password", - } - return Response(data, status=status.HTTP_200_OK) - else: - - error = serializer.errors.get("non_field_errors") - - data = {"error": True, "errors": serializer.errors, "error_text": error[0]} - response_status = status.HTTP_400_BAD_REQUEST - return Response(data, status=response_status) - - -class ResetPasswordView(APIView): - @swagger_auto_schema( - tags=["Auth"], manual_parameters=swagger_params.reset_password_params - ) - def post(self, request, uid, token, format=None): - params = request.post_data - try: - uid = force_str(urlsafe_base64_decode(uid)) - user_obj = User.objects.get(pk=uid) - if not user_obj.password: - if not user_obj.is_active: - user_obj.is_active = True - user_obj.save() - except (TypeError, ValueError, OverflowError, User.DoesNotExist): - user_obj = None - if user_obj is not None: - password1 = params.get("new_password1") - password2 = params.get("new_password2") - if password1 != password2: - return Response( - {"error": True, "errors": "The two password fields didn't match."}, - status=status.HTTP_400_BAD_REQUEST, - ) - else: - user_obj.set_password(password1) - user_obj.save() - return Response( - { - "error": False, - "message": "Password Updated Successfully. Please login", - }, - status=status.HTTP_200_OK, - ) - else: - return Response({"error": True, "errors": "Invalid Link"}) - - class UserStatusView(APIView): - ##authentication_classes = (JSONWebTokenAuthentication,) permission_classes = (IsAuthenticated,) - @swagger_auto_schema( - tags=["Users"], manual_parameters=swagger_params.users_status_params + @extend_schema( + description="User Status View",parameters=swagger_params1.organization_params, request=UserUpdateStatusSwaggerSerializer ) def post(self, request, pk, format=None): if self.request.profile.role != "ADMIN" and not self.request.user.is_superuser: @@ -888,8 +734,8 @@ class UserStatusView(APIView): }, status=status.HTTP_403_FORBIDDEN, ) - params = request.post_data - profiles = Profile.objects.filter(org=request.org) + params = request.data + profiles = Profile.objects.filter(org=request.profile.org) profile = profiles.get(id=pk) if params.get("status"): @@ -917,15 +763,14 @@ class UserStatusView(APIView): class DomainList(APIView): model = APISettings - ##authentication_classes = (JSONWebTokenAuthentication,) permission_classes = (IsAuthenticated,) - @swagger_auto_schema( - tags=["Settings"], manual_parameters=swagger_params.organization_params + @extend_schema( + tags=["Settings"],parameters=swagger_params1.organization_params ) def get(self, request, *args, **kwargs): - api_settings = APISettings.objects.filter(org=request.org) - users = Profile.objects.filter(is_active=True, org=request.org).order_by( + api_settings = APISettings.objects.filter(org=request.profile.org) + users = Profile.objects.filter(is_active=True, org=request.profile.org).order_by( "user__email" ) return Response( @@ -937,17 +782,17 @@ class DomainList(APIView): status=status.HTTP_200_OK, ) - @swagger_auto_schema( - tags=["Settings"], manual_parameters=swagger_params.api_setting_create_params + @extend_schema( + tags=["Settings"],parameters=swagger_params1.organization_params, request=APISettingsSwaggerSerializer ) def post(self, request, *args, **kwargs): - params = request.post_data + params = request.data assign_to_list = [] if params.get("lead_assigned_to"): assign_to_list = json.loads(params.get("lead_assigned_to")) serializer = APISettingsSerializer(data=params) if serializer.is_valid(): - settings_obj = serializer.save(created_by=request.profile, org=request.org) + settings_obj = serializer.save(created_by=request.profile, org=request.profile.org) if params.get("tags"): tags = json.loads(params.get("tags")) for tag in tags: @@ -972,8 +817,8 @@ class DomainDetailView(APIView): ##authentication_classes = (JSONWebTokenAuthentication,) permission_classes = (IsAuthenticated,) - @swagger_auto_schema( - tags=["Settings"], manual_parameters=swagger_params.organization_params + @extend_schema( + tags=["Settings"],parameters=swagger_params1.organization_params ) def get(self, request, pk, format=None): api_setting = self.get_object(pk) @@ -982,12 +827,12 @@ class DomainDetailView(APIView): status=status.HTTP_200_OK, ) - @swagger_auto_schema( - tags=["Settings"], manual_parameters=swagger_params.api_setting_create_params + @extend_schema( + tags=["Settings"],parameters=swagger_params1.organization_params, request=APISettingsSwaggerSerializer ) def put(self, request, pk, **kwargs): api_setting = self.get_object(pk) - params = request.post_data + params = request.data assign_to_list = [] if params.get("lead_assigned_to"): assign_to_list = json.loads(params.get("lead_assigned_to")) @@ -1014,8 +859,8 @@ class DomainDetailView(APIView): status=status.HTTP_400_BAD_REQUEST, ) - @swagger_auto_schema( - tags=["Settings"], manual_parameters=swagger_params.organization_params + @extend_schema( + tags=["Settings"],parameters=swagger_params1.organization_params ) def delete(self, request, pk, **kwargs): api_setting = self.get_object(pk) @@ -1026,125 +871,6 @@ class DomainDetailView(APIView): status=status.HTTP_200_OK, ) - -class ActivateUserView(View): - template = "common/user_activation_status.html" - # @swagger_auto_schema( - # tags=["Auth"], - # ) - def get(self, request, uid, token, activation_key, format=None): - user = User.objects.get(activation_key=activation_key) - if user: - if timezone.now() > user.key_expires: - resend_activation_link_to_user.delay( - user.email, - ) - context = { - "success": False, - "message": "Link expired. Please use the Activation link sent now to your mail.", - } - return render(request, self.template, context) - else: - try: - uid = force_str(urlsafe_base64_decode(uid)) - user = User.objects.get(pk=uid) - except (TypeError, ValueError, OverflowError, User.DoesNotExist): - user = None - if user is not None and account_activation_token.check_token( - user, token - ): - user.is_active = True - user.save() - - context = { - "success": True, - "message": "Thank you for your email confirmation. Now you can login to your account.", - } - return render(request, self.template, context) - - context = {"success": False, "message": "In Valid Token."} - return render(request, self.template, context) - - # def post(self, request, uid, token, activation_key, format=None): - # profile = get_object_or_404(Profile, activation_key=activation_key) - # if profile.user: - # if timezone.now() > profile.key_expires: - # resend_activation_link_to_user.delay( - # profile.user.email, - # ) - # return Response( - # { - # "error": False, - # "message": "Link expired. Please use the Activation link sent now to your mail.", - # }, - # status=status.HTTP_406_NOT_ACCEPTABLE, - # ) - # else: - # try: - # uid = force_str(urlsafe_base64_decode(uid)) - # user = User.objects.get(pk=uid) - # except (TypeError, ValueError, OverflowError, User.DoesNotExist): - # user = None - # if user is not None and account_activation_token.check_token( - # user, token - # ): - # user.is_active = True - # user.save() - # return Response( - # { - # "error": False, - # "message": "Thank you for your email confirmation. Now you can login to your account.", - # }, - # status=status.HTTP_200_OK, - # ) - # return Response( - # {"error": True, "errors": "Activation link is invalid!"}, - # status=status.HTTP_400_BAD_REQUEST, - # ) - - -class ResendActivationLinkView(APIView): - @swagger_auto_schema( - tags=["Auth"], manual_parameters=swagger_params.forgot_password_params - ) - def post(self, request, format=None): - params = request.post_data - user = get_object_or_404(User, email=params.get("email")) - if user.is_active: - return Response( - {"error": False, "message": "Account is active. Please login"}, - status=status.HTTP_200_OK, - ) - resend_activation_link_to_user.delay( - user.email, - ) - data = { - "error": False, - "message": "Please use the Activation link sent to your mail to activate account.", - } - return Response(data, status=status.HTTP_200_OK) - - -# class OrganizationListView(APIView, LimitOffsetPagination): - -# # ##authentication_classes = (JSONWebTokenAuthentication,) -# permission_classes = (IsAuthenticated,) - -# @swagger_auto_schema(tags=["Auth"]) -# def get(self, request): -# profiles = Profile.objects.filter(user=request.user, is_active=True) -# companies = Org.objects.filter(id__in=profiles.values_list("org", flat=True)) -# return Response( -# { -# "error": False, -# "companies": OrganizationSerializer(companies, many=True).data, -# }, -# status=status.HTTP_200_OK, -# ) - - -# @require_http_methods(["POST"]) -# @csrf_exempt class GoogleLoginView(APIView): """ Check for authentication with google @@ -1152,40 +878,33 @@ class GoogleLoginView(APIView): Returns token of logged In user """ - @swagger_auto_schema( - tags=["Auth"], + + @extend_schema( + description="Login through Google", request=SocialLoginSerializer, ) def post(self, request): - - form = SocialLoginSerializer(data=request.POST) - if form.is_valid(): - params = {"access_token": request.POST.get("accessToken")} - url = "https://www.googleapis.com/oauth2/v1/userinfo" - kw = dict(params=params, headers={}, timeout=60) - response = requests.request("GET", url, **kw) - if response.status_code == 200: - email_matches = User.objects.filter(email=response.json().get("email")) - if email_matches: - user = email_matches.first() - # user = authenticate(email=user.email) - login(request, user) - - payload = jwt_payload_handler(user) - response_data = { - "token": jwt_encode_handler(payload), - "error": False, - "id": user.id, - "employee_name": user.get_full_name(), - } - return JsonResponse(response_data, status=status.HTTP_200_OK) - return JsonResponse( - {"error": True, "message": "Email not valid"}, - status=status.HTTP_400_BAD_REQUEST, - ) - return JsonResponse( - {"error": True, "message": "Email not valid"}, - status=status.HTTP_400_BAD_REQUEST, - ) - return JsonResponse( - {"error": True, "errors": form.errors}, status=status.HTTP_200_OK - ) + payload = {'access_token': request.data.get("token")} # validate the token + r = requests.get('https://www.googleapis.com/oauth2/v2/userinfo', params=payload) + data = json.loads(r.text) + print(data) + if 'error' in data: + content = {'message': 'wrong google token / this google token is already expired.'} + return Response(content) + # create user if not exist + try: + user = User.objects.get(email=data['email']) + except User.DoesNotExist: + user = User() + user.email = data['email'] + user.profile_pic = data['picture'] + # provider random default password + user.password = make_password(BaseUserManager().make_random_password()) + user.email = data['email'] + user.save() + token = RefreshToken.for_user(user) # generate token without username & password + response = {} + response['username'] = user.email + response['access_token'] = str(token.access_token) + response['refresh_token'] = str(token) + response['user_id'] = user.id + return Response(response) diff --git a/contacts/migrations/0001_initial.py b/contacts/migrations/0001_initial.py index d1c54310..87991dd5 100644 --- a/contacts/migrations/0001_initial.py +++ b/contacts/migrations/0001_initial.py @@ -1,9 +1,10 @@ -# Generated by Django 2.1.2 on 2019-01-28 07:07 +# Generated by Django 4.2.1 on 2023-06-19 13:08 -import django.db.models.deletion -import phonenumber_field.modelfields from django.conf import settings from django.db import migrations, models +import django.db.models.deletion +import phonenumber_field.modelfields +import uuid class Migration(migrations.Migration): @@ -11,85 +12,49 @@ class Migration(migrations.Migration): initial = True dependencies = [ - ("accounts", "0001_initial"), - ("common", "0001_initial"), + ('common', '0001_initial'), migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('teams', '0001_initial'), ] operations = [ migrations.CreateModel( - name="Contact", + name='Contact', fields=[ - ( - "id", - models.AutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ( - "first_name", - models.CharField(max_length=255, verbose_name="First name"), - ), - ( - "last_name", - models.CharField(max_length=255, verbose_name="Last name"), - ), - ("email", models.EmailField(max_length=254, unique=True)), - ( - "phone", - phonenumber_field.modelfields.PhoneNumberField( - max_length=128, null=True, unique=True - ), - ), - ("description", models.TextField(blank=True, null=True)), - ( - "created_on", - models.DateTimeField(auto_now_add=True, verbose_name="Created on"), - ), - ("is_active", models.BooleanField(default=False)), - ( - "account", - models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - related_name="lead_account_contacts", - to="accounts.Account", - ), - ), - ( - "address", - models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - related_name="adress_contacts", - to="common.Address", - ), - ), - ( - "assigned_to", - models.ManyToManyField( - related_name="contact_assigned_users", - to=settings.AUTH_USER_MODEL, - ), - ), - ( - "created_by", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - related_name="contact_created_by", - to=settings.AUTH_USER_MODEL, - ), - ), - ("teams", models.ManyToManyField(to="common.Team")), + ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')), + ('updated_at', models.DateTimeField(auto_now=True, verbose_name='Last Modified At')), + ('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)), + ('salutation', models.CharField(blank=True, default='', max_length=255, verbose_name='Salutation')), + ('first_name', models.CharField(max_length=255, verbose_name='First name')), + ('last_name', models.CharField(max_length=255, verbose_name='Last name')), + ('date_of_birth', models.DateField(blank=True, null=True)), + ('organization', models.CharField(max_length=255, null=True, verbose_name='Organization')), + ('title', models.CharField(blank=True, default='', max_length=255, verbose_name='Title')), + ('primary_email', models.EmailField(max_length=254, unique=True)), + ('secondary_email', models.EmailField(blank=True, default='', max_length=254)), + ('mobile_number', phonenumber_field.modelfields.PhoneNumberField(max_length=128, null=True, region=None, unique=True)), + ('secondary_number', phonenumber_field.modelfields.PhoneNumberField(max_length=128, null=True, region=None)), + ('department', models.CharField(max_length=255, null=True, verbose_name='Department')), + ('language', models.CharField(max_length=255, null=True, verbose_name='Language')), + ('do_not_call', models.BooleanField(default=False)), + ('description', models.TextField(blank=True, null=True)), + ('linked_in_url', models.URLField(blank=True, null=True)), + ('facebook_url', models.URLField(blank=True, null=True)), + ('twitter_username', models.CharField(max_length=255, null=True)), + ('is_active', models.BooleanField(default=False)), + ('country', models.CharField(blank=True, choices=[('GB', 'United Kingdom'), ('AF', 'Afghanistan'), ('AX', 'Aland Islands'), ('AL', 'Albania'), ('DZ', 'Algeria'), ('AS', 'American Samoa'), ('AD', 'Andorra'), ('AO', 'Angola'), ('AI', 'Anguilla'), ('AQ', 'Antarctica'), ('AG', 'Antigua and Barbuda'), ('AR', 'Argentina'), ('AM', 'Armenia'), ('AW', 'Aruba'), ('AU', 'Australia'), ('AT', 'Austria'), ('AZ', 'Azerbaijan'), ('BS', 'Bahamas'), ('BH', 'Bahrain'), ('BD', 'Bangladesh'), ('BB', 'Barbados'), ('BY', 'Belarus'), ('BE', 'Belgium'), ('BZ', 'Belize'), ('BJ', 'Benin'), ('BM', 'Bermuda'), ('BT', 'Bhutan'), ('BO', 'Bolivia'), ('BA', 'Bosnia and Herzegovina'), ('BW', 'Botswana'), ('BV', 'Bouvet Island'), ('BR', 'Brazil'), ('IO', 'British Indian Ocean Territory'), ('BN', 'Brunei Darussalam'), ('BG', 'Bulgaria'), ('BF', 'Burkina Faso'), ('BI', 'Burundi'), ('KH', 'Cambodia'), ('CM', 'Cameroon'), ('CA', 'Canada'), ('CV', 'Cape Verde'), ('KY', 'Cayman Islands'), ('CF', 'Central African Republic'), ('TD', 'Chad'), ('CL', 'Chile'), ('CN', 'China'), ('CX', 'Christmas Island'), ('CC', 'Cocos (Keeling) Islands'), ('CO', 'Colombia'), ('KM', 'Comoros'), ('CG', 'Congo'), ('CD', 'Congo, The Democratic Republic of the'), ('CK', 'Cook Islands'), ('CR', 'Costa Rica'), ('CI', "Cote d'Ivoire"), ('HR', 'Croatia'), ('CU', 'Cuba'), ('CY', 'Cyprus'), ('CZ', 'Czech Republic'), ('DK', 'Denmark'), ('DJ', 'Djibouti'), ('DM', 'Dominica'), ('DO', 'Dominican Republic'), ('EC', 'Ecuador'), ('EG', 'Egypt'), ('SV', 'El Salvador'), ('GQ', 'Equatorial Guinea'), ('ER', 'Eritrea'), ('EE', 'Estonia'), ('ET', 'Ethiopia'), ('FK', 'Falkland Islands (Malvinas)'), ('FO', 'Faroe Islands'), ('FJ', 'Fiji'), ('FI', 'Finland'), ('FR', 'France'), ('GF', 'French Guiana'), ('PF', 'French Polynesia'), ('TF', 'French Southern Territories'), ('GA', 'Gabon'), ('GM', 'Gambia'), ('GE', 'Georgia'), ('DE', 'Germany'), ('GH', 'Ghana'), ('GI', 'Gibraltar'), ('GR', 'Greece'), ('GL', 'Greenland'), ('GD', 'Grenada'), ('GP', 'Guadeloupe'), ('GU', 'Guam'), ('GT', 'Guatemala'), ('GG', 'Guernsey'), ('GN', 'Guinea'), ('GW', 'Guinea-Bissau'), ('GY', 'Guyana'), ('HT', 'Haiti'), ('HM', 'Heard Island and McDonald Islands'), ('VA', 'Holy See (Vatican City State)'), ('HN', 'Honduras'), ('HK', 'Hong Kong'), ('HU', 'Hungary'), ('IS', 'Iceland'), ('IN', 'India'), ('ID', 'Indonesia'), ('IR', 'Iran, Islamic Republic of'), ('IQ', 'Iraq'), ('IE', 'Ireland'), ('IM', 'Isle of Man'), ('IL', 'Israel'), ('IT', 'Italy'), ('JM', 'Jamaica'), ('JP', 'Japan'), ('JE', 'Jersey'), ('JO', 'Jordan'), ('KZ', 'Kazakhstan'), ('KE', 'Kenya'), ('KI', 'Kiribati'), ('KP', "Korea, Democratic People's Republic of"), ('KR', 'Korea, Republic of'), ('KW', 'Kuwait'), ('KG', 'Kyrgyzstan'), ('LA', "Lao People's Democratic Republic"), ('LV', 'Latvia'), ('LB', 'Lebanon'), ('LS', 'Lesotho'), ('LR', 'Liberia'), ('LY', 'Libyan Arab Jamahiriya'), ('LI', 'Liechtenstein'), ('LT', 'Lithuania'), ('LU', 'Luxembourg'), ('MO', 'Macao'), ('MK', 'Macedonia, The Former Yugoslav Republic of'), ('MG', 'Madagascar'), ('MW', 'Malawi'), ('MY', 'Malaysia'), ('MV', 'Maldives'), ('ML', 'Mali'), ('MT', 'Malta'), ('MH', 'Marshall Islands'), ('MQ', 'Martinique'), ('MR', 'Mauritania'), ('MU', 'Mauritius'), ('YT', 'Mayotte'), ('MX', 'Mexico'), ('FM', 'Micronesia, Federated States of'), ('MD', 'Moldova'), ('MC', 'Monaco'), ('MN', 'Mongolia'), ('ME', 'Montenegro'), ('MS', 'Montserrat'), ('MA', 'Morocco'), ('MZ', 'Mozambique'), ('MM', 'Myanmar'), ('NA', 'Namibia'), ('NR', 'Nauru'), ('NP', 'Nepal'), ('NL', 'Netherlands'), ('AN', 'Netherlands Antilles'), ('NC', 'New Caledonia'), ('NZ', 'New Zealand'), ('NI', 'Nicaragua'), ('NE', 'Niger'), ('NG', 'Nigeria'), ('NU', 'Niue'), ('NF', 'Norfolk Island'), ('MP', 'Northern Mariana Islands'), ('NO', 'Norway'), ('OM', 'Oman'), ('PK', 'Pakistan'), ('PW', 'Palau'), ('PS', 'Palestinian Territory, Occupied'), ('PA', 'Panama'), ('PG', 'Papua New Guinea'), ('PY', 'Paraguay'), ('PE', 'Peru'), ('PH', 'Philippines'), ('PN', 'Pitcairn'), ('PL', 'Poland'), ('PT', 'Portugal'), ('PR', 'Puerto Rico'), ('QA', 'Qatar'), ('RE', 'Reunion'), ('RO', 'Romania'), ('RU', 'Russian Federation'), ('RW', 'Rwanda'), ('BL', 'Saint Barthelemy'), ('SH', 'Saint Helena'), ('KN', 'Saint Kitts and Nevis'), ('LC', 'Saint Lucia'), ('MF', 'Saint Martin'), ('PM', 'Saint Pierre and Miquelon'), ('VC', 'Saint Vincent and the Grenadines'), ('WS', 'Samoa'), ('SM', 'San Marino'), ('ST', 'Sao Tome and Principe'), ('SA', 'Saudi Arabia'), ('SN', 'Senegal'), ('RS', 'Serbia'), ('SC', 'Seychelles'), ('SL', 'Sierra Leone'), ('SG', 'Singapore'), ('SK', 'Slovakia'), ('SI', 'Slovenia'), ('SB', 'Solomon Islands'), ('SO', 'Somalia'), ('ZA', 'South Africa'), ('GS', 'South Georgia and the South Sandwich Islands'), ('ES', 'Spain'), ('LK', 'Sri Lanka'), ('SD', 'Sudan'), ('SR', 'Suriname'), ('SJ', 'Svalbard and Jan Mayen'), ('SZ', 'Swaziland'), ('SE', 'Sweden'), ('CH', 'Switzerland'), ('SY', 'Syrian Arab Republic'), ('TW', 'Taiwan, Province of China'), ('TJ', 'Tajikistan'), ('TZ', 'Tanzania, United Republic of'), ('TH', 'Thailand'), ('TL', 'Timor-Leste'), ('TG', 'Togo'), ('TK', 'Tokelau'), ('TO', 'Tonga'), ('TT', 'Trinidad and Tobago'), ('TN', 'Tunisia'), ('TR', 'Turkey'), ('TM', 'Turkmenistan'), ('TC', 'Turks and Caicos Islands'), ('TV', 'Tuvalu'), ('UG', 'Uganda'), ('UA', 'Ukraine'), ('AE', 'United Arab Emirates'), ('US', 'United States'), ('UM', 'United States Minor Outlying Islands'), ('UY', 'Uruguay'), ('UZ', 'Uzbekistan'), ('VU', 'Vanuatu'), ('VE', 'Venezuela'), ('VN', 'Viet Nam'), ('VG', 'Virgin Islands, British'), ('VI', 'Virgin Islands, U.S.'), ('WF', 'Wallis and Futuna'), ('EH', 'Western Sahara'), ('YE', 'Yemen'), ('ZM', 'Zambia'), ('ZW', 'Zimbabwe')], max_length=3, null=True)), + ('address', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='adress_contacts', to='common.address')), + ('assigned_to', models.ManyToManyField(related_name='contact_assigned_users', to='common.profile')), + ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='contact_created_by', to='common.profile')), + ('org', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='common.org')), + ('teams', models.ManyToManyField(related_name='contact_teams', to='teams.teams')), + ('updated_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_updated_by', to=settings.AUTH_USER_MODEL, verbose_name='Last Modified By')), ], + options={ + 'verbose_name': 'Contact', + 'verbose_name_plural': 'Contacts', + 'db_table': 'contacts', + 'ordering': ('-created_at',), + }, ), - # migrations.AlterUniqueTogether( - # name='contact', - # unique_together={('email',)}, - # ), ] diff --git a/contacts/migrations/0002_alter_contact_created_by.py b/contacts/migrations/0002_alter_contact_created_by.py new file mode 100644 index 00000000..117678bb --- /dev/null +++ b/contacts/migrations/0002_alter_contact_created_by.py @@ -0,0 +1,21 @@ +# Generated by Django 4.2.1 on 2023-06-29 07:31 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('contacts', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='contact', + name='created_by', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_created_by', to=settings.AUTH_USER_MODEL, verbose_name='Created By'), + ), + ] diff --git a/contacts/migrations/0002_auto_20190210_1810.py b/contacts/migrations/0002_auto_20190210_1810.py deleted file mode 100644 index a67b9c07..00000000 --- a/contacts/migrations/0002_auto_20190210_1810.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 2.1.5 on 2019-02-10 12:40 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ("contacts", "0001_initial"), - ] - - operations = [ - migrations.AlterModelOptions( - name="contact", - options={"ordering": ["-created_on"]}, - ), - ] diff --git a/contacts/migrations/0002_auto_20190212_1334.py b/contacts/migrations/0002_auto_20190212_1334.py deleted file mode 100644 index 1d3110f5..00000000 --- a/contacts/migrations/0002_auto_20190212_1334.py +++ /dev/null @@ -1,37 +0,0 @@ -# Generated by Django 2.1.5 on 2019-02-12 08:04 - -import django.db.models.deletion -from django.conf import settings -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("contacts", "0001_initial"), - ] - - operations = [ - migrations.AlterModelOptions( - name="contact", - options={"ordering": ["-created_on"]}, - ), - migrations.RemoveField( - model_name="contact", - name="account", - ), - migrations.RemoveField( - model_name="contact", - name="teams", - ), - migrations.AlterField( - model_name="contact", - name="created_by", - field=models.ForeignKey( - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="contact_created_by", - to=settings.AUTH_USER_MODEL, - ), - ), - ] diff --git a/contacts/migrations/0003_alter_contact_secondary_number_and_more.py b/contacts/migrations/0003_alter_contact_secondary_number_and_more.py new file mode 100644 index 00000000..227439f1 --- /dev/null +++ b/contacts/migrations/0003_alter_contact_secondary_number_and_more.py @@ -0,0 +1,24 @@ +# Generated by Django 4.2.1 on 2023-07-21 11:23 + +from django.db import migrations, models +import phonenumber_field.modelfields + + +class Migration(migrations.Migration): + + dependencies = [ + ('contacts', '0002_alter_contact_created_by'), + ] + + operations = [ + migrations.AlterField( + model_name='contact', + name='secondary_number', + field=phonenumber_field.modelfields.PhoneNumberField(blank=True, max_length=128, null=True, region=None), + ), + migrations.AlterField( + model_name='contact', + name='twitter_username', + field=models.CharField(blank=True, max_length=255, null=True), + ), + ] diff --git a/contacts/migrations/0003_merge_20190214_1427.py b/contacts/migrations/0003_merge_20190214_1427.py deleted file mode 100644 index 5c05469d..00000000 --- a/contacts/migrations/0003_merge_20190214_1427.py +++ /dev/null @@ -1,13 +0,0 @@ -# Generated by Django 2.1.7 on 2019-02-14 08:57 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ("contacts", "0002_auto_20190210_1810"), - ("contacts", "0002_auto_20190212_1334"), - ] - - operations = [] diff --git a/contacts/migrations/0004_contact_teams.py b/contacts/migrations/0004_contact_teams.py deleted file mode 100644 index 5733deac..00000000 --- a/contacts/migrations/0004_contact_teams.py +++ /dev/null @@ -1,21 +0,0 @@ -# Generated by Django 2.2.4 on 2019-09-17 05:46 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("teams", "0003_auto_20190909_1621"), - ("contacts", "0003_merge_20190214_1427"), - ] - - operations = [ - migrations.AddField( - model_name="contact", - name="teams", - field=models.ManyToManyField( - related_name="contact_teams", to="teams.Teams" - ), - ), - ] diff --git a/contacts/migrations/0005_contact_company.py b/contacts/migrations/0005_contact_company.py deleted file mode 100644 index dc7259f1..00000000 --- a/contacts/migrations/0005_contact_company.py +++ /dev/null @@ -1,25 +0,0 @@ -# Generated by Django 2.2.10 on 2020-04-23 10:29 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0020_auto_20200409_1653"), - ("contacts", "0004_contact_teams"), - ] - - operations = [ - migrations.AddField( - model_name="contact", - name="company", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - to="common.Company", - ), - ), - ] diff --git a/contacts/migrations/0006_remove_contact_company.py b/contacts/migrations/0006_remove_contact_company.py deleted file mode 100644 index ad965df6..00000000 --- a/contacts/migrations/0006_remove_contact_company.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 3.1.7 on 2021-03-23 14:25 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ("contacts", "0005_contact_company"), - ] - - operations = [ - migrations.RemoveField( - model_name="contact", - name="company", - ), - ] diff --git a/contacts/migrations/0007_auto_20210716_1554.py b/contacts/migrations/0007_auto_20210716_1554.py deleted file mode 100644 index 5b47eb1b..00000000 --- a/contacts/migrations/0007_auto_20210716_1554.py +++ /dev/null @@ -1,92 +0,0 @@ -# Generated by Django 3.2.5 on 2021-07-16 10:24 - -import phonenumber_field.modelfields -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("contacts", "0006_remove_contact_company"), - ] - - operations = [ - migrations.RenameField( - model_name="contact", - old_name="phone", - new_name="mobile_number", - ), - migrations.RenameField( - model_name="contact", - old_name="email", - new_name="primary_email", - ), - migrations.AddField( - model_name="contact", - name="date_of_birth", - field=models.DateField(null=True), - ), - migrations.AddField( - model_name="contact", - name="department", - field=models.CharField( - max_length=255, null=True, verbose_name="Department" - ), - ), - migrations.AddField( - model_name="contact", - name="do_not_call", - field=models.BooleanField(default=False), - ), - migrations.AddField( - model_name="contact", - name="facebook_url", - field=models.URLField(blank=True, null=True), - ), - migrations.AddField( - model_name="contact", - name="language", - field=models.CharField(max_length=255, null=True, verbose_name="Language"), - ), - migrations.AddField( - model_name="contact", - name="linked_in_url", - field=models.URLField(blank=True, null=True), - ), - migrations.AddField( - model_name="contact", - name="organization", - field=models.CharField( - max_length=255, null=True, verbose_name="Organization" - ), - ), - migrations.AddField( - model_name="contact", - name="salutation", - field=models.CharField( - max_length=255, null=True, verbose_name="Salutation" - ), - ), - migrations.AddField( - model_name="contact", - name="secondary_email", - field=models.EmailField(max_length=254, null=True), - ), - migrations.AddField( - model_name="contact", - name="secondary_number", - field=phonenumber_field.modelfields.PhoneNumberField( - max_length=128, null=True, region=None - ), - ), - migrations.AddField( - model_name="contact", - name="title", - field=models.CharField(max_length=255, null=True, verbose_name="Title"), - ), - migrations.AddField( - model_name="contact", - name="twitter_username", - field=models.CharField(max_length=255, null=True), - ), - ] diff --git a/contacts/migrations/0008_auto_20210913_1918.py b/contacts/migrations/0008_auto_20210913_1918.py deleted file mode 100644 index 0b88f211..00000000 --- a/contacts/migrations/0008_auto_20210913_1918.py +++ /dev/null @@ -1,42 +0,0 @@ -# Generated by Django 3.2 on 2021-09-13 13:48 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0034_auto_20210913_1918"), - ("contacts", "0007_auto_20210716_1554"), - ] - - operations = [ - migrations.AddField( - model_name="contact", - name="company", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - to="common.company", - ), - ), - migrations.AlterField( - model_name="contact", - name="assigned_to", - field=models.ManyToManyField( - related_name="contact_assigned_users", to="common.Profile" - ), - ), - migrations.AlterField( - model_name="contact", - name="created_by", - field=models.ForeignKey( - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="contact_created_by", - to="common.profile", - ), - ), - ] diff --git a/contacts/migrations/0009_rename_company_contact_org.py b/contacts/migrations/0009_rename_company_contact_org.py deleted file mode 100644 index f45eef09..00000000 --- a/contacts/migrations/0009_rename_company_contact_org.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 3.2 on 2021-09-22 12:31 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ("contacts", "0008_auto_20210913_1918"), - ] - - operations = [ - migrations.RenameField( - model_name="contact", - old_name="company", - new_name="org", - ), - ] diff --git a/contacts/migrations/0010_auto_20211006_1251.py b/contacts/migrations/0010_auto_20211006_1251.py deleted file mode 100644 index fba288b1..00000000 --- a/contacts/migrations/0010_auto_20211006_1251.py +++ /dev/null @@ -1,37 +0,0 @@ -# Generated by Django 3.2.7 on 2021-10-06 07:21 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("contacts", "0009_rename_company_contact_org"), - ] - - operations = [ - migrations.AlterField( - model_name="contact", - name="date_of_birth", - field=models.DateField(blank=True, null=True), - ), - migrations.AlterField( - model_name="contact", - name="salutation", - field=models.CharField( - blank=True, default="", max_length=255, verbose_name="Salutation" - ), - ), - migrations.AlterField( - model_name="contact", - name="secondary_email", - field=models.EmailField(blank=True, default="", max_length=254), - ), - migrations.AlterField( - model_name="contact", - name="title", - field=models.CharField( - blank=True, default="", max_length=255, verbose_name="Title" - ), - ), - ] diff --git a/contacts/migrations/0011_contact_country.py b/contacts/migrations/0011_contact_country.py deleted file mode 100644 index 2bdf8dad..00000000 --- a/contacts/migrations/0011_contact_country.py +++ /dev/null @@ -1,270 +0,0 @@ -# Generated by Django 3.2.11 on 2022-07-13 12:55 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("contacts", "0010_auto_20211006_1251"), - ] - - operations = [ - migrations.AddField( - model_name="contact", - name="country", - field=models.CharField( - blank=True, - choices=[ - ("GB", "United Kingdom"), - ("AF", "Afghanistan"), - ("AX", "Aland Islands"), - ("AL", "Albania"), - ("DZ", "Algeria"), - ("AS", "American Samoa"), - ("AD", "Andorra"), - ("AO", "Angola"), - ("AI", "Anguilla"), - ("AQ", "Antarctica"), - ("AG", "Antigua and Barbuda"), - ("AR", "Argentina"), - ("AM", "Armenia"), - ("AW", "Aruba"), - ("AU", "Australia"), - ("AT", "Austria"), - ("AZ", "Azerbaijan"), - ("BS", "Bahamas"), - ("BH", "Bahrain"), - ("BD", "Bangladesh"), - ("BB", "Barbados"), - ("BY", "Belarus"), - ("BE", "Belgium"), - ("BZ", "Belize"), - ("BJ", "Benin"), - ("BM", "Bermuda"), - ("BT", "Bhutan"), - ("BO", "Bolivia"), - ("BA", "Bosnia and Herzegovina"), - ("BW", "Botswana"), - ("BV", "Bouvet Island"), - ("BR", "Brazil"), - ("IO", "British Indian Ocean Territory"), - ("BN", "Brunei Darussalam"), - ("BG", "Bulgaria"), - ("BF", "Burkina Faso"), - ("BI", "Burundi"), - ("KH", "Cambodia"), - ("CM", "Cameroon"), - ("CA", "Canada"), - ("CV", "Cape Verde"), - ("KY", "Cayman Islands"), - ("CF", "Central African Republic"), - ("TD", "Chad"), - ("CL", "Chile"), - ("CN", "China"), - ("CX", "Christmas Island"), - ("CC", "Cocos (Keeling) Islands"), - ("CO", "Colombia"), - ("KM", "Comoros"), - ("CG", "Congo"), - ("CD", "Congo, The Democratic Republic of the"), - ("CK", "Cook Islands"), - ("CR", "Costa Rica"), - ("CI", "Cote d'Ivoire"), - ("HR", "Croatia"), - ("CU", "Cuba"), - ("CY", "Cyprus"), - ("CZ", "Czech Republic"), - ("DK", "Denmark"), - ("DJ", "Djibouti"), - ("DM", "Dominica"), - ("DO", "Dominican Republic"), - ("EC", "Ecuador"), - ("EG", "Egypt"), - ("SV", "El Salvador"), - ("GQ", "Equatorial Guinea"), - ("ER", "Eritrea"), - ("EE", "Estonia"), - ("ET", "Ethiopia"), - ("FK", "Falkland Islands (Malvinas)"), - ("FO", "Faroe Islands"), - ("FJ", "Fiji"), - ("FI", "Finland"), - ("FR", "France"), - ("GF", "French Guiana"), - ("PF", "French Polynesia"), - ("TF", "French Southern Territories"), - ("GA", "Gabon"), - ("GM", "Gambia"), - ("GE", "Georgia"), - ("DE", "Germany"), - ("GH", "Ghana"), - ("GI", "Gibraltar"), - ("GR", "Greece"), - ("GL", "Greenland"), - ("GD", "Grenada"), - ("GP", "Guadeloupe"), - ("GU", "Guam"), - ("GT", "Guatemala"), - ("GG", "Guernsey"), - ("GN", "Guinea"), - ("GW", "Guinea-Bissau"), - ("GY", "Guyana"), - ("HT", "Haiti"), - ("HM", "Heard Island and McDonald Islands"), - ("VA", "Holy See (Vatican City State)"), - ("HN", "Honduras"), - ("HK", "Hong Kong"), - ("HU", "Hungary"), - ("IS", "Iceland"), - ("IN", "India"), - ("ID", "Indonesia"), - ("IR", "Iran, Islamic Republic of"), - ("IQ", "Iraq"), - ("IE", "Ireland"), - ("IM", "Isle of Man"), - ("IL", "Israel"), - ("IT", "Italy"), - ("JM", "Jamaica"), - ("JP", "Japan"), - ("JE", "Jersey"), - ("JO", "Jordan"), - ("KZ", "Kazakhstan"), - ("KE", "Kenya"), - ("KI", "Kiribati"), - ("KP", "Korea, Democratic People's Republic of"), - ("KR", "Korea, Republic of"), - ("KW", "Kuwait"), - ("KG", "Kyrgyzstan"), - ("LA", "Lao People's Democratic Republic"), - ("LV", "Latvia"), - ("LB", "Lebanon"), - ("LS", "Lesotho"), - ("LR", "Liberia"), - ("LY", "Libyan Arab Jamahiriya"), - ("LI", "Liechtenstein"), - ("LT", "Lithuania"), - ("LU", "Luxembourg"), - ("MO", "Macao"), - ("MK", "Macedonia, The Former Yugoslav Republic of"), - ("MG", "Madagascar"), - ("MW", "Malawi"), - ("MY", "Malaysia"), - ("MV", "Maldives"), - ("ML", "Mali"), - ("MT", "Malta"), - ("MH", "Marshall Islands"), - ("MQ", "Martinique"), - ("MR", "Mauritania"), - ("MU", "Mauritius"), - ("YT", "Mayotte"), - ("MX", "Mexico"), - ("FM", "Micronesia, Federated States of"), - ("MD", "Moldova"), - ("MC", "Monaco"), - ("MN", "Mongolia"), - ("ME", "Montenegro"), - ("MS", "Montserrat"), - ("MA", "Morocco"), - ("MZ", "Mozambique"), - ("MM", "Myanmar"), - ("NA", "Namibia"), - ("NR", "Nauru"), - ("NP", "Nepal"), - ("NL", "Netherlands"), - ("AN", "Netherlands Antilles"), - ("NC", "New Caledonia"), - ("NZ", "New Zealand"), - ("NI", "Nicaragua"), - ("NE", "Niger"), - ("NG", "Nigeria"), - ("NU", "Niue"), - ("NF", "Norfolk Island"), - ("MP", "Northern Mariana Islands"), - ("NO", "Norway"), - ("OM", "Oman"), - ("PK", "Pakistan"), - ("PW", "Palau"), - ("PS", "Palestinian Territory, Occupied"), - ("PA", "Panama"), - ("PG", "Papua New Guinea"), - ("PY", "Paraguay"), - ("PE", "Peru"), - ("PH", "Philippines"), - ("PN", "Pitcairn"), - ("PL", "Poland"), - ("PT", "Portugal"), - ("PR", "Puerto Rico"), - ("QA", "Qatar"), - ("RE", "Reunion"), - ("RO", "Romania"), - ("RU", "Russian Federation"), - ("RW", "Rwanda"), - ("BL", "Saint Barthelemy"), - ("SH", "Saint Helena"), - ("KN", "Saint Kitts and Nevis"), - ("LC", "Saint Lucia"), - ("MF", "Saint Martin"), - ("PM", "Saint Pierre and Miquelon"), - ("VC", "Saint Vincent and the Grenadines"), - ("WS", "Samoa"), - ("SM", "San Marino"), - ("ST", "Sao Tome and Principe"), - ("SA", "Saudi Arabia"), - ("SN", "Senegal"), - ("RS", "Serbia"), - ("SC", "Seychelles"), - ("SL", "Sierra Leone"), - ("SG", "Singapore"), - ("SK", "Slovakia"), - ("SI", "Slovenia"), - ("SB", "Solomon Islands"), - ("SO", "Somalia"), - ("ZA", "South Africa"), - ("GS", "South Georgia and the South Sandwich Islands"), - ("ES", "Spain"), - ("LK", "Sri Lanka"), - ("SD", "Sudan"), - ("SR", "Suriname"), - ("SJ", "Svalbard and Jan Mayen"), - ("SZ", "Swaziland"), - ("SE", "Sweden"), - ("CH", "Switzerland"), - ("SY", "Syrian Arab Republic"), - ("TW", "Taiwan, Province of China"), - ("TJ", "Tajikistan"), - ("TZ", "Tanzania, United Republic of"), - ("TH", "Thailand"), - ("TL", "Timor-Leste"), - ("TG", "Togo"), - ("TK", "Tokelau"), - ("TO", "Tonga"), - ("TT", "Trinidad and Tobago"), - ("TN", "Tunisia"), - ("TR", "Turkey"), - ("TM", "Turkmenistan"), - ("TC", "Turks and Caicos Islands"), - ("TV", "Tuvalu"), - ("UG", "Uganda"), - ("UA", "Ukraine"), - ("AE", "United Arab Emirates"), - ("US", "United States"), - ("UM", "United States Minor Outlying Islands"), - ("UY", "Uruguay"), - ("UZ", "Uzbekistan"), - ("VU", "Vanuatu"), - ("VE", "Venezuela"), - ("VN", "Viet Nam"), - ("VG", "Virgin Islands, British"), - ("VI", "Virgin Islands, U.S."), - ("WF", "Wallis and Futuna"), - ("EH", "Western Sahara"), - ("YE", "Yemen"), - ("ZM", "Zambia"), - ("ZW", "Zimbabwe"), - ], - max_length=3, - null=True, - ), - ), - ] diff --git a/contacts/models.py b/contacts/models.py index dafe9366..4ac0944f 100644 --- a/contacts/models.py +++ b/contacts/models.py @@ -4,11 +4,12 @@ from django.utils.translation import gettext_lazy as _ from phonenumber_field.modelfields import PhoneNumberField from common.models import Address, Org, Profile +from common.base import BaseModel from common.utils import COUNTRIES from teams.models import Teams -class Contact(models.Model): +class Contact(BaseModel): salutation = models.CharField( _("Salutation"), max_length=255, default="", blank=True ) @@ -20,7 +21,7 @@ class Contact(models.Model): primary_email = models.EmailField(unique=True) secondary_email = models.EmailField(default="", blank=True) mobile_number = PhoneNumberField(null=True, unique=True) - secondary_number = PhoneNumberField(null=True) + secondary_number = PhoneNumberField(null=True,blank=True) department = models.CharField(_("Department"), max_length=255, null=True) language = models.CharField(_("Language"), max_length=255, null=True) do_not_call = models.BooleanField(default=False) @@ -34,26 +35,33 @@ class Contact(models.Model): description = models.TextField(blank=True, null=True) linked_in_url = models.URLField(blank=True, null=True) facebook_url = models.URLField(blank=True, null=True) - twitter_username = models.CharField(max_length=255, null=True) - created_by = models.ForeignKey( - Profile, related_name="contact_created_by", on_delete=models.SET_NULL, null=True - ) - created_on = models.DateTimeField(_("Created on"), auto_now_add=True) + twitter_username = models.CharField(max_length=255, blank=True,null=True) + # created_by = models.ForeignKey( + # Profile, related_name="contact_created_by", on_delete=models.SET_NULL, null=True + # ) is_active = models.BooleanField(default=False) assigned_to = models.ManyToManyField(Profile, related_name="contact_assigned_users") teams = models.ManyToManyField(Teams, related_name="contact_teams") org = models.ForeignKey(Org, on_delete=models.SET_NULL, null=True, blank=True) country = models.CharField(max_length=3, choices=COUNTRIES, blank=True, null=True) + class Meta: + verbose_name = "Contact" + verbose_name_plural = "Contacts" + db_table = "contacts" + ordering = ("-created_at",) + def __str__(self): return self.first_name - class Meta: - ordering = ["-created_on"] - @property def created_on_arrow(self): - return arrow.get(self.created_on).humanize() + return arrow.get(self.created_at).humanize() + + @property + def created_on(self): + return self.created_at + @property def get_team_users(self): diff --git a/contacts/serializer.py b/contacts/serializer.py index cacacc48..1c8d7922 100644 --- a/contacts/serializer.py +++ b/contacts/serializer.py @@ -1,13 +1,16 @@ from rest_framework import serializers -from common.serializer import (AttachmentsSerializer, BillingAddressSerializer, - OrganizationSerializer, ProfileSerializer) +from common.serializer import ( + AttachmentsSerializer, + BillingAddressSerializer, + OrganizationSerializer, + ProfileSerializer, +) from contacts.models import Contact from teams.serializer import TeamsSerializer class ContactSerializer(serializers.ModelSerializer): - created_by = ProfileSerializer() teams = TeamsSerializer(read_only=True, many=True) assigned_to = ProfileSerializer(read_only=True, many=True) address = BillingAddressSerializer(read_only=True) @@ -63,7 +66,8 @@ class CreateContactSerializer(serializers.ModelSerializer): def __init__(self, *args, **kwargs): request_obj = kwargs.pop("request_obj", None) super().__init__(*args, **kwargs) - self.org = request_obj.org + if request_obj: + self.org = request_obj.profile.org def validate_first_name(self, first_name): if self.instance: @@ -107,3 +111,11 @@ class CreateContactSerializer(serializers.ModelSerializer): "facebook_url", "twitter_username", ) + + +class ContactDetailEditSwaggerSerializer(serializers.Serializer): + comment = serializers.CharField() + contact_attachment = serializers.FileField() + +class ContactCommentEditSwaggerSerializer(serializers.Serializer): + comment = serializers.CharField() diff --git a/contacts/swagger_params.py b/contacts/swagger_params.py deleted file mode 100644 index 16a8460b..00000000 --- a/contacts/swagger_params.py +++ /dev/null @@ -1,76 +0,0 @@ -from drf_yasg import openapi - -organization_params_in_header = openapi.Parameter( - "org", openapi.IN_HEADER, required=True, type=openapi.TYPE_INTEGER -) - -organization_params = [ - organization_params_in_header, -] - -contact_list_get_params = [ - organization_params_in_header, - openapi.Parameter("name", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("city", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("assigned_to", openapi.IN_QUERY, type=openapi.TYPE_STRING), -] - -contact_create_post_params = [ - organization_params_in_header, - openapi.Parameter( - "salutation", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), - openapi.Parameter( - "first_name", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), - openapi.Parameter( - "last_name", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), - openapi.Parameter( - "date_of_birth", - openapi.IN_QUERY, - type=openapi.TYPE_STRING, - format="date", - example="2021-01-01", - ), - openapi.Parameter("organization", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter( - "title", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), - openapi.Parameter("primary_email", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("secondary_email", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("mobile_number", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("secondary_number", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("department", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("language", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("do_not_call", openapi.IN_QUERY, type=openapi.TYPE_BOOLEAN), - openapi.Parameter( - "address_line", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), - openapi.Parameter("street", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("city", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("state", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("pincode", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("country", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("description", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("linked_in_url", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("facebook_url", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("twitter_username", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("teams", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("assigned_to", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("contact_attachment", openapi.IN_QUERY, type=openapi.TYPE_FILE), -] - -contact_detail_get_params = [ - organization_params_in_header, - openapi.Parameter( - "contact_attachment", - openapi.IN_QUERY, - type=openapi.TYPE_FILE, - ), - openapi.Parameter("comment", openapi.IN_QUERY, type=openapi.TYPE_STRING), -] - -contact_comment_edit_params = [ - openapi.Parameter("comment", openapi.IN_QUERY, type=openapi.TYPE_STRING), -] diff --git a/contacts/swagger_params1.py b/contacts/swagger_params1.py new file mode 100644 index 00000000..ecc52d5e --- /dev/null +++ b/contacts/swagger_params1.py @@ -0,0 +1,61 @@ +from drf_spectacular.types import OpenApiTypes +from drf_spectacular.utils import OpenApiParameter + +organization_params_in_header = organization_params_in_header = OpenApiParameter( + "org", OpenApiTypes.STR, OpenApiParameter.HEADER +) + +organization_params = [ + organization_params_in_header, +] + +contact_list_get_params = [ + organization_params_in_header, + OpenApiParameter("name", OpenApiTypes.STR,OpenApiParameter.QUERY), + OpenApiParameter("city", OpenApiTypes.STR,OpenApiParameter.QUERY), + OpenApiParameter("assigned_to", OpenApiTypes.STR,OpenApiParameter.QUERY), +] + +contact_create_post_params = [ + organization_params_in_header, + OpenApiParameter( + "salutation", OpenApiParameter.QUERY, OpenApiTypes.STR + ), + OpenApiParameter( + "first_name", OpenApiParameter.QUERY, OpenApiTypes.STR + ), + OpenApiParameter( + "last_name", OpenApiParameter.QUERY, OpenApiTypes.STR + ), + OpenApiParameter( + "date_of_birth", + OpenApiParameter.QUERY, + OpenApiTypes.STR + ), + OpenApiParameter("organization", OpenApiTypes.STR,OpenApiParameter.QUERY), + OpenApiParameter( + "title", OpenApiParameter.QUERY, OpenApiTypes.STR + ), + OpenApiParameter("primary_email", OpenApiTypes.STR,OpenApiParameter.QUERY), + OpenApiParameter("secondary_email", OpenApiTypes.STR,OpenApiParameter.QUERY), + OpenApiParameter("mobile_number", OpenApiTypes.STR,OpenApiParameter.QUERY), + OpenApiParameter("secondary_number", OpenApiTypes.STR,OpenApiParameter.QUERY), + OpenApiParameter("department", OpenApiTypes.STR,OpenApiParameter.QUERY), + OpenApiParameter("language", OpenApiTypes.STR,OpenApiParameter.QUERY), + OpenApiParameter("do_not_call", OpenApiParameter.QUERY, OpenApiTypes.BOOL), + OpenApiParameter( + "address_line", OpenApiParameter.QUERY, OpenApiTypes.STR + ), + OpenApiParameter("street", OpenApiTypes.STR,OpenApiParameter.QUERY), + OpenApiParameter("city", OpenApiTypes.STR,OpenApiParameter.QUERY), + OpenApiParameter("state", OpenApiTypes.STR,OpenApiParameter.QUERY), + OpenApiParameter("pincode", OpenApiTypes.STR,OpenApiParameter.QUERY), + OpenApiParameter("country", OpenApiTypes.STR,OpenApiParameter.QUERY), + OpenApiParameter("description", OpenApiTypes.STR,OpenApiParameter.QUERY), + OpenApiParameter("linked_in_url", OpenApiTypes.STR,OpenApiParameter.QUERY), + OpenApiParameter("facebook_url", OpenApiTypes.STR,OpenApiParameter.QUERY), + OpenApiParameter("twitter_username", OpenApiTypes.STR,OpenApiParameter.QUERY), + OpenApiParameter("teams", OpenApiTypes.STR,OpenApiParameter.QUERY), + OpenApiParameter("assigned_to", OpenApiTypes.STR,OpenApiParameter.QUERY), + OpenApiParameter("contact_attachment", OpenApiParameter.QUERY, OpenApiTypes.BINARY), +] \ No newline at end of file diff --git a/contacts/urls.py b/contacts/urls.py index 6c38f619..6b9bb344 100644 --- a/contacts/urls.py +++ b/contacts/urls.py @@ -6,7 +6,8 @@ app_name = "api_contacts" urlpatterns = [ path("", views.ContactsListView.as_view()), - path("/", views.ContactDetailView.as_view()), - path("comment//", views.ContactCommentView.as_view()), - path("attachment//", views.ContactAttachmentView.as_view()), + path("/", views.ContactDetailView.as_view()), + path("comment//", views.ContactCommentView.as_view()), + path("attachment//", views.ContactAttachmentView.as_view()), ] + \ No newline at end of file diff --git a/contacts/views.py b/contacts/views.py index 99aaa2c1..d1ba3f39 100644 --- a/contacts/views.py +++ b/contacts/views.py @@ -2,7 +2,7 @@ import json from django.db.models import Q from django.shortcuts import get_object_or_404 -from drf_yasg.utils import swagger_auto_schema +from drf_spectacular.utils import OpenApiExample, OpenApiParameter, extend_schema from rest_framework import status from rest_framework.pagination import LimitOffsetPagination from rest_framework.permissions import IsAuthenticated @@ -10,11 +10,15 @@ from rest_framework.response import Response from rest_framework.views import APIView from common.models import Attachments, Comment, Profile -from common.serializer import (AttachmentsSerializer, BillingAddressSerializer, - CommentSerializer) +from common.serializer import ( + AttachmentsSerializer, + BillingAddressSerializer, + CommentSerializer, +) from common.utils import COUNTRIES + # from common.custom_auth import JSONWebTokenAuthentication -from contacts import swagger_params +from contacts import swagger_params1 from contacts.models import Contact, Profile from contacts.serializer import * from contacts.tasks import send_email_to_assigned_user @@ -28,8 +32,8 @@ class ContactsListView(APIView, LimitOffsetPagination): model = Contact def get_context_data(self, **kwargs): - params = request.post_data - queryset = self.model.objects.filter(org=self.request.org).order_by("-id") + params = self.request.query_params + queryset = self.model.objects.filter(org=self.request.profile.org).order_by("-id") if self.request.profile.role != "ADMIN" and not self.request.profile.is_admin: queryset = queryset.filter( Q(assigned_to__in=[self.request.profile]) @@ -67,25 +71,25 @@ class ContactsListView(APIView, LimitOffsetPagination): context.update({"contacts_count": self.count, "offset": offset}) context["contact_obj_list"] = contacts context["countries"] = COUNTRIES - users = Profile.objects.filter(is_active=True, org=self.request.org).values( + users = Profile.objects.filter(is_active=True, org=self.request.profile.org).values( "id", "user__email" ) context["users"] = users return context - @swagger_auto_schema( - tags=["contacts"], manual_parameters=swagger_params.contact_list_get_params + @extend_schema( + tags=["contacts"], parameters=swagger_params1.contact_list_get_params ) def get(self, request, *args, **kwargs): context = self.get_context_data(**kwargs) return Response(context) - @swagger_auto_schema( - tags=["contacts"], manual_parameters=swagger_params.contact_create_post_params + @extend_schema( + tags=["contacts"], parameters=swagger_params1.organization_params,request=CreateContactSerializer ) def post(self, request, *args, **kwargs): - params = request.post_data + params = request.data contact_serializer = CreateContactSerializer(data=params, request_obj=request) address_serializer = BillingAddressSerializer(data=params) @@ -103,18 +107,17 @@ class ContactsListView(APIView, LimitOffsetPagination): address_obj = address_serializer.save() contact_obj = contact_serializer.save(date_of_birth=params.get("date_of_birth")) contact_obj.address = address_obj - contact_obj.created_by = self.request.profile - contact_obj.org = request.org + contact_obj.org = request.profile.org contact_obj.save() if params.get("teams"): teams_list = json.loads(params.get("teams")) - teams = Teams.objects.filter(id__in=teams_list, org=request.org) + teams = Teams.objects.filter(id__in=teams_list, org=request.profile.org) contact_obj.teams.add(*teams) if params.get("assigned_to"): assinged_to_list = json.loads(params.get("assigned_to")) - profiles = Profile.objects.filter(id__in=assinged_to_list, org=request.org) + profiles = Profile.objects.filter(id__in=assinged_to_list, org=request.profile.org) contact_obj.assigned_to.add(*profiles) recipients = list(contact_obj.assigned_to.all().values_list("id", flat=True)) @@ -144,22 +147,22 @@ class ContactDetailView(APIView): def get_object(self, pk): return get_object_or_404(Contact, pk=pk) - @swagger_auto_schema( - tags=["contacts"], manual_parameters=swagger_params.contact_create_post_params + @extend_schema( + tags=["contacts"], parameters=swagger_params1.contact_create_post_params,request=CreateContactSerializer ) def put(self, request, pk, format=None): - params = request.post_data + data = request.data contact_obj = self.get_object(pk=pk) address_obj = contact_obj.address - if contact_obj.org != request.org: + if contact_obj.org != request.profile.org: return Response( {"error": True, "errors": "User company doesnot match with header...."}, status=status.HTTP_403_FORBIDDEN, ) contact_serializer = CreateContactSerializer( - data=params, instance=contact_obj, request_obj=request + data=data, instance=contact_obj, request_obj=request ) - address_serializer = BillingAddressSerializer(data=params, instance=address_obj) + address_serializer = BillingAddressSerializer(data=data, instance=address_obj) data = {} if not contact_serializer.is_valid(): data["contact_errors"] = contact_serializer.errors @@ -191,22 +194,22 @@ class ContactDetailView(APIView): address_obj = address_serializer.save() contact_obj = contact_serializer.save( - date_of_birth=params.get("date_of_birth") + date_of_birth=data.get("date_of_birth") ) contact_obj.address = address_obj contact_obj.save() contact_obj = contact_serializer.save() contact_obj.teams.clear() - if params.get("teams"): - teams_list = json.loads(params.get("teams")) - teams = Teams.objects.filter(id__in=teams_list, org=request.org) + if data.get("teams"): + teams_list = json.loads(data.get("teams")) + teams = Teams.objects.filter(id__in=teams_list, org=request.profile.org) contact_obj.teams.add(*teams) contact_obj.assigned_to.clear() - if params.get("assigned_to"): - assinged_to_list = json.loads(params.get("assigned_to")) + if data.get("assigned_to"): + assinged_to_list = json.loads(data.get("assigned_to")) profiles = Profile.objects.filter( - id__in=assinged_to_list, org=request.org + id__in=assinged_to_list, org=request.profile.org ) contact_obj.assigned_to.add(*profiles) @@ -234,8 +237,8 @@ class ContactDetailView(APIView): status=status.HTTP_200_OK, ) - @swagger_auto_schema( - tags=["contacts"], manual_parameters=swagger_params.organization_params + @extend_schema( + tags=["contacts"], parameters=swagger_params1.organization_params ) def get(self, request, pk, format=None): context = {} @@ -272,14 +275,14 @@ class ContactDetailView(APIView): if self.request.profile.is_admin or self.request.profile.role == "ADMIN": users_mention = list( - Profile.objects.filter(is_active=True, org=request.org).values( - "user__username" + Profile.objects.filter(is_active=True, org=request.profile.org).values( + "user__email" ) ) elif self.request.profile != contact_obj.created_by: - users_mention = [{"username": contact_obj.created_by.user.username}] + users_mention = [{"username": contact_obj.created_by.user.email}] else: - users_mention = list(contact_obj.assigned_to.all().values("user__username")) + users_mention = list(contact_obj.assigned_to.all().values("user__email")) if request.profile == contact_obj.created_by: user_assgn_list.append(self.request.profile.id) @@ -303,12 +306,12 @@ class ContactDetailView(APIView): ) return Response(context) - @swagger_auto_schema( - tags=["contacts"], manual_parameters=swagger_params.organization_params + @extend_schema( + tags=["contacts"], parameters=swagger_params1.organization_params ) def delete(self, request, pk, format=None): self.object = self.get_object(pk) - if self.object.org != request.org: + if self.object.org != request.profile.org: return Response( {"error": True, "errors": "User company doesnot match with header...."}, status=status.HTTP_403_FORBIDDEN, @@ -333,11 +336,11 @@ class ContactDetailView(APIView): status=status.HTTP_200_OK, ) - @swagger_auto_schema( - tags=["contacts"], manual_parameters=swagger_params.contact_detail_get_params + @extend_schema( + tags=["contacts"], parameters=swagger_params1.organization_params,request=ContactDetailEditSwaggerSerializer ) def post(self, request, pk, **kwargs): - params = request.post_data + params = request.data context = {} self.contact_obj = Contact.objects.get(pk=pk) if self.request.profile.role != "ADMIN" and not self.request.profile.is_admin: @@ -358,7 +361,7 @@ class ContactDetailView(APIView): comment_serializer.save( contact_id=self.contact_obj.id, commented_by_id=self.request.profile.id, - org=request.org, + org=request.profile.org, ) if self.request.FILES.get("contact_attachment"): @@ -393,11 +396,11 @@ class ContactCommentView(APIView): def get_object(self, pk): return self.model.objects.get(pk=pk) - @swagger_auto_schema( - tags=["contacts"], manual_parameters=swagger_params.contact_comment_edit_params + @extend_schema( + tags=["contacts"], parameters=swagger_params1.organization_params,request=ContactCommentEditSwaggerSerializer ) def put(self, request, pk, format=None): - params = request.post_data + params = request.data obj = self.get_object(pk) if ( request.profile.role == "ADMIN" @@ -423,8 +426,8 @@ class ContactCommentView(APIView): status=status.HTTP_403_FORBIDDEN, ) - @swagger_auto_schema( - tags=["contacts"], manual_parameters=swagger_params.organization_params + @extend_schema( + tags=["contacts"], parameters=swagger_params1.organization_params ) def delete(self, request, pk, format=None): self.object = self.get_object(pk) @@ -452,8 +455,8 @@ class ContactAttachmentView(APIView): # authentication_classes = (JSONWebTokenAuthentication,) permission_classes = (IsAuthenticated,) - @swagger_auto_schema( - tags=["contacts"], manual_parameters=swagger_params.organization_params + @extend_schema( + tags=["contacts"], parameters=swagger_params1.organization_params ) def delete(self, request, pk, format=None): self.object = self.model.objects.get(pk=pk) diff --git a/crm/settings.py b/crm/settings.py index fed4c58a..9576e9ad 100644 --- a/crm/settings.py +++ b/crm/settings.py @@ -4,6 +4,24 @@ from datetime import timedelta from corsheaders.defaults import default_headers from dotenv import load_dotenv +# JWT_AUTH = { +# 'JWT_PAYLOAD_GET_USERNAME_HANDLER': +# 'path.to.custom_jwt_payload_handler', +# 'JWT_PUBLIC_KEY': None, +# 'JWT_PRIVATE_KEY': None, +# 'JWT_ALGORITHM': 'HS256', +# 'JWT_VERIFY': True, +# 'JWT_VERIFY_EXPIRATION': True, +# 'JWT_LEEWAY': 0, +# 'JWT_EXPIRATION_DELTA': timedelta(seconds=300), +# 'JWT_AUDIENCE': None, +# 'JWT_ISSUER': None, +# 'JWT_ALLOW_REFRESH': False, +# 'JWT_REFRESH_EXPIRATION_DELTA': timedelta(days=7), +# 'JWT_AUTH_HEADER_PREFIX': 'Bearer', +# 'JWT_BEARER_FORMAT': 'Bearer' +# } + # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -19,30 +37,32 @@ DEBUG = True ALLOWED_HOSTS = ["*"] INSTALLED_APPS = [ - - 'wagtail.contrib.forms', - 'wagtail.contrib.redirects', - 'wagtail.embeds', - 'wagtail.sites', - 'wagtail.users', - 'wagtail.snippets', - 'wagtail.documents', - 'wagtail.images', - 'wagtail.search', - 'wagtail.admin', - 'wagtail', - 'cms', - 'wagtail.contrib.settings', - - - 'modelcluster', - 'taggit', - + "wagtail.contrib.forms", + "wagtail.contrib.redirects", + "wagtail.embeds", + "wagtail.sites", + "wagtail.users", + "wagtail.snippets", + "wagtail.documents", + "wagtail.images", + "wagtail.search", + "wagtail.admin", + "wagtail", + "cms", + "wagtail.contrib.settings", + "modelcluster", + "taggit", "django.contrib.auth", "django.contrib.contenttypes", "django.contrib.messages", "django.contrib.sessions", "django.contrib.staticfiles", + "phonenumber_field", + "rest_framework", + "rest_framework_simplejwt", + "corsheaders", + "django_ses", + "drf_spectacular", "common", "accounts", "cases", @@ -51,16 +71,10 @@ INSTALLED_APPS = [ "leads", "opportunity", "planner", - "phonenumber_field", "tasks", "invoices", "events", "teams", - "rest_framework", - "rest_framework_simplejwt", - "drf_yasg", - "corsheaders", - "django_ses", ] MIDDLEWARE = [ @@ -72,11 +86,9 @@ MIDDLEWARE = [ "django.contrib.messages.middleware.MessageMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", "corsheaders.middleware.CorsMiddleware", - # "common.custom_auth.TokenAuthMiddleware", + "crum.CurrentRequestUserMiddleware", "common.middleware.get_company.GetProfileAndOrg", - 'wagtail.contrib.redirects.middleware.RedirectMiddleware', - 'common.middleware.swagger_post.SwaggerMiddleware', - + "wagtail.contrib.redirects.middleware.RedirectMiddleware", ] ROOT_URLCONF = "crm.urls" @@ -96,8 +108,7 @@ TEMPLATES = [ "django.contrib.messages.context_processors.messages", "common.context_processors.common.app_name", # "django_settings_export.settings_export", - 'wagtail.contrib.settings.context_processors.settings', - + "wagtail.contrib.settings.context_processors.settings", ], }, }, @@ -152,11 +163,9 @@ EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend" AUTH_USER_MODEL = "common.User" -STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') +STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles") STATIC_URL = "/static/" -STATICFILES_DIRS = [ - os.path.join(BASE_DIR, 'static') -] +STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")] ENV_TYPE = os.environ["ENV_TYPE"] print(">>> ENV_TYPE", ENV_TYPE) @@ -237,7 +246,7 @@ LOGGING = { APPLICATION_NAME = "bottlecrm" -WAGTAIL_SITE_NAME = 'bottlecrm' +WAGTAIL_SITE_NAME = "bottlecrm" WAGTAILADMIN_BASE_URL = "https://bottlecrm.com" @@ -247,13 +256,29 @@ REST_FRAMEWORK = { "EXCEPTION_HANDLER": "rest_framework.views.exception_handler", "DEFAULT_AUTHENTICATION_CLASSES": ( "rest_framework_simplejwt.authentication.JWTAuthentication", - "rest_framework.authentication.SessionAuthentication", - "rest_framework.authentication.BasicAuthentication", + # "rest_framework.authentication.SessionAuthentication", + # "rest_framework.authentication.BasicAuthentication", ), "DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.LimitOffsetPagination", "PAGE_SIZE": 10, + "DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema", } + +SPECTACULAR_SETTINGS = { + "TITLE": "BottleCRM API", + "DESCRIPTION": "Open source CRM application", + "VERSION": "1.0.0", + "SERVE_INCLUDE_SCHEMA": False, + "COMPONENT_SPLIT_REQUEST": True, + "PREPROCESSING_HOOKS": ["common.custom_openapi.preprocessing_filter_spec"], + +} + +# JWT_SETTINGS = { +# 'bearerFormat': ('Bearer', 'jwt', 'Jwt') +# } + SWAGGER_SETTINGS = { "DEFAULT_INFO": "crm.urls.info", "SECURITY_DEFINITIONS": { @@ -263,7 +288,7 @@ SWAGGER_SETTINGS = { CORS_ALLOW_HEADERS = default_headers + ("org",) CORS_ORIGIN_ALLOW_ALL = True -CSRF_TRUSTED_ORIGINS = ['https://*.runcode.io', 'http://*'] +CSRF_TRUSTED_ORIGINS = ["https://*.runcode.io", "http://*"] SECURE_HSTS_SECONDS = 3600 SECURE_HSTS_INCLUDE_SUBDOMAINS = True @@ -290,7 +315,6 @@ SIMPLE_JWT = { "VERIFYING_KEY": None, "AUDIENCE": None, "ISSUER": None, - "AUTH_HEADER_TYPES": ("Bearer", "jwt", "Jwt"), "AUTH_HEADER_NAME": "HTTP_AUTHORIZATION", "USER_ID_FIELD": "id", "USER_ID_CLAIM": "user_id", @@ -301,4 +325,3 @@ JWT_ALGO = "HS256" DOMAIN_NAME = os.environ["DOMAIN_NAME"] SWAGGER_ROOT_URL = os.environ["SWAGGER_ROOT_URL"] - diff --git a/crm/urls.py b/crm/urls.py index c3cdc315..47358f62 100644 --- a/crm/urls.py +++ b/crm/urls.py @@ -6,26 +6,18 @@ from django.contrib.auth import views from django.urls import include, path from django.urls import re_path as url from django.views.generic import TemplateView -from drf_yasg import openapi -from drf_yasg.views import get_schema_view +from drf_spectacular.views import ( + SpectacularAPIView, + SpectacularRedocView, + SpectacularSwaggerView, +) +# from drf_yasg import openapi +# from drf_yasg.views import get_schema_view from rest_framework import permissions from wagtail import urls as wagtail_urls from wagtail.admin import urls as wagtailadmin_urls from wagtail.documents import urls as wagtaildocs_urls -openapi_info = openapi.Info( - title="Crm API", - default_version="v1", -) - -schema_view = get_schema_view( - openapi_info, - public=True, - url=settings.SWAGGER_ROOT_URL, - permission_classes=(permissions.AllowAny,), -) - - app_name = "crm" urlpatterns = [ @@ -34,34 +26,32 @@ urlpatterns = [ TemplateView.as_view(template_name="healthz.html"), name="healthz", ), - url( - r"^swagger(?P\.json|\.yaml)$", - schema_view.without_ui(cache_timeout=0), - name="schema-json", - ), - url( - r"^swagger/$", - schema_view.with_ui("swagger", cache_timeout=0), - name="schema-swagger-ui", - ), - url( - r"^redoc/$", schema_view.with_ui("redoc", cache_timeout=0), name="schema-redoc" - ), path("api/", include("common.app_urls", namespace="common_urls")), path( "logout/", views.LogoutView.as_view(), {"next_page": "/login/"}, name="logout" ), - path('admin/', include(wagtailadmin_urls)), - path('documents/', include(wagtaildocs_urls)), - path('', include(wagtail_urls)) - + path("admin/", include(wagtailadmin_urls)), + path("documents/", include(wagtaildocs_urls)), + path("schema/", SpectacularAPIView.as_view(), name="schema"), + # Optional UI: + path( + "swagger-ui/", + SpectacularSwaggerView.as_view(url_name="schema"), + name="swagger-ui", + ), + path( + "api/schema/redoc/", + SpectacularRedocView.as_view(url_name="schema"), + name="redoc", + ), + path("", include(wagtail_urls)), ] if settings.DEBUG: from django.conf.urls.static import static from django.contrib.staticfiles.urls import staticfiles_urlpatterns - + urlpatterns += staticfiles_urlpatterns() urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/emails/migrations/0001_initial.py b/emails/migrations/0001_initial.py index 4d95510a..346d070a 100644 --- a/emails/migrations/0001_initial.py +++ b/emails/migrations/0001_initial.py @@ -1,38 +1,42 @@ -# Generated by Django 2.1.2 on 2019-01-28 07:07 +# Generated by Django 4.2.1 on 2023-06-19 13:08 +from django.conf import settings from django.db import migrations, models +import django.db.models.deletion +import uuid class Migration(migrations.Migration): initial = True - dependencies = [] + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] operations = [ migrations.CreateModel( - name="Email", + name='Email', fields=[ - ( - "id", - models.AutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("from_email", models.EmailField(max_length=200)), - ("to_email", models.EmailField(max_length=200)), - ("subject", models.CharField(max_length=200)), - ("message", models.CharField(max_length=200)), - ("file", models.FileField(null=True, upload_to="files/")), - ("send_time", models.DateTimeField(auto_now_add=True)), - ("status", models.CharField(default="sent", max_length=200)), - ("important", models.BooleanField(default=False, max_length=10)), + ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')), + ('updated_at', models.DateTimeField(auto_now=True, verbose_name='Last Modified At')), + ('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)), + ('from_email', models.EmailField(max_length=200)), + ('to_email', models.EmailField(max_length=200)), + ('subject', models.CharField(max_length=200)), + ('message', models.CharField(max_length=200)), + ('file', models.FileField(null=True, upload_to='files/')), + ('send_time', models.DateTimeField(auto_now_add=True)), + ('status', models.CharField(default='sent', max_length=200)), + ('important', models.BooleanField(default=False, max_length=10)), + ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_created_by', to=settings.AUTH_USER_MODEL, verbose_name='Created By')), + ('updated_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_updated_by', to=settings.AUTH_USER_MODEL, verbose_name='Last Modified By')), ], options={ - "ordering": ["-id"], + 'verbose_name': 'Email', + 'verbose_name_plural': 'Emails', + 'db_table': 'email', + 'ordering': ('-created_at',), }, ), ] diff --git a/emails/models.py b/emails/models.py index b7e819df..0d608f76 100644 --- a/emails/models.py +++ b/emails/models.py @@ -1,9 +1,10 @@ from django.db import models +from common.base import BaseModel # Create your models here. -class Email(models.Model): +class Email(BaseModel): from_email = models.EmailField(max_length=200) to_email = models.EmailField(max_length=200) @@ -16,7 +17,10 @@ class Email(models.Model): important = models.BooleanField(max_length=10, default=False) class Meta: - ordering = ["-id"] + verbose_name = "Email" + verbose_name_plural = "Emails" + db_table = "email" + ordering = ("-created_at",) def __str__(self): - return self.subject + return f"{self.message_subject}" \ No newline at end of file diff --git a/events/migrations/0001_initial.py b/events/migrations/0001_initial.py index 9c4064fc..0371fea6 100644 --- a/events/migrations/0001_initial.py +++ b/events/migrations/0001_initial.py @@ -1,8 +1,9 @@ -# Generated by Django 2.1.7 on 2019-06-03 05:58 +# Generated by Django 4.2.1 on 2023-06-19 13:08 -import django.db.models.deletion from django.conf import settings from django.db import migrations, models +import django.db.models.deletion +import uuid class Migration(migrations.Migration): @@ -10,86 +11,43 @@ class Migration(migrations.Migration): initial = True dependencies = [ - ("contacts", "0003_merge_20190214_1427"), + ('contacts', '0001_initial'), + ('common', '0001_initial'), migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('teams', '0001_initial'), ] operations = [ migrations.CreateModel( - name="Event", + name='Event', fields=[ - ( - "id", - models.AutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("name", models.CharField(max_length=64, verbose_name="Event")), - ( - "event_type", - models.CharField( - choices=[ - ("Recurring", "Recurring"), - ("Non-Recurring", "Non-Recurring"), - ], - max_length=20, - ), - ), - ( - "status", - models.CharField( - blank=True, - choices=[ - ("Planned", "Planned"), - ("Held", "Held"), - ("Not Held", "Not Held"), - ("Not Started", "Not Started"), - ("Started", "Started"), - ("Completed", "Completed"), - ("Canceled", "Canceled"), - ("Deferred", "Deferred"), - ], - max_length=64, - null=True, - ), - ), - ("start_date", models.DateField(default=None)), - ("start_time", models.TimeField(default=None)), - ("end_date", models.DateField(default=None)), - ("end_time", models.TimeField(blank=True, default=None, null=True)), - ("description", models.TextField(blank=True, null=True)), - ( - "created_on", - models.DateTimeField(auto_now_add=True, verbose_name="Created on"), - ), - ("is_active", models.BooleanField(default=True)), - ("disabled", models.BooleanField(default=False)), - ( - "assigned_to", - models.ManyToManyField( - blank=True, - related_name="event_assigned", - to=settings.AUTH_USER_MODEL, - ), - ), - ( - "contacts", - models.ManyToManyField( - blank=True, related_name="event_contact", to="contacts.Contact" - ), - ), - ( - "created_by", - models.ForeignKey( - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="event_created_by_user", - to=settings.AUTH_USER_MODEL, - ), - ), + ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')), + ('updated_at', models.DateTimeField(auto_now=True, verbose_name='Last Modified At')), + ('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)), + ('name', models.CharField(max_length=64, verbose_name='Event')), + ('event_type', models.CharField(choices=[('Recurring', 'Recurring'), ('Non-Recurring', 'Non-Recurring')], max_length=20)), + ('status', models.CharField(blank=True, choices=[('Planned', 'Planned'), ('Held', 'Held'), ('Not Held', 'Not Held'), ('Not Started', 'Not Started'), ('Started', 'Started'), ('Completed', 'Completed'), ('Canceled', 'Canceled'), ('Deferred', 'Deferred')], max_length=64, null=True)), + ('start_date', models.DateField(default=None)), + ('start_time', models.TimeField(default=None)), + ('end_date', models.DateField(default=None)), + ('end_time', models.TimeField(blank=True, default=None, null=True)), + ('description', models.TextField(blank=True, null=True)), + ('created_on', models.DateTimeField(auto_now_add=True, verbose_name='Created on')), + ('is_active', models.BooleanField(default=True)), + ('disabled', models.BooleanField(default=False)), + ('date_of_meeting', models.DateField(blank=True, null=True)), + ('assigned_to', models.ManyToManyField(blank=True, related_name='event_assigned', to='common.profile')), + ('contacts', models.ManyToManyField(blank=True, related_name='event_contact', to='contacts.contact')), + ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='event_created_by_user', to='common.profile')), + ('org', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='common.org')), + ('teams', models.ManyToManyField(related_name='event_teams', to='teams.teams')), + ('updated_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_updated_by', to=settings.AUTH_USER_MODEL, verbose_name='Last Modified By')), ], + options={ + 'verbose_name': 'Event', + 'verbose_name_plural': 'Events', + 'db_table': 'event', + 'ordering': ('-created_at',), + }, ), ] diff --git a/events/migrations/0002_event_date_of_meeting.py b/events/migrations/0002_event_date_of_meeting.py deleted file mode 100644 index a96f20ee..00000000 --- a/events/migrations/0002_event_date_of_meeting.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 2.1.7 on 2019-06-03 13:14 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("events", "0001_initial"), - ] - - operations = [ - migrations.AddField( - model_name="event", - name="date_of_meeting", - field=models.DateField(blank=True, null=True), - ), - ] diff --git a/events/migrations/0003_event_teams.py b/events/migrations/0003_event_teams.py deleted file mode 100644 index 3dc0cc90..00000000 --- a/events/migrations/0003_event_teams.py +++ /dev/null @@ -1,19 +0,0 @@ -# Generated by Django 2.2.4 on 2019-09-17 05:46 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("teams", "0003_auto_20190909_1621"), - ("events", "0002_event_date_of_meeting"), - ] - - operations = [ - migrations.AddField( - model_name="event", - name="teams", - field=models.ManyToManyField(related_name="event_teams", to="teams.Teams"), - ), - ] diff --git a/events/migrations/0004_event_company.py b/events/migrations/0004_event_company.py deleted file mode 100644 index 8b1bdefa..00000000 --- a/events/migrations/0004_event_company.py +++ /dev/null @@ -1,25 +0,0 @@ -# Generated by Django 2.2.10 on 2020-04-24 08:40 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0020_auto_20200409_1653"), - ("events", "0003_event_teams"), - ] - - operations = [ - migrations.AddField( - model_name="event", - name="company", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - to="common.Company", - ), - ), - ] diff --git a/events/migrations/0005_remove_event_company.py b/events/migrations/0005_remove_event_company.py deleted file mode 100644 index 002af94b..00000000 --- a/events/migrations/0005_remove_event_company.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 3.1.7 on 2021-03-24 08:50 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ("events", "0004_event_company"), - ] - - operations = [ - migrations.RemoveField( - model_name="event", - name="company", - ), - ] diff --git a/events/migrations/0006_auto_20210913_1918.py b/events/migrations/0006_auto_20210913_1918.py deleted file mode 100644 index 794648b8..00000000 --- a/events/migrations/0006_auto_20210913_1918.py +++ /dev/null @@ -1,42 +0,0 @@ -# Generated by Django 3.2 on 2021-09-13 13:48 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0034_auto_20210913_1918"), - ("events", "0005_remove_event_company"), - ] - - operations = [ - migrations.AddField( - model_name="event", - name="company", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - to="common.company", - ), - ), - migrations.AlterField( - model_name="event", - name="assigned_to", - field=models.ManyToManyField( - blank=True, related_name="event_assigned", to="common.Profile" - ), - ), - migrations.AlterField( - model_name="event", - name="created_by", - field=models.ForeignKey( - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="event_created_by_user", - to="common.profile", - ), - ), - ] diff --git a/events/migrations/0007_rename_company_event_org.py b/events/migrations/0007_rename_company_event_org.py deleted file mode 100644 index cb694ba4..00000000 --- a/events/migrations/0007_rename_company_event_org.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 3.2 on 2021-09-22 12:31 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ("events", "0006_auto_20210913_1918"), - ] - - operations = [ - migrations.RenameField( - model_name="event", - old_name="company", - new_name="org", - ), - ] diff --git a/events/models.py b/events/models.py index 1f417762..8b01c326 100644 --- a/events/models.py +++ b/events/models.py @@ -3,13 +3,14 @@ from django.db import models from django.utils.translation import gettext_lazy as _ from common.models import Org, Profile +from common.base import BaseModel from contacts.models import Contact from teams.models import Teams # Create your models here. -class Event(models.Model): +class Event(BaseModel): EVENT_TYPE = ( ("Recurring", "Recurring"), ("Non-Recurring", "Non-Recurring"), @@ -56,6 +57,15 @@ class Event(models.Model): # tags = models.ManyToManyField(Tag) + class Meta: + verbose_name = "Event" + verbose_name_plural = "Events" + db_table = "event" + ordering = ("-created_at",) + + def __str__(self): + return f"{self.name}" + @property def created_on_arrow(self): return arrow.get(self.created_on).humanize() diff --git a/events/serializer.py b/events/serializer.py index 10950ab3..94f23c20 100644 --- a/events/serializer.py +++ b/events/serializer.py @@ -2,8 +2,12 @@ from datetime import datetime, timedelta from rest_framework import serializers -from common.serializer import (AttachmentsSerializer, CommentSerializer, - OrganizationSerializer, ProfileSerializer) +from common.serializer import ( + AttachmentsSerializer, + CommentSerializer, + OrganizationSerializer, + ProfileSerializer, +) from contacts.serializer import ContactSerializer from events.models import Event from teams.serializer import TeamsSerializer @@ -125,3 +129,29 @@ class EventCreateSerializer(serializers.ModelSerializer): "created_on", "org", ) + +class EventCreateSwaggerSerializer(serializers.ModelSerializer): + + recurring_days = serializers.CharField() + class Meta: + model = Event + fields = ( + "name", + "event_type", + "contacts", + "start_date", + "start_time", + "end_date", + "end_time", + "teams", + "assigned_to", + "description", + "recurring_days" + ) + +class EventDetailEditSwaggerSerializer(serializers.Serializer): + comment = serializers.CharField() + event_attachment = serializers.FileField() + +class EventCommentEditSwaggerSerializer(serializers.Serializer): + comment = serializers.CharField() diff --git a/events/swagger_params.py b/events/swagger_params.py deleted file mode 100644 index ab26abe3..00000000 --- a/events/swagger_params.py +++ /dev/null @@ -1,77 +0,0 @@ -from drf_yasg import openapi - -organization_params_in_header = openapi.Parameter( - "org", openapi.IN_HEADER, required=True, type=openapi.TYPE_INTEGER -) - -organization_params = [ - organization_params_in_header, -] - -event_list_get_params = [ - organization_params_in_header, - openapi.Parameter("name", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("created_by", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("assigned_users", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter( - "date_of_meeting", - openapi.IN_QUERY, - type=openapi.FORMAT_DATE, - example="2021-01-01", - ), -] - -event_detail_post_params = [ - organization_params_in_header, - openapi.Parameter( - "event_attachment", - openapi.IN_QUERY, - type=openapi.TYPE_FILE, - ), - openapi.Parameter("comment", openapi.IN_QUERY, type=openapi.TYPE_STRING), -] - -event_create_post_params = [ - organization_params_in_header, - openapi.Parameter( - "name", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), - openapi.Parameter( - "event_type", - openapi.IN_QUERY, - type=openapi.TYPE_STRING, - required=True, - enum=["Recurring", "Non-Recurring"], - ), - openapi.Parameter( - "contacts", - openapi.IN_QUERY, - type=openapi.TYPE_STRING, - required=True, - ), - openapi.Parameter( - "start_date", openapi.IN_QUERY, type=openapi.FORMAT_DATE, example="2021-01-01" - ), - openapi.Parameter( - "start_time", openapi.IN_QUERY, type=openapi.FORMAT_DATETIME, example="13:01:01" - ), - openapi.Parameter( - "end_date", openapi.IN_QUERY, type=openapi.FORMAT_DATE, example="2021-01-01" - ), - openapi.Parameter( - "end_time", openapi.IN_QUERY, type=openapi.FORMAT_DATETIME, example="13:01:01" - ), - openapi.Parameter( - "teams", - openapi.IN_QUERY, - type=openapi.TYPE_STRING, - ), - openapi.Parameter("assigned_to", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("description", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("recurring_days", openapi.IN_QUERY, type=openapi.TYPE_STRING), -] - -event_comment_edit_params = [ - organization_params_in_header, - openapi.Parameter("comment", openapi.IN_QUERY, type=openapi.TYPE_STRING), -] diff --git a/events/swagger_params1.py b/events/swagger_params1.py new file mode 100644 index 00000000..ec4b994c --- /dev/null +++ b/events/swagger_params1.py @@ -0,0 +1,37 @@ +from drf_spectacular.types import OpenApiTypes +from drf_spectacular.utils import OpenApiParameter + +organization_params_in_header = organization_params_in_header = OpenApiParameter( + "org", OpenApiTypes.STR, OpenApiParameter.HEADER +) + +organization_params = [ + organization_params_in_header, +] + +event_list_get_params = [ + organization_params_in_header, + OpenApiParameter("name", OpenApiTypes.STR,OpenApiParameter.QUERY), + OpenApiParameter("created_by", OpenApiTypes.STR,OpenApiParameter.QUERY), + OpenApiParameter("assigned_users", OpenApiTypes.STR,OpenApiParameter.QUERY), + OpenApiParameter( + "date_of_meeting", + OpenApiParameter.QUERY, + OpenApiTypes.DATE + ), +] + +event_detail_post_params = [ + organization_params_in_header, + OpenApiParameter( + "event_attachment", + OpenApiParameter.QUERY, + OpenApiTypes.BINARY + ), + OpenApiParameter("comment", OpenApiTypes.STR,OpenApiParameter.QUERY), +] + +event_comment_edit_params = [ + organization_params_in_header, + OpenApiParameter("comment", OpenApiTypes.STR,OpenApiParameter.QUERY), +] diff --git a/events/views.py b/events/views.py index e42f9770..0593ae54 100644 --- a/events/views.py +++ b/events/views.py @@ -2,7 +2,8 @@ import json from datetime import datetime, timedelta from django.db.models import Q -from drf_yasg.utils import swagger_auto_schema +from drf_spectacular.utils import OpenApiExample, OpenApiParameter, extend_schema + from rest_framework import status from rest_framework.pagination import LimitOffsetPagination from rest_framework.permissions import IsAuthenticated @@ -15,13 +16,13 @@ from common.models import Attachments, Comment, Profile, User from common.serializer import ( AttachmentsSerializer, CommentSerializer, - ProfileSerializer, + ProfileSerializer ) from contacts.models import Contact from contacts.serializer import ContactSerializer -from events import swagger_params +from events import swagger_params1 from events.models import Event -from events.serializer import EventCreateSerializer, EventSerializer +from events.serializer import EventCreateSerializer, EventSerializer, EventCreateSwaggerSerializer, EventDetailEditSwaggerSerializer, EventCommentEditSwaggerSerializer from events.tasks import send_email from teams.models import Teams from teams.serializer import TeamsSerializer @@ -43,9 +44,9 @@ class EventListView(APIView, LimitOffsetPagination): permission_classes = (IsAuthenticated,) def get_context_data(self, **kwargs): - params = self.request.post_data - queryset = self.model.objects.filter(org=self.request.org).order_by("-id") - contacts = Contact.objects.filter(org=self.request.org) + params = self.request.query_params + queryset = self.model.objects.filter(org=self.request.profile.org).order_by("-id") + contacts = Contact.objects.filter(org=self.request.profile.org) if self.request.profile.role != "ADMIN" and not self.request.profile.is_admin: queryset = queryset.filter( Q(assigned_to__in=[self.request.profile]) @@ -83,18 +84,18 @@ class EventListView(APIView, LimitOffsetPagination): context["contacts_list"] = ContactSerializer(contacts, many=True).data return context - @swagger_auto_schema( - tags=["Events"], manual_parameters=swagger_params.event_list_get_params + @extend_schema( + tags=["Events"], parameters=swagger_params1.event_list_get_params ) def get(self, request, *args, **kwargs): context = self.get_context_data(**kwargs) return Response(context) - @swagger_auto_schema( - tags=["Events"], manual_parameters=swagger_params.event_create_post_params + @extend_schema( + tags=["Events"], parameters=swagger_params1.organization_params,request=EventCreateSwaggerSerializer ) def post(self, request, *args, **kwargs): - params = request.post_data + params = request.data data = {} serializer = EventCreateSerializer(data=params, request_obj=request) if serializer.is_valid(): @@ -107,24 +108,24 @@ class EventListView(APIView, LimitOffsetPagination): date_of_meeting=params.get("start_date"), is_active=True, disabled=False, - org=request.org, + org=request.profile.org, ) if params.get("contacts"): obj_contact = Contact.objects.filter( - id=params.get("contacts"), org=request.org + id=params.get("contacts"), org=request.profile.org ) event_obj.contacts.add(obj_contact) if params.get("teams"): teams_list = json.loads(params.get("teams")) - teams = Teams.objects.filter(id__in=teams_list, org=request.org) + teams = Teams.objects.filter(id__in=teams_list, org=request.profile.org) event_obj.teams.add(*teams) if params.get("assigned_to"): assinged_to_list = json.loads(params.get("assigned_to")) profiles = Profile.objects.filter( - id__in=assinged_to_list, org=request.org + id__in=assinged_to_list, org=request.profile.org ) event_obj.assigned_to.add(*profiles) @@ -167,24 +168,24 @@ class EventListView(APIView, LimitOffsetPagination): start_time=data["start_time"], end_time=data["end_time"], date_of_meeting=each, - org=request.org, + org=request.profile.org, ) if params.get("contacts"): obj_contact = Contact.objects.filter( - id=params.get("contacts"), org=request.org + id=params.get("contacts"), org=request.profile.org ) event.contacts.add(obj_contact) if params.get("teams"): teams_list = json.loads(params.get("teams")) - teams = Teams.objects.filter(id__in=teams_list, org=request.org) + teams = Teams.objects.filter(id__in=teams_list, org=request.profile.org) event.teams.add(*teams) if params.get("assigned_to"): assinged_to_list = json.loads(params.get("assigned_to")) profiles = Profile.objects.filter( - id__in=assinged_to_list, org=request.org + id__in=assinged_to_list, org=request.profile.org ) event.assigned_to.add(*profiles) @@ -237,15 +238,15 @@ class EventDetailView(APIView): users_mention = list( Profile.objects.filter( is_active=True, - ).values("user__username") + ).values("user__email") ) elif self.request.profile != self.event_obj.created_by: - users_mention = [{"username": self.event_obj.created_by.user.username}] + users_mention = [{"username": self.event_obj.created_by.user.email}] else: users_mention = list( - self.event_obj.assigned_to.all().values("user__username") + self.event_obj.assigned_to.all().values("user__email") ) - profile_list = Profile.objects.filter(is_active=True, org=self.request.org) + profile_list = Profile.objects.filter(is_active=True, org=self.request.profile.org) if self.request.profile.role == "ADMIN" or self.request.profile.is_admin: profiles = profile_list.order_by("user__email") else: @@ -291,12 +292,12 @@ class EventDetailView(APIView): context["teams"] = TeamsSerializer(Teams.objects.all(), many=True).data return context - @swagger_auto_schema( - tags=["Events"], manual_parameters=swagger_params.organization_params + @extend_schema( + tags=["Events"], parameters=swagger_params1.organization_params ) def get(self, request, pk, **kwargs): self.event_obj = self.get_object(pk) - if self.event_obj.org != request.org: + if self.event_obj.org != request.profile.org: return Response( {"error": True, "errors": "User company doesnot match with header...."}, status=status.HTTP_403_FORBIDDEN, @@ -304,14 +305,14 @@ class EventDetailView(APIView): context = self.get_context_data(**kwargs) return Response(context) - @swagger_auto_schema( - tags=["Events"], manual_parameters=swagger_params.event_detail_post_params + @extend_schema( + tags=["Events"], parameters=swagger_params1.organization_params,request=EventDetailEditSwaggerSerializer ) def post(self, request, pk, **kwargs): - params = request.post_data + params = request.data context = {} self.event_obj = Event.objects.get(pk=pk) - if self.event_obj.org != request.org: + if self.event_obj.org != request.profile.org: return Response( { "error": True, @@ -361,14 +362,14 @@ class EventDetailView(APIView): ) return Response(context) - @swagger_auto_schema( - tags=["Events"], manual_parameters=swagger_params.event_create_post_params + @extend_schema( + tags=["Events"], parameters=swagger_params1.organization_params,request=EventCreateSwaggerSerializer ) def put(self, request, pk, **kwargs): - params = request.post_data + params = request.data data = {} self.event_obj = self.get_object(pk) - if self.event_obj.org != request.org: + if self.event_obj.org != request.profile.org: return Response( {"error": True, "errors": "User company doesnot match with header...."}, status=status.HTTP_403_FORBIDDEN, @@ -389,21 +390,21 @@ class EventDetailView(APIView): event_obj.contacts.clear() if params.get("contacts"): obj_contact = Contact.objects.filter( - id=params.get("contacts"), org=request.org + id=params.get("contacts"), org=request.profile.org ) event_obj.contacts.add(obj_contact) event_obj.teams.clear() if params.get("teams"): teams_list = json.loads(params.get("teams")) - teams = Teams.objects.filter(id__in=teams_list, org=request.org) + teams = Teams.objects.filter(id__in=teams_list, org=request.profile.org) event_obj.teams.add(*teams) event_obj.assigned_to.clear() if params.get("assigned_to"): assinged_to_list = json.loads(params.get("assigned_to")) profiles = Profile.objects.filter( - id__in=assinged_to_list, org=request.org + id__in=assinged_to_list, org=request.profile.org ) event_obj.assigned_to.add(*profiles) @@ -424,8 +425,8 @@ class EventDetailView(APIView): status=status.HTTP_400_BAD_REQUEST, ) - @swagger_auto_schema( - tags=["Events"], manual_parameters=swagger_params.organization_params + @extend_schema( + tags=["Events"], parameters=swagger_params1.organization_params ) def delete(self, request, pk, **kwargs): self.object = self.get_object(pk) @@ -433,7 +434,7 @@ class EventDetailView(APIView): request.profile.role == "ADMIN" or request.profile.is_admin or request.profile == self.object.created_by - ) and self.object.org == request.org: + ) and self.object.org == request.profile.org: self.object.delete() return Response( {"error": False, "message": "Event deleted Successfully"}, @@ -453,11 +454,11 @@ class EventCommentView(APIView): def get_object(self, pk): return self.model.objects.get(pk=pk) - @swagger_auto_schema( - tags=["Events"], manual_parameters=swagger_params.event_comment_edit_params + @extend_schema( + tags=["Events"], parameters=swagger_params1.organization_params,request=EventCommentEditSwaggerSerializer ) def put(self, request, pk, format=None): - params = request.post_data + params = request.data obj = self.get_object(pk) if ( request.profile.role == "ADMIN" @@ -483,8 +484,8 @@ class EventCommentView(APIView): status=status.HTTP_403_FORBIDDEN, ) - @swagger_auto_schema( - tags=["Events"], manual_parameters=swagger_params.organization_params + @extend_schema( + tags=["Events"], parameters=swagger_params1.organization_params ) def delete(self, request, pk, format=None): self.object = self.get_object(pk) @@ -512,8 +513,8 @@ class EventAttachmentView(APIView): # authentication_classes = (JSONWebTokenAuthentication,) permission_classes = (IsAuthenticated,) - @swagger_auto_schema( - tags=["Events"], manual_parameters=swagger_params.organization_params + @extend_schema( + tags=["Events"], parameters=swagger_params1.organization_params ) def delete(self, request, pk, format=None): self.object = self.model.objects.get(pk=pk) diff --git a/invoices/api_views.py b/invoices/api_views.py index 13ee501b..e04df926 100644 --- a/invoices/api_views.py +++ b/invoices/api_views.py @@ -14,16 +14,28 @@ from rest_framework.views import APIView from accounts.models import Account from accounts.serializer import AccountSerializer from common.models import Attachments, Comment, User + # from common.custom_auth import JSONWebTokenAuthentication -from common.serializer import (AttachmentsSerializer, BillingAddressSerializer, - CommentSerializer, UserSerializer) +from common.serializer import ( + AttachmentsSerializer, + BillingAddressSerializer, + CommentSerializer, + UserSerializer, +) from common.utils import COUNTRIES, CURRENCY_CODES -from invoices import swagger_params +from invoices import swagger_params1 from invoices.models import Invoice -from invoices.serializer import (InvoiceCreateSerializer, - InvoiceHistorySerializer, InvoiceSerailizer) -from invoices.tasks import (create_invoice_history, send_email, - send_invoice_email, send_invoice_email_cancel) +from invoices.serializer import ( + InvoiceCreateSerializer, + InvoiceHistorySerializer, + InvoiceSerailizer, +) +from invoices.tasks import ( + create_invoice_history, + send_email, + send_invoice_email, + send_invoice_email_cancel, +) from teams.models import Teams from teams.serializer import TeamsSerializer @@ -43,7 +55,7 @@ class InvoiceListView(APIView, LimitOffsetPagination): model = Invoice def get_context_data(self, **kwargs): - params = request.post_data + params = self.request.query_params queryset = self.model.objects.filter(company=self.request.company) accounts = Account.objects.filter(company=self.request.company) if self.request.user.role != "ADMIN" and not self.request.user.is_superuser: @@ -119,18 +131,14 @@ class InvoiceListView(APIView, LimitOffsetPagination): return context - @swagger_auto_schema( - tags=["Invoices"], manual_parameters=swagger_params.invoice_list_get_params - ) + @extend_schema(tags=["Invoices"], parameters=swagger_params1.invoice_list_get_params) def get(self, request, *args, **kwargs): context = self.get_context_data(**kwargs) return Response(context) - @swagger_auto_schema( - tags=["Invoices"], manual_parameters=swagger_params.invoice_create_post_params - ) + @extend_schema(tags=["Invoices"], parameters=swagger_params1.organization_params,request=InvoiceSwaggerSerailizer) def post(self, request, *args, **kwargs): - params = request.post_data + params = request.data data = {} serializer = InvoiceCreateSerializer(data=params, request_obj=request) from_address_serializer = BillingAddressSerializer(data=params) @@ -240,10 +248,10 @@ class InvoiceDetailView(APIView): return self.model.objects.filter(id=pk).first() @swagger_auto_schema( - tags=["Invoices"], manual_parameters=swagger_params.invoice_create_post_params + tags=["Invoices"], manual_parameters=swagger_params1.invoice_create_post_params ) def put(self, request, pk, format=None): - params = request.post_data + params = request.data invoice_obj = self.get_object(pk=pk) from_address_obj = invoice_obj.from_address to_address_obj = invoice_obj.to_address @@ -373,7 +381,7 @@ class InvoiceDetailView(APIView): ) @swagger_auto_schema( - tags=["Invoices"], manual_parameters=swagger_params.invoice_delete_params + tags=["Invoices"], manual_parameters=swagger_params1.invoice_delete_params ) def delete(self, request, pk, format=None): self.object = self.get_object(pk) @@ -400,7 +408,7 @@ class InvoiceDetailView(APIView): ) @swagger_auto_schema( - tags=["Invoices"], manual_parameters=swagger_params.invoice_delete_params + tags=["Invoices"], manual_parameters=swagger_params1.invoice_delete_params ) def get(self, request, pk, format=None): self.invoice = self.get_object(pk=pk) @@ -477,10 +485,10 @@ class InvoiceDetailView(APIView): return Response(context) @swagger_auto_schema( - tags=["Invoices"], manual_parameters=swagger_params.invoice_detail_post_params + tags=["Invoices"], manual_parameters=swagger_params1.invoice_detail_post_params ) def post(self, request, pk, **kwargs): - params = request.post_data + params = request.data context = {} self.invoice_obj = Invoice.objects.get(pk=pk) if self.invoice_obj.company != request.company: @@ -539,10 +547,10 @@ class InvoiceCommentView(APIView): return self.model.objects.get(pk=pk) @swagger_auto_schema( - tags=["Invoices"], manual_parameters=swagger_params.invoice_comment_edit_params + tags=["Invoices"], manual_parameters=swagger_params1.invoice_comment_edit_params ) def put(self, request, pk, format=None): - params = request.post_data + params = request.data obj = self.get_object(pk) if ( request.user.role == "ADMIN" @@ -570,7 +578,7 @@ class InvoiceCommentView(APIView): ) @swagger_auto_schema( - tags=["Invoices"], manual_parameters=swagger_params.invoice_delete_params + tags=["Invoices"], manual_parameters=swagger_params1.invoice_delete_params ) def delete(self, request, pk, format=None): self.object = self.get_object(pk) @@ -599,7 +607,7 @@ class InvoiceAttachmentView(APIView): permission_classes = (IsAuthenticated,) @swagger_auto_schema( - tags=["Invoices"], manual_parameters=swagger_params.invoice_delete_params + tags=["Invoices"], manual_parameters=swagger_params1.invoice_delete_params ) def delete(self, request, pk, format=None): self.object = self.model.objects.get(pk=pk) diff --git a/invoices/migrations/0001_initial.py b/invoices/migrations/0001_initial.py index 847191a5..a218a9db 100644 --- a/invoices/migrations/0001_initial.py +++ b/invoices/migrations/0001_initial.py @@ -1,9 +1,10 @@ -# Generated by Django 2.1.7 on 2019-05-23 09:48 +# Generated by Django 4.2.1 on 2023-06-19 13:08 -import django.db.models.deletion -import phonenumber_field.modelfields from django.conf import settings from django.db import migrations, models +import django.db.models.deletion +import phonenumber_field.modelfields +import uuid class Migration(migrations.Migration): @@ -11,282 +12,84 @@ class Migration(migrations.Migration): initial = True dependencies = [ - ("common", "0013_auto_20190508_1540"), + ('accounts', '0001_initial'), + ('common', '0001_initial'), migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('teams', '0001_initial'), ] operations = [ migrations.CreateModel( - name="Invoice", + name='Invoice', fields=[ - ( - "id", - models.AutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ( - "invoice_title", - models.CharField(max_length=50, verbose_name="Invoice Title"), - ), - ( - "invoice_number", - models.CharField(max_length=50, verbose_name="Invoice Number"), - ), - ("name", models.CharField(max_length=100, verbose_name="Name")), - ("email", models.EmailField(max_length=254, verbose_name="Email")), - ("quantity", models.PositiveIntegerField(default=0)), - ( - "rate", - models.DecimalField(decimal_places=2, default=0, max_digits=12), - ), - ( - "total_amount", - models.DecimalField( - blank=True, decimal_places=2, max_digits=12, null=True - ), - ), - ( - "currency", - models.CharField( - blank=True, - choices=[ - ("AED", "AED, Dirham"), - ("AFN", "AFN, Afghani"), - ("ALL", "ALL, Lek"), - ("AMD", "AMD, Dram"), - ("ANG", "ANG, Guilder"), - ("AOA", "AOA, Kwanza"), - ("ARS", "ARS, Peso"), - ("AUD", "AUD, Dollar"), - ("AWG", "AWG, Guilder"), - ("AZN", "AZN, Manat"), - ("BAM", "BAM, Marka"), - ("BBD", "BBD, Dollar"), - ("BDT", "BDT, Taka"), - ("BGN", "BGN, Lev"), - ("BHD", "BHD, Dinar"), - ("BIF", "BIF, Franc"), - ("BMD", "BMD, Dollar"), - ("BND", "BND, Dollar"), - ("BOB", "BOB, Boliviano"), - ("BRL", "BRL, Real"), - ("BSD", "BSD, Dollar"), - ("BTN", "BTN, Ngultrum"), - ("BWP", "BWP, Pula"), - ("BYR", "BYR, Ruble"), - ("BZD", "BZD, Dollar"), - ("CAD", "CAD, Dollar"), - ("CDF", "CDF, Franc"), - ("CHF", "CHF, Franc"), - ("CLP", "CLP, Peso"), - ("CNY", "CNY, Yuan Renminbi"), - ("COP", "COP, Peso"), - ("CRC", "CRC, Colon"), - ("CUP", "CUP, Peso"), - ("CVE", "CVE, Escudo"), - ("CZK", "CZK, Koruna"), - ("DJF", "DJF, Franc"), - ("DKK", "DKK, Krone"), - ("DOP", "DOP, Peso"), - ("DZD", "DZD, Dinar"), - ("EGP", "EGP, Pound"), - ("ERN", "ERN, Nakfa"), - ("ETB", "ETB, Birr"), - ("EUR", "EUR, Euro"), - ("FJD", "FJD, Dollar"), - ("FKP", "FKP, Pound"), - ("GBP", "GBP, Pound"), - ("GEL", "GEL, Lari"), - ("GHS", "GHS, Cedi"), - ("GIP", "GIP, Pound"), - ("GMD", "GMD, Dalasi"), - ("GNF", "GNF, Franc"), - ("GTQ", "GTQ, Quetzal"), - ("GYD", "GYD, Dollar"), - ("HKD", "HKD, Dollar"), - ("HNL", "HNL, Lempira"), - ("HRK", "HRK, Kuna"), - ("HTG", "HTG, Gourde"), - ("HUF", "HUF, Forint"), - ("IDR", "IDR, Rupiah"), - ("ILS", "ILS, Shekel"), - ("INR", "INR, Rupee"), - ("IQD", "IQD, Dinar"), - ("IRR", "IRR, Rial"), - ("ISK", "ISK, Krona"), - ("JMD", "JMD, Dollar"), - ("JOD", "JOD, Dinar"), - ("JPY", "JPY, Yen"), - ("KES", "KES, Shilling"), - ("KGS", "KGS, Som"), - ("KHR", "KHR, Riels"), - ("KMF", "KMF, Franc"), - ("KPW", "KPW, Won"), - ("KRW", "KRW, Won"), - ("KWD", "KWD, Dinar"), - ("KYD", "KYD, Dollar"), - ("KZT", "KZT, Tenge"), - ("LAK", "LAK, Kip"), - ("LBP", "LBP, Pound"), - ("LKR", "LKR, Rupee"), - ("LRD", "LRD, Dollar"), - ("LSL", "LSL, Loti"), - ("LTL", "LTL, Litas"), - ("LVL", "LVL, Lat"), - ("LYD", "LYD, Dinar"), - ("MAD", "MAD, Dirham"), - ("MDL", "MDL, Leu"), - ("MGA", "MGA, Ariary"), - ("MKD", "MKD, Denar"), - ("MMK", "MMK, Kyat"), - ("MNT", "MNT, Tugrik"), - ("MOP", "MOP, Pataca"), - ("MRO", "MRO, Ouguiya"), - ("MUR", "MUR, Rupee"), - ("MVR", "MVR, Rufiyaa"), - ("MWK", "MWK, Kwacha"), - ("MXN", "MXN, Peso"), - ("MYR", "MYR, Ringgit"), - ("MZN", "MZN, Metical"), - ("NAD", "NAD, Dollar"), - ("NGN", "NGN, Naira"), - ("NIO", "NIO, Cordoba"), - ("NOK", "NOK, Krone"), - ("NPR", "NPR, Rupee"), - ("NZD", "NZD, Dollar"), - ("OMR", "OMR, Rial"), - ("PAB", "PAB, Balboa"), - ("PEN", "PEN, Sol"), - ("PGK", "PGK, Kina"), - ("PHP", "PHP, Peso"), - ("PKR", "PKR, Rupee"), - ("PLN", "PLN, Zloty"), - ("PYG", "PYG, Guarani"), - ("QAR", "QAR, Rial"), - ("RON", "RON, Leu"), - ("RSD", "RSD, Dinar"), - ("RUB", "RUB, Ruble"), - ("RWF", "RWF, Franc"), - ("SAR", "SAR, Rial"), - ("SBD", "SBD, Dollar"), - ("SCR", "SCR, Rupee"), - ("SDG", "SDG, Pound"), - ("SEK", "SEK, Krona"), - ("SGD", "SGD, Dollar"), - ("SHP", "SHP, Pound"), - ("SLL", "SLL, Leone"), - ("SOS", "SOS, Shilling"), - ("SRD", "SRD, Dollar"), - ("SSP", "SSP, Pound"), - ("STD", "STD, Dobra"), - ("SYP", "SYP, Pound"), - ("SZL", "SZL, Lilangeni"), - ("THB", "THB, Baht"), - ("TJS", "TJS, Somoni"), - ("TMT", "TMT, Manat"), - ("TND", "TND, Dinar"), - ("TOP", "TOP, Paanga"), - ("TRY", "TRY, Lira"), - ("TTD", "TTD, Dollar"), - ("TWD", "TWD, Dollar"), - ("TZS", "TZS, Shilling"), - ("UAH", "UAH, Hryvnia"), - ("UGX", "UGX, Shilling"), - ("USD", "$, Dollar"), - ("UYU", "UYU, Peso"), - ("UZS", "UZS, Som"), - ("VEF", "VEF, Bolivar"), - ("VND", "VND, Dong"), - ("VUV", "VUV, Vatu"), - ("WST", "WST, Tala"), - ("XAF", "XAF, Franc"), - ("XCD", "XCD, Dollar"), - ("XOF", "XOF, Franc"), - ("XPF", "XPF, Franc"), - ("YER", "YER, Rial"), - ("ZAR", "ZAR, Rand"), - ("ZMK", "ZMK, Kwacha"), - ("ZWL", "ZWL, Dollar"), - ], - max_length=3, - null=True, - ), - ), - ( - "phone", - phonenumber_field.modelfields.PhoneNumberField( - blank=True, max_length=128, null=True - ), - ), - ("created_on", models.DateTimeField(auto_now_add=True)), - ( - "amount_due", - models.DecimalField( - blank=True, decimal_places=2, max_digits=12, null=True - ), - ), - ( - "amount_paid", - models.DecimalField( - blank=True, decimal_places=2, max_digits=12, null=True - ), - ), - ("is_email_sent", models.BooleanField(default=False)), - ( - "status", - models.CharField( - choices=[ - ("Draft", "Draft"), - ("Sent", "Sent"), - ("Paid", "Paid"), - ("Cancel", "Cancel"), - ("Pending", "Pending"), - ], - default="Draft", - max_length=15, - ), - ), - ( - "assigned_to", - models.ManyToManyField( - related_name="invoice_assigned_to", to=settings.AUTH_USER_MODEL - ), - ), - ( - "created_by", - models.ForeignKey( - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="invoice_created_by", - to=settings.AUTH_USER_MODEL, - ), - ), - ( - "from_address", - models.ForeignKey( - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="invoice_from_address", - to="common.Address", - ), - ), - ( - "to_address", - models.ForeignKey( - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="invoice_to_address", - to="common.Address", - ), - ), + ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')), + ('updated_at', models.DateTimeField(auto_now=True, verbose_name='Last Modified At')), + ('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)), + ('invoice_title', models.CharField(max_length=50, verbose_name='Invoice Title')), + ('invoice_number', models.CharField(max_length=50, verbose_name='Invoice Number')), + ('name', models.CharField(max_length=100, verbose_name='Name')), + ('email', models.EmailField(max_length=254, verbose_name='Email')), + ('quantity', models.PositiveIntegerField(default=0)), + ('rate', models.DecimalField(decimal_places=2, default=0, max_digits=12)), + ('total_amount', models.DecimalField(blank=True, decimal_places=2, max_digits=12, null=True)), + ('currency', models.CharField(blank=True, choices=[('AED', 'AED, Dirham'), ('AFN', 'AFN, Afghani'), ('ALL', 'ALL, Lek'), ('AMD', 'AMD, Dram'), ('ANG', 'ANG, Guilder'), ('AOA', 'AOA, Kwanza'), ('ARS', 'ARS, Peso'), ('AUD', 'AUD, Dollar'), ('AWG', 'AWG, Guilder'), ('AZN', 'AZN, Manat'), ('BAM', 'BAM, Marka'), ('BBD', 'BBD, Dollar'), ('BDT', 'BDT, Taka'), ('BGN', 'BGN, Lev'), ('BHD', 'BHD, Dinar'), ('BIF', 'BIF, Franc'), ('BMD', 'BMD, Dollar'), ('BND', 'BND, Dollar'), ('BOB', 'BOB, Boliviano'), ('BRL', 'BRL, Real'), ('BSD', 'BSD, Dollar'), ('BTN', 'BTN, Ngultrum'), ('BWP', 'BWP, Pula'), ('BYR', 'BYR, Ruble'), ('BZD', 'BZD, Dollar'), ('CAD', 'CAD, Dollar'), ('CDF', 'CDF, Franc'), ('CHF', 'CHF, Franc'), ('CLP', 'CLP, Peso'), ('CNY', 'CNY, Yuan Renminbi'), ('COP', 'COP, Peso'), ('CRC', 'CRC, Colon'), ('CUP', 'CUP, Peso'), ('CVE', 'CVE, Escudo'), ('CZK', 'CZK, Koruna'), ('DJF', 'DJF, Franc'), ('DKK', 'DKK, Krone'), ('DOP', 'DOP, Peso'), ('DZD', 'DZD, Dinar'), ('EGP', 'EGP, Pound'), ('ERN', 'ERN, Nakfa'), ('ETB', 'ETB, Birr'), ('EUR', 'EUR, Euro'), ('FJD', 'FJD, Dollar'), ('FKP', 'FKP, Pound'), ('GBP', 'GBP, Pound'), ('GEL', 'GEL, Lari'), ('GHS', 'GHS, Cedi'), ('GIP', 'GIP, Pound'), ('GMD', 'GMD, Dalasi'), ('GNF', 'GNF, Franc'), ('GTQ', 'GTQ, Quetzal'), ('GYD', 'GYD, Dollar'), ('HKD', 'HKD, Dollar'), ('HNL', 'HNL, Lempira'), ('HRK', 'HRK, Kuna'), ('HTG', 'HTG, Gourde'), ('HUF', 'HUF, Forint'), ('IDR', 'IDR, Rupiah'), ('ILS', 'ILS, Shekel'), ('INR', 'INR, Rupee'), ('IQD', 'IQD, Dinar'), ('IRR', 'IRR, Rial'), ('ISK', 'ISK, Krona'), ('JMD', 'JMD, Dollar'), ('JOD', 'JOD, Dinar'), ('JPY', 'JPY, Yen'), ('KES', 'KES, Shilling'), ('KGS', 'KGS, Som'), ('KHR', 'KHR, Riels'), ('KMF', 'KMF, Franc'), ('KPW', 'KPW, Won'), ('KRW', 'KRW, Won'), ('KWD', 'KWD, Dinar'), ('KYD', 'KYD, Dollar'), ('KZT', 'KZT, Tenge'), ('LAK', 'LAK, Kip'), ('LBP', 'LBP, Pound'), ('LKR', 'LKR, Rupee'), ('LRD', 'LRD, Dollar'), ('LSL', 'LSL, Loti'), ('LTL', 'LTL, Litas'), ('LVL', 'LVL, Lat'), ('LYD', 'LYD, Dinar'), ('MAD', 'MAD, Dirham'), ('MDL', 'MDL, Leu'), ('MGA', 'MGA, Ariary'), ('MKD', 'MKD, Denar'), ('MMK', 'MMK, Kyat'), ('MNT', 'MNT, Tugrik'), ('MOP', 'MOP, Pataca'), ('MRO', 'MRO, Ouguiya'), ('MUR', 'MUR, Rupee'), ('MVR', 'MVR, Rufiyaa'), ('MWK', 'MWK, Kwacha'), ('MXN', 'MXN, Peso'), ('MYR', 'MYR, Ringgit'), ('MZN', 'MZN, Metical'), ('NAD', 'NAD, Dollar'), ('NGN', 'NGN, Naira'), ('NIO', 'NIO, Cordoba'), ('NOK', 'NOK, Krone'), ('NPR', 'NPR, Rupee'), ('NZD', 'NZD, Dollar'), ('OMR', 'OMR, Rial'), ('PAB', 'PAB, Balboa'), ('PEN', 'PEN, Sol'), ('PGK', 'PGK, Kina'), ('PHP', 'PHP, Peso'), ('PKR', 'PKR, Rupee'), ('PLN', 'PLN, Zloty'), ('PYG', 'PYG, Guarani'), ('QAR', 'QAR, Rial'), ('RON', 'RON, Leu'), ('RSD', 'RSD, Dinar'), ('RUB', 'RUB, Ruble'), ('RWF', 'RWF, Franc'), ('SAR', 'SAR, Rial'), ('SBD', 'SBD, Dollar'), ('SCR', 'SCR, Rupee'), ('SDG', 'SDG, Pound'), ('SEK', 'SEK, Krona'), ('SGD', 'SGD, Dollar'), ('SHP', 'SHP, Pound'), ('SLL', 'SLL, Leone'), ('SOS', 'SOS, Shilling'), ('SRD', 'SRD, Dollar'), ('SSP', 'SSP, Pound'), ('STD', 'STD, Dobra'), ('SYP', 'SYP, Pound'), ('SZL', 'SZL, Lilangeni'), ('THB', 'THB, Baht'), ('TJS', 'TJS, Somoni'), ('TMT', 'TMT, Manat'), ('TND', 'TND, Dinar'), ('TOP', 'TOP, Paanga'), ('TRY', 'TRY, Lira'), ('TTD', 'TTD, Dollar'), ('TWD', 'TWD, Dollar'), ('TZS', 'TZS, Shilling'), ('UAH', 'UAH, Hryvnia'), ('UGX', 'UGX, Shilling'), ('USD', '$, Dollar'), ('UYU', 'UYU, Peso'), ('UZS', 'UZS, Som'), ('VEF', 'VEF, Bolivar'), ('VND', 'VND, Dong'), ('VUV', 'VUV, Vatu'), ('WST', 'WST, Tala'), ('XAF', 'XAF, Franc'), ('XCD', 'XCD, Dollar'), ('XOF', 'XOF, Franc'), ('XPF', 'XPF, Franc'), ('YER', 'YER, Rial'), ('ZAR', 'ZAR, Rand'), ('ZMK', 'ZMK, Kwacha'), ('ZWL', 'ZWL, Dollar')], max_length=3, null=True)), + ('phone', phonenumber_field.modelfields.PhoneNumberField(blank=True, max_length=128, null=True, region=None)), + ('amount_due', models.DecimalField(blank=True, decimal_places=2, max_digits=12, null=True)), + ('amount_paid', models.DecimalField(blank=True, decimal_places=2, max_digits=12, null=True)), + ('is_email_sent', models.BooleanField(default=False)), + ('status', models.CharField(choices=[('Draft', 'Draft'), ('Sent', 'Sent'), ('Paid', 'Paid'), ('Pending', 'Pending'), ('Cancelled', 'Cancel')], default='Draft', max_length=15)), + ('details', models.TextField(blank=True, null=True, verbose_name='Details')), + ('due_date', models.DateField(blank=True, null=True)), + ('tax', models.DecimalField(blank=True, decimal_places=2, max_digits=12, null=True)), + ('accounts', models.ManyToManyField(related_name='accounts_invoices', to='accounts.account')), + ('assigned_to', models.ManyToManyField(related_name='invoice_assigned_to', to=settings.AUTH_USER_MODEL)), + ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='invoice_created_by', to=settings.AUTH_USER_MODEL)), + ('from_address', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='invoice_from_address', to='common.address')), + ('org', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='common.org')), + ('teams', models.ManyToManyField(related_name='invoices_teams', to='teams.teams')), + ('to_address', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='invoice_to_address', to='common.address')), + ('updated_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_updated_by', to=settings.AUTH_USER_MODEL, verbose_name='Last Modified By')), ], options={ - "verbose_name": "Invoice", - "verbose_name_plural": "Invoices", + 'verbose_name': 'Invoice', + 'verbose_name_plural': 'Invoices', + 'db_table': 'invoice', + 'ordering': ('-created_at',), + }, + ), + migrations.CreateModel( + name='InvoiceHistory', + fields=[ + ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')), + ('updated_at', models.DateTimeField(auto_now=True, verbose_name='Last Modified At')), + ('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)), + ('invoice_title', models.CharField(max_length=50, verbose_name='Invoice Title')), + ('invoice_number', models.CharField(max_length=50, verbose_name='Invoice Number')), + ('name', models.CharField(max_length=100, verbose_name='Name')), + ('email', models.EmailField(max_length=254, verbose_name='Email')), + ('quantity', models.PositiveIntegerField(default=0)), + ('rate', models.DecimalField(decimal_places=2, default=0, max_digits=12)), + ('total_amount', models.DecimalField(blank=True, decimal_places=2, max_digits=12, null=True)), + ('currency', models.CharField(blank=True, choices=[('AED', 'AED, Dirham'), ('AFN', 'AFN, Afghani'), ('ALL', 'ALL, Lek'), ('AMD', 'AMD, Dram'), ('ANG', 'ANG, Guilder'), ('AOA', 'AOA, Kwanza'), ('ARS', 'ARS, Peso'), ('AUD', 'AUD, Dollar'), ('AWG', 'AWG, Guilder'), ('AZN', 'AZN, Manat'), ('BAM', 'BAM, Marka'), ('BBD', 'BBD, Dollar'), ('BDT', 'BDT, Taka'), ('BGN', 'BGN, Lev'), ('BHD', 'BHD, Dinar'), ('BIF', 'BIF, Franc'), ('BMD', 'BMD, Dollar'), ('BND', 'BND, Dollar'), ('BOB', 'BOB, Boliviano'), ('BRL', 'BRL, Real'), ('BSD', 'BSD, Dollar'), ('BTN', 'BTN, Ngultrum'), ('BWP', 'BWP, Pula'), ('BYR', 'BYR, Ruble'), ('BZD', 'BZD, Dollar'), ('CAD', 'CAD, Dollar'), ('CDF', 'CDF, Franc'), ('CHF', 'CHF, Franc'), ('CLP', 'CLP, Peso'), ('CNY', 'CNY, Yuan Renminbi'), ('COP', 'COP, Peso'), ('CRC', 'CRC, Colon'), ('CUP', 'CUP, Peso'), ('CVE', 'CVE, Escudo'), ('CZK', 'CZK, Koruna'), ('DJF', 'DJF, Franc'), ('DKK', 'DKK, Krone'), ('DOP', 'DOP, Peso'), ('DZD', 'DZD, Dinar'), ('EGP', 'EGP, Pound'), ('ERN', 'ERN, Nakfa'), ('ETB', 'ETB, Birr'), ('EUR', 'EUR, Euro'), ('FJD', 'FJD, Dollar'), ('FKP', 'FKP, Pound'), ('GBP', 'GBP, Pound'), ('GEL', 'GEL, Lari'), ('GHS', 'GHS, Cedi'), ('GIP', 'GIP, Pound'), ('GMD', 'GMD, Dalasi'), ('GNF', 'GNF, Franc'), ('GTQ', 'GTQ, Quetzal'), ('GYD', 'GYD, Dollar'), ('HKD', 'HKD, Dollar'), ('HNL', 'HNL, Lempira'), ('HRK', 'HRK, Kuna'), ('HTG', 'HTG, Gourde'), ('HUF', 'HUF, Forint'), ('IDR', 'IDR, Rupiah'), ('ILS', 'ILS, Shekel'), ('INR', 'INR, Rupee'), ('IQD', 'IQD, Dinar'), ('IRR', 'IRR, Rial'), ('ISK', 'ISK, Krona'), ('JMD', 'JMD, Dollar'), ('JOD', 'JOD, Dinar'), ('JPY', 'JPY, Yen'), ('KES', 'KES, Shilling'), ('KGS', 'KGS, Som'), ('KHR', 'KHR, Riels'), ('KMF', 'KMF, Franc'), ('KPW', 'KPW, Won'), ('KRW', 'KRW, Won'), ('KWD', 'KWD, Dinar'), ('KYD', 'KYD, Dollar'), ('KZT', 'KZT, Tenge'), ('LAK', 'LAK, Kip'), ('LBP', 'LBP, Pound'), ('LKR', 'LKR, Rupee'), ('LRD', 'LRD, Dollar'), ('LSL', 'LSL, Loti'), ('LTL', 'LTL, Litas'), ('LVL', 'LVL, Lat'), ('LYD', 'LYD, Dinar'), ('MAD', 'MAD, Dirham'), ('MDL', 'MDL, Leu'), ('MGA', 'MGA, Ariary'), ('MKD', 'MKD, Denar'), ('MMK', 'MMK, Kyat'), ('MNT', 'MNT, Tugrik'), ('MOP', 'MOP, Pataca'), ('MRO', 'MRO, Ouguiya'), ('MUR', 'MUR, Rupee'), ('MVR', 'MVR, Rufiyaa'), ('MWK', 'MWK, Kwacha'), ('MXN', 'MXN, Peso'), ('MYR', 'MYR, Ringgit'), ('MZN', 'MZN, Metical'), ('NAD', 'NAD, Dollar'), ('NGN', 'NGN, Naira'), ('NIO', 'NIO, Cordoba'), ('NOK', 'NOK, Krone'), ('NPR', 'NPR, Rupee'), ('NZD', 'NZD, Dollar'), ('OMR', 'OMR, Rial'), ('PAB', 'PAB, Balboa'), ('PEN', 'PEN, Sol'), ('PGK', 'PGK, Kina'), ('PHP', 'PHP, Peso'), ('PKR', 'PKR, Rupee'), ('PLN', 'PLN, Zloty'), ('PYG', 'PYG, Guarani'), ('QAR', 'QAR, Rial'), ('RON', 'RON, Leu'), ('RSD', 'RSD, Dinar'), ('RUB', 'RUB, Ruble'), ('RWF', 'RWF, Franc'), ('SAR', 'SAR, Rial'), ('SBD', 'SBD, Dollar'), ('SCR', 'SCR, Rupee'), ('SDG', 'SDG, Pound'), ('SEK', 'SEK, Krona'), ('SGD', 'SGD, Dollar'), ('SHP', 'SHP, Pound'), ('SLL', 'SLL, Leone'), ('SOS', 'SOS, Shilling'), ('SRD', 'SRD, Dollar'), ('SSP', 'SSP, Pound'), ('STD', 'STD, Dobra'), ('SYP', 'SYP, Pound'), ('SZL', 'SZL, Lilangeni'), ('THB', 'THB, Baht'), ('TJS', 'TJS, Somoni'), ('TMT', 'TMT, Manat'), ('TND', 'TND, Dinar'), ('TOP', 'TOP, Paanga'), ('TRY', 'TRY, Lira'), ('TTD', 'TTD, Dollar'), ('TWD', 'TWD, Dollar'), ('TZS', 'TZS, Shilling'), ('UAH', 'UAH, Hryvnia'), ('UGX', 'UGX, Shilling'), ('USD', '$, Dollar'), ('UYU', 'UYU, Peso'), ('UZS', 'UZS, Som'), ('VEF', 'VEF, Bolivar'), ('VND', 'VND, Dong'), ('VUV', 'VUV, Vatu'), ('WST', 'WST, Tala'), ('XAF', 'XAF, Franc'), ('XCD', 'XCD, Dollar'), ('XOF', 'XOF, Franc'), ('XPF', 'XPF, Franc'), ('YER', 'YER, Rial'), ('ZAR', 'ZAR, Rand'), ('ZMK', 'ZMK, Kwacha'), ('ZWL', 'ZWL, Dollar')], max_length=3, null=True)), + ('phone', phonenumber_field.modelfields.PhoneNumberField(blank=True, max_length=128, null=True, region=None)), + ('amount_due', models.DecimalField(blank=True, decimal_places=2, max_digits=12, null=True)), + ('amount_paid', models.DecimalField(blank=True, decimal_places=2, max_digits=12, null=True)), + ('is_email_sent', models.BooleanField(default=False)), + ('status', models.CharField(choices=[('Draft', 'Draft'), ('Sent', 'Sent'), ('Paid', 'Paid'), ('Pending', 'Pending'), ('Cancelled', 'Cancel')], default='Draft', max_length=15)), + ('details', models.TextField(blank=True, null=True, verbose_name='Details')), + ('due_date', models.DateField(blank=True, null=True)), + ('assigned_to', models.ManyToManyField(related_name='invoice_history_assigned_to', to=settings.AUTH_USER_MODEL)), + ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_created_by', to=settings.AUTH_USER_MODEL, verbose_name='Created By')), + ('from_address', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='invoice_history_from_address', to='common.address')), + ('invoice', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='invoice_history', to='invoices.invoice')), + ('to_address', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='invoice_history_to_address', to='common.address')), + ('updated_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='invoice_history_created_by', to=settings.AUTH_USER_MODEL)), + ], + options={ + 'verbose_name': 'InvoiceHistory', + 'verbose_name_plural': 'InvoiceHistories', + 'db_table': 'invoice_history', + 'ordering': ('-created_at',), }, ), ] diff --git a/invoices/migrations/0002_auto_20190524_1113.py b/invoices/migrations/0002_auto_20190524_1113.py deleted file mode 100644 index 57f15841..00000000 --- a/invoices/migrations/0002_auto_20190524_1113.py +++ /dev/null @@ -1,28 +0,0 @@ -# Generated by Django 2.1.7 on 2019-05-24 05:43 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("invoices", "0001_initial"), - ] - - operations = [ - migrations.AlterField( - model_name="invoice", - name="status", - field=models.CharField( - choices=[ - ("Draft", "Draft"), - ("Sent", "Sent"), - ("Paid", "Paid"), - ("Pending", "Pending"), - ("Cancel", "Cancel"), - ], - default="Draft", - max_length=15, - ), - ), - ] diff --git a/invoices/migrations/0003_auto_20190527_1620.py b/invoices/migrations/0003_auto_20190527_1620.py deleted file mode 100644 index 8b37ef05..00000000 --- a/invoices/migrations/0003_auto_20190527_1620.py +++ /dev/null @@ -1,23 +0,0 @@ -# Generated by Django 2.1.7 on 2019-05-27 10:50 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("invoices", "0002_auto_20190524_1113"), - ] - - operations = [ - migrations.AddField( - model_name="invoice", - name="details", - field=models.TextField(blank=True, null=True, verbose_name="Details"), - ), - migrations.AddField( - model_name="invoice", - name="due_date", - field=models.DateField(blank=True, null=True), - ), - ] diff --git a/invoices/migrations/0004_auto_20190603_1844.py b/invoices/migrations/0004_auto_20190603_1844.py deleted file mode 100644 index 1b1cde16..00000000 --- a/invoices/migrations/0004_auto_20190603_1844.py +++ /dev/null @@ -1,28 +0,0 @@ -# Generated by Django 2.1.7 on 2019-06-03 13:14 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("invoices", "0003_auto_20190527_1620"), - ] - - operations = [ - migrations.AlterField( - model_name="invoice", - name="status", - field=models.CharField( - choices=[ - ("Draft", "Draft"), - ("Sent", "Sent"), - ("Paid", "Paid"), - ("Pending", "Pending"), - ("Cancelled", "Cancel"), - ], - default="Draft", - max_length=15, - ), - ), - ] diff --git a/invoices/migrations/0005_invoicehistory.py b/invoices/migrations/0005_invoicehistory.py deleted file mode 100644 index a075b272..00000000 --- a/invoices/migrations/0005_invoicehistory.py +++ /dev/null @@ -1,301 +0,0 @@ -# Generated by Django 2.2.2 on 2019-07-24 05:46 - -import django.db.models.deletion -import phonenumber_field.modelfields -from django.conf import settings -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0017_auto_20190722_1443"), - migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ("invoices", "0004_auto_20190603_1844"), - ] - - operations = [ - migrations.CreateModel( - name="InvoiceHistory", - fields=[ - ( - "id", - models.AutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ( - "invoice_title", - models.CharField(max_length=50, verbose_name="Invoice Title"), - ), - ( - "invoice_number", - models.CharField(max_length=50, verbose_name="Invoice Number"), - ), - ("name", models.CharField(max_length=100, verbose_name="Name")), - ("email", models.EmailField(max_length=254, verbose_name="Email")), - ("quantity", models.PositiveIntegerField(default=0)), - ( - "rate", - models.DecimalField(decimal_places=2, default=0, max_digits=12), - ), - ( - "total_amount", - models.DecimalField( - blank=True, decimal_places=2, max_digits=12, null=True - ), - ), - ( - "currency", - models.CharField( - blank=True, - choices=[ - ("AED", "AED, Dirham"), - ("AFN", "AFN, Afghani"), - ("ALL", "ALL, Lek"), - ("AMD", "AMD, Dram"), - ("ANG", "ANG, Guilder"), - ("AOA", "AOA, Kwanza"), - ("ARS", "ARS, Peso"), - ("AUD", "AUD, Dollar"), - ("AWG", "AWG, Guilder"), - ("AZN", "AZN, Manat"), - ("BAM", "BAM, Marka"), - ("BBD", "BBD, Dollar"), - ("BDT", "BDT, Taka"), - ("BGN", "BGN, Lev"), - ("BHD", "BHD, Dinar"), - ("BIF", "BIF, Franc"), - ("BMD", "BMD, Dollar"), - ("BND", "BND, Dollar"), - ("BOB", "BOB, Boliviano"), - ("BRL", "BRL, Real"), - ("BSD", "BSD, Dollar"), - ("BTN", "BTN, Ngultrum"), - ("BWP", "BWP, Pula"), - ("BYR", "BYR, Ruble"), - ("BZD", "BZD, Dollar"), - ("CAD", "CAD, Dollar"), - ("CDF", "CDF, Franc"), - ("CHF", "CHF, Franc"), - ("CLP", "CLP, Peso"), - ("CNY", "CNY, Yuan Renminbi"), - ("COP", "COP, Peso"), - ("CRC", "CRC, Colon"), - ("CUP", "CUP, Peso"), - ("CVE", "CVE, Escudo"), - ("CZK", "CZK, Koruna"), - ("DJF", "DJF, Franc"), - ("DKK", "DKK, Krone"), - ("DOP", "DOP, Peso"), - ("DZD", "DZD, Dinar"), - ("EGP", "EGP, Pound"), - ("ERN", "ERN, Nakfa"), - ("ETB", "ETB, Birr"), - ("EUR", "EUR, Euro"), - ("FJD", "FJD, Dollar"), - ("FKP", "FKP, Pound"), - ("GBP", "GBP, Pound"), - ("GEL", "GEL, Lari"), - ("GHS", "GHS, Cedi"), - ("GIP", "GIP, Pound"), - ("GMD", "GMD, Dalasi"), - ("GNF", "GNF, Franc"), - ("GTQ", "GTQ, Quetzal"), - ("GYD", "GYD, Dollar"), - ("HKD", "HKD, Dollar"), - ("HNL", "HNL, Lempira"), - ("HRK", "HRK, Kuna"), - ("HTG", "HTG, Gourde"), - ("HUF", "HUF, Forint"), - ("IDR", "IDR, Rupiah"), - ("ILS", "ILS, Shekel"), - ("INR", "INR, Rupee"), - ("IQD", "IQD, Dinar"), - ("IRR", "IRR, Rial"), - ("ISK", "ISK, Krona"), - ("JMD", "JMD, Dollar"), - ("JOD", "JOD, Dinar"), - ("JPY", "JPY, Yen"), - ("KES", "KES, Shilling"), - ("KGS", "KGS, Som"), - ("KHR", "KHR, Riels"), - ("KMF", "KMF, Franc"), - ("KPW", "KPW, Won"), - ("KRW", "KRW, Won"), - ("KWD", "KWD, Dinar"), - ("KYD", "KYD, Dollar"), - ("KZT", "KZT, Tenge"), - ("LAK", "LAK, Kip"), - ("LBP", "LBP, Pound"), - ("LKR", "LKR, Rupee"), - ("LRD", "LRD, Dollar"), - ("LSL", "LSL, Loti"), - ("LTL", "LTL, Litas"), - ("LVL", "LVL, Lat"), - ("LYD", "LYD, Dinar"), - ("MAD", "MAD, Dirham"), - ("MDL", "MDL, Leu"), - ("MGA", "MGA, Ariary"), - ("MKD", "MKD, Denar"), - ("MMK", "MMK, Kyat"), - ("MNT", "MNT, Tugrik"), - ("MOP", "MOP, Pataca"), - ("MRO", "MRO, Ouguiya"), - ("MUR", "MUR, Rupee"), - ("MVR", "MVR, Rufiyaa"), - ("MWK", "MWK, Kwacha"), - ("MXN", "MXN, Peso"), - ("MYR", "MYR, Ringgit"), - ("MZN", "MZN, Metical"), - ("NAD", "NAD, Dollar"), - ("NGN", "NGN, Naira"), - ("NIO", "NIO, Cordoba"), - ("NOK", "NOK, Krone"), - ("NPR", "NPR, Rupee"), - ("NZD", "NZD, Dollar"), - ("OMR", "OMR, Rial"), - ("PAB", "PAB, Balboa"), - ("PEN", "PEN, Sol"), - ("PGK", "PGK, Kina"), - ("PHP", "PHP, Peso"), - ("PKR", "PKR, Rupee"), - ("PLN", "PLN, Zloty"), - ("PYG", "PYG, Guarani"), - ("QAR", "QAR, Rial"), - ("RON", "RON, Leu"), - ("RSD", "RSD, Dinar"), - ("RUB", "RUB, Ruble"), - ("RWF", "RWF, Franc"), - ("SAR", "SAR, Rial"), - ("SBD", "SBD, Dollar"), - ("SCR", "SCR, Rupee"), - ("SDG", "SDG, Pound"), - ("SEK", "SEK, Krona"), - ("SGD", "SGD, Dollar"), - ("SHP", "SHP, Pound"), - ("SLL", "SLL, Leone"), - ("SOS", "SOS, Shilling"), - ("SRD", "SRD, Dollar"), - ("SSP", "SSP, Pound"), - ("STD", "STD, Dobra"), - ("SYP", "SYP, Pound"), - ("SZL", "SZL, Lilangeni"), - ("THB", "THB, Baht"), - ("TJS", "TJS, Somoni"), - ("TMT", "TMT, Manat"), - ("TND", "TND, Dinar"), - ("TOP", "TOP, Paanga"), - ("TRY", "TRY, Lira"), - ("TTD", "TTD, Dollar"), - ("TWD", "TWD, Dollar"), - ("TZS", "TZS, Shilling"), - ("UAH", "UAH, Hryvnia"), - ("UGX", "UGX, Shilling"), - ("USD", "$, Dollar"), - ("UYU", "UYU, Peso"), - ("UZS", "UZS, Som"), - ("VEF", "VEF, Bolivar"), - ("VND", "VND, Dong"), - ("VUV", "VUV, Vatu"), - ("WST", "WST, Tala"), - ("XAF", "XAF, Franc"), - ("XCD", "XCD, Dollar"), - ("XOF", "XOF, Franc"), - ("XPF", "XPF, Franc"), - ("YER", "YER, Rial"), - ("ZAR", "ZAR, Rand"), - ("ZMK", "ZMK, Kwacha"), - ("ZWL", "ZWL, Dollar"), - ], - max_length=3, - null=True, - ), - ), - ( - "phone", - phonenumber_field.modelfields.PhoneNumberField( - blank=True, max_length=128, null=True - ), - ), - ("created_on", models.DateTimeField(auto_now_add=True)), - ( - "amount_due", - models.DecimalField( - blank=True, decimal_places=2, max_digits=12, null=True - ), - ), - ( - "amount_paid", - models.DecimalField( - blank=True, decimal_places=2, max_digits=12, null=True - ), - ), - ("is_email_sent", models.BooleanField(default=False)), - ( - "status", - models.CharField( - choices=[ - ("Draft", "Draft"), - ("Sent", "Sent"), - ("Paid", "Paid"), - ("Pending", "Pending"), - ("Cancelled", "Cancel"), - ], - default="Draft", - max_length=15, - ), - ), - ( - "details", - models.TextField(blank=True, null=True, verbose_name="Details"), - ), - ("due_date", models.DateField(blank=True, null=True)), - ( - "assigned_to", - models.ManyToManyField( - related_name="invoice_history_assigned_to", - to=settings.AUTH_USER_MODEL, - ), - ), - ( - "from_address", - models.ForeignKey( - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="invoice_history_from_address", - to="common.Address", - ), - ), - ( - "invoice", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - related_name="invoice_history", - to="invoices.Invoice", - ), - ), - ( - "to_address", - models.ForeignKey( - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="invoice_history_to_address", - to="common.Address", - ), - ), - ( - "updated_by", - models.ForeignKey( - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="invoice_history_created_by", - to=settings.AUTH_USER_MODEL, - ), - ), - ], - ), - ] diff --git a/invoices/migrations/0006_invoice_account.py b/invoices/migrations/0006_invoice_account.py deleted file mode 100644 index 0ec29397..00000000 --- a/invoices/migrations/0006_invoice_account.py +++ /dev/null @@ -1,21 +0,0 @@ -# Generated by Django 2.2.3 on 2019-07-29 05:47 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("accounts", "0008_account_assigned_to"), - ("invoices", "0005_invoicehistory"), - ] - - operations = [ - migrations.AddField( - model_name="invoice", - name="accounts", - field=models.ManyToManyField( - related_name="accounts_invoices", to="accounts.Account" - ), - ), - ] diff --git a/invoices/migrations/0007_auto_20190909_1621.py b/invoices/migrations/0007_auto_20190909_1621.py deleted file mode 100644 index 55bd1c8d..00000000 --- a/invoices/migrations/0007_auto_20190909_1621.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 2.2.4 on 2019-09-09 10:51 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ("invoices", "0006_invoice_account"), - ] - - operations = [ - migrations.AlterModelOptions( - name="invoicehistory", - options={"ordering": ("created_on",)}, - ), - ] diff --git a/invoices/migrations/0008_invoice_teams.py b/invoices/migrations/0008_invoice_teams.py deleted file mode 100644 index b812c708..00000000 --- a/invoices/migrations/0008_invoice_teams.py +++ /dev/null @@ -1,21 +0,0 @@ -# Generated by Django 2.2.4 on 2019-09-17 05:46 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("teams", "0003_auto_20190909_1621"), - ("invoices", "0007_auto_20190909_1621"), - ] - - operations = [ - migrations.AddField( - model_name="invoice", - name="teams", - field=models.ManyToManyField( - related_name="invoices_teams", to="teams.Teams" - ), - ), - ] diff --git a/invoices/migrations/0009_invoice_company.py b/invoices/migrations/0009_invoice_company.py deleted file mode 100644 index 8c40bc59..00000000 --- a/invoices/migrations/0009_invoice_company.py +++ /dev/null @@ -1,25 +0,0 @@ -# Generated by Django 2.2.10 on 2020-04-27 12:35 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0021_document_company"), - ("invoices", "0008_invoice_teams"), - ] - - operations = [ - migrations.AddField( - model_name="invoice", - name="company", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - to="common.Company", - ), - ), - ] diff --git a/invoices/migrations/0010_invoice_tax.py b/invoices/migrations/0010_invoice_tax.py deleted file mode 100644 index 17d58726..00000000 --- a/invoices/migrations/0010_invoice_tax.py +++ /dev/null @@ -1,20 +0,0 @@ -# Generated by Django 3.1 on 2020-09-25 08:29 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("invoices", "0009_invoice_company"), - ] - - operations = [ - migrations.AddField( - model_name="invoice", - name="tax", - field=models.DecimalField( - blank=True, decimal_places=2, max_digits=12, null=True - ), - ), - ] diff --git a/invoices/migrations/0011_rename_company_invoice_org.py b/invoices/migrations/0011_rename_company_invoice_org.py deleted file mode 100644 index 8a5c8e09..00000000 --- a/invoices/migrations/0011_rename_company_invoice_org.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 3.2 on 2021-09-22 12:31 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ("invoices", "0010_invoice_tax"), - ] - - operations = [ - migrations.RenameField( - model_name="invoice", - old_name="company", - new_name="org", - ), - ] diff --git a/invoices/models.py b/invoices/models.py index 83602ed5..68fc8ff0 100644 --- a/invoices/models.py +++ b/invoices/models.py @@ -7,11 +7,12 @@ from phonenumber_field.modelfields import PhoneNumberField from accounts.models import Account from common.models import Address, Org, User +from common.base import BaseModel from common.utils import CURRENCY_CODES from teams.models import Teams -class Invoice(models.Model): +class Invoice(BaseModel): """Model definition for Invoice.""" INVOICE_STATUS = ( @@ -49,7 +50,6 @@ class Invoice(models.Model): max_length=3, choices=CURRENCY_CODES, blank=True, null=True ) phone = PhoneNumberField(null=True, blank=True) - created_on = models.DateTimeField(auto_now_add=True) created_by = models.ForeignKey( User, related_name="invoice_created_by", on_delete=models.SET_NULL, null=True ) @@ -71,14 +71,14 @@ class Invoice(models.Model): tax = models.DecimalField(blank=True, null=True, max_digits=12, decimal_places=2) class Meta: - """Meta definition for Invoice.""" - verbose_name = "Invoice" verbose_name_plural = "Invoices" + db_table = "invoice" + ordering = ("-created_at",) def __str__(self): """Unicode representation of Invoice.""" - return self.invoice_number + return f"{self.invoice_number}" def save(self, *args, **kwargs): if not self.invoice_number: @@ -131,7 +131,7 @@ class Invoice(models.Model): @property def created_on_arrow(self): - return arrow.get(self.created_on).humanize() + return arrow.get(self.created_at).humanize() @property def get_team_users(self): @@ -153,7 +153,7 @@ class Invoice(models.Model): return User.objects.filter(id__in=list(user_ids)) -class InvoiceHistory(models.Model): +class InvoiceHistory(BaseModel): """Model definition for InvoiceHistory. This model is used to track/keep a record of the updates made to original invoice object.""" @@ -198,7 +198,6 @@ class InvoiceHistory(models.Model): max_length=3, choices=CURRENCY_CODES, blank=True, null=True ) phone = PhoneNumberField(null=True, blank=True) - created_on = models.DateTimeField(auto_now_add=True) # created_by = models.ForeignKey( # User, related_name='invoice_history_created_by', # on_delete=models.SET_NULL, null=True) @@ -221,13 +220,16 @@ class InvoiceHistory(models.Model): details = models.TextField(_("Details"), null=True, blank=True) due_date = models.DateField(blank=True, null=True) + class Meta: + verbose_name = "InvoiceHistory" + verbose_name_plural = "InvoiceHistories" + db_table = "invoice_history" + ordering = ("-created_at",) + def __str__(self): """Unicode representation of Invoice.""" return self.invoice_number - class Meta: - ordering = ("created_on",) - def formatted_total_amount(self): return self.currency + " " + str(self.total_amount) @@ -239,4 +241,4 @@ class InvoiceHistory(models.Model): @property def created_on_arrow(self): - return arrow.get(self.created_on).humanize() + return arrow.get(self.created_at).humanize() diff --git a/invoices/serializer.py b/invoices/serializer.py index de06f80e..15dd5c12 100644 --- a/invoices/serializer.py +++ b/invoices/serializer.py @@ -1,7 +1,10 @@ from rest_framework import serializers -from common.serializer import (BillingAddressSerializer, - OrganizationSerializer, UserSerializer) +from common.serializer import ( + BillingAddressSerializer, + OrganizationSerializer, + UserSerializer, +) from invoices.models import Invoice, InvoiceHistory from teams.serializer import TeamsSerializer @@ -123,3 +126,34 @@ class InvoiceCreateSerializer(serializers.ModelSerializer): "details", "org", ) + +class InvoiceSwaggerSerailizer(serializers.ModelSerializer): + + from_address = BillingAddressSerializer() + to_address = BillingAddressSerializer() + assigned_to = UserSerializer(read_only=True, many=True) + quality_hours = serializers.CharField() + class Meta: + model = Invoice + fields = ( + "invoice_title", + "status", + "name", + "email", + "phone", + "due_date", + "currency", + "rate", + "tax", + "total_amount", + "details", + "teams", + "from_address", + "to_address", + "assigned_to", + "currency", + "accounts", + "quality_hours" + ) + + diff --git a/invoices/swagger_params1.py b/invoices/swagger_params1.py new file mode 100644 index 00000000..37ab528e --- /dev/null +++ b/invoices/swagger_params1.py @@ -0,0 +1,79 @@ +from drf_spectacular.types import OpenApiTypes +from drf_spectacular.utils import OpenApiParameter + +organization_params_in_header = organization_params_in_header = OpenApiParameter( + "org", OpenApiTypes.STR, OpenApiParameter.HEADER +) + +organization_params = [ + organization_params_in_header, +] + +invoice_list_get_params = [ + organization_params, + OpenApiParameter( + "invoice_title_or_number",OpenApiParameter.QUERY, OpenApiTypes.STR + ), + OpenApiParameter("created_by",OpenApiParameter.QUERY, OpenApiTypes.INT), + OpenApiParameter("assigned_users",OpenApiParameter.QUERY, OpenApiTypes.STR), + OpenApiParameter("status",OpenApiParameter.QUERY, OpenApiTypes.STR), + OpenApiParameter("total_amount",OpenApiParameter.QUERY, OpenApiTypes.STR), +] + +invoice_detail_post_params = [ + organization_params, + OpenApiParameter( + "invoice_attachment", + OpenApiParameter.QUERY, + type=openapi.TYPE_FILE, + ), + OpenApiParameter("comment",OpenApiParameter.QUERY, OpenApiTypes.STR), +] + +invoice_delete_params = [ + organization_params, +] + +invoice_create_post_params = [ + organization_params, + OpenApiParameter( + "invoice_title",OpenApiParameter.QUERY, OpenApiTypes.STR, required=True, + ), + OpenApiParameter("status",OpenApiParameter.QUERY, OpenApiTypes.STR), + OpenApiParameter("from_address_line",OpenApiParameter.QUERY, OpenApiTypes.STR), + OpenApiParameter("from_street",OpenApiParameter.QUERY, OpenApiTypes.STR), + OpenApiParameter("from_city",OpenApiParameter.QUERY, OpenApiTypes.STR), + OpenApiParameter("from_state",OpenApiParameter.QUERY, OpenApiTypes.STR), + OpenApiParameter("from_postcode",OpenApiParameter.QUERY, OpenApiTypes.STR), + OpenApiParameter("from_country",OpenApiParameter.QUERY, OpenApiTypes.STR), + OpenApiParameter("to_address_line",OpenApiParameter.QUERY, OpenApiTypes.STR), + OpenApiParameter("to_street",OpenApiParameter.QUERY, OpenApiTypes.STR), + OpenApiParameter("to_city",OpenApiParameter.QUERY, OpenApiTypes.STR), + OpenApiParameter("to_state",OpenApiParameter.QUERY, OpenApiTypes.STR), + OpenApiParameter("to_postcode",OpenApiParameter.QUERY, OpenApiTypes.STR), + OpenApiParameter("to_country",OpenApiParameter.QUERY, OpenApiTypes.STR), + OpenApiParameter("name",OpenApiParameter.QUERY, OpenApiTypes.STR), + OpenApiParameter( + "email",OpenApiParameter.QUERY, OpenApiTypes.STR, required=True, + ), + OpenApiParameter("phone",OpenApiParameter.QUERY, OpenApiTypes.STR), + OpenApiParameter( + "due_date",OpenApiParameter.QUERY, type=openapi.FORMAT_DATE, example="2021-02-28" + ), + OpenApiParameter( + "currency",OpenApiParameter.QUERY, OpenApiTypes.STR,required=True, + ), + OpenApiParameter("teams",OpenApiParameter.QUERY, OpenApiTypes.STR), + OpenApiParameter("assigned_to",OpenApiParameter.QUERY, OpenApiTypes.STR), + OpenApiParameter("accounts",OpenApiParameter.QUERY, OpenApiTypes.STR), + OpenApiParameter("quality_hours",OpenApiParameter.QUERY, OpenApiTypes.INT), + OpenApiParameter("rate",OpenApiParameter.QUERY, OpenApiTypes.INT), + OpenApiParameter("tax",OpenApiParameter.QUERY, OpenApiTypes.INT), + OpenApiParameter("total_amount",OpenApiParameter.QUERY, OpenApiTypes.INT), + OpenApiParameter("details",OpenApiParameter.QUERY, OpenApiTypes.STR), +] + +invoice_comment_edit_params = [ + organization_params, + OpenApiParameter("comment",OpenApiParameter.QUERY, OpenApiTypes.STR), +] diff --git a/invoices/templates/invoices_detail.html b/invoices/templates/invoices_detail.html index 1b1bccfa..d62ad7f1 100644 --- a/invoices/templates/invoices_detail.html +++ b/invoices/templates/invoices_detail.html @@ -515,8 +515,8 @@ data: {{ users_mention| safe}}, map: function (user) { return { - value: user.username, - text: '' + user.username + '' + value: user.email, + text: '' + user.email + '' } } }) diff --git a/invoices/templates/invoices_detail_1.html b/invoices/templates/invoices_detail_1.html index 8c313e0c..4387aea7 100644 --- a/invoices/templates/invoices_detail_1.html +++ b/invoices/templates/invoices_detail_1.html @@ -627,8 +627,8 @@ data: {{ users_mention| safe}}, map: function (user) { return { - value: user.username, - text: '' + user.username + '' + value: user.email, + text: '' + user.email + '' } } }) diff --git a/invoices/templates/invoices_list.html b/invoices/templates/invoices_list.html index e0a0af2e..8d76d144 100644 --- a/invoices/templates/invoices_list.html +++ b/invoices/templates/invoices_list.html @@ -61,7 +61,7 @@ diff --git a/invoices/tests_celery_tasks.py b/invoices/tests_celery_tasks.py index 221c9ab4..3ea287aa 100644 --- a/invoices/tests_celery_tasks.py +++ b/invoices/tests_celery_tasks.py @@ -1,8 +1,7 @@ from django.test import TestCase from django.test.utils import override_settings -from invoices.tasks import (send_email, send_invoice_email, - send_invoice_email_cancel) +from invoices.tasks import send_email, send_invoice_email, send_invoice_email_cancel from invoices.tests import InvoiceCreateTest diff --git a/leads/migrations/0001_initial.py b/leads/migrations/0001_initial.py index 19a780c5..42594282 100644 --- a/leads/migrations/0001_initial.py +++ b/leads/migrations/0001_initial.py @@ -1,9 +1,10 @@ -# Generated by Django 2.1.2 on 2019-01-28 07:07 +# Generated by Django 4.2.1 on 2023-06-19 13:08 -import django.db.models.deletion -import phonenumber_field.modelfields from django.conf import settings from django.db import migrations, models +import django.db.models.deletion +import phonenumber_field.modelfields +import uuid class Migration(migrations.Migration): @@ -11,147 +12,77 @@ class Migration(migrations.Migration): initial = True dependencies = [ - ("accounts", "0001_initial"), - ("common", "0001_initial"), + ('teams', '0001_initial'), + ('accounts', '0001_initial'), + ('common', '0001_initial'), migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('contacts', '0001_initial'), ] operations = [ migrations.CreateModel( - name="Lead", + name='Company', fields=[ - ( - "id", - models.AutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ( - "title", - models.CharField( - blank=True, max_length=64, null=True, verbose_name="Title" - ), - ), - ( - "first_name", - models.CharField(max_length=255, verbose_name="First name"), - ), - ( - "last_name", - models.CharField(max_length=255, verbose_name="Last name"), - ), - ("email", models.EmailField(max_length=254)), - ( - "phone", - phonenumber_field.modelfields.PhoneNumberField( - blank=True, max_length=128, null=True - ), - ), - ( - "status", - models.CharField( - blank=True, - choices=[ - ("assigned", "Assigned"), - ("in process", "In Process"), - ("converted", "Converted"), - ("recycled", "Recycled"), - ("dead", "Dead"), - ], - max_length=255, - null=True, - verbose_name="Status of Lead", - ), - ), - ( - "source", - models.CharField( - blank=True, - choices=[ - ("call", "Call"), - ("email", "Email"), - ("existing customer", "Existing Customer"), - ("partner", "Partner"), - ("public relations", "Public Relations"), - ("compaign", "Campaign"), - ("other", "Other"), - ], - max_length=255, - null=True, - verbose_name="Source of Lead", - ), - ), - ( - "website", - models.CharField( - blank=True, max_length=255, null=True, verbose_name="Website" - ), - ), - ("description", models.TextField(blank=True, null=True)), - ( - "account_name", - models.CharField(blank=True, max_length=255, null=True), - ), - ( - "opportunity_amount", - models.DecimalField( - blank=True, - decimal_places=2, - max_digits=12, - null=True, - verbose_name="Opportunity Amount", - ), - ), - ( - "created_on", - models.DateTimeField(auto_now_add=True, verbose_name="Created on"), - ), - ("is_active", models.BooleanField(default=False)), - ( - "enquery_type", - models.CharField(blank=True, max_length=255, null=True), - ), - ( - "account", - models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - related_name="Leads", - to="accounts.Account", - ), - ), - ( - "address", - models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - related_name="leadaddress", - to="common.Address", - ), - ), - ( - "assigned_to", - models.ManyToManyField( - related_name="lead_assigned_users", to=settings.AUTH_USER_MODEL - ), - ), - ( - "created_by", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - related_name="lead_created_by", - to=settings.AUTH_USER_MODEL, - ), - ), - ("teams", models.ManyToManyField(to="common.Team")), + ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')), + ('updated_at', models.DateTimeField(auto_now=True, verbose_name='Last Modified At')), + ('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)), + ('name', models.CharField(blank=True, max_length=100, null=True)), + ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_created_by', to=settings.AUTH_USER_MODEL, verbose_name='Created By')), + ('org', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='common.org')), + ('updated_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_updated_by', to=settings.AUTH_USER_MODEL, verbose_name='Last Modified By')), ], options={ - "ordering": ["-created_on"], + 'verbose_name': 'Company', + 'verbose_name_plural': 'Companies', + 'db_table': 'company', + 'ordering': ('-created_at',), + }, + ), + migrations.CreateModel( + name='Lead', + fields=[ + ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')), + ('updated_at', models.DateTimeField(auto_now=True, verbose_name='Last Modified At')), + ('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)), + ('title', models.CharField(max_length=64, verbose_name='Title')), + ('first_name', models.CharField(max_length=255, null=True, verbose_name='First name')), + ('last_name', models.CharField(max_length=255, null=True, verbose_name='Last name')), + ('email', models.EmailField(blank=True, max_length=254, null=True)), + ('phone', phonenumber_field.modelfields.PhoneNumberField(blank=True, max_length=128, null=True, region=None)), + ('status', models.CharField(blank=True, choices=[('assigned', 'Assigned'), ('in process', 'In Process'), ('converted', 'Converted'), ('recycled', 'Recycled'), ('closed', 'Closed')], max_length=255, null=True, verbose_name='Status of Lead')), + ('source', models.CharField(blank=True, choices=[('call', 'Call'), ('email', 'Email'), ('existing customer', 'Existing Customer'), ('partner', 'Partner'), ('public relations', 'Public Relations'), ('compaign', 'Campaign'), ('other', 'Other')], max_length=255, null=True, verbose_name='Source of Lead')), + ('address_line', models.CharField(blank=True, max_length=255, null=True, verbose_name='Address')), + ('street', models.CharField(blank=True, max_length=55, null=True, verbose_name='Street')), + ('city', models.CharField(blank=True, max_length=255, null=True, verbose_name='City')), + ('state', models.CharField(blank=True, max_length=255, null=True, verbose_name='State')), + ('postcode', models.CharField(blank=True, max_length=64, null=True, verbose_name='Post/Zip-code')), + ('country', models.CharField(blank=True, choices=[('GB', 'United Kingdom'), ('AF', 'Afghanistan'), ('AX', 'Aland Islands'), ('AL', 'Albania'), ('DZ', 'Algeria'), ('AS', 'American Samoa'), ('AD', 'Andorra'), ('AO', 'Angola'), ('AI', 'Anguilla'), ('AQ', 'Antarctica'), ('AG', 'Antigua and Barbuda'), ('AR', 'Argentina'), ('AM', 'Armenia'), ('AW', 'Aruba'), ('AU', 'Australia'), ('AT', 'Austria'), ('AZ', 'Azerbaijan'), ('BS', 'Bahamas'), ('BH', 'Bahrain'), ('BD', 'Bangladesh'), ('BB', 'Barbados'), ('BY', 'Belarus'), ('BE', 'Belgium'), ('BZ', 'Belize'), ('BJ', 'Benin'), ('BM', 'Bermuda'), ('BT', 'Bhutan'), ('BO', 'Bolivia'), ('BA', 'Bosnia and Herzegovina'), ('BW', 'Botswana'), ('BV', 'Bouvet Island'), ('BR', 'Brazil'), ('IO', 'British Indian Ocean Territory'), ('BN', 'Brunei Darussalam'), ('BG', 'Bulgaria'), ('BF', 'Burkina Faso'), ('BI', 'Burundi'), ('KH', 'Cambodia'), ('CM', 'Cameroon'), ('CA', 'Canada'), ('CV', 'Cape Verde'), ('KY', 'Cayman Islands'), ('CF', 'Central African Republic'), ('TD', 'Chad'), ('CL', 'Chile'), ('CN', 'China'), ('CX', 'Christmas Island'), ('CC', 'Cocos (Keeling) Islands'), ('CO', 'Colombia'), ('KM', 'Comoros'), ('CG', 'Congo'), ('CD', 'Congo, The Democratic Republic of the'), ('CK', 'Cook Islands'), ('CR', 'Costa Rica'), ('CI', "Cote d'Ivoire"), ('HR', 'Croatia'), ('CU', 'Cuba'), ('CY', 'Cyprus'), ('CZ', 'Czech Republic'), ('DK', 'Denmark'), ('DJ', 'Djibouti'), ('DM', 'Dominica'), ('DO', 'Dominican Republic'), ('EC', 'Ecuador'), ('EG', 'Egypt'), ('SV', 'El Salvador'), ('GQ', 'Equatorial Guinea'), ('ER', 'Eritrea'), ('EE', 'Estonia'), ('ET', 'Ethiopia'), ('FK', 'Falkland Islands (Malvinas)'), ('FO', 'Faroe Islands'), ('FJ', 'Fiji'), ('FI', 'Finland'), ('FR', 'France'), ('GF', 'French Guiana'), ('PF', 'French Polynesia'), ('TF', 'French Southern Territories'), ('GA', 'Gabon'), ('GM', 'Gambia'), ('GE', 'Georgia'), ('DE', 'Germany'), ('GH', 'Ghana'), ('GI', 'Gibraltar'), ('GR', 'Greece'), ('GL', 'Greenland'), ('GD', 'Grenada'), ('GP', 'Guadeloupe'), ('GU', 'Guam'), ('GT', 'Guatemala'), ('GG', 'Guernsey'), ('GN', 'Guinea'), ('GW', 'Guinea-Bissau'), ('GY', 'Guyana'), ('HT', 'Haiti'), ('HM', 'Heard Island and McDonald Islands'), ('VA', 'Holy See (Vatican City State)'), ('HN', 'Honduras'), ('HK', 'Hong Kong'), ('HU', 'Hungary'), ('IS', 'Iceland'), ('IN', 'India'), ('ID', 'Indonesia'), ('IR', 'Iran, Islamic Republic of'), ('IQ', 'Iraq'), ('IE', 'Ireland'), ('IM', 'Isle of Man'), ('IL', 'Israel'), ('IT', 'Italy'), ('JM', 'Jamaica'), ('JP', 'Japan'), ('JE', 'Jersey'), ('JO', 'Jordan'), ('KZ', 'Kazakhstan'), ('KE', 'Kenya'), ('KI', 'Kiribati'), ('KP', "Korea, Democratic People's Republic of"), ('KR', 'Korea, Republic of'), ('KW', 'Kuwait'), ('KG', 'Kyrgyzstan'), ('LA', "Lao People's Democratic Republic"), ('LV', 'Latvia'), ('LB', 'Lebanon'), ('LS', 'Lesotho'), ('LR', 'Liberia'), ('LY', 'Libyan Arab Jamahiriya'), ('LI', 'Liechtenstein'), ('LT', 'Lithuania'), ('LU', 'Luxembourg'), ('MO', 'Macao'), ('MK', 'Macedonia, The Former Yugoslav Republic of'), ('MG', 'Madagascar'), ('MW', 'Malawi'), ('MY', 'Malaysia'), ('MV', 'Maldives'), ('ML', 'Mali'), ('MT', 'Malta'), ('MH', 'Marshall Islands'), ('MQ', 'Martinique'), ('MR', 'Mauritania'), ('MU', 'Mauritius'), ('YT', 'Mayotte'), ('MX', 'Mexico'), ('FM', 'Micronesia, Federated States of'), ('MD', 'Moldova'), ('MC', 'Monaco'), ('MN', 'Mongolia'), ('ME', 'Montenegro'), ('MS', 'Montserrat'), ('MA', 'Morocco'), ('MZ', 'Mozambique'), ('MM', 'Myanmar'), ('NA', 'Namibia'), ('NR', 'Nauru'), ('NP', 'Nepal'), ('NL', 'Netherlands'), ('AN', 'Netherlands Antilles'), ('NC', 'New Caledonia'), ('NZ', 'New Zealand'), ('NI', 'Nicaragua'), ('NE', 'Niger'), ('NG', 'Nigeria'), ('NU', 'Niue'), ('NF', 'Norfolk Island'), ('MP', 'Northern Mariana Islands'), ('NO', 'Norway'), ('OM', 'Oman'), ('PK', 'Pakistan'), ('PW', 'Palau'), ('PS', 'Palestinian Territory, Occupied'), ('PA', 'Panama'), ('PG', 'Papua New Guinea'), ('PY', 'Paraguay'), ('PE', 'Peru'), ('PH', 'Philippines'), ('PN', 'Pitcairn'), ('PL', 'Poland'), ('PT', 'Portugal'), ('PR', 'Puerto Rico'), ('QA', 'Qatar'), ('RE', 'Reunion'), ('RO', 'Romania'), ('RU', 'Russian Federation'), ('RW', 'Rwanda'), ('BL', 'Saint Barthelemy'), ('SH', 'Saint Helena'), ('KN', 'Saint Kitts and Nevis'), ('LC', 'Saint Lucia'), ('MF', 'Saint Martin'), ('PM', 'Saint Pierre and Miquelon'), ('VC', 'Saint Vincent and the Grenadines'), ('WS', 'Samoa'), ('SM', 'San Marino'), ('ST', 'Sao Tome and Principe'), ('SA', 'Saudi Arabia'), ('SN', 'Senegal'), ('RS', 'Serbia'), ('SC', 'Seychelles'), ('SL', 'Sierra Leone'), ('SG', 'Singapore'), ('SK', 'Slovakia'), ('SI', 'Slovenia'), ('SB', 'Solomon Islands'), ('SO', 'Somalia'), ('ZA', 'South Africa'), ('GS', 'South Georgia and the South Sandwich Islands'), ('ES', 'Spain'), ('LK', 'Sri Lanka'), ('SD', 'Sudan'), ('SR', 'Suriname'), ('SJ', 'Svalbard and Jan Mayen'), ('SZ', 'Swaziland'), ('SE', 'Sweden'), ('CH', 'Switzerland'), ('SY', 'Syrian Arab Republic'), ('TW', 'Taiwan, Province of China'), ('TJ', 'Tajikistan'), ('TZ', 'Tanzania, United Republic of'), ('TH', 'Thailand'), ('TL', 'Timor-Leste'), ('TG', 'Togo'), ('TK', 'Tokelau'), ('TO', 'Tonga'), ('TT', 'Trinidad and Tobago'), ('TN', 'Tunisia'), ('TR', 'Turkey'), ('TM', 'Turkmenistan'), ('TC', 'Turks and Caicos Islands'), ('TV', 'Tuvalu'), ('UG', 'Uganda'), ('UA', 'Ukraine'), ('AE', 'United Arab Emirates'), ('US', 'United States'), ('UM', 'United States Minor Outlying Islands'), ('UY', 'Uruguay'), ('UZ', 'Uzbekistan'), ('VU', 'Vanuatu'), ('VE', 'Venezuela'), ('VN', 'Viet Nam'), ('VG', 'Virgin Islands, British'), ('VI', 'Virgin Islands, U.S.'), ('WF', 'Wallis and Futuna'), ('EH', 'Western Sahara'), ('YE', 'Yemen'), ('ZM', 'Zambia'), ('ZW', 'Zimbabwe')], max_length=3, null=True)), + ('website', models.CharField(blank=True, max_length=255, null=True, verbose_name='Website')), + ('description', models.TextField(blank=True, null=True)), + ('account_name', models.CharField(blank=True, max_length=255, null=True)), + ('opportunity_amount', models.DecimalField(blank=True, decimal_places=2, max_digits=12, null=True, verbose_name='Opportunity Amount')), + ('is_active', models.BooleanField(default=False)), + ('enquiry_type', models.CharField(blank=True, max_length=255, null=True)), + ('created_from_site', models.BooleanField(default=False)), + ('skype_ID', models.CharField(blank=True, max_length=100, null=True)), + ('industry', models.CharField(blank=True, choices=[('ADVERTISING', 'ADVERTISING'), ('AGRICULTURE', 'AGRICULTURE'), ('APPAREL & ACCESSORIES', 'APPAREL & ACCESSORIES'), ('AUTOMOTIVE', 'AUTOMOTIVE'), ('BANKING', 'BANKING'), ('BIOTECHNOLOGY', 'BIOTECHNOLOGY'), ('BUILDING MATERIALS & EQUIPMENT', 'BUILDING MATERIALS & EQUIPMENT'), ('CHEMICAL', 'CHEMICAL'), ('COMPUTER', 'COMPUTER'), ('EDUCATION', 'EDUCATION'), ('ELECTRONICS', 'ELECTRONICS'), ('ENERGY', 'ENERGY'), ('ENTERTAINMENT & LEISURE', 'ENTERTAINMENT & LEISURE'), ('FINANCE', 'FINANCE'), ('FOOD & BEVERAGE', 'FOOD & BEVERAGE'), ('GROCERY', 'GROCERY'), ('HEALTHCARE', 'HEALTHCARE'), ('INSURANCE', 'INSURANCE'), ('LEGAL', 'LEGAL'), ('MANUFACTURING', 'MANUFACTURING'), ('PUBLISHING', 'PUBLISHING'), ('REAL ESTATE', 'REAL ESTATE'), ('SERVICE', 'SERVICE'), ('SOFTWARE', 'SOFTWARE'), ('SPORTS', 'SPORTS'), ('TECHNOLOGY', 'TECHNOLOGY'), ('TELECOMMUNICATIONS', 'TELECOMMUNICATIONS'), ('TELEVISION', 'TELEVISION'), ('TRANSPORTATION', 'TRANSPORTATION'), ('VENTURE CAPITAL', 'VENTURE CAPITAL')], max_length=255, null=True, verbose_name='Industry Type')), + ('organization', models.CharField(max_length=255, null=True, verbose_name='Organization')), + ('probability', models.IntegerField(blank=True, default=0, null=True)), + ('close_date', models.DateField(default=None, null=True)), + ('assigned_to', models.ManyToManyField(related_name='lead_assigned_users', to='common.profile')), + ('company', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='lead_company', to='leads.company')), + ('contacts', models.ManyToManyField(related_name='lead_contacts', to='contacts.contact')), + ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='lead_created_by', to='common.profile')), + ('org', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='lead_org', to='common.org')), + ('tags', models.ManyToManyField(blank=True, to='accounts.tags')), + ('teams', models.ManyToManyField(related_name='lead_teams', to='teams.teams')), + ('updated_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_updated_by', to=settings.AUTH_USER_MODEL, verbose_name='Last Modified By')), + ], + options={ + 'verbose_name': 'Lead', + 'verbose_name_plural': 'Leads', + 'db_table': 'lead', + 'ordering': ('-created_at',), }, ), ] diff --git a/leads/migrations/0002_alter_lead_created_by.py b/leads/migrations/0002_alter_lead_created_by.py new file mode 100644 index 00000000..97a18363 --- /dev/null +++ b/leads/migrations/0002_alter_lead_created_by.py @@ -0,0 +1,21 @@ +# Generated by Django 4.2.1 on 2023-06-29 07:31 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('leads', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='lead', + name='created_by', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_created_by', to=settings.AUTH_USER_MODEL, verbose_name='Created By'), + ), + ] diff --git a/leads/migrations/0002_lead_tags.py b/leads/migrations/0002_lead_tags.py deleted file mode 100644 index 5afeb9df..00000000 --- a/leads/migrations/0002_lead_tags.py +++ /dev/null @@ -1,19 +0,0 @@ -# Generated by Django 2.1.5 on 2019-02-01 13:10 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("accounts", "0003_auto_20190201_1840"), - ("leads", "0001_initial"), - ] - - operations = [ - migrations.AddField( - model_name="lead", - name="tags", - field=models.ManyToManyField(blank=True, to="accounts.Tags"), - ), - ] diff --git a/leads/migrations/0003_auto_20190211_1142.py b/leads/migrations/0003_auto_20190211_1142.py deleted file mode 100644 index 8dfeb420..00000000 --- a/leads/migrations/0003_auto_20190211_1142.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 2.1.5 on 2019-02-11 06:12 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("leads", "0002_lead_tags"), - ] - - operations = [ - migrations.AlterField( - model_name="lead", - name="email", - field=models.EmailField(blank=True, max_length=254, null=True), - ), - ] diff --git a/leads/migrations/0004_auto_20190212_1334.py b/leads/migrations/0004_auto_20190212_1334.py deleted file mode 100644 index 193f6dda..00000000 --- a/leads/migrations/0004_auto_20190212_1334.py +++ /dev/null @@ -1,41 +0,0 @@ -# Generated by Django 2.1.5 on 2019-02-12 08:04 - -import django.db.models.deletion -from django.conf import settings -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("contacts", "0002_auto_20190212_1334"), - ("leads", "0003_auto_20190211_1142"), - ] - - operations = [ - migrations.RemoveField( - model_name="lead", - name="account", - ), - migrations.RemoveField( - model_name="lead", - name="teams", - ), - migrations.AddField( - model_name="lead", - name="contacts", - field=models.ManyToManyField( - related_name="lead_contacts", to="contacts.Contact" - ), - ), - migrations.AlterField( - model_name="lead", - name="created_by", - field=models.ForeignKey( - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="lead_created_by", - to=settings.AUTH_USER_MODEL, - ), - ), - ] diff --git a/leads/migrations/0005_auto_20190212_1708.py b/leads/migrations/0005_auto_20190212_1708.py deleted file mode 100644 index f8665ae0..00000000 --- a/leads/migrations/0005_auto_20190212_1708.py +++ /dev/null @@ -1,309 +0,0 @@ -# Generated by Django 2.1.5 on 2019-02-12 11:38 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("leads", "0004_auto_20190212_1334"), - ] - - operations = [ - migrations.RemoveField( - model_name="lead", - name="address", - ), - migrations.AddField( - model_name="lead", - name="address_line", - field=models.CharField( - blank=True, max_length=255, null=True, verbose_name="Address" - ), - ), - migrations.AddField( - model_name="lead", - name="city", - field=models.CharField( - blank=True, max_length=255, null=True, verbose_name="City" - ), - ), - migrations.AddField( - model_name="lead", - name="country", - field=models.CharField( - blank=True, - choices=[ - ("GB", "United Kingdom"), - ("AF", "Afghanistan"), - ("AX", "Aland Islands"), - ("AL", "Albania"), - ("DZ", "Algeria"), - ("AS", "American Samoa"), - ("AD", "Andorra"), - ("AO", "Angola"), - ("AI", "Anguilla"), - ("AQ", "Antarctica"), - ("AG", "Antigua and Barbuda"), - ("AR", "Argentina"), - ("AM", "Armenia"), - ("AW", "Aruba"), - ("AU", "Australia"), - ("AT", "Austria"), - ("AZ", "Azerbaijan"), - ("BS", "Bahamas"), - ("BH", "Bahrain"), - ("BD", "Bangladesh"), - ("BB", "Barbados"), - ("BY", "Belarus"), - ("BE", "Belgium"), - ("BZ", "Belize"), - ("BJ", "Benin"), - ("BM", "Bermuda"), - ("BT", "Bhutan"), - ("BO", "Bolivia"), - ("BA", "Bosnia and Herzegovina"), - ("BW", "Botswana"), - ("BV", "Bouvet Island"), - ("BR", "Brazil"), - ("IO", "British Indian Ocean Territory"), - ("BN", "Brunei Darussalam"), - ("BG", "Bulgaria"), - ("BF", "Burkina Faso"), - ("BI", "Burundi"), - ("KH", "Cambodia"), - ("CM", "Cameroon"), - ("CA", "Canada"), - ("CV", "Cape Verde"), - ("KY", "Cayman Islands"), - ("CF", "Central African Republic"), - ("TD", "Chad"), - ("CL", "Chile"), - ("CN", "China"), - ("CX", "Christmas Island"), - ("CC", "Cocos (Keeling) Islands"), - ("CO", "Colombia"), - ("KM", "Comoros"), - ("CG", "Congo"), - ("CD", "Congo, The Democratic Republic of the"), - ("CK", "Cook Islands"), - ("CR", "Costa Rica"), - ("CI", "Cote d'Ivoire"), - ("HR", "Croatia"), - ("CU", "Cuba"), - ("CY", "Cyprus"), - ("CZ", "Czech Republic"), - ("DK", "Denmark"), - ("DJ", "Djibouti"), - ("DM", "Dominica"), - ("DO", "Dominican Republic"), - ("EC", "Ecuador"), - ("EG", "Egypt"), - ("SV", "El Salvador"), - ("GQ", "Equatorial Guinea"), - ("ER", "Eritrea"), - ("EE", "Estonia"), - ("ET", "Ethiopia"), - ("FK", "Falkland Islands (Malvinas)"), - ("FO", "Faroe Islands"), - ("FJ", "Fiji"), - ("FI", "Finland"), - ("FR", "France"), - ("GF", "French Guiana"), - ("PF", "French Polynesia"), - ("TF", "French Southern Territories"), - ("GA", "Gabon"), - ("GM", "Gambia"), - ("GE", "Georgia"), - ("DE", "Germany"), - ("GH", "Ghana"), - ("GI", "Gibraltar"), - ("GR", "Greece"), - ("GL", "Greenland"), - ("GD", "Grenada"), - ("GP", "Guadeloupe"), - ("GU", "Guam"), - ("GT", "Guatemala"), - ("GG", "Guernsey"), - ("GN", "Guinea"), - ("GW", "Guinea-Bissau"), - ("GY", "Guyana"), - ("HT", "Haiti"), - ("HM", "Heard Island and McDonald Islands"), - ("VA", "Holy See (Vatican City State)"), - ("HN", "Honduras"), - ("HK", "Hong Kong"), - ("HU", "Hungary"), - ("IS", "Iceland"), - ("IN", "India"), - ("ID", "Indonesia"), - ("IR", "Iran, Islamic Republic of"), - ("IQ", "Iraq"), - ("IE", "Ireland"), - ("IM", "Isle of Man"), - ("IL", "Israel"), - ("IT", "Italy"), - ("JM", "Jamaica"), - ("JP", "Japan"), - ("JE", "Jersey"), - ("JO", "Jordan"), - ("KZ", "Kazakhstan"), - ("KE", "Kenya"), - ("KI", "Kiribati"), - ("KP", "Korea, Democratic People's Republic of"), - ("KR", "Korea, Republic of"), - ("KW", "Kuwait"), - ("KG", "Kyrgyzstan"), - ("LA", "Lao People's Democratic Republic"), - ("LV", "Latvia"), - ("LB", "Lebanon"), - ("LS", "Lesotho"), - ("LR", "Liberia"), - ("LY", "Libyan Arab Jamahiriya"), - ("LI", "Liechtenstein"), - ("LT", "Lithuania"), - ("LU", "Luxembourg"), - ("MO", "Macao"), - ("MK", "Macedonia, The Former Yugoslav Republic of"), - ("MG", "Madagascar"), - ("MW", "Malawi"), - ("MY", "Malaysia"), - ("MV", "Maldives"), - ("ML", "Mali"), - ("MT", "Malta"), - ("MH", "Marshall Islands"), - ("MQ", "Martinique"), - ("MR", "Mauritania"), - ("MU", "Mauritius"), - ("YT", "Mayotte"), - ("MX", "Mexico"), - ("FM", "Micronesia, Federated States of"), - ("MD", "Moldova"), - ("MC", "Monaco"), - ("MN", "Mongolia"), - ("ME", "Montenegro"), - ("MS", "Montserrat"), - ("MA", "Morocco"), - ("MZ", "Mozambique"), - ("MM", "Myanmar"), - ("NA", "Namibia"), - ("NR", "Nauru"), - ("NP", "Nepal"), - ("NL", "Netherlands"), - ("AN", "Netherlands Antilles"), - ("NC", "New Caledonia"), - ("NZ", "New Zealand"), - ("NI", "Nicaragua"), - ("NE", "Niger"), - ("NG", "Nigeria"), - ("NU", "Niue"), - ("NF", "Norfolk Island"), - ("MP", "Northern Mariana Islands"), - ("NO", "Norway"), - ("OM", "Oman"), - ("PK", "Pakistan"), - ("PW", "Palau"), - ("PS", "Palestinian Territory, Occupied"), - ("PA", "Panama"), - ("PG", "Papua New Guinea"), - ("PY", "Paraguay"), - ("PE", "Peru"), - ("PH", "Philippines"), - ("PN", "Pitcairn"), - ("PL", "Poland"), - ("PT", "Portugal"), - ("PR", "Puerto Rico"), - ("QA", "Qatar"), - ("RE", "Reunion"), - ("RO", "Romania"), - ("RU", "Russian Federation"), - ("RW", "Rwanda"), - ("BL", "Saint Barthelemy"), - ("SH", "Saint Helena"), - ("KN", "Saint Kitts and Nevis"), - ("LC", "Saint Lucia"), - ("MF", "Saint Martin"), - ("PM", "Saint Pierre and Miquelon"), - ("VC", "Saint Vincent and the Grenadines"), - ("WS", "Samoa"), - ("SM", "San Marino"), - ("ST", "Sao Tome and Principe"), - ("SA", "Saudi Arabia"), - ("SN", "Senegal"), - ("RS", "Serbia"), - ("SC", "Seychelles"), - ("SL", "Sierra Leone"), - ("SG", "Singapore"), - ("SK", "Slovakia"), - ("SI", "Slovenia"), - ("SB", "Solomon Islands"), - ("SO", "Somalia"), - ("ZA", "South Africa"), - ("GS", "South Georgia and the South Sandwich Islands"), - ("ES", "Spain"), - ("LK", "Sri Lanka"), - ("SD", "Sudan"), - ("SR", "Suriname"), - ("SJ", "Svalbard and Jan Mayen"), - ("SZ", "Swaziland"), - ("SE", "Sweden"), - ("CH", "Switzerland"), - ("SY", "Syrian Arab Republic"), - ("TW", "Taiwan, Province of China"), - ("TJ", "Tajikistan"), - ("TZ", "Tanzania, United Republic of"), - ("TH", "Thailand"), - ("TL", "Timor-Leste"), - ("TG", "Togo"), - ("TK", "Tokelau"), - ("TO", "Tonga"), - ("TT", "Trinidad and Tobago"), - ("TN", "Tunisia"), - ("TR", "Turkey"), - ("TM", "Turkmenistan"), - ("TC", "Turks and Caicos Islands"), - ("TV", "Tuvalu"), - ("UG", "Uganda"), - ("UA", "Ukraine"), - ("AE", "United Arab Emirates"), - ("US", "United States"), - ("UM", "United States Minor Outlying Islands"), - ("UY", "Uruguay"), - ("UZ", "Uzbekistan"), - ("VU", "Vanuatu"), - ("VE", "Venezuela"), - ("VN", "Viet Nam"), - ("VG", "Virgin Islands, British"), - ("VI", "Virgin Islands, U.S."), - ("WF", "Wallis and Futuna"), - ("EH", "Western Sahara"), - ("YE", "Yemen"), - ("ZM", "Zambia"), - ("ZW", "Zimbabwe"), - ], - max_length=3, - null=True, - ), - ), - migrations.AddField( - model_name="lead", - name="postcode", - field=models.CharField( - blank=True, max_length=64, null=True, verbose_name="Post/Zip-code" - ), - ), - migrations.AddField( - model_name="lead", - name="state", - field=models.CharField( - blank=True, max_length=255, null=True, verbose_name="State" - ), - ), - migrations.AddField( - model_name="lead", - name="street", - field=models.CharField( - blank=True, max_length=55, null=True, verbose_name="Street" - ), - ), - ] diff --git a/leads/migrations/0006_auto_20190218_1217.py b/leads/migrations/0006_auto_20190218_1217.py deleted file mode 100644 index 4f04774d..00000000 --- a/leads/migrations/0006_auto_20190218_1217.py +++ /dev/null @@ -1,30 +0,0 @@ -# Generated by Django 2.1.7 on 2019-02-18 06:47 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("leads", "0005_auto_20190212_1708"), - ] - - operations = [ - migrations.AlterField( - model_name="lead", - name="status", - field=models.CharField( - blank=True, - choices=[ - ("assigned", "Assigned"), - ("in process", "In Process"), - ("converted", "Converted"), - ("recycled", "Recycled"), - ("dead", "Closed"), - ], - max_length=255, - null=True, - verbose_name="Status of Lead", - ), - ), - ] diff --git a/leads/migrations/0007_auto_20190306_1226.py b/leads/migrations/0007_auto_20190306_1226.py deleted file mode 100644 index 49bcac06..00000000 --- a/leads/migrations/0007_auto_20190306_1226.py +++ /dev/null @@ -1,30 +0,0 @@ -# Generated by Django 2.1.7 on 2019-03-06 06:56 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("leads", "0006_auto_20190218_1217"), - ] - - operations = [ - migrations.AlterField( - model_name="lead", - name="status", - field=models.CharField( - blank=True, - choices=[ - ("assigned", "Assigned"), - ("in process", "In Process"), - ("converted", "Converted"), - ("recycled", "Recycled"), - ("closed", "Closed"), - ], - max_length=255, - null=True, - verbose_name="Status of Lead", - ), - ), - ] diff --git a/leads/migrations/0008_auto_20190315_1503.py b/leads/migrations/0008_auto_20190315_1503.py deleted file mode 100644 index 71185579..00000000 --- a/leads/migrations/0008_auto_20190315_1503.py +++ /dev/null @@ -1,33 +0,0 @@ -# Generated by Django 2.1.7 on 2019-03-15 09:33 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("leads", "0007_auto_20190306_1226"), - ] - - operations = [ - migrations.AlterField( - model_name="lead", - name="first_name", - field=models.CharField( - max_length=255, null=True, verbose_name="First name" - ), - ), - migrations.AlterField( - model_name="lead", - name="last_name", - field=models.CharField(max_length=255, null=True, verbose_name="Last name"), - ), - migrations.AlterField( - model_name="lead", - name="title", - field=models.CharField( - default="title", max_length=64, verbose_name="Title" - ), - preserve_default=False, - ), - ] diff --git a/leads/migrations/0009_lead_created_from_site.py b/leads/migrations/0009_lead_created_from_site.py deleted file mode 100644 index 50f42473..00000000 --- a/leads/migrations/0009_lead_created_from_site.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 2.1.7 on 2019-05-29 06:51 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("leads", "0008_auto_20190315_1503"), - ] - - operations = [ - migrations.AddField( - model_name="lead", - name="created_from_site", - field=models.BooleanField(default=False), - ), - ] diff --git a/leads/migrations/0010_lead_teams.py b/leads/migrations/0010_lead_teams.py deleted file mode 100644 index 8c6d1d1d..00000000 --- a/leads/migrations/0010_lead_teams.py +++ /dev/null @@ -1,19 +0,0 @@ -# Generated by Django 2.2.4 on 2019-09-17 05:46 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("teams", "0003_auto_20190909_1621"), - ("leads", "0009_lead_created_from_site"), - ] - - operations = [ - migrations.AddField( - model_name="lead", - name="teams", - field=models.ManyToManyField(related_name="lead_teams", to="teams.Teams"), - ), - ] diff --git a/leads/migrations/0011_auto_20200401_0937.py b/leads/migrations/0011_auto_20200401_0937.py deleted file mode 100644 index 0f55c1b7..00000000 --- a/leads/migrations/0011_auto_20200401_0937.py +++ /dev/null @@ -1,20 +0,0 @@ -# Generated by Django 2.2.10 on 2020-04-01 04:07 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("leads", "0010_lead_teams"), - ] - - operations = [ - migrations.AlterField( - model_name="lead", - name="source", - field=models.CharField( - blank=True, max_length=255, null=True, verbose_name="Source of Lead" - ), - ), - ] diff --git a/leads/migrations/0012_lead_company.py b/leads/migrations/0012_lead_company.py deleted file mode 100644 index a6a6d0ee..00000000 --- a/leads/migrations/0012_lead_company.py +++ /dev/null @@ -1,25 +0,0 @@ -# Generated by Django 2.2.10 on 2020-04-27 10:41 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0020_auto_20200409_1653"), - ("leads", "0011_auto_20200401_0937"), - ] - - operations = [ - migrations.AddField( - model_name="lead", - name="company", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - to="common.Company", - ), - ), - ] diff --git a/leads/migrations/0013_remove_lead_company.py b/leads/migrations/0013_remove_lead_company.py deleted file mode 100644 index 950a67a5..00000000 --- a/leads/migrations/0013_remove_lead_company.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 3.1.7 on 2021-03-24 05:43 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ("leads", "0012_lead_company"), - ] - - operations = [ - migrations.RemoveField( - model_name="lead", - name="company", - ), - ] diff --git a/leads/migrations/0014_auto_20210324_1208.py b/leads/migrations/0014_auto_20210324_1208.py deleted file mode 100644 index 97af4c71..00000000 --- a/leads/migrations/0014_auto_20210324_1208.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 3.1.7 on 2021-03-24 06:38 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ("leads", "0013_remove_lead_company"), - ] - - operations = [ - migrations.RenameField( - model_name="lead", - old_name="enquery_type", - new_name="enquiry_type", - ), - ] diff --git a/leads/migrations/0015_auto_20210913_1918.py b/leads/migrations/0015_auto_20210913_1918.py deleted file mode 100644 index 03a71386..00000000 --- a/leads/migrations/0015_auto_20210913_1918.py +++ /dev/null @@ -1,42 +0,0 @@ -# Generated by Django 3.2 on 2021-09-13 13:48 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0034_auto_20210913_1918"), - ("leads", "0014_auto_20210324_1208"), - ] - - operations = [ - migrations.AddField( - model_name="lead", - name="company", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - to="common.company", - ), - ), - migrations.AlterField( - model_name="lead", - name="assigned_to", - field=models.ManyToManyField( - related_name="lead_assigned_users", to="common.Profile" - ), - ), - migrations.AlterField( - model_name="lead", - name="created_by", - field=models.ForeignKey( - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="lead_created_by", - to="common.profile", - ), - ), - ] diff --git a/leads/migrations/0016_rename_company_lead_org.py b/leads/migrations/0016_rename_company_lead_org.py deleted file mode 100644 index 818569d0..00000000 --- a/leads/migrations/0016_rename_company_lead_org.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 3.2 on 2021-09-22 12:31 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ("leads", "0015_auto_20210913_1918"), - ] - - operations = [ - migrations.RenameField( - model_name="lead", - old_name="company", - new_name="org", - ), - ] diff --git a/leads/migrations/0017_alter_lead_org.py b/leads/migrations/0017_alter_lead_org.py deleted file mode 100644 index d6fc1a3f..00000000 --- a/leads/migrations/0017_alter_lead_org.py +++ /dev/null @@ -1,26 +0,0 @@ -# Generated by Django 3.2.7 on 2021-10-06 07:21 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0037_alter_profile_org"), - ("leads", "0016_rename_company_lead_org"), - ] - - operations = [ - migrations.AlterField( - model_name="lead", - name="org", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="lead_org", - to="common.org", - ), - ), - ] diff --git a/leads/migrations/0018_auto_20211022_1731.py b/leads/migrations/0018_auto_20211022_1731.py deleted file mode 100644 index f6dbbef6..00000000 --- a/leads/migrations/0018_auto_20211022_1731.py +++ /dev/null @@ -1,119 +0,0 @@ -# Generated by Django 3.2.8 on 2021-10-22 12:01 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0037_alter_profile_org"), - ("leads", "0017_alter_lead_org"), - ] - - operations = [ - migrations.AddField( - model_name="lead", - name="industry", - field=models.CharField( - blank=True, - choices=[ - ("ADVERTISING", "ADVERTISING"), - ("AGRICULTURE", "AGRICULTURE"), - ("APPAREL & ACCESSORIES", "APPAREL & ACCESSORIES"), - ("AUTOMOTIVE", "AUTOMOTIVE"), - ("BANKING", "BANKING"), - ("BIOTECHNOLOGY", "BIOTECHNOLOGY"), - ( - "BUILDING MATERIALS & EQUIPMENT", - "BUILDING MATERIALS & EQUIPMENT", - ), - ("CHEMICAL", "CHEMICAL"), - ("COMPUTER", "COMPUTER"), - ("EDUCATION", "EDUCATION"), - ("ELECTRONICS", "ELECTRONICS"), - ("ENERGY", "ENERGY"), - ("ENTERTAINMENT & LEISURE", "ENTERTAINMENT & LEISURE"), - ("FINANCE", "FINANCE"), - ("FOOD & BEVERAGE", "FOOD & BEVERAGE"), - ("GROCERY", "GROCERY"), - ("HEALTHCARE", "HEALTHCARE"), - ("INSURANCE", "INSURANCE"), - ("LEGAL", "LEGAL"), - ("MANUFACTURING", "MANUFACTURING"), - ("PUBLISHING", "PUBLISHING"), - ("REAL ESTATE", "REAL ESTATE"), - ("SERVICE", "SERVICE"), - ("SOFTWARE", "SOFTWARE"), - ("SPORTS", "SPORTS"), - ("TECHNOLOGY", "TECHNOLOGY"), - ("TELECOMMUNICATIONS", "TELECOMMUNICATIONS"), - ("TELEVISION", "TELEVISION"), - ("TRANSPORTATION", "TRANSPORTATION"), - ("VENTURE CAPITAL", "VENTURE CAPITAL"), - ], - max_length=255, - null=True, - verbose_name="Industry Type", - ), - ), - migrations.AddField( - model_name="lead", - name="skype_ID", - field=models.CharField(blank=True, max_length=100, null=True), - ), - migrations.AlterField( - model_name="lead", - name="source", - field=models.CharField( - blank=True, - choices=[ - ("call", "Call"), - ("email", "Email"), - ("existing customer", "Existing Customer"), - ("partner", "Partner"), - ("public relations", "Public Relations"), - ("compaign", "Campaign"), - ("other", "Other"), - ], - max_length=255, - null=True, - verbose_name="Source of Lead", - ), - ), - migrations.CreateModel( - name="Organization", - fields=[ - ( - "id", - models.AutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("name", models.CharField(blank=True, max_length=100, null=True)), - ( - "org", - models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - to="common.org", - ), - ), - ], - ), - migrations.AddField( - model_name="lead", - name="organization", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="lead_company", - to="leads.organization", - ), - ), - ] diff --git a/leads/migrations/0019_auto_20211022_1732.py b/leads/migrations/0019_auto_20211022_1732.py deleted file mode 100644 index 9d89cede..00000000 --- a/leads/migrations/0019_auto_20211022_1732.py +++ /dev/null @@ -1,23 +0,0 @@ -# Generated by Django 3.2.8 on 2021-10-22 12:02 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0037_alter_profile_org"), - ("leads", "0018_auto_20211022_1731"), - ] - - operations = [ - migrations.RenameModel( - old_name="Organization", - new_name="Company", - ), - migrations.RenameField( - model_name="lead", - old_name="organization", - new_name="company", - ), - ] diff --git a/leads/migrations/0020_auto_20220714_1915.py b/leads/migrations/0020_auto_20220714_1915.py deleted file mode 100644 index b31b70b1..00000000 --- a/leads/migrations/0020_auto_20220714_1915.py +++ /dev/null @@ -1,30 +0,0 @@ -# Generated by Django 3.2.11 on 2022-07-14 13:45 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("leads", "0019_auto_20211022_1732"), - ] - - operations = [ - migrations.AddField( - model_name="lead", - name="close_date", - field=models.DateField(default=None, null=True), - ), - migrations.AddField( - model_name="lead", - name="organization", - field=models.CharField( - max_length=255, null=True, verbose_name="Organization" - ), - ), - migrations.AddField( - model_name="lead", - name="probability", - field=models.IntegerField(blank=True, default=0, null=True), - ), - ] diff --git a/leads/models.py b/leads/models.py index 5a8867b1..7294d5c4 100644 --- a/leads/models.py +++ b/leads/models.py @@ -6,18 +6,32 @@ from phonenumber_field.modelfields import PhoneNumberField from accounts.models import Tags from common.models import Org, Profile -from common.utils import (COUNTRIES, INDCHOICES, LEAD_SOURCE, LEAD_STATUS, - return_complete_address) +from common.base import BaseModel +from common.utils import ( + COUNTRIES, + INDCHOICES, + LEAD_SOURCE, + LEAD_STATUS, + return_complete_address, +) from contacts.models import Contact from teams.models import Teams -class Company(models.Model): +class Company(BaseModel): name = models.CharField(max_length=100, blank=True, null=True) org = models.ForeignKey(Org, on_delete=models.SET_NULL, null=True, blank=True) + class Meta: + verbose_name = "Company" + verbose_name_plural = "Companies" + db_table = "company" + ordering = ("-created_at",) -class Lead(models.Model): + def __str__(self): + return f"{self.name}" + +class Lead(BaseModel): title = models.CharField( pgettext_lazy("Treatment Pronouns for the customer", "Title"), max_length=64 ) @@ -46,10 +60,6 @@ class Lead(models.Model): opportunity_amount = models.DecimalField( _("Opportunity Amount"), decimal_places=2, max_digits=12, blank=True, null=True ) - created_by = models.ForeignKey( - Profile, related_name="lead_created_by", on_delete=models.SET_NULL, null=True - ) - created_on = models.DateTimeField(_("Created on"), auto_now_add=True) is_active = models.BooleanField(default=False) enquiry_type = models.CharField(max_length=255, blank=True, null=True) tags = models.ManyToManyField(Tags, blank=True) @@ -75,10 +85,13 @@ class Lead(models.Model): close_date = models.DateField(default=None, null=True) class Meta: - ordering = ["-created_on"] + verbose_name = "Lead" + verbose_name_plural = "Leads" + db_table = "lead" + ordering = ("-created_at",) def __str__(self): - return self.title + return f"{self.title}" def get_complete_address(self): return return_complete_address(self) @@ -91,7 +104,7 @@ class Lead(models.Model): @property def created_on_arrow(self): - return arrow.get(self.created_on).humanize() + return arrow.get(self.created_at).humanize() @property def get_team_users(self): diff --git a/leads/serializer.py b/leads/serializer.py index 6eec4aea..fd766ac5 100644 --- a/leads/serializer.py +++ b/leads/serializer.py @@ -1,8 +1,13 @@ from rest_framework import serializers from accounts.models import Account, Tags -from common.serializer import (AttachmentsSerializer, LeadCommentSerializer, - OrganizationSerializer, ProfileSerializer) +from common.serializer import ( + AttachmentsSerializer, + LeadCommentSerializer, + OrganizationSerializer, + ProfileSerializer, + UserSerializer, +) from contacts.serializer import ContactSerializer from leads.models import Company, Lead from teams.serializer import TeamsSerializer @@ -14,16 +19,21 @@ class TagsSerializer(serializers.ModelSerializer): fields = ("id", "name", "slug") +class CompanySwaggerSerializer(serializers.ModelSerializer): + class Meta: + model = Company + fields = ("name",) + class CompanySerializer(serializers.ModelSerializer): class Meta: model = Company - fields = ("id", "name") + fields = ("id", "name", "org") class LeadSerializer(serializers.ModelSerializer): contacts = ContactSerializer(read_only=True, many=True) assigned_to = ProfileSerializer(read_only=True, many=True) - created_by = ProfileSerializer() + created_by = UserSerializer() country = serializers.SerializerMethodField() tags = TagsSerializer(read_only=True, many=True) lead_attachment = AttachmentsSerializer(read_only=True, many=True) @@ -60,7 +70,7 @@ class LeadSerializer(serializers.ModelSerializer): "account_name", "opportunity_amount", "created_by", - "created_on", + "created_at", "is_active", "enquiry_type", "tags", @@ -81,13 +91,13 @@ class LeadCreateSerializer(serializers.ModelSerializer): def __init__(self, *args, **kwargs): request_obj = kwargs.pop("request_obj", None) super().__init__(*args, **kwargs) - if self.initial_data.get("status") == "converted": + if self.initial_data and self.initial_data.get("status") == "converted": self.fields["account_name"].required = True self.fields["email"].required = True self.fields["first_name"].required = False self.fields["last_name"].required = False self.fields["title"].required = True - self.org = request_obj.org + self.org = request_obj.profile.org if self.instance: if self.instance.created_from_site: @@ -155,3 +165,33 @@ class LeadCreateSerializer(serializers.ModelSerializer): "close_date", # "lead_attachment", ) + +class LeadCreateSwaggerSerializer(serializers.ModelSerializer): + class Meta: + model = Lead + fields = ["title","first_name","last_name","account_name","phone","email","lead_attachment","opportunity_amount","website", + "description","teams","assigned_to","contacts","status","source","address_line","street","city","state","postcode", + "country","tags","company","probability","industry","skype_ID"] + + +class CreateLeadFromSiteSwaggerSerializer(serializers.Serializer): + apikey=serializers.CharField() + title=serializers.CharField() + first_name=serializers.CharField() + last_name=serializers.CharField() + phone=serializers.CharField() + email=serializers.CharField() + source=serializers.CharField() + description=serializers.CharField() + + +class LeadDetailEditSwaggerSerializer(serializers.Serializer): + comment = serializers.CharField() + lead_attachment = serializers.FileField() + +class LeadCommentEditSwaggerSerializer(serializers.Serializer): + comment = serializers.CharField() + +class LeadUploadSwaggerSerializer(serializers.Serializer): + leads_file = serializers.FileField() + diff --git a/leads/swagger_params.py b/leads/swagger_params.py deleted file mode 100644 index 3778366e..00000000 --- a/leads/swagger_params.py +++ /dev/null @@ -1,102 +0,0 @@ -from drf_yasg import openapi - -organization_params_in_header = openapi.Parameter( - "org", openapi.IN_HEADER, required=True, type=openapi.TYPE_INTEGER -) - -organization_params = [ - organization_params_in_header, -] - -lead_list_get_params = [ - organization_params_in_header, - openapi.Parameter("title", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("source", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("assigned_to", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("status", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("tags", openapi.IN_QUERY, type=openapi.TYPE_STRING), -] - -lead_detail_get_params = [ - organization_params_in_header, - openapi.Parameter( - "lead_attachment", - openapi.IN_QUERY, - type=openapi.TYPE_FILE, - ), - openapi.Parameter("comment", openapi.IN_QUERY, type=openapi.TYPE_STRING), -] - -lead_create_post_params = [ - organization_params_in_header, - openapi.Parameter( - "title", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), - openapi.Parameter( - "first_name", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), - openapi.Parameter("last_name", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("account_name", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("phone", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("email", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter( - "lead_attachment", - openapi.IN_QUERY, - type=openapi.TYPE_FILE, - ), - openapi.Parameter( - "opportunity_amount", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), - openapi.Parameter("website", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("description", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("teams", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("assigned_to", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("contacts", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("status", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("source", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter( - "address_line", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), - openapi.Parameter("street", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("city", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("state", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("postcode", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("country", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("tags", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("company", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("industry", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("skype_ID", openapi.IN_QUERY, type=openapi.TYPE_STRING), -] - -lead_upload_post_params = [ - organization_params_in_header, - openapi.Parameter( - "leads_file", - openapi.IN_QUERY, - type=openapi.TYPE_FILE, - ), -] - -lead_comment_edit_params = [ - organization_params_in_header, - openapi.Parameter("comment", openapi.IN_QUERY, type=openapi.TYPE_STRING), -] - -create_lead_from_site = [ - openapi.Parameter( - "apikey", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), - openapi.Parameter( - "title", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), - openapi.Parameter("first_name", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("last_name", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("phone", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter( - "email", openapi.IN_QUERY, type=openapi.TYPE_STRING, required=True - ), - openapi.Parameter( - "source", openapi.IN_QUERY, type=openapi.TYPE_STRING, required=True - ), - openapi.Parameter("description", openapi.IN_QUERY, type=openapi.TYPE_STRING), -] diff --git a/leads/swagger_params1.py b/leads/swagger_params1.py new file mode 100644 index 00000000..4f3dbf23 --- /dev/null +++ b/leads/swagger_params1.py @@ -0,0 +1,24 @@ +from drf_spectacular.types import OpenApiTypes +from drf_spectacular.utils import OpenApiExample, OpenApiParameter, extend_schema + +organization_params_in_header = organization_params_in_header = OpenApiParameter( + "org", OpenApiTypes.STR, OpenApiParameter.HEADER +) + +organization_params = [ + organization_params_in_header, +] + +lead_list_get_params = [ + organization_params_in_header, + OpenApiParameter("title", OpenApiTypes.STR, OpenApiParameter.QUERY), + OpenApiParameter("source", OpenApiTypes.STR, OpenApiParameter.QUERY), + OpenApiParameter("assigned_to", OpenApiTypes.STR, OpenApiParameter.QUERY), + OpenApiParameter( + "status", + OpenApiTypes.STR, + OpenApiParameter.QUERY, + enum=["assigned", "in process", "converted", "recycled", "closed"], + ), + OpenApiParameter("tags", OpenApiTypes.STR, OpenApiParameter.QUERY), +] diff --git a/leads/tests_celery_tasks.py b/leads/tests_celery_tasks.py index f657209b..ade0e3aa 100644 --- a/leads/tests_celery_tasks.py +++ b/leads/tests_celery_tasks.py @@ -1,9 +1,12 @@ from django.test import TestCase from django.test.utils import override_settings -from leads.tasks import (create_lead_from_file, send_email, - send_email_to_assigned_user, - send_lead_assigned_emails) +from leads.tasks import ( + create_lead_from_file, + send_email, + send_email_to_assigned_user, + send_lead_assigned_emails, +) from leads.tests import TestLeadModel diff --git a/leads/urls.py b/leads/urls.py index a5552675..55d27049 100644 --- a/leads/urls.py +++ b/leads/urls.py @@ -1,6 +1,7 @@ from django.urls import path from leads import views +from .import views app_name = "api_leads" @@ -11,8 +12,10 @@ urlpatterns = [ name="create_lead_from_site", ), path("", views.LeadListView.as_view()), - path("/", views.LeadDetailView.as_view()), + path("/", views.LeadDetailView.as_view()), path("upload/", views.LeadUploadView.as_view()), - path("comment//", views.LeadCommentView.as_view()), - path("attachment//", views.LeadAttachmentView.as_view()), + path("comment//", views.LeadCommentView.as_view()), + path("attachment//", views.LeadAttachmentView.as_view()), + path("companies",views.CompaniesView.as_view()), + path('company/', views.CompanyDetail.as_view()), ] diff --git a/leads/views.py b/leads/views.py index 3636fe8a..228c2e8c 100644 --- a/leads/views.py +++ b/leads/views.py @@ -2,7 +2,7 @@ import json from django.db.models import Q from django.shortcuts import get_object_or_404 -from drf_yasg.utils import swagger_auto_schema +from drf_spectacular.utils import OpenApiExample, OpenApiParameter, extend_schema from rest_framework import status from rest_framework.pagination import LimitOffsetPagination from rest_framework.permissions import IsAuthenticated @@ -11,34 +11,53 @@ from rest_framework.views import APIView from accounts.models import Account, Tags from common.models import APISettings, Attachments, Comment, Profile + # from common.custom_auth import JSONWebTokenAuthentication -from common.serializer import (AttachmentsSerializer, CommentSerializer, - LeadCommentSerializer, ProfileSerializer) +from common.serializer import ( + AttachmentsSerializer, + CommentSerializer, + LeadCommentSerializer, + ProfileSerializer, +) +from .forms import LeadListForm +from .models import Company,Lead from common.utils import COUNTRIES, INDCHOICES, LEAD_SOURCE, LEAD_STATUS from contacts.models import Contact -from leads import swagger_params +from leads import swagger_params1 from leads.forms import LeadListForm from leads.models import Company, Lead -from leads.serializer import (CompanySerializer, LeadCreateSerializer, - LeadSerializer, TagsSerializer) -from leads.tasks import (create_lead_from_file, send_email_to_assigned_user, - send_lead_assigned_emails) +from leads.serializer import ( + CompanySerializer, + CompanySwaggerSerializer, + LeadCreateSerializer, + LeadSerializer, + TagsSerializer, + LeadCreateSwaggerSerializer, + LeadDetailEditSwaggerSerializer, + LeadCommentEditSwaggerSerializer, + CreateLeadFromSiteSwaggerSerializer, + LeadUploadSwaggerSerializer +) +from leads.tasks import ( + create_lead_from_file, + send_email_to_assigned_user, + send_lead_assigned_emails, +) from teams.models import Teams from teams.serializer import TeamsSerializer class LeadListView(APIView, LimitOffsetPagination): model = Lead - # authentication_classes = (JSONWebTokenAuthentication,) permission_classes = (IsAuthenticated,) def get_context_data(self, **kwargs): - params = request.post_data + params = self.request.query_params queryset = ( - self.model.objects.filter(org=self.request.org) + self.model.objects.filter(org=self.request.profile.org) .exclude(status="converted") .select_related("created_by") - .prefetch_related( + .prefetch_related( "tags", "assigned_to", ) @@ -46,7 +65,7 @@ class LeadListView(APIView, LimitOffsetPagination): if self.request.profile.role != "ADMIN" and not self.request.user.is_superuser: queryset = queryset.filter( Q(assigned_to__in=[self.request.profile]) - | Q(created_by=self.request.profile) + | Q(created_by=self.request.profile.user) ) if params: @@ -109,7 +128,7 @@ class LeadListView(APIView, LimitOffsetPagination): "close_leads": close_leads, "offset": offset, } - contacts = Contact.objects.filter(org=self.request.org).values( + contacts = Contact.objects.filter(org=self.request.profile.org).values( "id", "first_name" ) @@ -117,11 +136,11 @@ class LeadListView(APIView, LimitOffsetPagination): context["status"] = LEAD_STATUS context["source"] = LEAD_SOURCE context["companies"] = CompanySerializer( - Company.objects.filter(org=self.request.org), many=True + Company.objects.filter(org=self.request.profile.org), many=True ).data context["tags"] = TagsSerializer(Tags.objects.all(), many=True).data - users = Profile.objects.filter(is_active=True, org=self.request.org).values( + users = Profile.objects.filter(is_active=True, org=self.request.profile.org).values( "id", "user__email" ) context["users"] = users @@ -129,23 +148,24 @@ class LeadListView(APIView, LimitOffsetPagination): context["industries"] = INDCHOICES return context - @swagger_auto_schema( - tags=["Leads"], manual_parameters=swagger_params.lead_list_get_params - ) + @extend_schema(tags=["Leads"], parameters=swagger_params1.lead_list_get_params) def get(self, request, *args, **kwargs): context = self.get_context_data(**kwargs) return Response(context) - @swagger_auto_schema( - tags=["Leads"], manual_parameters=swagger_params.lead_create_post_params + @extend_schema( + tags=["Leads"],description="Leads Create", parameters=swagger_params1.organization_params,request=LeadCreateSwaggerSerializer ) def post(self, request, *args, **kwargs): - params = request.post_data - serializer = LeadCreateSerializer(data=params, request_obj=request) + + print('test') + data = request.data + serializer = LeadCreateSerializer(data=data, request_obj=request) if serializer.is_valid(): - lead_obj = serializer.save(created_by=request.profile, org=request.org) - if params.get("tags"): - tags = json.loads(params.get("tags")) + lead_obj = serializer.save(created_by=request.profile.user + , org=request.profile.org) + if data.get("tags",None): + tags = json.loads(data.get("tags")) for t in tags: tag = Tags.objects.filter(slug=t.lower()) if tag.exists(): @@ -154,9 +174,9 @@ class LeadListView(APIView, LimitOffsetPagination): tag = Tags.objects.create(name=t) lead_obj.tags.add(tag) - if params.get("contacts"): + if data.get("contacts",None): obj_contact = Contact.objects.filter( - id__in=json.loads(params.get("contacts")), org=request.org + id__in=json.loads(data.get("contacts")), org=request.profile.org ) lead_obj.contacts.add(*obj_contact) @@ -168,33 +188,33 @@ class LeadListView(APIView, LimitOffsetPagination): if request.FILES.get("lead_attachment"): attachment = Attachments() - attachment.created_by = request.profile + attachment.created_by = request.profile.user attachment.file_name = request.FILES.get("lead_attachment").name attachment.lead = lead_obj attachment.attachment = request.FILES.get("lead_attachment") attachment.save() - if params.get("teams"): - teams_list = json.loads(params.get("teams")) - teams = Teams.objects.filter(id__in=teams_list, org=request.org) + if data.get("teams",None): + teams_list = json.loads(data.get("teams")) + teams = Teams.objects.filter(id__in=teams_list, org=request.profile.org) lead_obj.teams.add(*teams) - if params.get("assigned_to"): - assinged_to_list = json.loads(params.get("assigned_to")) + if data.get("assigned_to",None): + assinged_to_list = json.loads(data.get("assigned_to")) profiles = Profile.objects.filter( - id__in=assinged_to_list, org=request.org + id__in=assinged_to_list, org=request.profile.org ) lead_obj.assigned_to.add(*profiles) - if params.get("status") == "converted": + if data.get("status") == "converted": account_object = Account.objects.create( - created_by=request.profile, + created_by=request.profile.user, name=lead_obj.account_name, email=lead_obj.email, phone=lead_obj.phone, - description=params.get("description"), - website=params.get("website"), - org=request.org, + description=data.get("description"), + website=data.get("website"), + org=request.profile.org, ) account_object.billing_address_line = lead_obj.address_line @@ -214,8 +234,8 @@ class LeadListView(APIView, LimitOffsetPagination): for tag in lead_obj.tags.all(): account_object.tags.add(tag) - if params.get("assigned_to"): - assigned_to_list = json.loads(params.getlist("assigned_to")) + if data.get("assigned_to",None): + assigned_to_list = json.loads(data.getlist("assigned_to")) recipients = assigned_to_list send_email_to_assigned_user.delay( recipients, @@ -247,13 +267,13 @@ class LeadDetailView(APIView): return get_object_or_404(Lead, id=pk) def get_context_data(self, **kwargs): - params = request.post_data + params = self.request.query_params context = {} user_assgn_list = [ assigned_to.id for assigned_to in self.lead_obj.assigned_to.all() ] - if self.request.profile == self.lead_obj.created_by: - user_assgn_list.append(self.request.profile.id) + if self.request.profile.user == self.lead_obj.created_by: + user_assgn_list.append(self.request.profile.user) if self.request.profile.role != "ADMIN" and not self.request.user.is_superuser: if self.request.profile.id not in user_assgn_list: return Response( @@ -275,22 +295,22 @@ class LeadDetailView(APIView): if self.request.user.is_superuser or self.request.profile.role == "ADMIN": users_mention = list( - Profile.objects.filter(is_active=True, org=self.request.org).values( - "user__username" + Profile.objects.filter(is_active=True, org=self.request.profile.org).values( + "user__email" ) ) - elif self.request.profile != self.lead_obj.created_by: + elif self.request.profile.user != self.lead_obj.created_by: users_mention = [{"username": self.lead_obj.created_by.username}] else: users_mention = list( - self.lead_obj.assigned_to.all().values("user__username") + self.lead_obj.assigned_to.all().values("user__email") ) if self.request.profile.role == "ADMIN" or self.request.user.is_superuser: users = Profile.objects.filter( - is_active=True, org=self.request.org + is_active=True, org=self.request.profile.org ).order_by("user__email") else: - users = Profile.objects.filter(role="ADMIN", org=self.request.org).order_by( + users = Profile.objects.filter(role="ADMIN", org=self.request.profile.org).order_by( "user__email" ) user_assgn_list = [ @@ -298,7 +318,7 @@ class LeadDetailView(APIView): for assigned_to in self.lead_obj.get_assigned_users_not_in_teams ] - if self.request.profile == self.lead_obj.created_by: + if self.request.profile.user == self.lead_obj.created_by: user_assgn_list.append(self.request.profile.id) if self.request.profile.role != "ADMIN" and not self.request.user.is_superuser: if self.request.profile.id not in user_assgn_list: @@ -329,35 +349,32 @@ class LeadDetailView(APIView): context["source"] = LEAD_SOURCE context["status"] = LEAD_STATUS context["teams"] = TeamsSerializer( - Teams.objects.filter(org=self.request.org), many=True + Teams.objects.filter(org=self.request.profile.org), many=True ).data context["countries"] = COUNTRIES return context - @swagger_auto_schema( - tags=["Leads"], manual_parameters=swagger_params.organization_params - ) + @extend_schema(tags=["Leads"],parameters=swagger_params1.organization_params,description="Lead Detail") def get(self, request, pk, **kwargs): self.lead_obj = self.get_object(pk) context = self.get_context_data(**kwargs) return Response(context) - @swagger_auto_schema( - tags=["Leads"], manual_parameters=swagger_params.lead_detail_get_params - ) + @extend_schema(tags=["Leads"], parameters=swagger_params1.organization_params,request=LeadDetailEditSwaggerSerializer) def post(self, request, pk, **kwargs): - params = request.post_data + params = request.data + context = {} self.lead_obj = Lead.objects.get(pk=pk) - if self.lead_obj.org != request.org: + if self.lead_obj.org != request.profile.org: return Response( {"error": True, "errors": "User company doesnot match with header...."}, status=status.HTTP_403_FORBIDDEN, ) if self.request.profile.role != "ADMIN" and not self.request.user.is_superuser: if not ( - (self.request.profile == self.lead_obj.created_by) + (self.request.profile.user == self.lead_obj.created_by) or (self.request.profile in self.lead_obj.assigned_to.all()) ): return Response( @@ -377,7 +394,8 @@ class LeadDetailView(APIView): if self.request.FILES.get("lead_attachment"): attachment = Attachments() - attachment.created_by = self.request.profile + attachment.created_by = self.request.profile.user + attachment.file_name = self.request.FILES.get("lead_attachment").name attachment.lead = self.lead_obj attachment.attachment = self.request.FILES.get("lead_attachment") @@ -396,13 +414,11 @@ class LeadDetailView(APIView): ) return Response(context) - @swagger_auto_schema( - tags=["Leads"], manual_parameters=swagger_params.lead_create_post_params - ) + @extend_schema(tags=["Leads"], parameters=swagger_params1.organization_params,request=LeadCreateSwaggerSerializer) def put(self, request, pk, **kwargs): - params = request.post_data + params = request.data self.lead_obj = self.get_object(pk) - if self.lead_obj.org != request.org: + if self.lead_obj.org != request.profile.org: return Response( { "error": True, @@ -444,7 +460,7 @@ class LeadDetailView(APIView): ) if request.FILES.get("lead_attachment"): attachment = Attachments() - attachment.created_by = request.profile + attachment.created_by = request.profile.user attachment.file_name = request.FILES.get("lead_attachment").name attachment.lead = lead_obj attachment.attachment = request.FILES.get("lead_attachment") @@ -453,34 +469,34 @@ class LeadDetailView(APIView): lead_obj.contacts.clear() if params.get("contacts"): obj_contact = Contact.objects.filter( - id=params.get("contacts"), org=request.org + id=params.get("contacts"), org=request.profile.org ) lead_obj.contacts.add(obj_contact) lead_obj.teams.clear() if params.get("teams"): teams_list = json.loads(params.get("teams")) - teams = Teams.objects.filter(id__in=teams_list, org=request.org) + teams = Teams.objects.filter(id__in=teams_list, org=request.profile.org) lead_obj.teams.add(*teams) lead_obj.assigned_to.clear() if params.get("assigned_to"): assinged_to_list = json.loads(params.get("assigned_to")) profiles = Profile.objects.filter( - id__in=assinged_to_list, org=request.org + id__in=assinged_to_list, org=request.profile.org ) lead_obj.assigned_to.add(*profiles) if params.get("status") == "converted": account_object = Account.objects.create( - created_by=request.profile, + created_by=request.profile.user, name=lead_obj.account_name, email=lead_obj.email, phone=lead_obj.phone, description=params.get("description"), website=params.get("website"), lead=lead_obj, - org=request.org, + org=request.profile.org, ) account_object.billing_address_line = lead_obj.address_line account_object.billing_street = lead_obj.street @@ -527,16 +543,15 @@ class LeadDetailView(APIView): status=status.HTTP_400_BAD_REQUEST, ) - @swagger_auto_schema( - tags=["Leads"], manual_parameters=swagger_params.organization_params - ) + @extend_schema(tags=["Leads"],parameters=swagger_params1.organization_params, description="Lead Delete") def delete(self, request, pk, **kwargs): self.object = self.get_object(pk) if ( request.profile.role == "ADMIN" or request.user.is_superuser - or request.profile == self.object.created_by - ) and self.object.org == request.org: + or request.profile.user + == self.object.created_by + ) and self.object.org == request.profile.org: self.object.delete() return Response( {"error": False, "message": "Lead deleted Successfully"}, @@ -553,9 +568,7 @@ class LeadUploadView(APIView): # authentication_classes = (JSONWebTokenAuthentication,) permission_classes = (IsAuthenticated,) - @swagger_auto_schema( - tags=["Leads"], manual_parameters=swagger_params.lead_upload_post_params - ) + @extend_schema(tags=["Leads"], parameters=swagger_params1.organization_params,request=LeadUploadSwaggerSerializer) def post(self, request, *args, **kwargs): lead_form = LeadListForm(request.POST, request.FILES) if lead_form.is_valid(): @@ -564,7 +577,7 @@ class LeadUploadView(APIView): lead_form.invalid_rows, request.profile.id, request.get_host(), - request.org.id, + request.profile.org.id, ) return Response( {"error": False, "message": "Leads created Successfully"}, @@ -584,11 +597,9 @@ class LeadCommentView(APIView): def get_object(self, pk): return self.model.objects.get(pk=pk) - @swagger_auto_schema( - tags=["Leads"], manual_parameters=swagger_params.lead_comment_edit_params - ) + @extend_schema(tags=["Leads"], parameters=swagger_params1.organization_params,request=LeadCommentEditSwaggerSerializer) def put(self, request, pk, format=None): - params = request.post_data + params = request.data obj = self.get_object(pk) if ( request.profile.role == "ADMIN" @@ -614,9 +625,7 @@ class LeadCommentView(APIView): status=status.HTTP_403_FORBIDDEN, ) - @swagger_auto_schema( - tags=["Leads"], manual_parameters=swagger_params.organization_params - ) + @extend_schema(tags=["Leads"], parameters=swagger_params1.organization_params) def delete(self, request, pk, format=None): self.object = self.get_object(pk) if ( @@ -644,15 +653,13 @@ class LeadAttachmentView(APIView): # authentication_classes = (JSONWebTokenAuthentication,) permission_classes = (IsAuthenticated,) - @swagger_auto_schema( - tags=["Leads"], manual_parameters=swagger_params.organization_params - ) + @extend_schema(tags=["Leads"], parameters=swagger_params1.organization_params) def delete(self, request, pk, format=None): self.object = self.model.objects.get(pk=pk) if ( request.profile.role == "ADMIN" or request.user.is_superuser - or request.profile == self.object.created_by + or request.profile.user == self.object.created_by ): self.object.delete() return Response( @@ -669,11 +676,12 @@ class LeadAttachmentView(APIView): class CreateLeadFromSite(APIView): - @swagger_auto_schema( - tags=["Leads"], manual_parameters=swagger_params.create_lead_from_site + @extend_schema( + tags=["Leads"], + parameters=swagger_params1.organization_params,request=CreateLeadFromSiteSwaggerSerializer ) def post(self, request, *args, **kwargs): - params = request.post_data + params = request.data api_key = params.get("apikey") # api_setting = APISettings.objects.filter( # website=website_address, apikey=api_key).first() @@ -732,3 +740,93 @@ class CreateLeadFromSite(APIView): {"error": True, "message": "Invalid data"}, status=status.HTTP_400_BAD_REQUEST, ) + + +class CompaniesView(APIView): + + permission_classes = (IsAuthenticated,) + + @extend_schema(tags=["Company"],parameters=swagger_params1.organization_params) + def get(self, request, *args, **kwargs): + try: + companies=Company.objects.filter(org=request.profile.org) + serializer=CompanySerializer(companies,many=True) + return Response( + {"error": False, "data": serializer.data}, + status=status.HTTP_200_OK, + ) + except: + return Response( + {"error": True, "message": "Organization is missing"}, + status=status.HTTP_400_BAD_REQUEST, + ) + + + @extend_schema( + tags=["Company"],description="Company Create",parameters=swagger_params1.organization_params,request=CompanySwaggerSerializer + ) + def post(self, request, *args, **kwargs): + request.data['org'] = request.profile.org.id; + print(request.data) + company=CompanySerializer(data=request.data) + if Company.objects.filter(**request.data).exists(): + return Response( + {"error": True, "message": "This data already exists"}, + status=status.HTTP_400_BAD_REQUEST, + ) + if company.is_valid(): + company.save() + return Response( + {"error": False, "message": "Company created successfully"}, + status=status.HTTP_200_OK, + ) + else: + return Response( + {"error": True, "message": company.errors}, + status=status.HTTP_400_BAD_REQUEST, + ) + +class CompanyDetail(APIView): + + permission_classes = (IsAuthenticated,) + + + def get_object(self, pk): + try: + return Company.objects.get( + pk=pk + ) + except Company.DoesNotExist: + raise Http404 + + @extend_schema(tags=["Company"],parameters=swagger_params1.organization_params) + def get(self, request, pk, format=None): + company = self.get_object(pk) + serializer = CompanySerializer(company) + return Response( + {"error": False, "data": serializer.data}, + status=status.HTTP_200_OK, + ) + @extend_schema(tags=["Company"],description="Company Update",parameters=swagger_params1.organization_params,request=CompanySerializer) + def put(self, request, pk, format=None): + company = self.get_object(pk) + serializer = CompanySerializer(company, data=request.data) + if serializer.is_valid(): + serializer.save() + return Response( + {"error": False, "data": serializer.data,'message': 'Updated Successfully'}, + status=status.HTTP_200_OK, + ) + return Response( + {"error": True,'message': serializer.errors}, + status=status.HTTP_400_BAD_REQUEST, + ) + @extend_schema(tags=["Company"],parameters=swagger_params1.organization_params) + def delete(self, request, pk, format=None): + Company = self.get_object(pk) + Company.delete() + return Response( + {"error": False, 'message': 'Deleted successfully'}, + status=status.HTTP_200_OK, + ) + \ No newline at end of file diff --git a/opportunity/migrations/0001_initial.py b/opportunity/migrations/0001_initial.py index 369039c2..9cc9679b 100644 --- a/opportunity/migrations/0001_initial.py +++ b/opportunity/migrations/0001_initial.py @@ -1,8 +1,9 @@ -# Generated by Django 2.1.2 on 2019-01-28 07:07 +# Generated by Django 4.2.1 on 2023-06-19 13:08 -import django.db.models.deletion from django.conf import settings from django.db import migrations, models +import django.db.models.deletion +import uuid class Migration(migrations.Migration): @@ -10,287 +11,44 @@ class Migration(migrations.Migration): initial = True dependencies = [ - ("accounts", "0001_initial"), - ("common", "0001_initial"), - ("contacts", "0001_initial"), + ('teams', '0001_initial'), + ('accounts', '0001_initial'), + ('common', '0001_initial'), migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('contacts', '0001_initial'), ] operations = [ migrations.CreateModel( - name="Opportunity", + name='Opportunity', fields=[ - ( - "id", - models.AutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("name", models.CharField(max_length=64, verbose_name="Name")), - ( - "stage", - models.CharField( - choices=[ - ("QUALIFICATION", "QUALIFICATION"), - ("NEEDS ANALYSIS", "NEEDS ANALYSIS"), - ("VALUE PROPOSITION", "VALUE PROPOSITION"), - ("ID.DECISION MAKERS", "ID.DECISION MAKERS"), - ("PERCEPTION ANALYSIS", "PERCEPTION ANALYSIS"), - ("PROPOSAL/PRICE QUOTE", "PROPOSAL/PRICE QUOTE"), - ("NEGOTIATION/REVIEW", "NEGOTIATION/REVIEW"), - ("CLOSED WON", "CLOSED WON"), - ("CLOSED LOST", "CLOSED LOST"), - ], - max_length=64, - verbose_name="Stage", - ), - ), - ( - "currency", - models.CharField( - blank=True, - choices=[ - ("AED", "AED, Dirham"), - ("AFN", "AFN, Afghani"), - ("ALL", "ALL, Lek"), - ("AMD", "AMD, Dram"), - ("ANG", "ANG, Guilder"), - ("AOA", "AOA, Kwanza"), - ("ARS", "ARS, Peso"), - ("AUD", "AUD, Dollar"), - ("AWG", "AWG, Guilder"), - ("AZN", "AZN, Manat"), - ("BAM", "BAM, Marka"), - ("BBD", "BBD, Dollar"), - ("BDT", "BDT, Taka"), - ("BGN", "BGN, Lev"), - ("BHD", "BHD, Dinar"), - ("BIF", "BIF, Franc"), - ("BMD", "BMD, Dollar"), - ("BND", "BND, Dollar"), - ("BOB", "BOB, Boliviano"), - ("BRL", "BRL, Real"), - ("BSD", "BSD, Dollar"), - ("BTN", "BTN, Ngultrum"), - ("BWP", "BWP, Pula"), - ("BYR", "BYR, Ruble"), - ("BZD", "BZD, Dollar"), - ("CAD", "CAD, Dollar"), - ("CDF", "CDF, Franc"), - ("CHF", "CHF, Franc"), - ("CLP", "CLP, Peso"), - ("CNY", "CNY, Yuan Renminbi"), - ("COP", "COP, Peso"), - ("CRC", "CRC, Colon"), - ("CUP", "CUP, Peso"), - ("CVE", "CVE, Escudo"), - ("CZK", "CZK, Koruna"), - ("DJF", "DJF, Franc"), - ("DKK", "DKK, Krone"), - ("DOP", "DOP, Peso"), - ("DZD", "DZD, Dinar"), - ("EGP", "EGP, Pound"), - ("ERN", "ERN, Nakfa"), - ("ETB", "ETB, Birr"), - ("EUR", "EUR, Euro"), - ("FJD", "FJD, Dollar"), - ("FKP", "FKP, Pound"), - ("GBP", "GBP, Pound"), - ("GEL", "GEL, Lari"), - ("GHS", "GHS, Cedi"), - ("GIP", "GIP, Pound"), - ("GMD", "GMD, Dalasi"), - ("GNF", "GNF, Franc"), - ("GTQ", "GTQ, Quetzal"), - ("GYD", "GYD, Dollar"), - ("HKD", "HKD, Dollar"), - ("HNL", "HNL, Lempira"), - ("HRK", "HRK, Kuna"), - ("HTG", "HTG, Gourde"), - ("HUF", "HUF, Forint"), - ("IDR", "IDR, Rupiah"), - ("ILS", "ILS, Shekel"), - ("INR", "INR, Rupee"), - ("IQD", "IQD, Dinar"), - ("IRR", "IRR, Rial"), - ("ISK", "ISK, Krona"), - ("JMD", "JMD, Dollar"), - ("JOD", "JOD, Dinar"), - ("JPY", "JPY, Yen"), - ("KES", "KES, Shilling"), - ("KGS", "KGS, Som"), - ("KHR", "KHR, Riels"), - ("KMF", "KMF, Franc"), - ("KPW", "KPW, Won"), - ("KRW", "KRW, Won"), - ("KWD", "KWD, Dinar"), - ("KYD", "KYD, Dollar"), - ("KZT", "KZT, Tenge"), - ("LAK", "LAK, Kip"), - ("LBP", "LBP, Pound"), - ("LKR", "LKR, Rupee"), - ("LRD", "LRD, Dollar"), - ("LSL", "LSL, Loti"), - ("LTL", "LTL, Litas"), - ("LVL", "LVL, Lat"), - ("LYD", "LYD, Dinar"), - ("MAD", "MAD, Dirham"), - ("MDL", "MDL, Leu"), - ("MGA", "MGA, Ariary"), - ("MKD", "MKD, Denar"), - ("MMK", "MMK, Kyat"), - ("MNT", "MNT, Tugrik"), - ("MOP", "MOP, Pataca"), - ("MRO", "MRO, Ouguiya"), - ("MUR", "MUR, Rupee"), - ("MVR", "MVR, Rufiyaa"), - ("MWK", "MWK, Kwacha"), - ("MXN", "MXN, Peso"), - ("MYR", "MYR, Ringgit"), - ("MZN", "MZN, Metical"), - ("NAD", "NAD, Dollar"), - ("NGN", "NGN, Naira"), - ("NIO", "NIO, Cordoba"), - ("NOK", "NOK, Krone"), - ("NPR", "NPR, Rupee"), - ("NZD", "NZD, Dollar"), - ("OMR", "OMR, Rial"), - ("PAB", "PAB, Balboa"), - ("PEN", "PEN, Sol"), - ("PGK", "PGK, Kina"), - ("PHP", "PHP, Peso"), - ("PKR", "PKR, Rupee"), - ("PLN", "PLN, Zloty"), - ("PYG", "PYG, Guarani"), - ("QAR", "QAR, Rial"), - ("RON", "RON, Leu"), - ("RSD", "RSD, Dinar"), - ("RUB", "RUB, Ruble"), - ("RWF", "RWF, Franc"), - ("SAR", "SAR, Rial"), - ("SBD", "SBD, Dollar"), - ("SCR", "SCR, Rupee"), - ("SDG", "SDG, Pound"), - ("SEK", "SEK, Krona"), - ("SGD", "SGD, Dollar"), - ("SHP", "SHP, Pound"), - ("SLL", "SLL, Leone"), - ("SOS", "SOS, Shilling"), - ("SRD", "SRD, Dollar"), - ("SSP", "SSP, Pound"), - ("STD", "STD, Dobra"), - ("SYP", "SYP, Pound"), - ("SZL", "SZL, Lilangeni"), - ("THB", "THB, Baht"), - ("TJS", "TJS, Somoni"), - ("TMT", "TMT, Manat"), - ("TND", "TND, Dinar"), - ("TOP", "TOP, Paanga"), - ("TRY", "TRY, Lira"), - ("TTD", "TTD, Dollar"), - ("TWD", "TWD, Dollar"), - ("TZS", "TZS, Shilling"), - ("UAH", "UAH, Hryvnia"), - ("UGX", "UGX, Shilling"), - ("USD", "$, Dollar"), - ("UYU", "UYU, Peso"), - ("UZS", "UZS, Som"), - ("VEF", "VEF, Bolivar"), - ("VND", "VND, Dong"), - ("VUV", "VUV, Vatu"), - ("WST", "WST, Tala"), - ("XAF", "XAF, Franc"), - ("XCD", "XCD, Dollar"), - ("XOF", "XOF, Franc"), - ("XPF", "XPF, Franc"), - ("YER", "YER, Rial"), - ("ZAR", "ZAR, Rand"), - ("ZMK", "ZMK, Kwacha"), - ("ZWL", "ZWL, Dollar"), - ], - max_length=3, - null=True, - ), - ), - ( - "amount", - models.DecimalField( - blank=True, - decimal_places=2, - max_digits=12, - null=True, - verbose_name="Opportunity Amount", - ), - ), - ( - "lead_source", - models.CharField( - blank=True, - choices=[ - ("NONE", "NONE"), - ("CALL", "CALL"), - ("EMAIL", " EMAIL"), - ("EXISTING CUSTOMER", "EXISTING CUSTOMER"), - ("PARTNER", "PARTNER"), - ("PUBLIC RELATIONS", "PUBLIC RELATIONS"), - ("CAMPAIGN", "CAMPAIGN"), - ("WEBSITE", "WEBSITE"), - ("OTHER", "OTHER"), - ], - max_length=255, - null=True, - verbose_name="Source of Lead", - ), - ), - ("probability", models.IntegerField(blank=True, default=0, null=True)), - ("closed_on", models.DateField(blank=True, null=True)), - ("description", models.TextField(blank=True, null=True)), - ( - "created_on", - models.DateTimeField(auto_now_add=True, verbose_name="Created on"), - ), - ("is_active", models.BooleanField(default=False)), - ( - "account", - models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - related_name="opportunities", - to="accounts.Account", - ), - ), - ( - "assigned_to", - models.ManyToManyField( - related_name="opportunity_assigned_to", - to=settings.AUTH_USER_MODEL, - ), - ), - ( - "closed_by", - models.ForeignKey( - null=True, - on_delete=django.db.models.deletion.CASCADE, - to=settings.AUTH_USER_MODEL, - ), - ), - ("contacts", models.ManyToManyField(to="contacts.Contact")), - ( - "created_by", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - related_name="opportunity_created_by", - to=settings.AUTH_USER_MODEL, - ), - ), - ("teams", models.ManyToManyField(to="common.Team")), + ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')), + ('updated_at', models.DateTimeField(auto_now=True, verbose_name='Last Modified At')), + ('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)), + ('name', models.CharField(max_length=64, verbose_name='Name')), + ('stage', models.CharField(choices=[('QUALIFICATION', 'QUALIFICATION'), ('NEEDS ANALYSIS', 'NEEDS ANALYSIS'), ('VALUE PROPOSITION', 'VALUE PROPOSITION'), ('ID.DECISION MAKERS', 'ID.DECISION MAKERS'), ('PERCEPTION ANALYSIS', 'PERCEPTION ANALYSIS'), ('PROPOSAL/PRICE QUOTE', 'PROPOSAL/PRICE QUOTE'), ('NEGOTIATION/REVIEW', 'NEGOTIATION/REVIEW'), ('CLOSED WON', 'CLOSED WON'), ('CLOSED LOST', 'CLOSED LOST')], max_length=64, verbose_name='Stage')), + ('currency', models.CharField(blank=True, choices=[('AED', 'AED, Dirham'), ('AFN', 'AFN, Afghani'), ('ALL', 'ALL, Lek'), ('AMD', 'AMD, Dram'), ('ANG', 'ANG, Guilder'), ('AOA', 'AOA, Kwanza'), ('ARS', 'ARS, Peso'), ('AUD', 'AUD, Dollar'), ('AWG', 'AWG, Guilder'), ('AZN', 'AZN, Manat'), ('BAM', 'BAM, Marka'), ('BBD', 'BBD, Dollar'), ('BDT', 'BDT, Taka'), ('BGN', 'BGN, Lev'), ('BHD', 'BHD, Dinar'), ('BIF', 'BIF, Franc'), ('BMD', 'BMD, Dollar'), ('BND', 'BND, Dollar'), ('BOB', 'BOB, Boliviano'), ('BRL', 'BRL, Real'), ('BSD', 'BSD, Dollar'), ('BTN', 'BTN, Ngultrum'), ('BWP', 'BWP, Pula'), ('BYR', 'BYR, Ruble'), ('BZD', 'BZD, Dollar'), ('CAD', 'CAD, Dollar'), ('CDF', 'CDF, Franc'), ('CHF', 'CHF, Franc'), ('CLP', 'CLP, Peso'), ('CNY', 'CNY, Yuan Renminbi'), ('COP', 'COP, Peso'), ('CRC', 'CRC, Colon'), ('CUP', 'CUP, Peso'), ('CVE', 'CVE, Escudo'), ('CZK', 'CZK, Koruna'), ('DJF', 'DJF, Franc'), ('DKK', 'DKK, Krone'), ('DOP', 'DOP, Peso'), ('DZD', 'DZD, Dinar'), ('EGP', 'EGP, Pound'), ('ERN', 'ERN, Nakfa'), ('ETB', 'ETB, Birr'), ('EUR', 'EUR, Euro'), ('FJD', 'FJD, Dollar'), ('FKP', 'FKP, Pound'), ('GBP', 'GBP, Pound'), ('GEL', 'GEL, Lari'), ('GHS', 'GHS, Cedi'), ('GIP', 'GIP, Pound'), ('GMD', 'GMD, Dalasi'), ('GNF', 'GNF, Franc'), ('GTQ', 'GTQ, Quetzal'), ('GYD', 'GYD, Dollar'), ('HKD', 'HKD, Dollar'), ('HNL', 'HNL, Lempira'), ('HRK', 'HRK, Kuna'), ('HTG', 'HTG, Gourde'), ('HUF', 'HUF, Forint'), ('IDR', 'IDR, Rupiah'), ('ILS', 'ILS, Shekel'), ('INR', 'INR, Rupee'), ('IQD', 'IQD, Dinar'), ('IRR', 'IRR, Rial'), ('ISK', 'ISK, Krona'), ('JMD', 'JMD, Dollar'), ('JOD', 'JOD, Dinar'), ('JPY', 'JPY, Yen'), ('KES', 'KES, Shilling'), ('KGS', 'KGS, Som'), ('KHR', 'KHR, Riels'), ('KMF', 'KMF, Franc'), ('KPW', 'KPW, Won'), ('KRW', 'KRW, Won'), ('KWD', 'KWD, Dinar'), ('KYD', 'KYD, Dollar'), ('KZT', 'KZT, Tenge'), ('LAK', 'LAK, Kip'), ('LBP', 'LBP, Pound'), ('LKR', 'LKR, Rupee'), ('LRD', 'LRD, Dollar'), ('LSL', 'LSL, Loti'), ('LTL', 'LTL, Litas'), ('LVL', 'LVL, Lat'), ('LYD', 'LYD, Dinar'), ('MAD', 'MAD, Dirham'), ('MDL', 'MDL, Leu'), ('MGA', 'MGA, Ariary'), ('MKD', 'MKD, Denar'), ('MMK', 'MMK, Kyat'), ('MNT', 'MNT, Tugrik'), ('MOP', 'MOP, Pataca'), ('MRO', 'MRO, Ouguiya'), ('MUR', 'MUR, Rupee'), ('MVR', 'MVR, Rufiyaa'), ('MWK', 'MWK, Kwacha'), ('MXN', 'MXN, Peso'), ('MYR', 'MYR, Ringgit'), ('MZN', 'MZN, Metical'), ('NAD', 'NAD, Dollar'), ('NGN', 'NGN, Naira'), ('NIO', 'NIO, Cordoba'), ('NOK', 'NOK, Krone'), ('NPR', 'NPR, Rupee'), ('NZD', 'NZD, Dollar'), ('OMR', 'OMR, Rial'), ('PAB', 'PAB, Balboa'), ('PEN', 'PEN, Sol'), ('PGK', 'PGK, Kina'), ('PHP', 'PHP, Peso'), ('PKR', 'PKR, Rupee'), ('PLN', 'PLN, Zloty'), ('PYG', 'PYG, Guarani'), ('QAR', 'QAR, Rial'), ('RON', 'RON, Leu'), ('RSD', 'RSD, Dinar'), ('RUB', 'RUB, Ruble'), ('RWF', 'RWF, Franc'), ('SAR', 'SAR, Rial'), ('SBD', 'SBD, Dollar'), ('SCR', 'SCR, Rupee'), ('SDG', 'SDG, Pound'), ('SEK', 'SEK, Krona'), ('SGD', 'SGD, Dollar'), ('SHP', 'SHP, Pound'), ('SLL', 'SLL, Leone'), ('SOS', 'SOS, Shilling'), ('SRD', 'SRD, Dollar'), ('SSP', 'SSP, Pound'), ('STD', 'STD, Dobra'), ('SYP', 'SYP, Pound'), ('SZL', 'SZL, Lilangeni'), ('THB', 'THB, Baht'), ('TJS', 'TJS, Somoni'), ('TMT', 'TMT, Manat'), ('TND', 'TND, Dinar'), ('TOP', 'TOP, Paanga'), ('TRY', 'TRY, Lira'), ('TTD', 'TTD, Dollar'), ('TWD', 'TWD, Dollar'), ('TZS', 'TZS, Shilling'), ('UAH', 'UAH, Hryvnia'), ('UGX', 'UGX, Shilling'), ('USD', '$, Dollar'), ('UYU', 'UYU, Peso'), ('UZS', 'UZS, Som'), ('VEF', 'VEF, Bolivar'), ('VND', 'VND, Dong'), ('VUV', 'VUV, Vatu'), ('WST', 'WST, Tala'), ('XAF', 'XAF, Franc'), ('XCD', 'XCD, Dollar'), ('XOF', 'XOF, Franc'), ('XPF', 'XPF, Franc'), ('YER', 'YER, Rial'), ('ZAR', 'ZAR, Rand'), ('ZMK', 'ZMK, Kwacha'), ('ZWL', 'ZWL, Dollar')], max_length=3, null=True)), + ('amount', models.DecimalField(blank=True, decimal_places=2, max_digits=12, null=True, verbose_name='Opportunity Amount')), + ('lead_source', models.CharField(blank=True, choices=[('NONE', 'NONE'), ('CALL', 'CALL'), ('EMAIL', ' EMAIL'), ('EXISTING CUSTOMER', 'EXISTING CUSTOMER'), ('PARTNER', 'PARTNER'), ('PUBLIC RELATIONS', 'PUBLIC RELATIONS'), ('CAMPAIGN', 'CAMPAIGN'), ('WEBSITE', 'WEBSITE'), ('OTHER', 'OTHER')], max_length=255, null=True, verbose_name='Source of Lead')), + ('probability', models.IntegerField(blank=True, default=0, null=True)), + ('closed_on', models.DateField(blank=True, null=True)), + ('description', models.TextField(blank=True, null=True)), + ('is_active', models.BooleanField(default=False)), + ('account', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='opportunities', to='accounts.account')), + ('assigned_to', models.ManyToManyField(related_name='opportunity_assigned_to', to='common.profile')), + ('closed_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='oppurtunity_closed_by', to='common.profile')), + ('contacts', models.ManyToManyField(to='contacts.contact')), + ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='opportunity_created_by', to='common.profile')), + ('org', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='oppurtunity_org', to='common.org')), + ('tags', models.ManyToManyField(blank=True, to='accounts.tags')), + ('teams', models.ManyToManyField(related_name='oppurtunity_teams', to='teams.teams')), + ('updated_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_updated_by', to=settings.AUTH_USER_MODEL, verbose_name='Last Modified By')), ], options={ - "ordering": ["-created_on"], + 'verbose_name': 'Opportunity', + 'verbose_name_plural': 'Opportunities', + 'db_table': 'opportunity', + 'ordering': ('-created_at',), }, ), ] diff --git a/opportunity/migrations/0002_opportunity_tags.py b/opportunity/migrations/0002_opportunity_tags.py deleted file mode 100644 index 4fae6728..00000000 --- a/opportunity/migrations/0002_opportunity_tags.py +++ /dev/null @@ -1,19 +0,0 @@ -# Generated by Django 2.1.5 on 2019-02-06 10:15 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("accounts", "0004_account_status"), - ("opportunity", "0001_initial"), - ] - - operations = [ - migrations.AddField( - model_name="opportunity", - name="tags", - field=models.ManyToManyField(blank=True, to="accounts.Tags"), - ), - ] diff --git a/opportunity/migrations/0003_auto_20190212_1334.py b/opportunity/migrations/0003_auto_20190212_1334.py deleted file mode 100644 index 384259c0..00000000 --- a/opportunity/migrations/0003_auto_20190212_1334.py +++ /dev/null @@ -1,38 +0,0 @@ -# Generated by Django 2.1.5 on 2019-02-12 08:04 - -import django.db.models.deletion -from django.conf import settings -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("opportunity", "0002_opportunity_tags"), - ] - - operations = [ - migrations.RemoveField( - model_name="opportunity", - name="teams", - ), - migrations.AlterField( - model_name="opportunity", - name="closed_by", - field=models.ForeignKey( - null=True, - on_delete=django.db.models.deletion.SET_NULL, - to=settings.AUTH_USER_MODEL, - ), - ), - migrations.AlterField( - model_name="opportunity", - name="created_by", - field=models.ForeignKey( - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="opportunity_created_by", - to=settings.AUTH_USER_MODEL, - ), - ), - ] diff --git a/opportunity/migrations/0004_opportunity_teams.py b/opportunity/migrations/0004_opportunity_teams.py deleted file mode 100644 index 629ad440..00000000 --- a/opportunity/migrations/0004_opportunity_teams.py +++ /dev/null @@ -1,21 +0,0 @@ -# Generated by Django 2.2.4 on 2019-09-17 05:46 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("teams", "0003_auto_20190909_1621"), - ("opportunity", "0003_auto_20190212_1334"), - ] - - operations = [ - migrations.AddField( - model_name="opportunity", - name="teams", - field=models.ManyToManyField( - related_name="oppurtunity_teams", to="teams.Teams" - ), - ), - ] diff --git a/opportunity/migrations/0005_opportunity_company.py b/opportunity/migrations/0005_opportunity_company.py deleted file mode 100644 index ce743c9c..00000000 --- a/opportunity/migrations/0005_opportunity_company.py +++ /dev/null @@ -1,25 +0,0 @@ -# Generated by Django 2.2.10 on 2020-04-27 12:03 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0021_document_company"), - ("opportunity", "0004_opportunity_teams"), - ] - - operations = [ - migrations.AddField( - model_name="opportunity", - name="company", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - to="common.Company", - ), - ), - ] diff --git a/opportunity/migrations/0006_remove_opportunity_company.py b/opportunity/migrations/0006_remove_opportunity_company.py deleted file mode 100644 index 7802c8e5..00000000 --- a/opportunity/migrations/0006_remove_opportunity_company.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 3.1.7 on 2021-03-24 08:02 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ("opportunity", "0005_opportunity_company"), - ] - - operations = [ - migrations.RemoveField( - model_name="opportunity", - name="company", - ), - ] diff --git a/opportunity/migrations/0007_auto_20210913_1918.py b/opportunity/migrations/0007_auto_20210913_1918.py deleted file mode 100644 index 749dafce..00000000 --- a/opportunity/migrations/0007_auto_20210913_1918.py +++ /dev/null @@ -1,51 +0,0 @@ -# Generated by Django 3.2 on 2021-09-13 13:48 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0034_auto_20210913_1918"), - ("opportunity", "0006_remove_opportunity_company"), - ] - - operations = [ - migrations.AddField( - model_name="opportunity", - name="company", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - to="common.company", - ), - ), - migrations.AlterField( - model_name="opportunity", - name="assigned_to", - field=models.ManyToManyField( - related_name="opportunity_assigned_to", to="common.Profile" - ), - ), - migrations.AlterField( - model_name="opportunity", - name="closed_by", - field=models.ForeignKey( - null=True, - on_delete=django.db.models.deletion.SET_NULL, - to="common.profile", - ), - ), - migrations.AlterField( - model_name="opportunity", - name="created_by", - field=models.ForeignKey( - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="opportunity_created_by", - to="common.profile", - ), - ), - ] diff --git a/opportunity/migrations/0008_rename_company_opportunity_org.py b/opportunity/migrations/0008_rename_company_opportunity_org.py deleted file mode 100644 index 60a11b67..00000000 --- a/opportunity/migrations/0008_rename_company_opportunity_org.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 3.2 on 2021-09-22 12:31 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ("opportunity", "0007_auto_20210913_1918"), - ] - - operations = [ - migrations.RenameField( - model_name="opportunity", - old_name="company", - new_name="org", - ), - ] diff --git a/opportunity/migrations/0009_auto_20211006_1251.py b/opportunity/migrations/0009_auto_20211006_1251.py deleted file mode 100644 index 7b4c5c57..00000000 --- a/opportunity/migrations/0009_auto_20211006_1251.py +++ /dev/null @@ -1,37 +0,0 @@ -# Generated by Django 3.2.7 on 2021-10-06 07:21 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0037_alter_profile_org"), - ("opportunity", "0008_rename_company_opportunity_org"), - ] - - operations = [ - migrations.AlterField( - model_name="opportunity", - name="closed_by", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="oppurtunity_closed_by", - to="common.profile", - ), - ), - migrations.AlterField( - model_name="opportunity", - name="org", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="oppurtunity_org", - to="common.org", - ), - ), - ] diff --git a/opportunity/models.py b/opportunity/models.py index 0ef725a1..beea932d 100644 --- a/opportunity/models.py +++ b/opportunity/models.py @@ -5,12 +5,13 @@ from django.utils.translation import pgettext_lazy from accounts.models import Account, Tags from common.models import Org, Profile +from common.base import BaseModel from common.utils import CURRENCY_CODES, SOURCES, STAGES from contacts.models import Contact from teams.models import Teams -class Opportunity(models.Model): +class Opportunity(BaseModel): name = models.CharField(pgettext_lazy("Name of Opportunity", "Name"), max_length=64) account = models.ForeignKey( Account, @@ -52,7 +53,6 @@ class Opportunity(models.Model): on_delete=models.SET_NULL, null=True, ) - created_on = models.DateTimeField(_("Created on"), auto_now_add=True) is_active = models.BooleanField(default=False) tags = models.ManyToManyField(Tags, blank=True) teams = models.ManyToManyField(Teams, related_name="oppurtunity_teams") @@ -65,14 +65,17 @@ class Opportunity(models.Model): ) class Meta: - ordering = ["-created_on"] + verbose_name = "Opportunity" + verbose_name_plural = "Opportunities" + db_table = "opportunity" + ordering = ("-created_at",) def __str__(self): - return self.name + return f"{self.name}" @property def created_on_arrow(self): - return arrow.get(self.created_on).humanize() + return arrow.get(self.created_at).humanize() @property def get_team_users(self): diff --git a/opportunity/serializer.py b/opportunity/serializer.py index e10ec748..234f2ddd 100644 --- a/opportunity/serializer.py +++ b/opportunity/serializer.py @@ -102,3 +102,32 @@ class OpportunityCreateSerializer(serializers.ModelSerializer): # "get_team_and_assigned_users", # "get_assigned_users_not_in_teams", ) + +class OpportunityCreateSwaggerSerializer(serializers.ModelSerializer): + due_date = serializers.DateField() + opportunity_attachment = serializers.FileField() + class Meta: + model = Opportunity + fields = ( + "name", + "account", + "amount", + "currency", + "stage", + "teams", + "lead_source", + "probability", + "description", + "assigned_to", + "contacts", + "due_date", + "tags", + "opportunity_attachment" + ) + +class OpportunityDetailEditSwaggerSerializer(serializers.Serializer): + comment = serializers.CharField() + opportunity_attachment = serializers.FileField() + +class OpportunityCommentEditSwaggerSerializer(serializers.Serializer): + comment = serializers.CharField() diff --git a/opportunity/swagger_params.py b/opportunity/swagger_params.py deleted file mode 100644 index 95f8b7b3..00000000 --- a/opportunity/swagger_params.py +++ /dev/null @@ -1,59 +0,0 @@ -from drf_yasg import openapi - -organization_params_in_header = openapi.Parameter( - "org", openapi.IN_HEADER, required=True, type=openapi.TYPE_INTEGER -) - -organization_params = [ - organization_params_in_header, -] - -opportunity_list_get_params = [ - organization_params_in_header, - openapi.Parameter("name", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("account", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("stage", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("lead_source", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("tags", openapi.IN_QUERY, type=openapi.TYPE_STRING), -] - -opportunity_detail_get_params = [ - organization_params_in_header, - openapi.Parameter( - "opportunity_attachment", - openapi.IN_QUERY, - type=openapi.TYPE_FILE, - ), - openapi.Parameter("comment", openapi.IN_QUERY, type=openapi.TYPE_STRING), -] - -opportunity_create_post_params = [ - organization_params_in_header, - openapi.Parameter( - "name", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), - openapi.Parameter("account", openapi.IN_QUERY, type=openapi.TYPE_INTEGER), - openapi.Parameter("amount", openapi.IN_QUERY, type=openapi.TYPE_INTEGER), - openapi.Parameter("currency", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("stage", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("lead_source", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("probability", openapi.IN_QUERY, type=openapi.TYPE_INTEGER), - openapi.Parameter("teams", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("assigned_to", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("contacts", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter( - "due_date", openapi.IN_QUERY, type=openapi.FORMAT_DATE, example="2021-01-13" - ), - openapi.Parameter("tags", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("description", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter( - "opportunity_attachment", - openapi.IN_QUERY, - type=openapi.TYPE_FILE, - ), -] - -opportunity_comment_edit_params = [ - organization_params_in_header, - openapi.Parameter("comment", openapi.IN_QUERY, type=openapi.TYPE_STRING), -] diff --git a/opportunity/swagger_params1.py b/opportunity/swagger_params1.py new file mode 100644 index 00000000..929658cb --- /dev/null +++ b/opportunity/swagger_params1.py @@ -0,0 +1,35 @@ +from drf_spectacular.types import OpenApiTypes +from drf_spectacular.utils import OpenApiParameter + +organization_params_in_header = organization_params_in_header = OpenApiParameter( + "org", OpenApiTypes.STR, OpenApiParameter.HEADER +) + +organization_params = [ + organization_params_in_header, +] + + +opportunity_list_get_params = [ + organization_params_in_header, + OpenApiParameter("name", OpenApiTypes.STR,OpenApiParameter.QUERY), + OpenApiParameter("account", OpenApiTypes.STR,OpenApiParameter.QUERY), + OpenApiParameter("stage", OpenApiTypes.STR,OpenApiParameter.QUERY), + OpenApiParameter("lead_source", OpenApiTypes.STR,OpenApiParameter.QUERY), + OpenApiParameter("tags", OpenApiTypes.STR,OpenApiParameter.QUERY), +] + +opportunity_detail_get_params = [ + organization_params_in_header, + OpenApiParameter( + "opportunity_attachment", + OpenApiParameter.QUERY, + OpenApiTypes.BINARY, + ), + OpenApiParameter("comment", OpenApiTypes.STR,OpenApiParameter.QUERY), +] + +opportunity_comment_edit_params = [ + organization_params_in_header, + OpenApiParameter("comment", OpenApiTypes.STR,OpenApiParameter.QUERY), +] diff --git a/opportunity/views.py b/opportunity/views.py index e4df4b70..dc26775a 100644 --- a/opportunity/views.py +++ b/opportunity/views.py @@ -1,7 +1,7 @@ import json from django.db.models import Q -from drf_yasg.utils import swagger_auto_schema +from drf_spectacular.utils import OpenApiExample, OpenApiParameter, extend_schema from rest_framework import status from rest_framework.pagination import LimitOffsetPagination from rest_framework.permissions import IsAuthenticated @@ -11,16 +11,19 @@ from rest_framework.views import APIView from accounts.models import Account, Tags from accounts.serializer import AccountSerializer, TagsSerailizer from common.models import Attachments, Comment, Profile + # from common.custom_auth import JSONWebTokenAuthentication -from common.serializer import (AttachmentsSerializer, CommentSerializer, - ProfileSerializer) +from common.serializer import ( + AttachmentsSerializer, + CommentSerializer, + ProfileSerializer, +) from common.utils import CURRENCY_CODES, SOURCES, STAGES from contacts.models import Contact from contacts.serializer import ContactSerializer -from opportunity import swagger_params +from opportunity import swagger_params1 from opportunity.models import Opportunity -from opportunity.serializer import (OpportunityCreateSerializer, - OpportunitySerializer) +from opportunity.serializer import * from opportunity.tasks import send_email_to_assigned_user from teams.models import Teams @@ -32,10 +35,10 @@ class OpportunityListView(APIView, LimitOffsetPagination): model = Opportunity def get_context_data(self, **kwargs): - params = request.post_data - queryset = self.model.objects.filter(org=self.request.org).order_by("-id") - accounts = Account.objects.filter(org=self.request.org) - contacts = Contact.objects.filter(org=self.request.org) + params = self.request.query_params + queryset = self.model.objects.filter(org=self.request.profile.org).order_by("-id") + accounts = Account.objects.filter(org=self.request.profile.org) + contacts = Contact.objects.filter(org=self.request.profile.org) if self.request.profile.role != "ADMIN" and not self.request.user.is_superuser: queryset = queryset.filter( Q(created_by=self.request.profile) | Q(assigned_to=self.request.profile) @@ -93,31 +96,31 @@ class OpportunityListView(APIView, LimitOffsetPagination): return context - @swagger_auto_schema( + @extend_schema( tags=["Opportunities"], - manual_parameters=swagger_params.opportunity_list_get_params, + parameters=swagger_params1.opportunity_list_get_params, ) def get(self, request, *args, **kwargs): context = self.get_context_data(**kwargs) return Response(context) - @swagger_auto_schema( + @extend_schema( tags=["Opportunities"], - manual_parameters=swagger_params.opportunity_create_post_params, + parameters=swagger_params1.organization_params,request=OpportunityCreateSwaggerSerializer ) def post(self, request, *args, **kwargs): - params = request.post_data + params = request.data serializer = OpportunityCreateSerializer(data=params, request_obj=request) if serializer.is_valid(): opportunity_obj = serializer.save( created_by=request.profile, closed_on=params.get("due_date"), - org=request.org, + org=request.profile.org, ) if params.get("contacts"): contacts_list = json.loads(params.get("contacts")) - contacts = Contact.objects.filter(id__in=contacts_list, org=request.org) + contacts = Contact.objects.filter(id__in=contacts_list, org=request.profile.org) opportunity_obj.contacts.add(*contacts) if params.get("tags"): @@ -137,13 +140,13 @@ class OpportunityListView(APIView, LimitOffsetPagination): if params.get("teams"): teams_list = json.loads(params.get("teams")) - teams = Teams.objects.filter(id__in=teams_list, org=request.org) + teams = Teams.objects.filter(id__in=teams_list, org=request.profile.org) opportunity_obj.teams.add(*teams) if params.get("assigned_to"): assinged_to_list = json.loads(params.get("assigned_to")) profiles = Profile.objects.filter( - id__in=assinged_to_list, org=request.org, is_active=True + id__in=assinged_to_list, org=request.profile.org, is_active=True ) opportunity_obj.assigned_to.add(*profiles) @@ -184,14 +187,14 @@ class OpportunityDetailView(APIView): def get_object(self, pk): return self.model.objects.filter(id=pk).first() - @swagger_auto_schema( + @extend_schema( tags=["Opportunities"], - manual_parameters=swagger_params.opportunity_create_post_params, + parameters=swagger_params1.organization_params,request=OpportunityCreateSwaggerSerializer ) def put(self, request, pk, format=None): - params = request.post_data + params = request.data opportunity_object = self.get_object(pk=pk) - if opportunity_object.org != request.org: + if opportunity_object.org != request.profile.org: return Response( {"error": True, "errors": "User company doesnot match with header...."}, status=status.HTTP_403_FORBIDDEN, @@ -224,7 +227,7 @@ class OpportunityDetailView(APIView): opportunity_object.contacts.clear() if params.get("contacts"): contacts_list = json.loads(params.get("contacts")) - contacts = Contact.objects.filter(id__in=contacts_list, org=request.org) + contacts = Contact.objects.filter(id__in=contacts_list, org=request.profile.org) opportunity_object.contacts.add(*contacts) opportunity_object.tags.clear() @@ -246,14 +249,14 @@ class OpportunityDetailView(APIView): opportunity_object.teams.clear() if params.get("teams"): teams_list = json.loads(params.get("teams")) - teams = Teams.objects.filter(id__in=teams_list, org=request.org) + teams = Teams.objects.filter(id__in=teams_list, org=request.profile.org) opportunity_object.teams.add(*teams) opportunity_object.assigned_to.clear() if params.get("assigned_to"): assinged_to_list = json.loads(params.get("assigned_to")) profiles = Profile.objects.filter( - id__in=assinged_to_list, org=request.org, is_active=True + id__in=assinged_to_list, org=request.profile.org, is_active=True ) opportunity_object.assigned_to.add(*profiles) @@ -284,12 +287,12 @@ class OpportunityDetailView(APIView): status=status.HTTP_400_BAD_REQUEST, ) - @swagger_auto_schema( - tags=["Opportunities"], manual_parameters=swagger_params.organization_params + @extend_schema( + tags=["Opportunities"], parameters=swagger_params1.organization_params ) def delete(self, request, pk, format=None): self.object = self.get_object(pk) - if self.object.org != request.org: + if self.object.org != request.profile.org: return Response( {"error": True, "errors": "User company doesnot match with header...."}, status=status.HTTP_403_FORBIDDEN, @@ -309,14 +312,14 @@ class OpportunityDetailView(APIView): status=status.HTTP_200_OK, ) - @swagger_auto_schema( - tags=["Opportunities"], manual_parameters=swagger_params.organization_params + @extend_schema( + tags=["Opportunities"], parameters=swagger_params1.organization_params ) def get(self, request, pk, format=None): self.opportunity = self.get_object(pk=pk) context = {} context["opportunity_obj"] = OpportunitySerializer(self.opportunity).data - if self.opportunity.org != request.org: + if self.opportunity.org != request.profile.org: return Response( {"error": True, "errors": "User company doesnot match with header...."}, status=status.HTTP_403_FORBIDDEN, @@ -345,14 +348,14 @@ class OpportunityDetailView(APIView): if self.request.user.is_superuser or self.request.profile.role == "ADMIN": users_mention = list( - Profile.objects.filter(is_active=True, org=self.request.org).values( - "user__username" + Profile.objects.filter(is_active=True, org=self.request.profile.org).values( + "user__email" ) ) elif self.request.profile != self.opportunity.created_by: if self.opportunity.created_by: users_mention = [ - {"username": self.opportunity.created_by.user.username} + {"username": self.opportunity.created_by.user.email} ] else: users_mention = [] @@ -372,7 +375,7 @@ class OpportunityDetailView(APIView): ).data, "users": ProfileSerializer( Profile.objects.filter( - is_active=True, org=self.request.org + is_active=True, org=self.request.profile.org ).order_by("user__email"), many=True, ).data, @@ -385,15 +388,15 @@ class OpportunityDetailView(APIView): ) return Response(context) - @swagger_auto_schema( + @extend_schema( tags=["Opportunities"], - manual_parameters=swagger_params.opportunity_detail_get_params, + parameters=swagger_params1.organization_params,request=OpportunityDetailEditSwaggerSerializer ) def post(self, request, pk, **kwargs): - params = request.post_data + params = request.data context = {} self.opportunity_obj = Opportunity.objects.get(pk=pk) - if self.opportunity_obj.org != request.org: + if self.opportunity_obj.org != request.profile.org: return Response( {"error": True, "errors": "User company doesnot match with header...."}, status=status.HTTP_403_FORBIDDEN, @@ -452,12 +455,12 @@ class OpportunityCommentView(APIView): def get_object(self, pk): return self.model.objects.get(pk=pk) - @swagger_auto_schema( + @extend_schema( tags=["Opportunities"], - manual_parameters=swagger_params.opportunity_comment_edit_params, + parameters=swagger_params1.organization_params,request=OpportunityCommentEditSwaggerSerializer ) def put(self, request, pk, format=None): - params = request.post_data + params = request.data obj = self.get_object(pk) if ( request.profile.role == "ADMIN" @@ -484,8 +487,8 @@ class OpportunityCommentView(APIView): status=status.HTTP_403_FORBIDDEN, ) - @swagger_auto_schema( - tags=["Opportunities"], manual_parameters=swagger_params.organization_params + @extend_schema( + tags=["Opportunities"], parameters=swagger_params1.organization_params ) def delete(self, request, pk, format=None): self.object = self.get_object(pk) @@ -513,8 +516,8 @@ class OpportunityAttachmentView(APIView): # authentication_classes = (JSONWebTokenAuthentication,) permission_classes = (IsAuthenticated,) - @swagger_auto_schema( - tags=["Opportunities"], manual_parameters=swagger_params.organization_params + @extend_schema( + tags=["Opportunities"], parameters=swagger_params1.organization_params ) def delete(self, request, pk, format=None): self.object = self.model.objects.get(pk=pk) diff --git a/planner/migrations/0001_initial.py b/planner/migrations/0001_initial.py index 46522269..a50ab301 100644 --- a/planner/migrations/0001_initial.py +++ b/planner/migrations/0001_initial.py @@ -1,8 +1,9 @@ -# Generated by Django 2.1.2 on 2019-01-28 07:07 +# Generated by Django 4.2.1 on 2023-06-19 13:08 -import django.db.models.deletion from django.conf import settings from django.db import migrations, models +import django.db.models.deletion +import uuid class Migration(migrations.Migration): @@ -10,182 +11,64 @@ class Migration(migrations.Migration): initial = True dependencies = [ - ("common", "0002_auto_20190128_1237"), - ("contenttypes", "0002_remove_content_type_name"), - ("leads", "0001_initial"), - ("contacts", "0001_initial"), + ('contenttypes', '0002_remove_content_type_name'), + ('leads', '0001_initial'), + ('contacts', '0001_initial'), migrations.swappable_dependency(settings.AUTH_USER_MODEL), ] operations = [ migrations.CreateModel( - name="Event", + name='Reminder', fields=[ - ( - "id", - models.AutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("name", models.CharField(max_length=64, verbose_name="Event")), - ( - "event_type", - models.CharField(max_length=7, verbose_name="Type of the event"), - ), - ("object_id", models.PositiveIntegerField(blank=True, null=True)), - ( - "status", - models.CharField( - blank=True, - choices=[ - ("Planned", "Planned"), - ("Held", "Held"), - ("Not Held", "Not Held"), - ("Not Started", "Not Started"), - ("Started", "Started"), - ("Completed", "Completed"), - ("Canceled", "Canceled"), - ("Deferred", "Deferred"), - ], - max_length=64, - verbose_name="Status", - ), - ), - ("direction", models.CharField(blank=True, max_length=20)), - ("start_date", models.DateField(default=None)), - ("close_date", models.DateField(default=None, null=True)), - ( - "duration", - models.IntegerField( - default=None, null=True, verbose_name="Durations" - ), - ), - ("priority", models.CharField(blank=True, max_length=10)), - ("updated_on", models.DateTimeField(auto_now=True)), - ( - "created_on", - models.DateTimeField(auto_now_add=True, verbose_name="Created on"), - ), - ("description", models.TextField(blank=True, null=True)), - ("is_active", models.BooleanField(default=False)), - ( - "assigned_to", - models.ManyToManyField( - blank=True, - related_name="event_assigned_users", - to=settings.AUTH_USER_MODEL, - ), - ), - ( - "attendees_contacts", - models.ManyToManyField( - blank=True, - related_name="attendees_contact", - to="contacts.Contact", - ), - ), - ( - "attendees_leads", - models.ManyToManyField( - blank=True, related_name="attendees_lead", to="leads.Lead" - ), - ), - ( - "attendees_user", - models.ManyToManyField( - blank=True, - related_name="attendees_user", - to=settings.AUTH_USER_MODEL, - ), - ), - ( - "content_type", - models.ForeignKey( - blank=True, - choices=[ - (10, "Account"), - (13, "Lead"), - (14, "Opportunity"), - (11, "Case"), - ], - limit_choices_to=models.Q( - models.Q( - ("app_label", "account"), - ("id", 10), - ("model", "Account"), - ), - models.Q( - ("app_label", "leads"), ("id", 13), ("model", "Lead") - ), - models.Q( - ("app_label", "opportunity"), - ("id", 14), - ("model", "Opportunity"), - ), - models.Q( - ("app_label", "cases"), ("id", 11), ("model", "Case") - ), - _connector="OR", - ), - null=True, - on_delete=django.db.models.deletion.CASCADE, - to="contenttypes.ContentType", - ), - ), - ( - "created_by", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - related_name="event_created_by", - to=settings.AUTH_USER_MODEL, - ), - ), + ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')), + ('updated_at', models.DateTimeField(auto_now=True, verbose_name='Last Modified At')), + ('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)), + ('reminder_type', models.CharField(blank=True, max_length=5, null=True)), + ('reminder_time', models.IntegerField(blank=True, null=True, verbose_name='Reminder')), + ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_created_by', to=settings.AUTH_USER_MODEL, verbose_name='Created By')), + ('updated_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_updated_by', to=settings.AUTH_USER_MODEL, verbose_name='Last Modified By')), ], + options={ + 'verbose_name': 'Reminder', + 'verbose_name_plural': 'Reminders', + 'db_table': 'reminder', + 'ordering': ('-created_at',), + }, ), migrations.CreateModel( - name="Reminder", + name='PlannerEvent', fields=[ - ( - "id", - models.AutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ( - "reminder_type", - models.CharField(blank=True, max_length=5, null=True), - ), - ( - "reminder_time", - models.IntegerField(blank=True, null=True, verbose_name="Reminder"), - ), + ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')), + ('updated_at', models.DateTimeField(auto_now=True, verbose_name='Last Modified At')), + ('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)), + ('name', models.CharField(max_length=64, verbose_name='Event')), + ('event_type', models.CharField(max_length=7, verbose_name='Type of the event')), + ('object_id', models.PositiveIntegerField(blank=True, null=True)), + ('status', models.CharField(blank=True, choices=[('Planned', 'Planned'), ('Held', 'Held'), ('Not Held', 'Not Held'), ('Not Started', 'Not Started'), ('Started', 'Started'), ('Completed', 'Completed'), ('Canceled', 'Canceled'), ('Deferred', 'Deferred')], max_length=64, verbose_name='Status')), + ('direction', models.CharField(blank=True, max_length=20)), + ('start_date', models.DateField(default=None)), + ('close_date', models.DateField(default=None, null=True)), + ('duration', models.IntegerField(default=None, null=True, verbose_name='Durations')), + ('priority', models.CharField(blank=True, max_length=10)), + ('updated_on', models.DateTimeField(auto_now=True)), + ('created_on', models.DateTimeField(auto_now_add=True, verbose_name='Created on')), + ('description', models.TextField(blank=True, null=True)), + ('is_active', models.BooleanField(default=False)), + ('assigned_to', models.ManyToManyField(blank=True, related_name='event_assigned_users', to=settings.AUTH_USER_MODEL)), + ('attendees_contacts', models.ManyToManyField(blank=True, related_name='attendees_contact', to='contacts.contact')), + ('attendees_leads', models.ManyToManyField(blank=True, related_name='attendees_lead', to='leads.lead')), + ('attendees_user', models.ManyToManyField(blank=True, related_name='attendees_user', to=settings.AUTH_USER_MODEL)), + ('content_type', models.ForeignKey(blank=True, choices=[(10, 'Account'), (13, 'Lead'), (14, 'Opportunity'), (11, 'Case')], limit_choices_to=models.Q(models.Q(('app_label', 'account'), ('id', 10), ('model', 'Account')), models.Q(('app_label', 'leads'), ('id', 13), ('model', 'Lead')), models.Q(('app_label', 'opportunity'), ('id', 14), ('model', 'Opportunity')), models.Q(('app_label', 'cases'), ('id', 11), ('model', 'Case')), _connector='OR'), null=True, on_delete=django.db.models.deletion.CASCADE, to='contenttypes.contenttype')), + ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='event_created_by', to=settings.AUTH_USER_MODEL)), + ('reminders', models.ManyToManyField(blank=True, to='planner.reminder')), + ('updated_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='updated_user', to=settings.AUTH_USER_MODEL)), ], - ), - migrations.AddField( - model_name="event", - name="reminders", - field=models.ManyToManyField(blank=True, to="planner.Reminder"), - ), - migrations.AddField( - model_name="event", - name="teams", - field=models.ManyToManyField(blank=True, to="common.Team"), - ), - migrations.AddField( - model_name="event", - name="updated_by", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - related_name="updated_user", - to=settings.AUTH_USER_MODEL, - ), + options={ + 'verbose_name': 'PlannerEvent', + 'verbose_name_plural': 'PlannerEvents', + 'db_table': 'planner_event', + 'ordering': ('-created_at',), + }, ), ] diff --git a/planner/migrations/0002_auto_20190212_1334.py b/planner/migrations/0002_auto_20190212_1334.py deleted file mode 100644 index 286c5623..00000000 --- a/planner/migrations/0002_auto_20190212_1334.py +++ /dev/null @@ -1,40 +0,0 @@ -# Generated by Django 2.1.5 on 2019-02-12 08:04 - -import django.db.models.deletion -from django.conf import settings -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("planner", "0001_initial"), - ] - - operations = [ - migrations.RemoveField( - model_name="event", - name="teams", - ), - migrations.AlterField( - model_name="event", - name="created_by", - field=models.ForeignKey( - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="event_created_by", - to=settings.AUTH_USER_MODEL, - ), - ), - migrations.AlterField( - model_name="event", - name="updated_by", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="updated_user", - to=settings.AUTH_USER_MODEL, - ), - ), - ] diff --git a/planner/models.py b/planner/models.py index 81bc7943..2493f802 100644 --- a/planner/models.py +++ b/planner/models.py @@ -5,12 +5,13 @@ from django.utils.translation import gettext_lazy as _ from django.utils.translation import pgettext_lazy from common.models import User +from common.base import BaseModel from common.utils import EVENT_PARENT_TYPE, EVENT_STATUS from contacts.models import Contact from leads.models import Lead -class Reminder(models.Model): +class Reminder(BaseModel): reminder_type = models.CharField(max_length=5, blank=True, null=True) reminder_time = models.IntegerField( pgettext_lazy("time of the reminder to event in Seconds", "Reminder"), @@ -18,11 +19,17 @@ class Reminder(models.Model): null=True, ) + class Meta: + verbose_name = "Reminder" + verbose_name_plural = "Reminders" + db_table = "reminder" + ordering = ("-created_at",) + def __str__(self): - return self.reminder_type + return f"{self.reminder_type}" -class Event(models.Model): +class PlannerEvent(BaseModel): limit = ( models.Q(app_label="account", model="Account", id=10) | models.Q(app_label="leads", model="Lead", id=13) @@ -84,10 +91,16 @@ class Event(models.Model): User, related_name="event_created_by", on_delete=models.SET_NULL, null=True ) assigned_to = models.ManyToManyField( - User, blank=True, related_name="event_assigned_users" + User, blank=True, related_name="event_assigned_users", ) description = models.TextField(blank=True, null=True) is_active = models.BooleanField(default=False) + class Meta: + verbose_name = "PlannerEvent" + verbose_name_plural = "PlannerEvents" + db_table = "planner_event" + ordering = ("-created_at",) + def __str__(self): - return self.name + return f"{self.name}" diff --git a/planner/templates/users.html b/planner/templates/users.html index a7a866f2..c6529f16 100644 --- a/planner/templates/users.html +++ b/planner/templates/users.html @@ -31,7 +31,7 @@ - {{ user.username }} + {{ user.email }} {{ user.email }} diff --git a/requirements.txt b/requirements.txt index b73499aa..96865827 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,19 +1,23 @@ -django==4.1.1 +django==4.2.1 celery==5.2.7 -python-dotenv==0.21.0 -django-cors-headers==3.13.0 +python-dotenv==1.0.0 +django-cors-headers==4.0.0 djangorestframework==3.14.0 -djangorestframework-simplejwt==5.2.0 -drf-yasg==1.21.4 -django-ses==3.1.2 -psycopg2-binary==2.9.3 -whitenoise==6.2.0 -sentry-sdk==1.9.8 +djangorestframework-simplejwt==5.2.2 +drf-spectacular==0.26.2 +django-ses==3.5.0 +psycopg2-binary==2.9.6 +whitenoise==6.4.0 +sentry-sdk==1.24.0 -wagtail>=4.0.2,<4.0.3 +wagtail==5.0.1 django_extensions==3.2.1 +django_storages==1.13.2 +drf-rw-serializers==1.0.5 +django-crum==0.7.9 +Redis==4.6.0 # remove it -django-phonenumber-field==6.3.0 +django-phonenumber-field==7.1.0 arrow==1.2.3 -phonenumbers==8.12.55 +phonenumbers==8.13.13 diff --git a/schema.yaml b/schema.yaml new file mode 100644 index 00000000..33aa9340 --- /dev/null +++ b/schema.yaml @@ -0,0 +1,1734 @@ +openapi: 3.0.3 +info: + title: BottleCRM API + version: 1.0.0 + description: Open source CRM application +paths: + /api/accounts/: + get: + operationId: accounts_retrieve + tags: + - accounts + security: + - jwtAuth: [] + responses: + '200': + description: No response body + post: + operationId: accounts_create + tags: + - accounts + security: + - jwtAuth: [] + responses: + '200': + description: No response body + /api/accounts/{id}/: + get: + operationId: accounts_retrieve_2 + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: integer + tags: + - Accounts + security: + - jwtAuth: [] + responses: + '200': + description: No response body + post: + operationId: accounts_create_2 + parameters: + - in: query + name: account_attachment + schema: + type: string + - in: query + name: comment + schema: + type: string + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: integer + tags: + - Accounts + security: + - jwtAuth: [] + responses: + '200': + description: No response body + put: + operationId: accounts_update + parameters: + - in: query + name: account_attachment + schema: + type: string + - in: query + name: assigned_to + schema: + type: string + - in: query + name: billing_address_line + schema: + type: string + - in: query + name: billing_city + schema: + type: string + - in: query + name: billing_country + schema: + type: string + - in: query + name: billing_postcode + schema: + type: string + - in: query + name: billing_state + schema: + type: string + - in: query + name: billing_street + schema: + type: string + - in: query + name: contacts + schema: + type: string + - in: query + name: email + schema: + type: string + - in: path + name: id + schema: + type: integer + required: true + - in: query + name: lead + schema: + type: string + - in: query + name: name + schema: + type: string + - in: header + name: org + schema: + type: integer + - in: query + name: phone + schema: + type: string + - in: query + name: status + schema: + type: string + enum: + - close + - open + - in: query + name: tags + schema: + type: string + - in: query + name: teams + schema: + type: string + - in: query + name: website + schema: + type: string + tags: + - Accounts + security: + - jwtAuth: [] + responses: + '200': + description: No response body + delete: + operationId: accounts_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: integer + tags: + - Accounts + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/accounts/{id}/create_mail/: + post: + operationId: accounts_create_mail_create + parameters: + - in: query + name: from_email + schema: + type: string + - in: path + name: id + schema: + type: integer + required: true + - in: query + name: message_body + schema: + type: string + - in: query + name: message_subject + schema: + type: string + - in: header + name: org + schema: + type: integer + - in: query + name: recipients + schema: + type: string + - in: query + name: scheduled_date_time + schema: + type: string + - in: query + name: scheduled_later + schema: + type: string + - in: query + name: timezone + schema: + type: string + tags: + - Accounts + security: + - jwtAuth: [] + responses: + '200': + description: No response body + /api/accounts/attachment/{id}/: + delete: + operationId: accounts_attachment_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: integer + tags: + - Accounts + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/accounts/comment/{id}/: + put: + operationId: accounts_comment_update + parameters: + - in: query + name: comment + schema: + type: string + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: integer + tags: + - Accounts + security: + - jwtAuth: [] + responses: + '200': + description: No response body + delete: + operationId: accounts_comment_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: integer + tags: + - Accounts + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/api-settings/: + get: + operationId: api_settings_retrieve + description: Domain List + tags: + - api-settings + security: + - jwtAuth: [] + responses: + '200': + description: No response body + post: + operationId: api_settings_create + tags: + - api-settings + security: + - jwtAuth: [] + responses: + '200': + description: No response body + /api/api-settings/{id}/: + get: + operationId: api_settings_retrieve_2 + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - api-settings + security: + - jwtAuth: [] + responses: + '200': + description: No response body + put: + operationId: api_settings_update + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - api-settings + security: + - jwtAuth: [] + responses: + '200': + description: No response body + delete: + operationId: api_settings_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - api-settings + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/auth/create-org/: + get: + operationId: auth_create_org_retrieve + description: Just Pass the token, will return ORG list, associated with user + tags: + - auth + security: + - jwtAuth: [] + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/OrgProfileCreate' + description: '' + post: + operationId: auth_create_org_create + description: Organization and profile Creation api + tags: + - auth + requestBody: + content: + application/x-www-form-urlencoded: + schema: + $ref: '#/components/schemas/OrgProfileCreateRequest' + required: true + security: + - jwtAuth: [] + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/OrgProfileCreate' + description: '' + /api/auth/forgot-password/: + post: + operationId: auth_forgot_password_create + description: Forget Password Api + tags: + - auth + requestBody: + content: + application/x-www-form-urlencoded: + schema: + $ref: '#/components/schemas/ForgotPasswordRequest' + required: true + security: + - jwtAuth: [] + - {} + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/ForgotPassword' + description: '' + /api/auth/google/: + post: + operationId: auth_google_create + description: Login through Google + tags: + - auth + security: + - jwtAuth: [] + - {} + responses: + '200': + description: No response body + /api/auth/login/: + post: + operationId: auth_login_create + description: API authentication using login & password + tags: + - auth + requestBody: + content: + application/x-www-form-urlencoded: + schema: + $ref: '#/components/schemas/LoginSealizerRequest' + required: true + security: + - jwtAuth: [] + - {} + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/LoginSealizer' + description: '' + /api/auth/register/: + post: + operationId: auth_register_create + description: API authentication using login & password + tags: + - auth + requestBody: + content: + application/x-www-form-urlencoded: + schema: + $ref: '#/components/schemas/RegisterOrganizationRequest' + required: true + security: + - jwtAuth: [] + - {} + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/RegisterOrganization' + description: '' + /api/auth/resend-activation-link/: + post: + operationId: auth_resend_activation_link_create + description: Re-Send activation link + tags: + - auth + security: + - jwtAuth: [] + - {} + responses: + '200': + description: No response body + /api/auth/reset-password/{uid}/{token}/: + post: + operationId: auth_reset_password_create + description: Reset Password + parameters: + - in: path + name: token + schema: + type: string + required: true + - in: path + name: uid + schema: + type: string + required: true + tags: + - auth + security: + - jwtAuth: [] + - {} + responses: + '200': + description: No response body + /api/auth/token/refresh/: + post: + operationId: auth_token_refresh_create + description: |- + Takes a refresh type JSON web token and returns an access type JSON web + token if the refresh token is valid. + tags: + - auth + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/TokenRefreshRequest' + application/x-www-form-urlencoded: + schema: + $ref: '#/components/schemas/TokenRefreshRequest' + multipart/form-data: + schema: + $ref: '#/components/schemas/TokenRefreshRequest' + required: true + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/TokenRefresh' + description: '' + /api/cases/: + get: + operationId: cases_retrieve + tags: + - cases + security: + - jwtAuth: [] + responses: + '200': + description: No response body + post: + operationId: cases_create + tags: + - cases + security: + - jwtAuth: [] + responses: + '200': + description: No response body + /api/cases/{id}/: + get: + operationId: cases_retrieve_2 + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - cases + security: + - jwtAuth: [] + responses: + '200': + description: No response body + post: + operationId: cases_create_2 + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - cases + security: + - jwtAuth: [] + responses: + '200': + description: No response body + put: + operationId: cases_update + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - cases + security: + - jwtAuth: [] + responses: + '200': + description: No response body + delete: + operationId: cases_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - cases + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/cases/attachment/{id}/: + delete: + operationId: cases_attachment_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - cases + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/cases/comment/{id}/: + put: + operationId: cases_comment_update + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - cases + security: + - jwtAuth: [] + responses: + '200': + description: No response body + delete: + operationId: cases_comment_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - cases + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/contacts/: + get: + operationId: contacts_retrieve + tags: + - contacts + security: + - jwtAuth: [] + responses: + '200': + description: No response body + post: + operationId: contacts_create + tags: + - contacts + security: + - jwtAuth: [] + responses: + '200': + description: No response body + /api/contacts/{id}/: + get: + operationId: contacts_retrieve_2 + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - contacts + security: + - jwtAuth: [] + responses: + '200': + description: No response body + post: + operationId: contacts_create_2 + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - contacts + security: + - jwtAuth: [] + responses: + '200': + description: No response body + put: + operationId: contacts_update + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - contacts + security: + - jwtAuth: [] + responses: + '200': + description: No response body + delete: + operationId: contacts_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - contacts + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/contacts/attachment/{id}/: + delete: + operationId: contacts_attachment_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - contacts + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/contacts/comment/{id}/: + put: + operationId: contacts_comment_update + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - contacts + security: + - jwtAuth: [] + responses: + '200': + description: No response body + delete: + operationId: contacts_comment_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - contacts + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/dashboard/: + get: + operationId: dashboard_retrieve + tags: + - dashboard + security: + - jwtAuth: [] + responses: + '200': + description: No response body + /api/documents/: + get: + operationId: documents_retrieve + tags: + - documents + security: + - jwtAuth: [] + responses: + '200': + description: No response body + post: + operationId: documents_create + tags: + - documents + security: + - jwtAuth: [] + responses: + '200': + description: No response body + /api/documents/{id}/: + get: + operationId: documents_retrieve_2 + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - documents + security: + - jwtAuth: [] + responses: + '200': + description: No response body + put: + operationId: documents_update + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - documents + security: + - jwtAuth: [] + responses: + '200': + description: No response body + delete: + operationId: documents_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - documents + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/events/: + get: + operationId: events_retrieve + description: User account registration + tags: + - events + security: + - jwtAuth: [] + responses: + '200': + description: No response body + post: + operationId: events_create + description: User account registration + tags: + - events + security: + - jwtAuth: [] + responses: + '200': + description: No response body + /api/events/{id}/: + get: + operationId: events_retrieve_2 + description: User account registration + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - events + security: + - jwtAuth: [] + responses: + '200': + description: No response body + post: + operationId: events_create_2 + description: User account registration + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - events + security: + - jwtAuth: [] + responses: + '200': + description: No response body + put: + operationId: events_update + description: User account registration + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - events + security: + - jwtAuth: [] + responses: + '200': + description: No response body + delete: + operationId: events_destroy + description: User account registration + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - events + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/events/attachment/{id}/: + delete: + operationId: events_attachment_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - events + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/events/comment/{id}/: + put: + operationId: events_comment_update + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - events + security: + - jwtAuth: [] + responses: + '200': + description: No response body + delete: + operationId: events_comment_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - events + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/leads/: + get: + operationId: leads_retrieve + tags: + - Leads + security: + - jwtAuth: [] + responses: + '200': + description: No response body + post: + operationId: leads_create + description: Leads Create + tags: + - leads + security: + - jwtAuth: [] + responses: + '200': + description: No response body + /api/leads/{id}/: + get: + operationId: leads_retrieve_2 + description: Lead Detail + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - leads + security: + - jwtAuth: [] + responses: + '200': + description: No response body + post: + operationId: leads_create_2 + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - leads + security: + - jwtAuth: [] + responses: + '200': + description: No response body + put: + operationId: leads_update + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - leads + security: + - jwtAuth: [] + responses: + '200': + description: No response body + delete: + operationId: leads_destroy + description: Lead Delete + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - leads + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/leads/attachment/{id}/: + delete: + operationId: leads_attachment_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - leads + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/leads/comment/{id}/: + put: + operationId: leads_comment_update + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - leads + security: + - jwtAuth: [] + responses: + '200': + description: No response body + delete: + operationId: leads_comment_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - leads + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/leads/create-from-site/: + post: + operationId: leads_create_from_site_create + tags: + - leads + security: + - jwtAuth: [] + - {} + responses: + '200': + description: No response body + /api/leads/upload/: + post: + operationId: leads_upload_create + tags: + - Leads + security: + - jwtAuth: [] + responses: + '200': + description: No response body + /api/opportunities/: + get: + operationId: opportunities_retrieve + tags: + - opportunities + security: + - jwtAuth: [] + responses: + '200': + description: No response body + post: + operationId: opportunities_create + tags: + - opportunities + security: + - jwtAuth: [] + responses: + '200': + description: No response body + /api/opportunities/{id}/: + get: + operationId: opportunities_retrieve_2 + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - opportunities + security: + - jwtAuth: [] + responses: + '200': + description: No response body + post: + operationId: opportunities_create_2 + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - opportunities + security: + - jwtAuth: [] + responses: + '200': + description: No response body + put: + operationId: opportunities_update + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - opportunities + security: + - jwtAuth: [] + responses: + '200': + description: No response body + delete: + operationId: opportunities_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - opportunities + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/opportunities/attachment/{id}/: + delete: + operationId: opportunities_attachment_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - opportunities + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/opportunities/comment/{id}/: + put: + operationId: opportunities_comment_update + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - opportunities + security: + - jwtAuth: [] + responses: + '200': + description: No response body + delete: + operationId: opportunities_comment_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - opportunities + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/profile/: + get: + operationId: profile_retrieve + tags: + - profile + security: + - jwtAuth: [] + responses: + '200': + description: No response body + /api/profile/change-password/: + post: + operationId: profile_change_password_create + tags: + - profile + security: + - jwtAuth: [] + responses: + '200': + description: No response body + /api/tasks/: + get: + operationId: tasks_retrieve + tags: + - tasks + security: + - jwtAuth: [] + responses: + '200': + description: No response body + post: + operationId: tasks_create + tags: + - tasks + security: + - jwtAuth: [] + responses: + '200': + description: No response body + /api/tasks/{id}/: + get: + operationId: tasks_retrieve_2 + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - tasks + security: + - jwtAuth: [] + responses: + '200': + description: No response body + post: + operationId: tasks_create_2 + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - tasks + security: + - jwtAuth: [] + responses: + '200': + description: No response body + put: + operationId: tasks_update + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - tasks + security: + - jwtAuth: [] + responses: + '200': + description: No response body + delete: + operationId: tasks_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - tasks + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/tasks/attachment/{id}/: + delete: + operationId: tasks_attachment_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - tasks + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/tasks/comment/{id}/: + put: + operationId: tasks_comment_update + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - tasks + security: + - jwtAuth: [] + responses: + '200': + description: No response body + delete: + operationId: tasks_comment_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - tasks + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/teams/: + get: + operationId: teams_retrieve + tags: + - teams + security: + - jwtAuth: [] + responses: + '200': + description: No response body + post: + operationId: teams_create + tags: + - teams + security: + - jwtAuth: [] + responses: + '200': + description: No response body + /api/teams/{id}/: + get: + operationId: teams_retrieve_2 + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - teams + security: + - jwtAuth: [] + responses: + '200': + description: No response body + put: + operationId: teams_update + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - teams + security: + - jwtAuth: [] + responses: + '200': + description: No response body + delete: + operationId: teams_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - teams + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/users/: + get: + operationId: users_retrieve + tags: + - users + security: + - jwtAuth: [] + responses: + '200': + description: No response body + post: + operationId: users_create + tags: + - users + security: + - jwtAuth: [] + responses: + '200': + description: No response body + /api/users/{id}/: + get: + operationId: users_retrieve_2 + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - users + security: + - jwtAuth: [] + responses: + '200': + description: No response body + put: + operationId: users_update + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - users + security: + - jwtAuth: [] + responses: + '200': + description: No response body + delete: + operationId: users_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - users + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/users/{id}/status/: + post: + operationId: users_status_create + description: User Status View + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - users + security: + - jwtAuth: [] + responses: + '200': + description: No response body + /api/users/get-teams-and-users/: + get: + operationId: users_get_teams_and_users_retrieve + tags: + - users + security: + - jwtAuth: [] + responses: + '200': + description: No response body +components: + schemas: + ForgotPassword: + type: object + properties: + email: + type: string + maxLength: 200 + required: + - email + ForgotPasswordRequest: + type: object + properties: + email: + type: string + minLength: 1 + maxLength: 200 + required: + - email + LoginSealizer: + type: object + properties: + email: + type: string + maxLength: 255 + access_token: + type: string + readOnly: true + refresh_token: + type: string + readOnly: true + required: + - access_token + - email + - refresh_token + LoginSealizerRequest: + type: object + properties: + email: + type: string + minLength: 1 + maxLength: 255 + password: + type: string + writeOnly: true + minLength: 1 + maxLength: 128 + required: + - email + - password + OrgProfileCreate: + type: object + description: It is for creating organization + properties: + id: + type: integer + readOnly: true + name: + type: string + maxLength: 255 + address: + type: string + maxLength: 255 + user_limit: + type: string + maxLength: 255 + country: + type: string + maxLength: 255 + required: + - address + - country + - id + - name + - user_limit + OrgProfileCreateRequest: + type: object + description: It is for creating organization + properties: + name: + type: string + minLength: 1 + maxLength: 255 + address: + type: string + minLength: 1 + maxLength: 255 + user_limit: + type: string + minLength: 1 + maxLength: 255 + country: + type: string + minLength: 1 + maxLength: 255 + required: + - address + - country + - name + - user_limit + RegisterOrganization: + type: object + properties: + email: + type: string + format: email + first_name: + type: string + maxLength: 255 + password: + type: string + maxLength: 100 + required: + - email + - first_name + - password + RegisterOrganizationRequest: + type: object + properties: + email: + type: string + format: email + minLength: 1 + first_name: + type: string + minLength: 1 + maxLength: 255 + password: + type: string + minLength: 1 + maxLength: 100 + required: + - email + - first_name + - password + TokenRefresh: + type: object + properties: + access: + type: string + readOnly: true + required: + - access + TokenRefreshRequest: + type: object + properties: + refresh: + type: string + writeOnly: true + minLength: 1 + required: + - refresh + securitySchemes: + jwtAuth: + type: http + scheme: bearer + bearerFormat: JWT diff --git a/schema.yml b/schema.yml new file mode 100644 index 00000000..243deed2 --- /dev/null +++ b/schema.yml @@ -0,0 +1,3107 @@ +openapi: 3.0.3 +info: + title: BottleCRM API + version: 1.0.0 + description: Open source CRM application +paths: + /api/accounts/: + get: + operationId: accounts_retrieve + parameters: + - in: query + name: city + schema: + type: string + - in: query + name: name + schema: + type: string + - in: header + name: org + schema: + type: string + - in: query + name: tags + schema: + type: string + tags: + - Accounts + security: + - jwtAuth: [] + responses: + '200': + description: No response body + post: + operationId: accounts_create + parameters: + - in: query + name: account_attachment + schema: + type: string + - in: query + name: assigned_to + schema: + type: string + - in: query + name: billing_address_line + schema: + type: string + - in: query + name: billing_city + schema: + type: string + - in: query + name: billing_country + schema: + type: string + - in: query + name: billing_postcode + schema: + type: string + - in: query + name: billing_state + schema: + type: string + - in: query + name: billing_street + schema: + type: string + - in: query + name: contacts + schema: + type: string + - in: query + name: email + schema: + type: string + - in: query + name: lead + schema: + type: string + - in: query + name: name + schema: + type: string + - in: header + name: org + schema: + type: string + - in: query + name: phone + schema: + type: string + - in: query + name: status + schema: + type: string + enum: + - close + - open + - in: query + name: tags + schema: + type: string + - in: query + name: teams + schema: + type: string + - in: query + name: website + schema: + type: string + tags: + - Accounts + security: + - jwtAuth: [] + responses: + '200': + description: No response body + /api/accounts/{id}/: + get: + operationId: accounts_retrieve_2 + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - Accounts + security: + - jwtAuth: [] + responses: + '200': + description: No response body + post: + operationId: accounts_create_2 + parameters: + - in: query + name: account_attachment + schema: + type: string + - in: query + name: comment + schema: + type: string + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - Accounts + security: + - jwtAuth: [] + responses: + '200': + description: No response body + put: + operationId: accounts_update + parameters: + - in: query + name: account_attachment + schema: + type: string + - in: query + name: assigned_to + schema: + type: string + - in: query + name: billing_address_line + schema: + type: string + - in: query + name: billing_city + schema: + type: string + - in: query + name: billing_country + schema: + type: string + - in: query + name: billing_postcode + schema: + type: string + - in: query + name: billing_state + schema: + type: string + - in: query + name: billing_street + schema: + type: string + - in: query + name: contacts + schema: + type: string + - in: query + name: email + schema: + type: string + - in: path + name: id + schema: + type: integer + required: true + - in: query + name: lead + schema: + type: string + - in: query + name: name + schema: + type: string + - in: header + name: org + schema: + type: string + - in: query + name: phone + schema: + type: string + - in: query + name: status + schema: + type: string + enum: + - close + - open + - in: query + name: tags + schema: + type: string + - in: query + name: teams + schema: + type: string + - in: query + name: website + schema: + type: string + tags: + - Accounts + security: + - jwtAuth: [] + responses: + '200': + description: No response body + delete: + operationId: accounts_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - Accounts + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/accounts/{id}/create_mail/: + post: + operationId: accounts_create_mail_create + parameters: + - in: query + name: from_email + schema: + type: string + - in: path + name: id + schema: + type: integer + required: true + - in: query + name: message_body + schema: + type: string + - in: query + name: message_subject + schema: + type: string + - in: header + name: org + schema: + type: string + - in: query + name: recipients + schema: + type: string + - in: query + name: scheduled_date_time + schema: + type: string + - in: query + name: scheduled_later + schema: + type: string + - in: query + name: timezone + schema: + type: string + tags: + - Accounts + security: + - jwtAuth: [] + responses: + '200': + description: No response body + /api/accounts/attachment/{id}/: + delete: + operationId: accounts_attachment_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - Accounts + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/accounts/comment/{id}/: + put: + operationId: accounts_comment_update + parameters: + - in: query + name: comment + schema: + type: string + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - Accounts + security: + - jwtAuth: [] + responses: + '200': + description: No response body + delete: + operationId: accounts_comment_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - Accounts + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/api-settings/: + get: + operationId: api_settings_retrieve + description: Domain List + tags: + - api-settings + security: + - jwtAuth: [] + responses: + '200': + description: No response body + post: + operationId: api_settings_create + tags: + - api-settings + security: + - jwtAuth: [] + responses: + '200': + description: No response body + /api/api-settings/{id}/: + get: + operationId: api_settings_retrieve_2 + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - api-settings + security: + - jwtAuth: [] + responses: + '200': + description: No response body + put: + operationId: api_settings_update + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - api-settings + security: + - jwtAuth: [] + responses: + '200': + description: No response body + delete: + operationId: api_settings_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - api-settings + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/auth/google/: + post: + operationId: auth_google_create + description: Login through Google + tags: + - auth + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/SocialLoginRequest' + application/x-www-form-urlencoded: + schema: + $ref: '#/components/schemas/SocialLoginRequest' + multipart/form-data: + schema: + $ref: '#/components/schemas/SocialLoginRequest' + required: true + security: + - jwtAuth: [] + - {} + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/SocialLogin' + description: '' + /api/auth/refresh-token/: + post: + operationId: auth_refresh_token_create + description: |- + Takes a refresh type JSON web token and returns an access type JSON web + token if the refresh token is valid. + tags: + - auth + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/TokenRefreshRequest' + application/x-www-form-urlencoded: + schema: + $ref: '#/components/schemas/TokenRefreshRequest' + multipart/form-data: + schema: + $ref: '#/components/schemas/TokenRefreshRequest' + required: true + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/TokenRefresh' + description: '' + /api/cases/: + get: + operationId: cases_retrieve + parameters: + - in: header + name: org + schema: + type: string + tags: + - Cases + security: + - jwtAuth: [] + responses: + '200': + description: No response body + post: + operationId: cases_create + parameters: + - in: header + name: org + schema: + type: string + tags: + - Cases + security: + - jwtAuth: [] + responses: + '200': + description: No response body + /api/cases/{id}/: + get: + operationId: cases_retrieve_2 + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - Cases + security: + - jwtAuth: [] + responses: + '200': + description: No response body + post: + operationId: cases_create_2 + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - Cases + security: + - jwtAuth: [] + responses: + '200': + description: No response body + put: + operationId: cases_update + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - Cases + security: + - jwtAuth: [] + responses: + '200': + description: No response body + delete: + operationId: cases_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - Cases + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/cases/attachment/{id}/: + delete: + operationId: cases_attachment_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - Cases + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/cases/comment/{id}/: + put: + operationId: cases_comment_update + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - Cases + security: + - jwtAuth: [] + responses: + '200': + description: No response body + delete: + operationId: cases_comment_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - Cases + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/contacts/: + get: + operationId: contacts_retrieve + parameters: + - in: header + name: org + schema: + type: string + tags: + - contacts + security: + - jwtAuth: [] + responses: + '200': + description: No response body + post: + operationId: contacts_create + parameters: + - in: header + name: org + schema: + type: string + tags: + - contacts + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/CreateContactRequest' + application/x-www-form-urlencoded: + schema: + $ref: '#/components/schemas/CreateContactRequest' + multipart/form-data: + schema: + $ref: '#/components/schemas/CreateContactRequest' + required: true + security: + - jwtAuth: [] + responses: + '200': + description: No response body + /api/contacts/{id}/: + get: + operationId: contacts_retrieve_2 + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - contacts + security: + - jwtAuth: [] + responses: + '200': + description: No response body + post: + operationId: contacts_create_2 + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - contacts + security: + - jwtAuth: [] + responses: + '200': + description: No response body + put: + operationId: contacts_update + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - contacts + security: + - jwtAuth: [] + responses: + '200': + description: No response body + delete: + operationId: contacts_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - contacts + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/contacts/attachment/{id}/: + delete: + operationId: contacts_attachment_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - contacts + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/contacts/comment/{id}/: + put: + operationId: contacts_comment_update + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - contacts + security: + - jwtAuth: [] + responses: + '200': + description: No response body + delete: + operationId: contacts_comment_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - contacts + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/dashboard/: + get: + operationId: dashboard_retrieve + parameters: + - in: header + name: org + schema: + type: string + tags: + - dashboard + security: + - jwtAuth: [] + responses: + '200': + description: No response body + /api/documents/: + get: + operationId: documents_retrieve + tags: + - documents + security: + - jwtAuth: [] + responses: + '200': + description: No response body + post: + operationId: documents_create + tags: + - documents + security: + - jwtAuth: [] + responses: + '200': + description: No response body + /api/documents/{id}/: + get: + operationId: documents_retrieve_2 + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - documents + security: + - jwtAuth: [] + responses: + '200': + description: No response body + put: + operationId: documents_update + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - documents + security: + - jwtAuth: [] + responses: + '200': + description: No response body + delete: + operationId: documents_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - documents + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/events/: + get: + operationId: events_retrieve + description: User account registration + tags: + - events + security: + - jwtAuth: [] + responses: + '200': + description: No response body + post: + operationId: events_create + description: User account registration + tags: + - events + security: + - jwtAuth: [] + responses: + '200': + description: No response body + /api/events/{id}/: + get: + operationId: events_retrieve_2 + description: User account registration + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - events + security: + - jwtAuth: [] + responses: + '200': + description: No response body + post: + operationId: events_create_2 + description: User account registration + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - events + security: + - jwtAuth: [] + responses: + '200': + description: No response body + put: + operationId: events_update + description: User account registration + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - events + security: + - jwtAuth: [] + responses: + '200': + description: No response body + delete: + operationId: events_destroy + description: User account registration + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - events + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/events/attachment/{id}/: + delete: + operationId: events_attachment_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - Events + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/events/comment/{id}/: + put: + operationId: events_comment_update + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - Events + security: + - jwtAuth: [] + responses: + '200': + description: No response body + delete: + operationId: events_comment_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - Events + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/leads/: + get: + operationId: leads_retrieve + parameters: + - in: query + name: assigned_to + schema: + type: string + - in: header + name: org + schema: + type: string + - in: query + name: source + schema: + type: string + - in: query + name: status + schema: + type: string + enum: + - assigned + - closed + - converted + - in process + - recycled + - in: query + name: tags + schema: + type: string + - in: query + name: title + schema: + type: string + tags: + - Leads + security: + - jwtAuth: [] + responses: + '200': + description: No response body + post: + operationId: leads_create + description: Leads Create + parameters: + - in: header + name: org + schema: + type: string + tags: + - Leads + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/LeadCreateSwaggerRequest' + application/x-www-form-urlencoded: + schema: + $ref: '#/components/schemas/LeadCreateSwaggerRequest' + multipart/form-data: + schema: + $ref: '#/components/schemas/LeadCreateSwaggerRequest' + required: true + security: + - jwtAuth: [] + responses: + '200': + description: No response body + /api/leads/{id}/: + get: + operationId: leads_retrieve_2 + description: Lead Detail + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - Leads + security: + - jwtAuth: [] + responses: + '200': + description: No response body + post: + operationId: leads_create_2 + parameters: + - in: query + name: comment + schema: + type: string + - in: path + name: id + schema: + type: integer + required: true + - in: query + name: lead_attachment + schema: + type: string + - in: header + name: org + schema: + type: string + tags: + - Leads + security: + - jwtAuth: [] + responses: + '200': + description: No response body + put: + operationId: leads_update + parameters: + - in: query + name: account_name + schema: + type: string + - in: query + name: address_line + schema: + type: string + - in: query + name: assigned_to + schema: + type: string + - in: query + name: city + schema: + type: string + - in: query + name: company + schema: + type: string + - in: query + name: contacts + schema: {} + - in: query + name: country + schema: + type: string + - in: query + name: description + schema: + type: string + - in: query + name: email + schema: + type: string + format: email + - in: query + name: first_name + schema: + type: string + - in: path + name: id + schema: + type: integer + required: true + - in: query + name: industry + schema: + type: string + - in: query + name: last_name + schema: + type: string + - in: query + name: lead_attachment + schema: {} + - in: query + name: opportunity_amount + schema: + type: string + - in: header + name: org + schema: + type: string + - in: query + name: phone + schema: + type: string + - in: query + name: postcode + schema: + type: string + - in: query + name: skype_ID + schema: + type: string + - in: query + name: source + schema: + type: string + - in: query + name: state + schema: + type: string + - in: query + name: status + schema: + type: string + enum: + - assigned + - closed + - converted + - in process + - recycled + - in: query + name: street + schema: + type: string + - in: query + name: tags + schema: + type: string + - in: query + name: teams + schema: + type: string + - in: query + name: title + schema: + type: string + - in: query + name: website + schema: + type: string + tags: + - Leads + security: + - jwtAuth: [] + responses: + '200': + description: No response body + delete: + operationId: leads_destroy + description: Lead Delete + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - Leads + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/leads/attachment/{id}/: + delete: + operationId: leads_attachment_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - Leads + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/leads/comment/{id}/: + put: + operationId: leads_comment_update + parameters: + - in: query + name: comment + schema: + type: string + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - Leads + security: + - jwtAuth: [] + responses: + '200': + description: No response body + delete: + operationId: leads_comment_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - Leads + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/leads/companies: + get: + operationId: leads_companies_retrieve + tags: + - Company + security: + - jwtAuth: [] + responses: + '200': + description: No response body + post: + operationId: leads_companies_create + description: Company Create + tags: + - Company + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/CompanyRequest' + application/x-www-form-urlencoded: + schema: + $ref: '#/components/schemas/CompanyRequest' + multipart/form-data: + schema: + $ref: '#/components/schemas/CompanyRequest' + security: + - jwtAuth: [] + responses: + '200': + description: No response body + /api/leads/company/{id}: + get: + operationId: leads_company_retrieve + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - Company + security: + - jwtAuth: [] + responses: + '200': + description: No response body + put: + operationId: leads_company_update + description: Company Create + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - Company + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/CompanyRequest' + application/x-www-form-urlencoded: + schema: + $ref: '#/components/schemas/CompanyRequest' + multipart/form-data: + schema: + $ref: '#/components/schemas/CompanyRequest' + security: + - jwtAuth: [] + responses: + '200': + description: No response body + delete: + operationId: leads_company_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - Company + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/leads/create-from-site/: + post: + operationId: leads_create_from_site_create + parameters: + - in: query + name: apikey + schema: + type: string + - in: query + name: description + schema: + type: string + - in: query + name: email + schema: + type: string + - in: query + name: first_name + schema: + type: string + - in: query + name: last_name + schema: + type: string + - in: query + name: phone + schema: + type: string + - in: query + name: source + schema: + type: string + - in: query + name: title + schema: + type: string + tags: + - Leads + security: + - jwtAuth: [] + - {} + responses: + '200': + description: No response body + /api/leads/upload/: + post: + operationId: leads_upload_create + parameters: + - in: query + name: leads_file + schema: {} + - in: header + name: org + schema: + type: string + tags: + - Leads + security: + - jwtAuth: [] + responses: + '200': + description: No response body + /api/opportunities/: + get: + operationId: opportunities_retrieve + parameters: + - in: header + name: org + schema: + type: string + tags: + - Opportunities + security: + - jwtAuth: [] + responses: + '200': + description: No response body + post: + operationId: opportunities_create + parameters: + - in: header + name: org + schema: + type: string + tags: + - Opportunities + security: + - jwtAuth: [] + responses: + '200': + description: No response body + /api/opportunities/{id}/: + get: + operationId: opportunities_retrieve_2 + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - Opportunities + security: + - jwtAuth: [] + responses: + '200': + description: No response body + post: + operationId: opportunities_create_2 + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - Opportunities + security: + - jwtAuth: [] + responses: + '200': + description: No response body + put: + operationId: opportunities_update + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - Opportunities + security: + - jwtAuth: [] + responses: + '200': + description: No response body + delete: + operationId: opportunities_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - Opportunities + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/opportunities/attachment/{id}/: + delete: + operationId: opportunities_attachment_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - Opportunities + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/opportunities/comment/{id}/: + put: + operationId: opportunities_comment_update + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - Opportunities + security: + - jwtAuth: [] + responses: + '200': + description: No response body + delete: + operationId: opportunities_comment_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - Opportunities + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/org/: + get: + operationId: org_retrieve + description: Just Pass the token, will return ORG list, associated with user + tags: + - org + security: + - jwtAuth: [] + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/OrgProfileCreate' + description: '' + post: + operationId: org_create + description: Organization and profile Creation api + tags: + - org + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/OrgProfileCreateRequest' + application/x-www-form-urlencoded: + schema: + $ref: '#/components/schemas/OrgProfileCreateRequest' + multipart/form-data: + schema: + $ref: '#/components/schemas/OrgProfileCreateRequest' + required: true + security: + - jwtAuth: [] + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/OrgProfileCreate' + description: '' + /api/profile/: + get: + operationId: profile_retrieve + parameters: + - in: header + name: org + schema: + type: string + tags: + - profile + security: + - jwtAuth: [] + responses: + '200': + description: No response body + /api/tasks/: + get: + operationId: tasks_retrieve + parameters: + - in: header + name: org + schema: + type: string + tags: + - Tasks + security: + - jwtAuth: [] + responses: + '200': + description: No response body + post: + operationId: tasks_create + parameters: + - in: header + name: org + schema: + type: string + tags: + - Tasks + security: + - jwtAuth: [] + responses: + '200': + description: No response body + /api/tasks/{id}/: + get: + operationId: tasks_retrieve_2 + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - Tasks + security: + - jwtAuth: [] + responses: + '200': + description: No response body + post: + operationId: tasks_create_2 + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - Tasks + security: + - jwtAuth: [] + responses: + '200': + description: No response body + put: + operationId: tasks_update + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - Tasks + security: + - jwtAuth: [] + responses: + '200': + description: No response body + delete: + operationId: tasks_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - Tasks + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/tasks/attachment/{id}/: + delete: + operationId: tasks_attachment_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - Tasks + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/tasks/comment/{id}/: + put: + operationId: tasks_comment_update + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - Tasks + security: + - jwtAuth: [] + responses: + '200': + description: No response body + delete: + operationId: tasks_comment_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - Tasks + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/teams/: + get: + operationId: teams_retrieve + parameters: + - in: header + name: org + schema: + type: string + tags: + - Teams + security: + - jwtAuth: [] + responses: + '200': + description: No response body + post: + operationId: teams_create + parameters: + - in: header + name: org + schema: + type: string + tags: + - Teams + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/TeamswaggerCreateRequest' + application/x-www-form-urlencoded: + schema: + $ref: '#/components/schemas/TeamswaggerCreateRequest' + multipart/form-data: + schema: + $ref: '#/components/schemas/TeamswaggerCreateRequest' + required: true + security: + - jwtAuth: [] + responses: + '200': + description: No response body + /api/teams/{id}/: + get: + operationId: teams_retrieve_2 + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - Teams + security: + - jwtAuth: [] + responses: + '200': + description: No response body + put: + operationId: teams_update + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - Teams + security: + - jwtAuth: [] + responses: + '200': + description: No response body + delete: + operationId: teams_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + - in: header + name: org + schema: + type: string + tags: + - Teams + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/users/: + get: + operationId: users_retrieve + parameters: + - in: header + name: org + schema: + type: string + tags: + - users + security: + - jwtAuth: [] + responses: + '200': + description: No response body + post: + operationId: users_create + tags: + - users + security: + - jwtAuth: [] + responses: + '200': + description: No response body + /api/users/{id}/: + get: + operationId: users_retrieve_2 + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - users + security: + - jwtAuth: [] + responses: + '200': + description: No response body + put: + operationId: users_update + parameters: + - in: query + name: address_line + schema: + type: string + - in: query + name: alternate_email + schema: + type: string + - in: query + name: alternate_phone + schema: + type: string + - in: query + name: city + schema: + type: string + - in: query + name: country + schema: + type: string + - in: query + name: description + schema: + type: string + - in: query + name: email + schema: + type: string + - in: query + name: first_name + schema: + type: string + - in: query + name: has_marketing_access + schema: + type: boolean + - in: query + name: has_sales_access + schema: + type: boolean + - in: path + name: id + schema: + type: integer + required: true + - in: query + name: is_organization_admin + schema: + type: boolean + - in: query + name: last_name + schema: + type: string + - in: header + name: org + schema: + type: string + - in: query + name: phone + schema: + type: string + - in: query + name: pincode + schema: + type: string + - in: query + name: role + schema: + type: string + enum: + - ADMIN + - USER + - in: query + name: skype_ID + schema: + type: string + - in: query + name: state + schema: + type: string + - in: query + name: street + schema: + type: string + - in: query + name: teams + schema: + type: string + tags: + - users + security: + - jwtAuth: [] + responses: + '200': + description: No response body + delete: + operationId: users_destroy + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - users + security: + - jwtAuth: [] + responses: + '204': + description: No response body + /api/users/{id}/status/: + post: + operationId: users_status_create + description: User Status View + parameters: + - in: path + name: id + schema: + type: integer + required: true + tags: + - users + security: + - jwtAuth: [] + responses: + '200': + description: No response body + /api/users/get-teams-and-users/: + get: + operationId: users_get_teams_and_users_retrieve + parameters: + - in: header + name: org + schema: + type: string + tags: + - users + security: + - jwtAuth: [] + responses: + '200': + description: No response body +components: + schemas: + BlankEnum: + enum: + - '' + CompanyRequest: + type: object + properties: + name: + type: string + nullable: true + maxLength: 100 + CountryEnum: + enum: + - GB + - AF + - AX + - AL + - DZ + - AS + - AD + - AO + - AI + - AQ + - AG + - AR + - AM + - AW + - AU + - AT + - AZ + - BS + - BH + - BD + - BB + - BY + - BE + - BZ + - BJ + - BM + - BT + - BO + - BA + - BW + - BV + - BR + - IO + - BN + - BG + - BF + - BI + - KH + - CM + - CA + - CV + - KY + - CF + - TD + - CL + - CN + - CX + - CC + - CO + - KM + - CG + - CD + - CK + - CR + - CI + - HR + - CU + - CY + - CZ + - DK + - DJ + - DM + - DO + - EC + - EG + - SV + - GQ + - ER + - EE + - ET + - FK + - FO + - FJ + - FI + - FR + - GF + - PF + - TF + - GA + - GM + - GE + - DE + - GH + - GI + - GR + - GL + - GD + - GP + - GU + - GT + - GG + - GN + - GW + - GY + - HT + - HM + - VA + - HN + - HK + - HU + - IS + - IN + - ID + - IR + - IQ + - IE + - IM + - IL + - IT + - JM + - JP + - JE + - JO + - KZ + - KE + - KI + - KP + - KR + - KW + - KG + - LA + - LV + - LB + - LS + - LR + - LY + - LI + - LT + - LU + - MO + - MK + - MG + - MW + - MY + - MV + - ML + - MT + - MH + - MQ + - MR + - MU + - YT + - MX + - FM + - MD + - MC + - MN + - ME + - MS + - MA + - MZ + - MM + - NA + - NR + - NP + - NL + - AN + - NC + - NZ + - NI + - NE + - NG + - NU + - NF + - MP + - 'NO' + - OM + - PK + - PW + - PS + - PA + - PG + - PY + - PE + - PH + - PN + - PL + - PT + - PR + - QA + - RE + - RO + - RU + - RW + - BL + - SH + - KN + - LC + - MF + - PM + - VC + - WS + - SM + - ST + - SA + - SN + - RS + - SC + - SL + - SG + - SK + - SI + - SB + - SO + - ZA + - GS + - ES + - LK + - SD + - SR + - SJ + - SZ + - SE + - CH + - SY + - TW + - TJ + - TZ + - TH + - TL + - TG + - TK + - TO + - TT + - TN + - TR + - TM + - TC + - TV + - UG + - UA + - AE + - US + - UM + - UY + - UZ + - VU + - VE + - VN + - VG + - VI + - WF + - EH + - YE + - ZM + - ZW + type: string + description: |- + * `GB` - United Kingdom + * `AF` - Afghanistan + * `AX` - Aland Islands + * `AL` - Albania + * `DZ` - Algeria + * `AS` - American Samoa + * `AD` - Andorra + * `AO` - Angola + * `AI` - Anguilla + * `AQ` - Antarctica + * `AG` - Antigua and Barbuda + * `AR` - Argentina + * `AM` - Armenia + * `AW` - Aruba + * `AU` - Australia + * `AT` - Austria + * `AZ` - Azerbaijan + * `BS` - Bahamas + * `BH` - Bahrain + * `BD` - Bangladesh + * `BB` - Barbados + * `BY` - Belarus + * `BE` - Belgium + * `BZ` - Belize + * `BJ` - Benin + * `BM` - Bermuda + * `BT` - Bhutan + * `BO` - Bolivia + * `BA` - Bosnia and Herzegovina + * `BW` - Botswana + * `BV` - Bouvet Island + * `BR` - Brazil + * `IO` - British Indian Ocean Territory + * `BN` - Brunei Darussalam + * `BG` - Bulgaria + * `BF` - Burkina Faso + * `BI` - Burundi + * `KH` - Cambodia + * `CM` - Cameroon + * `CA` - Canada + * `CV` - Cape Verde + * `KY` - Cayman Islands + * `CF` - Central African Republic + * `TD` - Chad + * `CL` - Chile + * `CN` - China + * `CX` - Christmas Island + * `CC` - Cocos (Keeling) Islands + * `CO` - Colombia + * `KM` - Comoros + * `CG` - Congo + * `CD` - Congo, The Democratic Republic of the + * `CK` - Cook Islands + * `CR` - Costa Rica + * `CI` - Cote d'Ivoire + * `HR` - Croatia + * `CU` - Cuba + * `CY` - Cyprus + * `CZ` - Czech Republic + * `DK` - Denmark + * `DJ` - Djibouti + * `DM` - Dominica + * `DO` - Dominican Republic + * `EC` - Ecuador + * `EG` - Egypt + * `SV` - El Salvador + * `GQ` - Equatorial Guinea + * `ER` - Eritrea + * `EE` - Estonia + * `ET` - Ethiopia + * `FK` - Falkland Islands (Malvinas) + * `FO` - Faroe Islands + * `FJ` - Fiji + * `FI` - Finland + * `FR` - France + * `GF` - French Guiana + * `PF` - French Polynesia + * `TF` - French Southern Territories + * `GA` - Gabon + * `GM` - Gambia + * `GE` - Georgia + * `DE` - Germany + * `GH` - Ghana + * `GI` - Gibraltar + * `GR` - Greece + * `GL` - Greenland + * `GD` - Grenada + * `GP` - Guadeloupe + * `GU` - Guam + * `GT` - Guatemala + * `GG` - Guernsey + * `GN` - Guinea + * `GW` - Guinea-Bissau + * `GY` - Guyana + * `HT` - Haiti + * `HM` - Heard Island and McDonald Islands + * `VA` - Holy See (Vatican City State) + * `HN` - Honduras + * `HK` - Hong Kong + * `HU` - Hungary + * `IS` - Iceland + * `IN` - India + * `ID` - Indonesia + * `IR` - Iran, Islamic Republic of + * `IQ` - Iraq + * `IE` - Ireland + * `IM` - Isle of Man + * `IL` - Israel + * `IT` - Italy + * `JM` - Jamaica + * `JP` - Japan + * `JE` - Jersey + * `JO` - Jordan + * `KZ` - Kazakhstan + * `KE` - Kenya + * `KI` - Kiribati + * `KP` - Korea, Democratic People's Republic of + * `KR` - Korea, Republic of + * `KW` - Kuwait + * `KG` - Kyrgyzstan + * `LA` - Lao People's Democratic Republic + * `LV` - Latvia + * `LB` - Lebanon + * `LS` - Lesotho + * `LR` - Liberia + * `LY` - Libyan Arab Jamahiriya + * `LI` - Liechtenstein + * `LT` - Lithuania + * `LU` - Luxembourg + * `MO` - Macao + * `MK` - Macedonia, The Former Yugoslav Republic of + * `MG` - Madagascar + * `MW` - Malawi + * `MY` - Malaysia + * `MV` - Maldives + * `ML` - Mali + * `MT` - Malta + * `MH` - Marshall Islands + * `MQ` - Martinique + * `MR` - Mauritania + * `MU` - Mauritius + * `YT` - Mayotte + * `MX` - Mexico + * `FM` - Micronesia, Federated States of + * `MD` - Moldova + * `MC` - Monaco + * `MN` - Mongolia + * `ME` - Montenegro + * `MS` - Montserrat + * `MA` - Morocco + * `MZ` - Mozambique + * `MM` - Myanmar + * `NA` - Namibia + * `NR` - Nauru + * `NP` - Nepal + * `NL` - Netherlands + * `AN` - Netherlands Antilles + * `NC` - New Caledonia + * `NZ` - New Zealand + * `NI` - Nicaragua + * `NE` - Niger + * `NG` - Nigeria + * `NU` - Niue + * `NF` - Norfolk Island + * `MP` - Northern Mariana Islands + * `NO` - Norway + * `OM` - Oman + * `PK` - Pakistan + * `PW` - Palau + * `PS` - Palestinian Territory, Occupied + * `PA` - Panama + * `PG` - Papua New Guinea + * `PY` - Paraguay + * `PE` - Peru + * `PH` - Philippines + * `PN` - Pitcairn + * `PL` - Poland + * `PT` - Portugal + * `PR` - Puerto Rico + * `QA` - Qatar + * `RE` - Reunion + * `RO` - Romania + * `RU` - Russian Federation + * `RW` - Rwanda + * `BL` - Saint Barthelemy + * `SH` - Saint Helena + * `KN` - Saint Kitts and Nevis + * `LC` - Saint Lucia + * `MF` - Saint Martin + * `PM` - Saint Pierre and Miquelon + * `VC` - Saint Vincent and the Grenadines + * `WS` - Samoa + * `SM` - San Marino + * `ST` - Sao Tome and Principe + * `SA` - Saudi Arabia + * `SN` - Senegal + * `RS` - Serbia + * `SC` - Seychelles + * `SL` - Sierra Leone + * `SG` - Singapore + * `SK` - Slovakia + * `SI` - Slovenia + * `SB` - Solomon Islands + * `SO` - Somalia + * `ZA` - South Africa + * `GS` - South Georgia and the South Sandwich Islands + * `ES` - Spain + * `LK` - Sri Lanka + * `SD` - Sudan + * `SR` - Suriname + * `SJ` - Svalbard and Jan Mayen + * `SZ` - Swaziland + * `SE` - Sweden + * `CH` - Switzerland + * `SY` - Syrian Arab Republic + * `TW` - Taiwan, Province of China + * `TJ` - Tajikistan + * `TZ` - Tanzania, United Republic of + * `TH` - Thailand + * `TL` - Timor-Leste + * `TG` - Togo + * `TK` - Tokelau + * `TO` - Tonga + * `TT` - Trinidad and Tobago + * `TN` - Tunisia + * `TR` - Turkey + * `TM` - Turkmenistan + * `TC` - Turks and Caicos Islands + * `TV` - Tuvalu + * `UG` - Uganda + * `UA` - Ukraine + * `AE` - United Arab Emirates + * `US` - United States + * `UM` - United States Minor Outlying Islands + * `UY` - Uruguay + * `UZ` - Uzbekistan + * `VU` - Vanuatu + * `VE` - Venezuela + * `VN` - Viet Nam + * `VG` - Virgin Islands, British + * `VI` - Virgin Islands, U.S. + * `WF` - Wallis and Futuna + * `EH` - Western Sahara + * `YE` - Yemen + * `ZM` - Zambia + * `ZW` - Zimbabwe + CreateContactRequest: + type: object + properties: + salutation: + type: string + maxLength: 255 + first_name: + type: string + minLength: 1 + maxLength: 255 + last_name: + type: string + minLength: 1 + maxLength: 255 + organization: + type: string + nullable: true + minLength: 1 + maxLength: 255 + title: + type: string + maxLength: 255 + primary_email: + type: string + format: email + minLength: 1 + maxLength: 254 + secondary_email: + type: string + format: email + maxLength: 254 + mobile_number: + type: string + nullable: true + minLength: 1 + maxLength: 128 + secondary_number: + type: string + nullable: true + minLength: 1 + maxLength: 128 + department: + type: string + nullable: true + minLength: 1 + maxLength: 255 + country: + nullable: true + oneOf: + - $ref: '#/components/schemas/CountryEnum' + - $ref: '#/components/schemas/BlankEnum' + - $ref: '#/components/schemas/NullEnum' + language: + type: string + nullable: true + minLength: 1 + maxLength: 255 + do_not_call: + type: boolean + address: + type: string + format: uuid + nullable: true + description: + type: string + nullable: true + linked_in_url: + type: string + format: uri + nullable: true + maxLength: 200 + facebook_url: + type: string + format: uri + nullable: true + maxLength: 200 + twitter_username: + type: string + nullable: true + minLength: 1 + maxLength: 255 + required: + - first_name + - last_name + - primary_email + IndustryEnum: + enum: + - ADVERTISING + - AGRICULTURE + - APPAREL & ACCESSORIES + - AUTOMOTIVE + - BANKING + - BIOTECHNOLOGY + - BUILDING MATERIALS & EQUIPMENT + - CHEMICAL + - COMPUTER + - EDUCATION + - ELECTRONICS + - ENERGY + - ENTERTAINMENT & LEISURE + - FINANCE + - FOOD & BEVERAGE + - GROCERY + - HEALTHCARE + - INSURANCE + - LEGAL + - MANUFACTURING + - PUBLISHING + - REAL ESTATE + - SERVICE + - SOFTWARE + - SPORTS + - TECHNOLOGY + - TELECOMMUNICATIONS + - TELEVISION + - TRANSPORTATION + - VENTURE CAPITAL + type: string + description: |- + * `ADVERTISING` - ADVERTISING + * `AGRICULTURE` - AGRICULTURE + * `APPAREL & ACCESSORIES` - APPAREL & ACCESSORIES + * `AUTOMOTIVE` - AUTOMOTIVE + * `BANKING` - BANKING + * `BIOTECHNOLOGY` - BIOTECHNOLOGY + * `BUILDING MATERIALS & EQUIPMENT` - BUILDING MATERIALS & EQUIPMENT + * `CHEMICAL` - CHEMICAL + * `COMPUTER` - COMPUTER + * `EDUCATION` - EDUCATION + * `ELECTRONICS` - ELECTRONICS + * `ENERGY` - ENERGY + * `ENTERTAINMENT & LEISURE` - ENTERTAINMENT & LEISURE + * `FINANCE` - FINANCE + * `FOOD & BEVERAGE` - FOOD & BEVERAGE + * `GROCERY` - GROCERY + * `HEALTHCARE` - HEALTHCARE + * `INSURANCE` - INSURANCE + * `LEGAL` - LEGAL + * `MANUFACTURING` - MANUFACTURING + * `PUBLISHING` - PUBLISHING + * `REAL ESTATE` - REAL ESTATE + * `SERVICE` - SERVICE + * `SOFTWARE` - SOFTWARE + * `SPORTS` - SPORTS + * `TECHNOLOGY` - TECHNOLOGY + * `TELECOMMUNICATIONS` - TELECOMMUNICATIONS + * `TELEVISION` - TELEVISION + * `TRANSPORTATION` - TRANSPORTATION + * `VENTURE CAPITAL` - VENTURE CAPITAL + LeadCreateSwaggerRequest: + type: object + properties: + title: + type: string + minLength: 1 + maxLength: 64 + first_name: + type: string + nullable: true + minLength: 1 + maxLength: 255 + last_name: + type: string + nullable: true + minLength: 1 + maxLength: 255 + account_name: + type: string + nullable: true + maxLength: 255 + phone: + type: string + nullable: true + maxLength: 128 + email: + type: string + format: email + nullable: true + maxLength: 254 + lead_attachment: + type: array + items: + type: string + format: uuid + opportunity_amount: + type: string + format: decimal + pattern: ^-?\d{0,10}(?:\.\d{0,2})?$ + nullable: true + website: + type: string + nullable: true + maxLength: 255 + description: + type: string + nullable: true + teams: + type: array + items: + type: string + format: uuid + assigned_to: + type: array + items: + type: string + format: uuid + contacts: + type: array + items: + type: string + format: uuid + status: + nullable: true + title: Status of Lead + oneOf: + - $ref: '#/components/schemas/StatusEnum' + - $ref: '#/components/schemas/BlankEnum' + - $ref: '#/components/schemas/NullEnum' + source: + nullable: true + title: Source of Lead + oneOf: + - $ref: '#/components/schemas/SourceEnum' + - $ref: '#/components/schemas/BlankEnum' + - $ref: '#/components/schemas/NullEnum' + address_line: + type: string + nullable: true + title: Address + maxLength: 255 + street: + type: string + nullable: true + maxLength: 55 + city: + type: string + nullable: true + maxLength: 255 + state: + type: string + nullable: true + maxLength: 255 + postcode: + type: string + nullable: true + title: Post/Zip-code + maxLength: 64 + country: + nullable: true + oneOf: + - $ref: '#/components/schemas/CountryEnum' + - $ref: '#/components/schemas/BlankEnum' + - $ref: '#/components/schemas/NullEnum' + tags: + type: array + items: + type: string + format: uuid + company: + type: string + format: uuid + nullable: true + probability: + type: integer + maximum: 2147483647 + minimum: -2147483648 + nullable: true + industry: + nullable: true + title: Industry Type + oneOf: + - $ref: '#/components/schemas/IndustryEnum' + - $ref: '#/components/schemas/BlankEnum' + - $ref: '#/components/schemas/NullEnum' + skype_ID: + type: string + nullable: true + maxLength: 100 + required: + - assigned_to + - contacts + - lead_attachment + - teams + - title + NullEnum: + enum: + - null + OrgProfileCreate: + type: object + description: It is for creating organization + properties: + name: + type: string + maxLength: 255 + required: + - name + OrgProfileCreateRequest: + type: object + description: It is for creating organization + properties: + name: + type: string + minLength: 1 + maxLength: 255 + required: + - name + SocialLogin: + type: object + properties: + token: + type: string + required: + - token + SocialLoginRequest: + type: object + properties: + token: + type: string + minLength: 1 + required: + - token + SourceEnum: + enum: + - call + - email + - existing customer + - partner + - public relations + - compaign + - other + type: string + description: |- + * `call` - Call + * `email` - Email + * `existing customer` - Existing Customer + * `partner` - Partner + * `public relations` - Public Relations + * `compaign` - Campaign + * `other` - Other + StatusEnum: + enum: + - assigned + - in process + - converted + - recycled + - closed + type: string + description: |- + * `assigned` - Assigned + * `in process` - In Process + * `converted` - Converted + * `recycled` - Recycled + * `closed` - Closed + TeamswaggerCreateRequest: + type: object + properties: + name: + type: string + minLength: 1 + maxLength: 100 + description: + type: string + minLength: 1 + users: + type: array + items: + type: string + format: uuid + required: + - description + - name + - users + TokenRefresh: + type: object + properties: + access: + type: string + readOnly: true + required: + - access + TokenRefreshRequest: + type: object + properties: + refresh: + type: string + writeOnly: true + minLength: 1 + required: + - refresh + securitySchemes: + jwtAuth: + type: http + scheme: bearer + bearerFormat: JWT diff --git a/tasks/migrations/0001_initial.py b/tasks/migrations/0001_initial.py index 6153244b..1929aff3 100644 --- a/tasks/migrations/0001_initial.py +++ b/tasks/migrations/0001_initial.py @@ -1,8 +1,9 @@ -# Generated by Django 2.1.7 on 2019-05-07 10:38 +# Generated by Django 4.2.1 on 2023-06-19 13:08 -import django.db.models.deletion from django.conf import settings from django.db import migrations, models +import django.db.models.deletion +import uuid class Migration(migrations.Migration): @@ -10,75 +11,37 @@ class Migration(migrations.Migration): initial = True dependencies = [ - ("accounts", "0007_email"), + ('teams', '0001_initial'), + ('accounts', '0001_initial'), + ('common', '0001_initial'), migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ("contacts", "0003_merge_20190214_1427"), + ('contacts', '0001_initial'), ] operations = [ migrations.CreateModel( - name="Task", + name='Task', fields=[ - ( - "id", - models.AutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("title", models.CharField(max_length=200, verbose_name="title")), - ( - "status", - models.CharField( - choices=[ - ("New", "New"), - ("In Progress", "In Progress"), - ("Completed", "Completed"), - ], - max_length=50, - verbose_name="status", - ), - ), - ( - "priority", - models.CharField( - choices=[ - ("Low", "Low"), - ("Medium", "Medium"), - ("High", "High"), - ], - max_length=50, - verbose_name="priority", - ), - ), - ("due_date", models.DateField(blank=True, null=True)), - ( - "account", - models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="accounts_tasks", - to="accounts.Account", - ), - ), - ( - "assigned_to", - models.ManyToManyField( - related_name="users_tasks", to=settings.AUTH_USER_MODEL - ), - ), - ( - "contacts", - models.ManyToManyField( - related_name="contacts_tasks", to="contacts.Contact" - ), - ), + ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')), + ('updated_at', models.DateTimeField(auto_now=True, verbose_name='Last Modified At')), + ('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)), + ('title', models.CharField(max_length=200, verbose_name='title')), + ('status', models.CharField(choices=[('New', 'New'), ('In Progress', 'In Progress'), ('Completed', 'Completed')], max_length=50, verbose_name='status')), + ('priority', models.CharField(choices=[('Low', 'Low'), ('Medium', 'Medium'), ('High', 'High')], max_length=50, verbose_name='priority')), + ('due_date', models.DateField(blank=True, null=True)), + ('account', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='accounts_tasks', to='accounts.account')), + ('assigned_to', models.ManyToManyField(related_name='users_tasks', to='common.profile')), + ('contacts', models.ManyToManyField(related_name='contacts_tasks', to='contacts.contact')), + ('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='task_created', to='common.profile')), + ('org', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='task_org', to='common.org')), + ('teams', models.ManyToManyField(related_name='tasks_teams', to='teams.teams')), + ('updated_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_updated_by', to=settings.AUTH_USER_MODEL, verbose_name='Last Modified By')), ], options={ - "ordering": ["-due_date"], + 'verbose_name': 'Task', + 'verbose_name_plural': 'Tasks', + 'db_table': 'task', + 'ordering': ('-due_date',), }, ), ] diff --git a/tasks/migrations/0002_task_created_by.py b/tasks/migrations/0002_task_created_by.py deleted file mode 100644 index 67cb3790..00000000 --- a/tasks/migrations/0002_task_created_by.py +++ /dev/null @@ -1,27 +0,0 @@ -# Generated by Django 2.1.7 on 2019-05-08 10:10 - -import django.db.models.deletion -from django.conf import settings -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ("tasks", "0001_initial"), - ] - - operations = [ - migrations.AddField( - model_name="task", - name="created_by", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="task_created", - to=settings.AUTH_USER_MODEL, - ), - ), - ] diff --git a/tasks/migrations/0003_task_created_on.py b/tasks/migrations/0003_task_created_on.py deleted file mode 100644 index aeb19769..00000000 --- a/tasks/migrations/0003_task_created_on.py +++ /dev/null @@ -1,24 +0,0 @@ -# Generated by Django 2.2.2 on 2019-07-15 07:02 - -import django.utils.timezone -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("tasks", "0002_task_created_by"), - ] - - operations = [ - migrations.AddField( - model_name="task", - name="created_on", - field=models.DateTimeField( - auto_now_add=True, - default=django.utils.timezone.now, - verbose_name="Created on", - ), - preserve_default=False, - ), - ] diff --git a/tasks/migrations/0004_task_teams.py b/tasks/migrations/0004_task_teams.py deleted file mode 100644 index f0e9fec6..00000000 --- a/tasks/migrations/0004_task_teams.py +++ /dev/null @@ -1,19 +0,0 @@ -# Generated by Django 2.2.4 on 2019-09-17 05:46 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("teams", "0003_auto_20190909_1621"), - ("tasks", "0003_task_created_on"), - ] - - operations = [ - migrations.AddField( - model_name="task", - name="teams", - field=models.ManyToManyField(related_name="tasks_teams", to="teams.Teams"), - ), - ] diff --git a/tasks/migrations/0005_task_company.py b/tasks/migrations/0005_task_company.py deleted file mode 100644 index 3d17b241..00000000 --- a/tasks/migrations/0005_task_company.py +++ /dev/null @@ -1,25 +0,0 @@ -# Generated by Django 2.2.10 on 2020-04-27 12:23 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0021_document_company"), - ("tasks", "0004_task_teams"), - ] - - operations = [ - migrations.AddField( - model_name="task", - name="company", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - to="common.Company", - ), - ), - ] diff --git a/tasks/migrations/0006_remove_task_company.py b/tasks/migrations/0006_remove_task_company.py deleted file mode 100644 index bdf472d1..00000000 --- a/tasks/migrations/0006_remove_task_company.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 3.1.7 on 2021-03-24 08:25 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ("tasks", "0005_task_company"), - ] - - operations = [ - migrations.RemoveField( - model_name="task", - name="company", - ), - ] diff --git a/tasks/migrations/0007_auto_20210913_1918.py b/tasks/migrations/0007_auto_20210913_1918.py deleted file mode 100644 index 7b70d3d8..00000000 --- a/tasks/migrations/0007_auto_20210913_1918.py +++ /dev/null @@ -1,43 +0,0 @@ -# Generated by Django 3.2 on 2021-09-13 13:48 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0034_auto_20210913_1918"), - ("tasks", "0006_remove_task_company"), - ] - - operations = [ - migrations.AddField( - model_name="task", - name="company", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - to="common.company", - ), - ), - migrations.AlterField( - model_name="task", - name="assigned_to", - field=models.ManyToManyField( - related_name="users_tasks", to="common.Profile" - ), - ), - migrations.AlterField( - model_name="task", - name="created_by", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="task_created", - to="common.profile", - ), - ), - ] diff --git a/tasks/migrations/0008_rename_company_task_org.py b/tasks/migrations/0008_rename_company_task_org.py deleted file mode 100644 index df5d0bc6..00000000 --- a/tasks/migrations/0008_rename_company_task_org.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 3.2 on 2021-09-22 12:31 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ("tasks", "0007_auto_20210913_1918"), - ] - - operations = [ - migrations.RenameField( - model_name="task", - old_name="company", - new_name="org", - ), - ] diff --git a/tasks/migrations/0009_alter_task_org.py b/tasks/migrations/0009_alter_task_org.py deleted file mode 100644 index 18bc51b6..00000000 --- a/tasks/migrations/0009_alter_task_org.py +++ /dev/null @@ -1,26 +0,0 @@ -# Generated by Django 3.2.7 on 2021-10-06 07:21 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0037_alter_profile_org"), - ("tasks", "0008_rename_company_task_org"), - ] - - operations = [ - migrations.AlterField( - model_name="task", - name="org", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="task_org", - to="common.org", - ), - ), - ] diff --git a/tasks/models.py b/tasks/models.py index 4a647203..1578c694 100644 --- a/tasks/models.py +++ b/tasks/models.py @@ -3,12 +3,13 @@ from django.db import models from django.utils.translation import gettext_lazy as _ from accounts.models import Account +from common.base import BaseModel from common.models import Org, Profile from contacts.models import Contact from teams.models import Teams -class Task(models.Model): +class Task(BaseModel): STATUS_CHOICES = ( ("New", "New"), @@ -22,7 +23,6 @@ class Task(models.Model): status = models.CharField(_("status"), max_length=50, choices=STATUS_CHOICES) priority = models.CharField(_("priority"), max_length=50, choices=PRIORITY_CHOICES) due_date = models.DateField(blank=True, null=True) - created_on = models.DateTimeField(_("Created on"), auto_now_add=True) account = models.ForeignKey( Account, related_name="accounts_tasks", @@ -48,14 +48,17 @@ class Task(models.Model): ) class Meta: - ordering = ["-due_date"] + verbose_name = "Task" + verbose_name_plural = "Tasks" + db_table = "task" + ordering = ("-due_date",) def __str__(self): - return self.title - + return f"{self.title}" + @property def created_on_arrow(self): - return arrow.get(self.created_on).humanize() + return arrow.get(self.created_at).humanize() @property def get_team_users(self): diff --git a/tasks/serializer.py b/tasks/serializer.py index dee6c3d9..b0d399a4 100644 --- a/tasks/serializer.py +++ b/tasks/serializer.py @@ -1,7 +1,10 @@ from rest_framework import serializers -from common.serializer import (AttachmentsSerializer, CommentSerializer, - ProfileSerializer) +from common.serializer import ( + AttachmentsSerializer, + CommentSerializer, + ProfileSerializer, +) from contacts.serializer import ContactSerializer from tasks.models import Task from teams.serializer import TeamsSerializer @@ -67,3 +70,25 @@ class TaskCreateSerializer(serializers.ModelSerializer): "created_by", "created_on", ) + +class TaskDetailEditSwaggerSerializer(serializers.Serializer): + comment = serializers.CharField() + task_attachment = serializers.FileField() + +class TaskCommentEditSwaggerSerializer(serializers.Serializer): + comment = serializers.CharField() + +class TaskCreateSwaggerSerializer(serializers.ModelSerializer): + class Meta: + model = Task + fields = ( + "title", + "status", + "priority", + "due_date", + "account", + "contacts", + "teams", + "assigned_to" + ) + diff --git a/tasks/swagger_params.py b/tasks/swagger_params.py deleted file mode 100644 index 22993609..00000000 --- a/tasks/swagger_params.py +++ /dev/null @@ -1,51 +0,0 @@ -from drf_yasg import openapi - -organization_params_in_header = openapi.Parameter( - "org", openapi.IN_HEADER, required=True, type=openapi.TYPE_INTEGER -) - -organization_params = [ - organization_params_in_header, -] - -task_list_get_params = [ - organization_params_in_header, - openapi.Parameter("title", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("status", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("priority", openapi.IN_QUERY, type=openapi.TYPE_STRING), -] - -task_detail_post_params = [ - organization_params_in_header, - openapi.Parameter( - "task_attachment", - openapi.IN_QUERY, - type=openapi.TYPE_FILE, - ), - openapi.Parameter("comment", openapi.IN_QUERY, type=openapi.TYPE_STRING), -] - -task_create_post_params = [ - organization_params_in_header, - openapi.Parameter( - "title", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), - openapi.Parameter("status", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("priority", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter( - "due_date", openapi.IN_QUERY, type=openapi.FORMAT_DATE, example="2021-01-01" - ), - openapi.Parameter("account", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("contacts", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter( - "teams", - openapi.IN_QUERY, - type=openapi.TYPE_STRING, - ), - openapi.Parameter("assigned_to", openapi.IN_QUERY, type=openapi.TYPE_STRING), -] - -task_comment_edit_params = [ - organization_params_in_header, - openapi.Parameter("comment", openapi.IN_QUERY, type=openapi.TYPE_STRING), -] diff --git a/tasks/swagger_params1.py b/tasks/swagger_params1.py new file mode 100644 index 00000000..494aef2e --- /dev/null +++ b/tasks/swagger_params1.py @@ -0,0 +1,17 @@ +from drf_spectacular.types import OpenApiTypes +from drf_spectacular.utils import OpenApiParameter + +organization_params_in_header = organization_params_in_header = OpenApiParameter( + "org", OpenApiTypes.STR, OpenApiParameter.HEADER +) + +organization_params = [ + organization_params_in_header, +] + +task_list_get_params = [ + organization_params_in_header, + OpenApiParameter("title", OpenApiTypes.STR,OpenApiParameter.QUERY), + OpenApiParameter("status", OpenApiTypes.STR,OpenApiParameter.QUERY), + OpenApiParameter("priority", OpenApiTypes.STR,OpenApiParameter.QUERY), +] diff --git a/tasks/views.py b/tasks/views.py index 142a144e..724c22d2 100644 --- a/tasks/views.py +++ b/tasks/views.py @@ -1,7 +1,7 @@ import json from django.db.models import Q -from drf_yasg.utils import swagger_auto_schema +from drf_spectacular.utils import OpenApiExample, OpenApiParameter, extend_schema from rest_framework import status from rest_framework.pagination import LimitOffsetPagination from rest_framework.permissions import IsAuthenticated @@ -20,9 +20,9 @@ from common.serializer import ( ) from contacts.models import Contact from contacts.serializer import ContactSerializer -from tasks import swagger_params +from tasks import swagger_params1 from tasks.models import Task -from tasks.serializer import TaskCreateSerializer, TaskSerializer +from tasks.serializer import * from tasks.utils import PRIORITY_CHOICES, STATUS_CHOICES from teams.models import Teams from teams.serializer import TeamsSerializer @@ -34,10 +34,10 @@ class TaskListView(APIView, LimitOffsetPagination): permission_classes = (IsAuthenticated,) def get_context_data(self, **kwargs): - params = self.request.post_data - queryset = self.model.objects.filter(org=self.request.org).order_by("-id") - accounts = Account.objects.filter(org=self.request.org) - contacts = Contact.objects.filter(org=self.request.org) + params = self.request.query_params + queryset = self.model.objects.filter(org=self.request.profile.org).order_by("-id") + accounts = Account.objects.filter(org=self.request.profile.org) + contacts = Contact.objects.filter(org=self.request.profile.org) if self.request.profile.role != "ADMIN" and not self.request.profile.is_admin: queryset = queryset.filter( Q(assigned_to__in=[self.request.profile]) @@ -81,39 +81,39 @@ class TaskListView(APIView, LimitOffsetPagination): context["contacts_list"] = ContactSerializer(contacts, many=True).data return context - @swagger_auto_schema( - tags=["Tasks"], manual_parameters=swagger_params.task_list_get_params + @extend_schema( + tags=["Tasks"], parameters=swagger_params1.task_list_get_params ) def get(self, request, *args, **kwargs): context = self.get_context_data(**kwargs) return Response(context) - @swagger_auto_schema( - tags=["Tasks"], manual_parameters=swagger_params.task_create_post_params + @extend_schema( + tags=["Tasks"], parameters=swagger_params1.organization_params,request=TaskCreateSwaggerSerializer ) def post(self, request, *args, **kwargs): - params = request.post_data + params = request.data serializer = TaskCreateSerializer(data=params, request_obj=request) if serializer.is_valid(): task_obj = serializer.save( created_by=request.profile, due_date=params.get("due_date"), - org=request.org, + org=request.profile.org, ) if params.get("contacts"): contacts_list = json.loads(params.get("contacts")) - contacts = Contact.objects.filter(id__in=contacts_list, org=request.org) + contacts = Contact.objects.filter(id__in=contacts_list, org=request.profile.org) task_obj.contacts.add(*contacts) if params.get("teams"): teams_list = json.loads(params.get("teams")) - teams = Teams.objects.filter(id__in=teams_list, org=request.org) + teams = Teams.objects.filter(id__in=teams_list, org=request.profile.org) task_obj.teams.add(*teams) if params.get("assigned_to"): assinged_to_list = json.loads(params.get("assigned_to")) profiles = Profile.objects.filter( - id__in=assinged_to_list, org=request.org, is_active=True + id__in=assinged_to_list, org=request.profile.org, is_active=True ) task_obj.assigned_to.add(*profiles) @@ -159,22 +159,22 @@ class TaskDetailView(APIView): if self.request.profile.is_admin or self.request.profile.role == "ADMIN": users_mention = list( - Profile.objects.filter(is_active=True, org=self.request.org).values( - "user__username" + Profile.objects.filter(is_active=True, org=self.request.profile.org).values( + "user__email" ) ) elif self.request.profile != self.task_obj.created_by: - users_mention = [{"username": self.task_obj.created_by.user.username}] + users_mention = [{"username": self.task_obj.created_by.user.email}] else: users_mention = list( - self.task_obj.assigned_to.all().values("user__username") + self.task_obj.assigned_to.all().values("user__email") ) if self.request.profile.role == "ADMIN" or self.request.profile.is_admin: users = Profile.objects.filter( - is_active=True, org=self.request.org + is_active=True, org=self.request.profile.org ).order_by("user__email") else: - users = Profile.objects.filter(role="ADMIN", org=self.request.org).order_by( + users = Profile.objects.filter(role="ADMIN", org=self.request.profile.org).order_by( "user__email" ) @@ -209,19 +209,19 @@ class TaskDetailView(APIView): context["teams"] = TeamsSerializer(Teams.objects.all(), many=True).data return context - @swagger_auto_schema( - tags=["Tasks"], manual_parameters=swagger_params.organization_params + @extend_schema( + tags=["Tasks"], parameters=swagger_params1.organization_params ) def get(self, request, pk, **kwargs): self.task_obj = self.get_object(pk) context = self.get_context_data(**kwargs) return Response(context) - @swagger_auto_schema( - tags=["Tasks"], manual_parameters=swagger_params.task_detail_post_params + @extend_schema( + tags=["Tasks"], parameters=swagger_params1.organization_params,request=TaskDetailEditSwaggerSerializer ) def post(self, request, pk, **kwargs): - params = request.post_data + params = request.data context = {} self.task_obj = Task.objects.get(pk=pk) if self.request.profile.role != "ADMIN" and not self.request.profile.is_admin: @@ -265,11 +265,11 @@ class TaskDetailView(APIView): ) return Response(context) - @swagger_auto_schema( - tags=["Tasks"], manual_parameters=swagger_params.task_create_post_params + @extend_schema( + tags=["Tasks"], parameters=swagger_params1.organization_params,request=TaskCreateSwaggerSerializer ) def put(self, request, pk, **kwargs): - params = request.post_data + params = request.data self.task_obj = self.get_object(pk) serializer = TaskCreateSerializer( data=params, @@ -284,20 +284,20 @@ class TaskDetailView(APIView): task_obj.contacts.clear() if params.get("contacts"): contacts_list = json.loads(params.get("contacts")) - contacts = Contact.objects.filter(id__in=contacts_list, org=request.org) + contacts = Contact.objects.filter(id__in=contacts_list, org=request.profile.org) task_obj.contacts.add(*contacts) task_obj.teams.clear() if params.get("teams"): teams_list = json.loads(params.get("teams")) - teams = Teams.objects.filter(id__in=teams_list, org=request.org) + teams = Teams.objects.filter(id__in=teams_list, org=request.profile.org) task_obj.teams.add(*teams) task_obj.assigned_to.clear() if params.get("assigned_to"): assinged_to_list = json.loads(params.get("assigned_to")) profiles = Profile.objects.filter( - id__in=assinged_to_list, org=request.org, is_active=True + id__in=assinged_to_list, org=request.profile.org, is_active=True ) task_obj.assigned_to.add(*profiles) @@ -310,8 +310,8 @@ class TaskDetailView(APIView): status=status.HTTP_400_BAD_REQUEST, ) - @swagger_auto_schema( - tags=["Tasks"], manual_parameters=swagger_params.organization_params + @extend_schema( + tags=["Tasks"], parameters=swagger_params1.organization_params ) def delete(self, request, pk, **kwargs): self.object = self.get_object(pk) @@ -339,11 +339,11 @@ class TaskCommentView(APIView): def get_object(self, pk): return self.model.objects.get(pk=pk) - @swagger_auto_schema( - tags=["Tasks"], manual_parameters=swagger_params.task_comment_edit_params + @extend_schema( + tags=["Tasks"], parameters=swagger_params1.organization_params,request=TaskCommentEditSwaggerSerializer ) def put(self, request, pk, format=None): - params = request.post_data + params = request.data obj = self.get_object(pk) if ( request.profile.role == "ADMIN" @@ -371,8 +371,8 @@ class TaskCommentView(APIView): status=status.HTTP_403_FORBIDDEN, ) - @swagger_auto_schema( - tags=["Tasks"], manual_parameters=swagger_params.organization_params + @extend_schema( + tags=["Tasks"], parameters=swagger_params1.organization_params ) def delete(self, request, pk, format=None): self.object = self.get_object(pk) @@ -400,8 +400,8 @@ class TaskAttachmentView(APIView): # authentication_classes = (JSONWebTokenAuthentication,) permission_classes = (IsAuthenticated,) - @swagger_auto_schema( - tags=["Tasks"], manual_parameters=swagger_params.organization_params + @extend_schema( + tags=["Tasks"], parameters=swagger_params1.organization_params ) def delete(self, request, pk, format=None): self.object = self.model.objects.get(pk=pk) diff --git a/teams/migrations/0001_initial.py b/teams/migrations/0001_initial.py index 950c5054..37a5f807 100644 --- a/teams/migrations/0001_initial.py +++ b/teams/migrations/0001_initial.py @@ -1,7 +1,9 @@ -# Generated by Django 2.2.2 on 2019-06-24 06:27 +# Generated by Django 4.2.1 on 2023-06-19 13:08 from django.conf import settings from django.db import migrations, models +import django.db.models.deletion +import uuid class Migration(migrations.Migration): @@ -9,30 +11,30 @@ class Migration(migrations.Migration): initial = True dependencies = [ + ('common', '0001_initial'), migrations.swappable_dependency(settings.AUTH_USER_MODEL), ] operations = [ migrations.CreateModel( - name="Teams", + name='Teams', fields=[ - ( - "id", - models.AutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("name", models.CharField(max_length=100)), - ("description", models.TextField()), - ( - "users", - models.ManyToManyField( - related_name="user_teams", to=settings.AUTH_USER_MODEL - ), - ), + ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')), + ('updated_at', models.DateTimeField(auto_now=True, verbose_name='Last Modified At')), + ('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)), + ('name', models.CharField(max_length=100)), + ('description', models.TextField()), + ('created_on', models.DateTimeField(auto_now_add=True, verbose_name='Created on')), + ('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='teams_created', to='common.profile')), + ('org', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='common.org')), + ('updated_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_updated_by', to=settings.AUTH_USER_MODEL, verbose_name='Last Modified By')), + ('users', models.ManyToManyField(related_name='user_teams', to='common.profile')), ], + options={ + 'verbose_name': 'Team', + 'verbose_name_plural': 'Teams', + 'db_table': 'eams', + 'ordering': ('-created_at',), + }, ), ] diff --git a/teams/migrations/0002_alter_teams_table.py b/teams/migrations/0002_alter_teams_table.py new file mode 100644 index 00000000..e4fe82d4 --- /dev/null +++ b/teams/migrations/0002_alter_teams_table.py @@ -0,0 +1,17 @@ +# Generated by Django 4.2.1 on 2023-07-12 09:52 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('teams', '0001_initial'), + ] + + operations = [ + migrations.AlterModelTable( + name='teams', + table='teams', + ), + ] diff --git a/teams/migrations/0002_auto_20190624_1250.py b/teams/migrations/0002_auto_20190624_1250.py deleted file mode 100644 index 689d06ea..00000000 --- a/teams/migrations/0002_auto_20190624_1250.py +++ /dev/null @@ -1,38 +0,0 @@ -# Generated by Django 2.2.2 on 2019-06-24 07:20 - -import django.db.models.deletion -import django.utils.timezone -from django.conf import settings -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ("teams", "0001_initial"), - ] - - operations = [ - migrations.AddField( - model_name="teams", - name="created_by", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="teams_created", - to=settings.AUTH_USER_MODEL, - ), - ), - migrations.AddField( - model_name="teams", - name="created_on", - field=models.DateTimeField( - auto_now_add=True, - default=django.utils.timezone.now, - verbose_name="Created on", - ), - preserve_default=False, - ), - ] diff --git a/teams/migrations/0003_alter_teams_created_by.py b/teams/migrations/0003_alter_teams_created_by.py new file mode 100644 index 00000000..8acdbecc --- /dev/null +++ b/teams/migrations/0003_alter_teams_created_by.py @@ -0,0 +1,21 @@ +# Generated by Django 4.2.1 on 2023-07-24 08:19 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('teams', '0002_alter_teams_table'), + ] + + operations = [ + migrations.AlterField( + model_name='teams', + name='created_by', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_created_by', to=settings.AUTH_USER_MODEL, verbose_name='Created By'), + ), + ] diff --git a/teams/migrations/0003_auto_20190909_1621.py b/teams/migrations/0003_auto_20190909_1621.py deleted file mode 100644 index 39f07e44..00000000 --- a/teams/migrations/0003_auto_20190909_1621.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 2.2.4 on 2019-09-09 10:51 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ("teams", "0002_auto_20190624_1250"), - ] - - operations = [ - migrations.AlterModelOptions( - name="teams", - options={"ordering": ("id",)}, - ), - ] diff --git a/teams/migrations/0004_teams_company.py b/teams/migrations/0004_teams_company.py deleted file mode 100644 index 53406fc6..00000000 --- a/teams/migrations/0004_teams_company.py +++ /dev/null @@ -1,25 +0,0 @@ -# Generated by Django 2.2.10 on 2020-04-24 09:26 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0020_auto_20200409_1653"), - ("teams", "0003_auto_20190909_1621"), - ] - - operations = [ - migrations.AddField( - model_name="teams", - name="company", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - to="common.Company", - ), - ), - ] diff --git a/teams/migrations/0005_remove_teams_company.py b/teams/migrations/0005_remove_teams_company.py deleted file mode 100644 index 1550c468..00000000 --- a/teams/migrations/0005_remove_teams_company.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 3.1.7 on 2021-03-23 16:20 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ("teams", "0004_teams_company"), - ] - - operations = [ - migrations.RemoveField( - model_name="teams", - name="company", - ), - ] diff --git a/teams/migrations/0006_auto_20210913_1918.py b/teams/migrations/0006_auto_20210913_1918.py deleted file mode 100644 index 7c2eb0a1..00000000 --- a/teams/migrations/0006_auto_20210913_1918.py +++ /dev/null @@ -1,43 +0,0 @@ -# Generated by Django 3.2 on 2021-09-13 13:48 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("common", "0034_auto_20210913_1918"), - ("teams", "0005_remove_teams_company"), - ] - - operations = [ - migrations.AddField( - model_name="teams", - name="company", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - to="common.company", - ), - ), - migrations.AlterField( - model_name="teams", - name="created_by", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="teams_created", - to="common.profile", - ), - ), - migrations.AlterField( - model_name="teams", - name="users", - field=models.ManyToManyField( - related_name="user_teams", to="common.Profile" - ), - ), - ] diff --git a/teams/migrations/0007_rename_company_teams_org.py b/teams/migrations/0007_rename_company_teams_org.py deleted file mode 100644 index b8e32dae..00000000 --- a/teams/migrations/0007_rename_company_teams_org.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 3.2 on 2021-09-22 12:31 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ("teams", "0006_auto_20210913_1918"), - ] - - operations = [ - migrations.RenameField( - model_name="teams", - old_name="company", - new_name="org", - ), - ] diff --git a/teams/models.py b/teams/models.py index 710e9251..41dc6f31 100644 --- a/teams/models.py +++ b/teams/models.py @@ -3,28 +3,26 @@ from django.db import models from django.utils.translation import gettext_lazy as _ from common.models import Org, Profile +from common.base import BaseModel -class Teams(models.Model): + +class Teams(BaseModel): name = models.CharField(max_length=100) description = models.TextField() users = models.ManyToManyField(Profile, related_name="user_teams") created_on = models.DateTimeField(_("Created on"), auto_now_add=True) - created_by = models.ForeignKey( - Profile, - related_name="teams_created", - blank=True, - null=True, - on_delete=models.SET_NULL, - ) org = models.ForeignKey(Org, on_delete=models.SET_NULL, null=True, blank=True) class Meta: - ordering = ("id",) + verbose_name = "Team" + verbose_name_plural = "Teams" + db_table = "teams" + ordering = ("-created_at",) def __str__(self): - return self.name - + return f"{self.name}" + @property def created_on_arrow(self): return arrow.get(self.created_on).humanize() diff --git a/teams/serializer.py b/teams/serializer.py index d2e868f0..0d122d6a 100644 --- a/teams/serializer.py +++ b/teams/serializer.py @@ -22,10 +22,11 @@ class TeamsSerializer(serializers.ModelSerializer): class TeamCreateSerializer(serializers.ModelSerializer): + def __init__(self, *args, **kwargs): request_obj = kwargs.pop("request_obj", None) super().__init__(*args, **kwargs) - self.org = request_obj.org + self.org = request_obj.profile.org self.fields["name"].required = True self.fields["description"].required = False @@ -53,3 +54,14 @@ class TeamCreateSerializer(serializers.ModelSerializer): "created_on_arrow", "org", ) + +class TeamswaggerCreateSerializer(serializers.ModelSerializer): + + + class Meta: + model = Teams + fields = ( + "name", + "description", + "users", + ) \ No newline at end of file diff --git a/teams/swagger_params.py b/teams/swagger_params.py deleted file mode 100644 index 7c2e84b9..00000000 --- a/teams/swagger_params.py +++ /dev/null @@ -1,27 +0,0 @@ -from drf_yasg import openapi - -organization_params_in_header = openapi.Parameter( - "org", openapi.IN_HEADER, required=True, type=openapi.TYPE_INTEGER -) - -organization_params = [ - organization_params_in_header, -] - -teams_list_get_params = [ - organization_params_in_header, - openapi.Parameter("team_name", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("created_by", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter("assigned_users", openapi.IN_QUERY, type=openapi.TYPE_STRING), -] - -teams_create_post_params = [ - organization_params_in_header, - openapi.Parameter( - "name", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), - openapi.Parameter("description", openapi.IN_QUERY, type=openapi.TYPE_STRING), - openapi.Parameter( - "assign_users", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING - ), -] diff --git a/teams/swagger_params1.py b/teams/swagger_params1.py new file mode 100644 index 00000000..7f146a42 --- /dev/null +++ b/teams/swagger_params1.py @@ -0,0 +1,17 @@ +from drf_spectacular.types import OpenApiTypes +from drf_spectacular.utils import OpenApiParameter + +organization_params_in_header = organization_params_in_header = OpenApiParameter( + "org", OpenApiTypes.STR, OpenApiParameter.HEADER +) + +organization_params = [ + organization_params_in_header, +] + +teams_list_get_params = [ + organization_params_in_header, + OpenApiParameter("team_name", OpenApiTypes.STR,OpenApiParameter.QUERY), + OpenApiParameter("created_by", OpenApiTypes.STR,OpenApiParameter.QUERY), + OpenApiParameter("assigned_users", OpenApiTypes.STR,OpenApiParameter.QUERY), +] diff --git a/teams/views.py b/teams/views.py index 88e5d90c..7d3cdf18 100644 --- a/teams/views.py +++ b/teams/views.py @@ -1,6 +1,5 @@ import json - -from drf_yasg.utils import swagger_auto_schema +from drf_spectacular.utils import OpenApiExample, OpenApiParameter, extend_schema # from common.custom_auth import JSONWebTokenAuthentication from rest_framework import status @@ -10,9 +9,9 @@ from rest_framework.response import Response from rest_framework.views import APIView from common.models import Profile -from teams import swagger_params +from teams import swagger_params1 from teams.models import Teams -from teams.serializer import TeamCreateSerializer, TeamsSerializer +from teams.serializer import TeamCreateSerializer, TeamsSerializer,TeamswaggerCreateSerializer from teams.tasks import remove_users, update_team_users @@ -22,8 +21,8 @@ class TeamsListView(APIView, LimitOffsetPagination): permission_classes = (IsAuthenticated,) def get_context_data(self, **kwargs): - params = self.request.post_data - queryset = self.model.objects.filter(org=self.request.org).order_by("-id") + params = self.request.query_params + queryset = self.model.objects.filter(org=self.request.profile.org).order_by("-id") if params: if params.get("team_name"): queryset = queryset.filter(name__icontains=params.get("team_name")) @@ -52,10 +51,10 @@ class TeamsListView(APIView, LimitOffsetPagination): context["teams"] = teams return context - @swagger_auto_schema( - tags=["Teams"], manual_parameters=swagger_params.teams_list_get_params + @extend_schema( + tags=["Teams"], parameters=swagger_params1.teams_list_get_params ) - def get(self, request, *args, **kwargs): + def get(self, *args, **kwargs): if self.request.profile.role != "ADMIN" and not self.request.profile.is_admin: return Response( { @@ -67,8 +66,8 @@ class TeamsListView(APIView, LimitOffsetPagination): context = self.get_context_data(**kwargs) return Response(context) - @swagger_auto_schema( - tags=["Teams"], manual_parameters=swagger_params.teams_create_post_params + @extend_schema( + tags=["Teams"], request=TeamswaggerCreateSerializer,parameters=swagger_params1.organization_params ) def post(self, request, *args, **kwargs): if self.request.profile.role != "ADMIN" and not self.request.profile.is_admin: @@ -79,16 +78,16 @@ class TeamsListView(APIView, LimitOffsetPagination): }, status=status.HTTP_403_FORBIDDEN, ) - params = request.post_data - + params = self.request.data + print(request,self.request) serializer = TeamCreateSerializer(data=params, request_obj=request) if serializer.is_valid(): - team_obj = serializer.save(created_by=request.profile, org=request.org) + team_obj = serializer.save(org=request.profile.org) if params.get("assign_users"): - assinged_to_list = json.loads(params.get("assign_users")) + assinged_to_list = json.loads(params.get("users")) profiles = Profile.objects.filter( - id__in=assinged_to_list, org=request.org + id__in=assinged_to_list, org=request.profile.org ) if profiles: team_obj.users.add(*profiles) @@ -108,10 +107,10 @@ class TeamsDetailView(APIView): permission_classes = (IsAuthenticated,) def get_object(self, pk): - return self.model.objects.get(pk=pk, org=self.request.org) + return self.model.objects.get(pk=pk, org=self.request.profile.org) - @swagger_auto_schema( - tags=["Teams"], manual_parameters=swagger_params.organization_params + @extend_schema( + tags=["Teams"], parameters=swagger_params1.organization_params ) def get(self, request, pk, **kwargs): if self.request.profile.role != "ADMIN" and not self.request.profile.is_admin: @@ -127,8 +126,8 @@ class TeamsDetailView(APIView): context["team"] = TeamsSerializer(self.team_obj).data return Response(context) - @swagger_auto_schema( - tags=["Teams"], manual_parameters=swagger_params.teams_create_post_params + @extend_schema( + tags=["Teams"], request=TeamswaggerCreateSerializer,parameters=swagger_params1.organization_params ) def put(self, request, pk, *args, **kwargs): if self.request.profile.role != "ADMIN" and not self.request.profile.is_admin: @@ -139,7 +138,7 @@ class TeamsDetailView(APIView): }, status=status.HTTP_403_FORBIDDEN, ) - params = request.post_data + params = request.data self.team = self.get_object(pk) actual_users = self.team.get_users() removed_users = [] @@ -153,7 +152,7 @@ class TeamsDetailView(APIView): if params.get("assign_users"): assinged_to_list = json.loads(params.get("assign_users")) profiles = Profile.objects.filter( - id__in=assinged_to_list, org=request.org + id__in=assinged_to_list, org=request.profile.org ) if profiles: team_obj.users.add(*profiles) @@ -172,8 +171,8 @@ class TeamsDetailView(APIView): status=status.HTTP_400_BAD_REQUEST, ) - @swagger_auto_schema( - tags=["Teams"], manual_parameters=swagger_params.organization_params + @extend_schema( + tags=["Teams"], parameters=swagger_params1.organization_params ) def delete(self, request, pk, **kwargs): if self.request.profile.role != "ADMIN" and not self.request.profile.is_admin: