Ejemplo n.º 1
0
    def save(self, commit=True):
        super(UserForm, self).save(commit=False)
        self.delete_path = ""

        x = self.cleaned_data.get("x")
        y = self.cleaned_data.get("y")
        w = self.cleaned_data.get("width")
        h = self.cleaned_data.get("height")

        if self.instance.image:
            image = Image.open(self.instance.image)
            if x is not None:
                cropped_image = image.crop((x, y, w + x, h + y))
                resized_image = cropped_image.resize((200, 200),
                                                     Image.ANTIALIAS)

                folder_path = join(settings.MEDIA_ROOT, "users")
                # check if the folder already exists
                if not os.path.isdir(folder_path):
                    os.makedirs(folder_path)

                if "users" not in self.instance.image.path:
                    self.delete_path = self.instance.image.path

                resized_image.save(self.instance.image.path)

            image_resize(self.instance.image.path)
        if not self.is_edit or self.cleaned_data["new_password"] != "":
            self.instance.set_password(self.cleaned_data["new_password"])

        self.instance.save()
        if self.delete_path:
            os.remove(self.delete_path)
        return self.instance
Ejemplo n.º 2
0
    def form_valid(self, form):
        self.object = form.save(commit=False)

        self.object.user = self.request.user

        talk_id = self.kwargs.get("talk_id", "-1")
        user = get_object_or_404(User, email=self.kwargs.get("email", ""))
        space_type = self.kwargs.get("space_type", "general")
        space = self.kwargs.get("space", 0)

        if talk_id == "-1":
            talk = Conversation.objects.create(
                user_one=self.request.user, user_two=user
            )
        else:
            talk = get_object_or_404(Conversation, id=talk_id)

        self.object.talk = talk

        if space_type == "subject":
            self.object.subject = get_object_or_404(Subject, id=space)
            space = self.object.subject.slug

        self.object.save()

        simple_notify = textwrap.shorten(
            strip_tags(self.object.text), width=30, placeholder="..."
        )

        if self.object.image:
            simple_notify += " ".join(_("[Photo]"))

            image_resize(self.object.image.path)

        notification = {
            "type": "chat",
            "subtype": space_type,
            "space": space,
            "user_icon": self.object.user.image_url,
            "notify_title": str(self.object.user),
            "simple_notify": simple_notify,
            "view_url": reverse("chat:view_message", args=(self.object.id,), kwargs={}),
            "complete": render_to_string(
                "chat/_message.html", {"talk_msg": self.object}, self.request
            ),
            "container": "chat-" + str(self.object.user.id),
            "last_date": _("Last message in %s")
            % (formats.date_format(self.object.create_date, "SHORT_DATETIME_FORMAT")),
        }

        notification = json.dumps(notification)

        Group("user-%s" % user.id).send({"text": notification})

        sendChatPushNotification(user, self.object)

        ChatVisualizations.objects.create(viewed=False, message=self.object, user=user)

        return super(SendMessage, self).form_valid(form)
Ejemplo n.º 3
0
    def paintEvent(self, event):
        def scale_height(current_width, current_height, max_width, max_height):
            width_percent = max_width / current_width
            height_percent = max_height / current_height
            percent = height_percent if height_percent < width_percent else width_percent
            return current_height * percent

        if not self.image is None:
            w, h, channels = self.image.shape
            canvas_size = self.size()
            new_height = int(
                scale_height(w, h, canvas_size.width(), canvas_size.height()))
            # scale the image with OpenCV instead of Qt. The result is much better
            # e.g. one pixel line are not dropped in the OpenCV version
            #image = image_resize(self.image, height=new_height, inter=cv2.INTER_NEAREST)
            image = image_resize(self.image,
                                 height=new_height,
                                 inter=cv2.INTER_LINEAR)
            image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
            image = QImage(image, image.shape[1], image.shape[0],
                           image.strides[0], QImage.Format_RGB888)
            pixmap = QPixmap.fromImage(image)

            painter = QtGui.QPainter(self)
            point = QtCore.QPoint(0, 0)

            point.setX((canvas_size.width() - pixmap.width()) / 2)
            point.setY((canvas_size.height() - pixmap.height()) / 2)
            painter.drawPixmap(point, pixmap)
Ejemplo n.º 4
0
    def form_valid(self, form, formset):
        self.object = form.save(commit=False)

        slug = self.kwargs.get('slug', '')
        subject = get_object_or_404(Subject, slug=slug)

        self.object.subject = subject

        self.object.save()

        if self.object.question_img:
            image_resize(self.object.question_img.path)

        alternatives = formset.save(commit=False)

        for alt in alternatives:
            alt.question = self.object

            alt.save()

            if alt.alt_img:
                image_resize(alt.alt_img.path)

        self.log_context['category_id'] = self.object.subject.category.id
        self.log_context['category_name'] = self.object.subject.category.name
        self.log_context['category_slug'] = self.object.subject.category.slug
        self.log_context['subject_id'] = self.object.subject.id
        self.log_context['subject_name'] = self.object.subject.name
        self.log_context['subject_slug'] = self.object.subject.slug
        self.log_context['question_id'] = self.object.id
        self.log_context['question_content'] = self.object.enunciado

        super(QuestionCreateView,
              self).createLog(self.request.user, self.log_component,
                              self.log_action, self.log_resource,
                              self.log_context)

        return redirect(self.get_success_url())
Ejemplo n.º 5
0
from processing.image.black_white import Filter as Filter1
from processing.image.skeletonize import Filter as Filter2

TEST_IMAGE = "./test-images/Jeannette_Logo.png"

configuration_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "config", "configuration.ini"))
conf = Configuration(configuration_dir)

filter1 = Filter1()
filter1.threshold = 128

filter2 = Filter2()

img = cv2.imread(TEST_IMAGE, cv2.IMREAD_COLOR)
img = image_resize(img, height=600)
img1, cnt = filter1.process(img, None)
img2, cnt = filter2.process(img1, None)


img = 255 - cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img1 = 255 - cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
img2 = 255 - cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)

# calculate the watershed distance
#
img1 = cv2.distanceTransform(img1, cv2.DIST_L2, 5)
img1 = cv2.convertScaleAbs(img1)
img1 = cv2.normalize(img1, None, 255, 0, cv2.NORM_MINMAX, cv2.CV_8UC1)

# calculate the mask and use just the pixel and the intensity for the carving depth
Ejemplo n.º 6
0
    def _process(self, image, cnt):
        if self.path:
            image = cv2.imread(self.path, cv2.IMREAD_COLOR)
            image = image_resize(image, height=600)

        return image, cnt