예제 #1
0
파일: admin.py 프로젝트: zeeshanali/ETTLIMS
    def print_barcode(modeladmin, request, queryset):
        for q in queryset:
            fields = [
                "{{{{ o.{f} }}}}".format(f=f)
                for f in btm.barcode_fields.split()
            ]
            # Shorten dates
            #fields = [f.isoformat().split("T")[0] if isinstance(f, datetime.datetime) else f for f in fields]
            #print("len: %d" % len(fields), file=sys.stderr)
            # throw error if not enough fields are given
            if len(fields) < btm.template.nr_fields:
                print("Not enough fields given", file=sys.stderr)

            # change template to work for python2.6, replace {} with {0}, {1} etc
            templ = str(btm.template.template)
            for i in range(btm.template.nr_fields):
                templ = templ.replace("{}", "{{{0}}}".format(i), 1)

            out = templ.format(*fields)
            t = Template(out)
            c = Context({"o": q})
            if LIMS_LPR:
                lpr("-P", btm.printer.name, '-o', 'raw', _in=t.render(c))
            else:
                #print(out, file=sys.stderr)
                print(t.render(c), file=sys.stderr)
            messages.success(
                request, "Printing {0} barcode on {1} for {2}".format(
                    btm.template, btm.printer, q))
예제 #2
0
파일: admin.py 프로젝트: novigit/SCGLIMS
def print_barcode(modeladmin, request, queryset):
    for q in queryset:
        ct = ContentType.objects.get_for_model(queryset.model)
        btm = BarcodeToModel.objects.get(content_type=ct)
        fields = [getattr(q, f) for f in btm.barcode_fields.split()]
        print("len: %d" % len(fields), file=sys.stderr)
        # add extra fields if not enough fields are given
        if len(fields) < 4:
            fields += (4 - len(fields)) * [""]
        out = btm.barcode.template.format(*fields)
        print(out, file=sys.stderr)
        lpr("-P", btm.barcode.name, _in=out)
예제 #3
0
 def print_barcode(modeladmin, request, queryset):
     for q in queryset:
         fields = ["{{{{ o.{f} }}}}".format(f=f) for f in btm.barcode_fields.split()]
         # Shorten dates
         #fields = [f.isoformat().split("T")[0] if isinstance(f, datetime.datetime) else f for f in fields]
         #print("len: %d" % len(fields), file=sys.stderr)
         # throw error if not enough fields are given
         if len(fields) < 4:
             print("Not enough fields given", file=sys.stderr)
         out = btm.template.template.format(*fields)
         t = Template(out)
         c = Context({"o": q})
         if LIMS_LPR:
             lpr("-P", btm.printer.name, '-o', 'raw', _in=t.render(c))
         else:
             #print(out, file=sys.stderr)
             print(t.render(c), file=sys.stderr)
         messages.success(request, "Printing {} barcode on {} for {}".format(btm.template, btm.printer, q))
예제 #4
0
파일: admin.py 프로젝트: felixeye/ETTLIMS
    def print_barcode(modeladmin, request, queryset):
        for q in queryset:
            fields = ["{{{{ o.{f} }}}}".format(f=f) for f in btm.barcode_fields.split()]
            # Shorten dates
            #fields = [f.isoformat().split("T")[0] if isinstance(f, datetime.datetime) else f for f in fields]
            #print("len: %d" % len(fields), file=sys.stderr)
            # throw error if not enough fields are given
            if len(fields) < btm.template.nr_fields:
                print("Not enough fields given", file=sys.stderr)

            # change template to work for python2.6, replace {} with {0}, {1} etc
            templ = str(btm.template.template)
            for i in range(btm.template.nr_fields):
                templ = templ.replace("{}", "{{{0}}}".format(i), 1)

            out = templ.format(*fields)
            t = Template(out)
            c = Context({"o": q})
            if LIMS_LPR:
                lpr("-P", btm.printer.name, '-o', 'raw', _in=t.render(c))
            else:
                #print(out, file=sys.stderr)
                print(t.render(c), file=sys.stderr)
            messages.success(request, "Printing {0} barcode on {1} for {2}".format(btm.template, btm.printer, q))
예제 #5
0
 def print(self, filename=None):
     self.topdf(filename=filename)
     import sh
     sh.lpr('temp.pdf')
     sh.rm('temp.pdf')