How to use the smartmin.models.SmartModel function in smartmin

To help you get started, we’ve selected a few smartmin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nyaruka / smartmin / test_runner / blog / models.py View on Github external
    @classmethod
    def prepare_fields(cls, field_dict, import_params=None, user=None):
        field_dict['order'] = int(float(field_dict['order']))
        return field_dict

    @classmethod
    def validate_import_header(cls, header):
        if 'title' not in header:
            raise Exception('missing "title" header')

    def __unicode__(self):
        return self.title


class Category(SmartModel):
    name = models.SlugField(max_length=64, unique=True,
                            help_text="The name of this category")
github nyaruka / smartmin / test_runner / blog / models.py View on Github external
from __future__ import unicode_literals

from django.db import models
from smartmin.models import SmartModel, ActiveManager


class Post(SmartModel):
    title = models.CharField(max_length=128,
                             help_text="The title of this blog post, keep it relevant")
    body = models.TextField(help_text="The body of the post, go crazy")
    order = models.IntegerField(help_text="The order for this post, posts with smaller orders come first")
    tags = models.CharField(max_length=128,
                            help_text="Any tags for this post")

    objects = models.Manager()
    active = ActiveManager()

    @classmethod
    def pre_create_instance(cls, field_dict):
        field_dict['body'] = "Body: %s" % field_dict['body']
        return field_dict

    @classmethod
github nyaruka / django-quickblocks / django_quickblocks / models.py View on Github external
from django.db import models
from django.contrib.auth.models import User
from smartmin.models import SmartModel

class QuickBlockType(SmartModel):
    """
    Quick Block Types just group fields by a slug.. letting you do lookups by type.  In the future
    it may be nice to specify which fields should be displayed when creating fields of a new type.
    """
    name = models.CharField(max_length=75, unique=True,
                            help_text="The human readable name for this content type")
    slug = models.SlugField(max_length=50, unique=True,
                            help_text="The slug to idenfity this content type, used with the template tags")
    description = models.TextField(blank=True, null=True,
                                   help_text="A description of where this content type is used on the site and how it will be dsiplayed")

    has_title = models.BooleanField(default=True,
                                    help_text="Whether this content should include a title")
    has_image = models.BooleanField(default=True,
                                    help_text="Whether this content should include an image")
    has_rich_text = models.BooleanField(default=True,
github nyaruka / klab / klab / events / models.py View on Github external
import json

from django.core.cache import cache
from django.db import models
from django.conf import settings
from smartmin.models import SmartModel

from klab import flickr
from datetime import datetime, timedelta

class Event(SmartModel):
    """
    The blueprint of events
    """
    RECURRENCE_CHOICES = (
        ('W', "Weekly"),
        ('M', "Monthly"),
        )

    parent = models.ForeignKey('self', related_name='children', null=True, blank=True)
    date = models.DateField(help_text="The date when the event will occur")
    time = models.TimeField(help_text="The start time for the event")
    duration = models.IntegerField(help_text="The duration in minutes of the event")
    title = models.CharField(max_length=64,
                                   help_text="What is the title of this event")
    logo = models.ImageField(upload_to="photos/", help_text="The image representing the event in general (should be square)")
    description = models.TextField(max_length=1024,
github nyaruka / klab / klab / blog / models.py View on Github external
from django.core.urlresolvers import reverse
from klab import flickr

import json
from django.db import models
from smartmin.models import SmartModel
from django.core.cache import cache

class Post(SmartModel):
    """
    Blog post
    """
    TYPE_BLOG = 'B'
    TYPE_STARTUP = 'S'
    POST_TYPES_CHOICES = ((TYPE_BLOG, "Blog"),
                          (TYPE_STARTUP, "Startup"))

    title = models.CharField(max_length=128,
                             help_text="Meaningful one line explenation")
    body = models.TextField(help_text="Detailed content of the post")
    image_id = models.CharField(max_length=128,
                            help_text="The flickr image id tagged blog")

    post_type = models.CharField(default=TYPE_BLOG, max_length=1, choices=POST_TYPES_CHOICES,
                                 help_text="Whether this post is a blog post or a startup")
github nyaruka / smartmin / smartmin / models.py View on Github external
def save(self, *args, **kwargs):
        update_fields = kwargs.get('update_fields', None)

        if (update_fields is None or 'modified_on' in update_fields) and not kwargs.pop('preserve_modified_on', False):
            self.modified_on = timezone.now()

        return super(SmartModel, self).save(*args, **kwargs)
github nyaruka / django-quickblocks / django_quickblocks / models.py View on Github external
help_text="Whether this content should include a summary field")
    has_link = models.BooleanField(default=True,
                                   help_text="Whether this content should include a link")
    has_gallery = models.BooleanField(default=False,
                                      help_text="Whether this content should allow upload of additional images, ie a gallery")
    has_color = models.BooleanField(default=False,
                                    help_text="Whether this content has a color field")
    has_video = models.BooleanField(default=False,
                                    help_text="Whether this content should allow setting a YouTube id")
    has_tags = models.BooleanField(default=False,
                                   help_text="Whether this content should allow tags")

    def __unicode__(self):
        return self.name

class QuickBlock(SmartModel):
    """
    A QuickBlock is just a block of content, organized by type and priority.  All fields are optional
    letting you use them for different things.
    """
    quickblock_type = models.ForeignKey(QuickBlockType,
                                        verbose_name="Content Type",
                                        help_text="The category, or type for this content block")

    title = models.CharField(max_length=255, blank=True, null=True,
                             help_text="The title for this block of content, optional")
    summary = models.TextField(blank=True, null=True,
                               help_text="The summary for this item, should be short")
    content = models.TextField(blank=True, null=True,
                               help_text="The body of text for this content block, optional")
    image = models.ImageField(blank=True, null=True, upload_to='quickblocks',
                              help_text="Any image that should be displayed with this content block, optional")
github nyaruka / smartmin / smartmin / csv_imports / models.py View on Github external
from smartmin.models import SmartModel


def generate_file_path(instance, filename):

    file_path_prefix = 'csv_imports/'

    name, extension = os.path.splitext(filename)

    if len(name) + len(extension) >= 100:
        name = name[:100-len(extension)-len(file_path_prefix)]

    return "%s%s%s" % (file_path_prefix, name, extension)


class ImportTask(SmartModel):
    PENDING = 'PENDING'
    STARTED = 'STARTED'
    RUNNING = 'RUNNING'
    SUCCESS = 'SUCCESS'
    FAILURE = 'FAILURE'

    READY_STATES = [SUCCESS, FAILURE]

    csv_file = models.FileField(upload_to=generate_file_path, verbose_name="Import file",
                                help_text="A comma delimited file of records to import")

    model_class = models.CharField(max_length=255, help_text="The model we are importing for")

    import_params = models.TextField(blank=True, null=True, help_text="JSON blob of form parameters on task creation")

    import_log = models.TextField()
github nyaruka / klab / klab / opportunities / models.py View on Github external
from django.db import models
from smartmin.models import SmartModel
from django.utils import timezone
from django.dispatch import receiver
from django.db.models.signals import pre_save

from datetime import datetime, timedelta

class Opportunity(SmartModel):
    title = models.CharField(max_length=128,
                             help_text="A title for the opportunity")
    description = models.TextField(max_length=2048,
                                   help_text="A summary of the opportunity in 2000 caracters")
    link = models.CharField(max_length=256,
                            help_text="Provide a link if possible", blank=True, null=True)

    remaining_days = models.IntegerField(default=0, 
                                   help_text="Number of days remaining before expiration, leave it blank for unlimited")

    deadline = models.DateField(null=True,blank=True)

    class Meta:
        verbose_name_plural = "Opportunities"

@receiver(pre_save, sender=Opportunity)
github nyaruka / klab / klab / events / models.py View on Github external
if not cache.get(key):
                    event_photos = flickr.api.walk(user_id=flickr.user_id, tags=self.photo_tag)
                    event_photos_list = list(iter(event_photos))
                    cache.set(key, json.dumps([dict(elt.items()) for elt in event_photos_list]), None)

                cached_event_photos = cache.get(key)
                event_photos = json.loads(cached_event_photos)

                return event_photos
            except:
                # otherwise give back nothing
                return None


class Video(SmartModel):
    name = models.CharField(help_text="The name of the video", max_length=255)
    summary = models.TextField(help_text="A short blurb about the video")
    description = models.TextField(help_text="The full description for the video")
    youtube_id = models.CharField(max_length=255, help_text="The id youtube uses for this video")