Beispiel #1
0
    def validate(self):
        super().validate()

        error = None
        start = self.model_value('start_at')
        end = self.model_value('expire_at')
        if start is None or start == '':
            error = ('start_at', '*Date value is missing')
        elif end is None or end == '':
            error = ('expire_at', '*Date value is missing')
        else:
            tz = timezone.get_current_timezone()
            start = tz.localize(datetime.strptime(start, "%Y/%m/%d"))
            if start < timezone.now():
                error = ('start_at', '*Start date cannot be before today')

            end = tz.localize(datetime.strptime(end, "%Y/%m/%d"))
            if end < timezone.now():
                error = ('expire_at', '*Expire date cannot be before today')

            if start > end:
                error = ('start_at', '*Start date cannot be before expire date')

        if error is None:
            self.add_model_value('start_at', start)
            self.add_model_value('expire_at', start)
        else:
            self.set_error(*error)

        files = self.m_values.get('files', '')
        if files != '':
            images = files.split(',')
            # FIXME :: fetch support for multiple images
            upload = FileUpload.fetch_file(images[0], self.request().user)
            if upload is not None:
                self.add_model_value('image', upload.file)
        else:
            self.set_error('fk_business', 'Image not uploaded')

        self.add_model_value('fk_user', self.request().user)
        business_id = self.model_value('fk_business')
        business = Business.fetch_by_id(business_id)
        if business is not None:
            self.add_model_value('fk_business', business)
        else:
            self.set_error('fk_business', 'Business does not exist')

        # compute the slug
        slug = self.model_value('name')+'-by-'+self.request().user.name
        slug = App_Slugify(slug)
        if Offer.fetch_by_slug(slug) is None:
            self.add_model_value('slug', slug)
        else:
            self.set_error('name', '*Offer with same name is already posted by you')

        return self.valid()
Beispiel #2
0
def offer_detail_view(request, slug):
    print('slug : '+slug)
    offer = Offer.fetch_by_slug(slug)
    data = {'title': 'View Offers', 'offer': offer}
    return App_Render(request, 'offer/offer_item_detail_1.html', data)