예제 #1
0
    def dehydrate(self, bundle):
        """
        Implements the dehydrate method to manipulate data
        before it is returned to the client
        """
        #Checks if the country is set
        bundle = self._set_country(bundle)
           
        #Adds the quantity to the data field
        bundle.data['quantity'] = bundle.obj.quantity
             
        #Replaces custom-type with type after supply creation
        if "custom-type" in bundle.data:
            bundle.data['type'] = bundle.obj.type
            del bundle.data['custom-type']
        
        #Dehydrates the suppliers information if 
        #requesting a single resource, if creating a new resource
        #or updating a single resource
        if re.search("api/v1/supply/(w+\-)?\d+", bundle.request.path) or bundle.request.method == 'POST' or bundle.request.method == 'PUT':
            bundle.data['suppliers'] = [self.dehydrate_supplier(bundle, supplier) for supplier in bundle.obj.suppliers.all()]

            if not bundle.obj.sticker:
                sticker_page = StickerPage(code="DRS-{0}".format(bundle.obj.id), 
                                           description=bundle.obj.description)
                filename = sticker_page.create("DRS-{0}".format(bundle.obj.id))    
                stickers = S3Object.create(filename, 
                                           "supplies/stickers/{0}".format(filename), 
                                           'document.dellarobbiathailand.com', 
                                           encrypt_key=True)
                bundle.obj.sticker = stickers
                bundle.obj.save()
                
            bundle.data['sticker'] = {'url':bundle.obj.sticker.generate_url()}
        #If getting a list
        else:
            bundle.data['suppliers'] = [{'name': supplier.name,
                                         'id': supplier.id} for supplier in bundle.obj.suppliers.all()]
        
        #Merging product data from a supplier with the resource
        #if gettings supplies for a single supplier
        if bundle.request.GET.has_key('supplier_id'):
            
            #Set the supply's supplier to using 
            #objects internals to get info
            bundle.obj.supplier = Supplier.objects.get(pk=bundle.request.GET.get('supplier_id'))
            bundle.data.update({'purchasing_units': bundle.obj.purchasing_units,
                                'cost': bundle.obj.cost,
                                'reference': bundle.obj.reference,
                                'lead_time': bundle.obj.lead_time,
                                'upc': bundle.obj.upc})
        if bundle.obj.image:
            try:
                bundle.data['image'] = {'id': bundle.obj.image.id,
                                        'url': bundle.obj.image.generate_url(3600)}
            except (AttributeError, KeyError) as e:
                logger.warn(e)
        logger.debug(bundle.data)
        return bundle
예제 #2
0
 def create_stickers(self, key, secret):
     sticker_page = StickerPage(code="DRS-{0}".format(self.id), 
                                description=self.description)
     filename = sticker_page.create()    
     stickers = S3Object.create(filename, 
                                "supplies/stickers/{0}".format(filename), 
                                'document.dellarobbiathailand.com', 
                                 key, 
                                 secret,
                                 encrypt_key=True,
                                 )
     self.sticker = stickers
     self.save()
예제 #3
0
 def create_stickers(self, key, secret):
     sticker_page = StickerPage(code="DRS-{0}".format(self.id),
                                description=self.description)
     filename = sticker_page.create()
     stickers = S3Object.create(
         filename,
         "supplies/stickers/{0}".format(filename),
         'document.dellarobbiathailand.com',
         key,
         secret,
         encrypt_key=True,
     )
     self.sticker = stickers
     self.save()
예제 #4
0
from reportlab.graphics.barcode import code128

from hr.models import Employee
from media.stickers import StickerPage

logger = logging.getLogger(__name__)

pdfmetrics.registerFont(TTFont('Tahoma', settings.FONT_ROOT + 'Tahoma.ttf'))
pdfmetrics.registerFont(TTFont('Garuda', settings.FONT_ROOT + 'Garuda.ttf'))


django.setup()
        
if __name__ == "__main__":
    
        e1 = Employee.objects.get(pk=11000055)
        e2 = Employee.objects.get(pk=11000133)
        codes = [('DREM-{0}'.format(e1.id), u'{0}'.format(e1.name)), ('DREM-{0}'.format(e2.id), u'{0}'.format(e2.name))]
        sp = StickerPage(codes=codes)
        sp.create("EmployeeStickers.pdf")
            
            
    
    
    
    
    
    
    
    
    
예제 #5
0
    def dehydrate(self, bundle):
        """
        Implements the dehydrate method to manipulate data
        before it is returned to the client
        """
        #Checks if the country is set
        bundle = self._set_country(bundle)

        #Adds the quantity to the data field
        bundle.data['quantity'] = bundle.obj.quantity

        #Replaces custom-type with type after supply creation
        if "custom-type" in bundle.data:
            bundle.data['type'] = bundle.obj.type
            del bundle.data['custom-type']

        #Dehydrates the suppliers information if
        #requesting a single resource, if creating a new resource
        #or updating a single resource
        if re.search(
                "api/v1/supply/(w+\-)?\d+", bundle.request.path
        ) or bundle.request.method == 'POST' or bundle.request.method == 'PUT':
            bundle.data['suppliers'] = [
                self.dehydrate_supplier(bundle, supplier)
                for supplier in bundle.obj.suppliers.all()
            ]

            if not bundle.obj.sticker:
                sticker_page = StickerPage(code="DRS-{0}".format(
                    bundle.obj.id),
                                           description=bundle.obj.description)
                filename = sticker_page.create("DRS-{0}".format(bundle.obj.id))
                stickers = S3Object.create(
                    filename,
                    "supplies/stickers/{0}".format(filename),
                    'document.dellarobbiathailand.com',
                    encrypt_key=True)
                bundle.obj.sticker = stickers
                bundle.obj.save()

            bundle.data['sticker'] = {'url': bundle.obj.sticker.generate_url()}
        #If getting a list
        else:
            bundle.data['suppliers'] = [{
                'name': supplier.name,
                'id': supplier.id
            } for supplier in bundle.obj.suppliers.all()]

        #Merging product data from a supplier with the resource
        #if gettings supplies for a single supplier
        if bundle.request.GET.has_key('supplier_id'):

            #Set the supply's supplier to using
            #objects internals to get info
            bundle.obj.supplier = Supplier.objects.get(
                pk=bundle.request.GET.get('supplier_id'))
            bundle.data.update({
                'purchasing_units': bundle.obj.purchasing_units,
                'cost': bundle.obj.cost,
                'reference': bundle.obj.reference,
                'lead_time': bundle.obj.lead_time,
                'upc': bundle.obj.upc
            })
        if bundle.obj.image:
            try:
                bundle.data['image'] = {
                    'id': bundle.obj.image.id,
                    'url': bundle.obj.image.generate_url(3600)
                }
            except (AttributeError, KeyError) as e:
                logger.warn(e)
        logger.debug(bundle.data)
        return bundle