def read(self, request, tag): from_value = request.GET.get('from', None) show_number = request.GET.get('num', 30) if tag == 'deleted': res_list = Picture.ranged(Q(tags__in=[tag]), from_value, show_number, "-creation") else: res_list = Picture.ranged(Q(tags__in=[tag]) & Q(tags__nin=["deleted"]), from_value, show_number, "-creation") return SerializedObject(res_list).to_python()
def create(self, request): data = simplejson.load(request) selected = data["selected"] tags = data["tags"] if not selected: return rc.NOT_FOUND objs = [ObjectId(x) for x in selected] entry_list = Picture.objects(id__in=objs) for p in entry_list: p.tags = tags p.save() return rc.ALL_OK
def read(self, request): from_value = request.GET.get('from', None) show_number = request.GET.get('num', 30) res_list = Picture.ranged(Q(tags__size=0) | Q(tags__exists=False), from_value, show_number, "-creation") return SerializedObject(res_list, fields=self.fields).to_python()
def process_file(self, filename): if Picture.objects.filter(path=filename).count() != 0: return False img = Image.open(filename) ts = os.path.getctime(filename) creation = datetime.fromtimestamp(ts) size = os.path.getsize(filename) sha = self.shahash(filename) p = Picture() p.path = filename.decode('utf-8') p.hashcode = sha p.creation = creation p.width, p.height = img.size p.size = size if Picture.objects.filter(hashcode=sha).count() > 0: p.tags = ['deleted'] p.save() try: p.thumbnail = self.generate_thumbnail(img, filename, str(p.id)) except: p.delete() raise p.save() print filename, size, img.format, img.size, img.mode, creation, sha return True