Skip to content

Instantly share code, notes, and snippets.

View elcolie's full-sized avatar

El 李天宝 elcolie

View GitHub Profile
$(function() {
var resultCollector = Quagga.ResultCollector.create({
capture: true,
capacity: 20,
blacklist: [{code: "2167361334", format: "i2of5"}],
filter: function(codeResult) {
// only store results which match this constraint
// e.g.: codeResult
return true;
}
import functools
@functools.total_ordering
class GIRow:
def __init__(self, dmd_name: str, md_name: str, rtr_name: str,
province: str, district: str, sub_district: str, address: str, node_type: str, node_alive: bool, imei: str,
goodsmovement_dt: str, active_user: str, user_node: str, profile_name: str, product_code: str):
self.dmd_name = dmd_name
self.md_name = md_name
self.rtr_name = rtr_name
self.province = province
class Location(models.Model):
mac = models.CharField(max_length=17)
timestamp = models.DateTimeField()
floor_number = models.PositiveSmallIntegerField()
x = models.IntegerField()
y = models.IntegerField()
located_inside = models.BooleanField()
zones = JSONField()
class MemberToMac(models.Model):
@elcolie
elcolie / models.py
Created September 26, 2017 12:08
models.py
from django.db import models
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _
class AbstractTimeStampMarker(models.Model):
created_at = models.DateTimeField(auto_now_add=True, verbose_name=_("Created at"))
updated_at = models.DateTimeField(auto_now=True, verbose_name=_("Updated at"))
class Meta:
@elcolie
elcolie / serializers.py
Created September 26, 2017 12:09
serializers.py
from soken_web.apps.uploaded_files.models import CustomerFromExcel
from rest_framework import serializers
class ModelControllerSerializer(serializers.ModelSerializer):
class Meta:
abstract = True
def create(self, validated_data):
@elcolie
elcolie / viewsets.py
Created September 26, 2017 12:09
viewsets.py
from rest_framework import status
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from soken_web.apps.uploaded_files.api.serializers import CustomerFromExcelSerializer
from soken_web.apps.uploaded_files.models import CustomerFromExcel
class CustomerFromExcelViewset(ModelViewSet):
queryset = CustomerFromExcel.objects.all()
from django.db import models
from django.utils.translation import ugettext_lazy as _
from model_controller.models import AbstractModelController
from django.contrib.auth.models import User
class AbstractTimeStampMarker(models.Model):
created_at = models.DateTimeField(auto_now_add=True, verbose_name=_("Created at"))
updated_at = models.DateTimeField(auto_now=True, verbose_name=_("Updated at"))
from django.contrib import admin
from django.contrib.auth.models import User
from import_export import resources, fields, widgets
from import_export.admin import ImportExportMixin
from model_controller.admins import ModelControllerAdmin
from reversion.admin import VersionAdmin
from soken_web.apps.zipcodes.models import ZIPCodeAddress, ZIPCodeAddressImportExport
ZIPCODE_BASIC_FIELDS = [
import logging
from soken_web.apps.shops.api.serializers import ShopSerializer
from soken_web.apps.userprofiles.api.serializers import UserProfileSerializer
from soken_web.apps.userprofiles.models import UserProfile
logger = logging.getLogger('django')
# token.py
@elcolie
elcolie / tests.py
Created October 6, 2017 09:30
Workable patch by using RESTful
def test_mobile_update_customer(self):
user = User.objects.create(username='warhead')
self.client.force_authenticate(user=user)
mommy.make(Customer, family_name='IBM', created_user=self.soken_staff, updated_user=self.soken_staff)
data = {
"family_name": "C0D1UM"
}
customer = Customer.objects.first()
res = self.client.patch(reverse('api:customer-detail', kwargs={'pk': customer.id}), data=data)
self.assertEqual(200, res.status_code)