This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Customer(models.Model): | |
... | |
customer_types = ( | |
(1, "Prospect"), | |
(2, "Lead"), | |
(3, "Customer"), | |
) | |
type = models.IntegerField(choices=customer_types, default=1) | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Migration(migrations.Migration): | |
initial = True | |
dependencies = [ | |
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | |
] | |
operations = [ | |
migrations.CreateModel( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.management.base import BaseCommand | |
from django.apps import apps | |
from tqdm import tqdm | |
class Command(BaseCommand): | |
help = 'Drops table data from a specified app name' | |
def add_arguments(self, parser): | |
parser.add_argument('--app', type=str, help='The app name you wish to truncate the data from all models!') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myApp.component('users', { | |
bindings: { | |
users: '<' | |
}, | |
template: '<ul class="list-group"><user ng-repeat="user in ctrl.users" user="user"></user></ul>', | |
controllerAs: 'ctrl', | |
controller: function(userService) { | |
if (userService.checkRole()) { | |
this.admin = true; | |
} else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db.models.signals import post_save | |
from django.dispatch import receiver | |
from .models import * | |
import pika | |
import json | |
@receiver(post_save, sender=Customer) | |
def send_welcome_email(sender, instance, created, *args, **kwargs): | |
if created: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib import admin | |
from .models import * | |
class CustomerAdmin(admin.ModelAdmin): | |
list_display = ['first_name', 'last_name', 'email', 'welcome_email_sent'] | |
list_display_links = ['first_name', 'last_name'] | |
admin.site.register(Customer, CustomerAdmin) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def csv_file_from_list(self, headers: list, data: list, single_record_indicator=False): | |
""" | |
Creates and stores a CSV, rather than use a queryset it uses a list | |
:param headers | |
:param data | |
:param single_record_indicator | |
:return: list | |
""" | |
file_path = os.path.join(os.path.abspath(os.path.dirname("__file__")), "store", "csv", self.file_name) | |
with open(file_path, 'w') as file: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.views.generic.base import View | |
from django.db.models import QuerySet | |
from django.http import HttpResponse | |
from .generate import Generate | |
from io import BytesIO | |
from zipfile import ZipFile, ZIP_DEFLATED | |
from django.db.utils import DEFAULT_DB_ALIAS | |
from django.contrib.admin.utils import NestedObjects | |
from random import randint | |
import os |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def generate_csv(self, request, columns: list=None): | |
""" | |
View to handle logic to determine if mixin properties are set and perform actions on said properties, | |
kept in seperate method to keep "method" methods cleaner | |
:param request: | |
:return: | |
""" | |
if self.custom_queryset: | |
if columns is None: | |
csv_props = Generate(request, cls=None).csv_file(headers=self.custom_headers, data=self.custom_queryset) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def csv_file_custom_columns(self, headers: list, data: QuerySet, columns: list=None): | |
""" | |
Creates and stores a CSV, with a custom selection of columns | |
:param headers | |
:param data | |
:param columns | |
:return: list | |
""" | |
file_path = os.path.join(os.path.abspath(os.path.dirname("__file__")), "store", "csv", self.file_name) | |
with open(file_path, 'w') as file: |