Esempio n. 1
0
    def get(_, lang, paged=1):
        try:
            image_model = Image()

            total = image_model.get_all().count()

            pagination = Pagination(
                page=paged, per_page=10, total=total, slug='')

            images = image_model.get_all()[
                     pagination.offset:pagination.offset + pagination.per_page]

            res = ImagesSerializer(images, many=True).data

            return JsonResponse({
                'total': pagination.pages,
                'paged': paged,
                'images': res,
                'lang': lang,
            }, safe=False)

        except Exception as e:
            return JsonResponse({
                'status': 500,
                'message': 'Exception Error ' + str(e)
            }, status=500)
Esempio n. 2
0
    def remove_image(cls, topic_id):
        all_image_ids = [v.id for v in Image.get_all()]
        try:
            topic = cls.objects.get(id=topic_id)
            for v in all_image_ids:
                topic.images.remove(v)

        except:
            pass
Esempio n. 3
0
    def get(request, lang, paged=1):

        image_model = Image()

        total = image_model.get_all().count()

        pagination = Pagination(
            page=paged, per_page=10, total=total,
            slug='/{}/admin/images/page/'.format(lang))

        images = image_model.get_all()[
                 pagination.offset:pagination.offset + pagination.per_page]

        return TemplateResponse(request, 'images.html', {
            'title': '画像一覧 | FEED App 管理',
            'images': images,
            'information': pagination.information(),
            'pagination': pagination,
            'lang': lang,
        })
Esempio n. 4
0
    def add_image(cls, topic_id, image_ids):
        image_ids = list(map(int, image_ids))
        all_image_ids = [v.id for v in Image.get_all()]
        try:
            topic = cls.objects.get(id=topic_id)
            for v in all_image_ids:
                if v in image_ids:
                    try:
                        topic.images.add(v)
                    except:
                        pass
                else:
                    topic.images.remove(v)

        except:
            pass
Esempio n. 5
0
class TopicEnForm(forms.Form):
    post_type = forms.CharField(required=True, error_messages=ERROR_MESSAGES)
    new = forms.BooleanField(required=False, error_messages=ERROR_MESSAGES)
    title = forms.CharField(required=True, error_messages=ERROR_MESSAGES)
    text = forms.CharField(required=True, error_messages=ERROR_MESSAGES)
    url = forms.CharField(required=True, error_messages=ERROR_MESSAGES)
    button_label = forms.CharField(required=True,
                                   error_messages=ERROR_MESSAGES)
    published_at = forms.DateTimeField(required=True,
                                       error_messages=ERROR_MESSAGES)
    event_date = forms.DateTimeField(required=False,
                                     error_messages=ERROR_MESSAGES)
    thumbnail = forms.CharField(required=True, error_messages=ERROR_MESSAGES)
    images = forms.MultipleChoiceField(
        required=False,
        widget=forms.CheckboxSelectMultiple,
        choices=lambda: [(v.id, v.id) for v in Image.get_all()],
        error_messages=ERROR_MESSAGES)
    videos = forms.MultipleChoiceField(
        required=False,
        widget=forms.CheckboxSelectMultiple,
        choices=lambda: [(v.id, v.id) for v in VideoEn.get_all()],
        error_messages=ERROR_MESSAGES)