Skip to content

Instantly share code, notes, and snippets.

André Duarte clint74

Block or report user

Report or block clint74

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View admin.py
# Using django import_export with transactions
# the whole was about 40 minutes before change, now 5 minutes.
from import_export.utils import atomic_if_using_transaction
from django.db import connections, DEFAULT_DB_ALIAS
from django.core.exceptions import ImproperlyConfigured
class PubliResource(resources.ModelResource):
use_transactions_in_dry_run = False # <=====
View crud-api-admin.py
from django.contrib import admin
from .models import Cliente, Funcionario
admin.site.register(Cliente)
admin.site.register(Funcionario)
View gist:2982dbda31d0a302581b4d83f21a6740
# Tabela domain
MariaDB [opensips]> desc domain;
+---------------+------------------+------+-----+---------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+------------------+------+-----+---------------------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| domain | char(64) | NO | UNI | | |
| attrs | char(255) | YES | | NULL | |
| created_at | datetime | YES | | NULL | |
| last_modified | datetime | NO | | 1900-01-01 00:00:01 | |
View reset_database_migrations.sh
#!/bin/sh
#remove migrations files
find .. -path "*/migrations/*.py" -not -name "__init__.py" -delete
find .. -path "*/migrations/*.pyc" -delete
#delete records from migrations table
psql -d <nome_projeto> -c 'delete from django_migrations;'
#create migrations again
View robots.py
import platform
import requests
from time import sleep
import os
import sys
from contextlib import contextmanager
from os import mkdir, getcwd
from selenium import webdriver
from PIL import Image
from selenium.webdriver.chrome.options import Options
View login.py
from django.http import HttpResponse, HttpResponseRedirect
from django.contrib.auth import authenticate, login
def login(request):
if request.POST:
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user is not None:
View quasar-vue-mask.vue
<template>
<q-page>
<q-input
float-label="CNPJ/CPF BR"
v-mask="['###.###.###-##', '##.###.###/####-##']"
placeholder="only numbers"
v-model="form.cpfCnpj"
</q-input>
</q-page>
</template>
@clint74
clint74 / cron_django_task_script.py
Created Aug 29, 2018
Run cron task in your Django environment
View cron_django_task_script.py
#!/home/andre/.virtualenvs/myproject/bin/python
import os
import sys
DEBUG = False
#DEBUG = True
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
View scripts.html
{% load staticfiles %}
<script type="text/javascript" src="{% static 'js/jquery-3.3.1.slim.min.js' %}"></script>
<script type="text/javascript" src="{% static 'js/popper.min.js' %}"></script>
<script type="text/javascript" src="{% static 'js/bootstrap.min.js' %}"></script>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.13/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue-resource@1.3.5"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
View form.py
from django import forms
from advertisement.models import Advertisement, Category
class AdvertisementForm(forms.ModelForm):
class Meta:
model = Advertisement
fields = [
'title',
You can’t perform that action at this time.