Giter Club home page Giter Club logo

django-colorful's Introduction

django-colorful

An extension to the Django web framework that provides a database and form field to accept and store colors in the RGB format.

https://travis-ci.org/charettes/django-colorful.svg?branch=master https://coveralls.io/repos/charettes/django-colorful/badge.svg?branch=master&service=github

Installation

>>> pip install django-colorful

Make sure 'colorful' is in your INSTALLED_APPS:

INSTALLED_APPS.append('colorful')

Usage

In order to use a color field you just have to add it to your model definition:

from django.db import models
from colorful.fields import RGBColorField

class Tag(models.Model):
    color = RGBColorField()

The RGBColorField class also accepts a color keyword argument which can be set to a list of colors that should be visible as preset color palette:

color = RGBColorField(colors=['#FF0000', '#00FF00', '#0000FF'])

The ColorFieldWidget should take care of providing a JavaScript based shim on browsers that don't support the HTML5 color input.

Note

To enable HTML5 color input with Django Grappelli ensure that GRAPPELLI_CLEAN_INPUT_TYPES is set to False in your settings file.

django-colorful's People

Contributors

allanlewis avatar bashmish avatar budzinski avatar charettes avatar cjmochrie avatar dakrauth avatar fitoria avatar gabn88 avatar gbezyuk avatar jspitzen avatar kmike avatar kraiz avatar thomwiggers avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-colorful's Issues

Release new version to PyPI with colors argument

Great project! The colors argument was added a long time ago... any chance can you release this to PyPI? django_colorful-1.1.0 does not include it. The version number will need an update. Thanks!

modal dialog?

Hi there,

we use RGBColorField (great tool!) in our django application. I wonder if it's possible for it to behave like a modal dialog...?

Scenario:

  • on web page X, user clicks on the color field
  • the "color picker" dialog opens, in which the user is supposed to pick a color
  • the user, however, closes page X (should not be possible!)
  • the dialog remains open.

Are there any solutions for preventing the web page from closing before closing the color picker dialog?

Thanks in advance!
Adrian

Duplicates

Hi!

Every time I press Save in admin I have 2 new color (#000). It doesn't depend if I change field with color, just click Save ... Why?

My model:

class Color(models.Model):
    color = RGBColorField(verbose_name=u'Color')
    ware = models.ForeignKey(Ware, verbose_name=u"Ware", related_name="colors")

My admin:

class ColorInline(admin.TabularInline):
    model = Color
    extra = 2
    max_num = 10

@admin.register(Ware)
class WareAdmin(admin.ModelAdmin):
    list_display  = ('id','title',)
    inlines = [ColorInline,]

ImportError: No module named django.utils

I'm getting the following error when trying to pip install a requirements file containing django and django-colorful:

  Using cached django-colorful-1.2.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-8sI7z4/django-colorful/setup.py", line 4, in <module>
        import colorful
      File "colorful/__init__.py", line 3, in <module>
        from django.utils import version
    ImportError: No module named django.utils

Obviously, Django isn't installed at this point, and so accessing django.utils fails.

why db storage '#' symbol?

I found that in db django-colorful storage '#ff0000' with varchar(7).
But why using archer(6) and storage 'ff0000'?

color palet shows behind bootstrap model

If you see the css,

div.colorPicker-palette {
width: 110px;
position: absolute;
border: 1px solid #598FEF;
background-color: #EFEFEF;
padding: 2px;
z-index: 9999;
}

However, in browsers that don't support native html5 color input the palette shows like:
<div id="color_selector" style="left: 975px; top: 209.7px; display: block; z-index: 1050;"><div style="background-color: rgb(153, 204, 255);">&nbsp;</div><div class="color_swatch" style="background-color: rgb(255, 255, 255);">&nbsp;</div><div id="color_custom"><label for="color_value">Hex</label><input id="color_value" type="text" size="8"></div></div>

So I think the css class should be:

color_selector instead of div.colorPicker-palette?

Link to pypi in readme

Hey there, I really liked your app, it is really easy to use. However, I found this github before I realized it is hosted on PyPi. A link (or any mention of it) in your readme file would be nice.

INSTALLED_APPS.append('colorful') not working

Hi,
I'm quite new to python (so also Django) and web servers.
But I followed the Django tutorial https://docs.djangoproject.com/en/1.11/intro/tutorial01/
So now I'm able to acces a web page.
I want to have a color picker on my page, but while trying, I don't get where or how I should use the INSTALLED_APPS.append('colorful'). If I add manualy 'colorful' in the INSTALLED_APPS list, I get an error too.

Any feedback would be welcome!
Thanks in advance
Floris

Importing django in __init__.py breaks pip installation (in some cases)

https://github.com/charettes/django-colorful/blob/master/colorful/__init__.py#L3 means that Django already needs to be available before installing, and installation fails when it's not. For example:

Collecting django-colorful
  Downloading https://files.pythonhosted.org/packages/bc/5a/ef813bdfa9e9f4acd3efb363317b2e17b9ff67fb37e3880b7a3019037e29/django-colorful-1.2.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-wheel-zs0hbc37/django-colorful/setup.py", line 4, in <module>
        import colorful
      File "/tmp/pip-wheel-zs0hbc37/django-colorful/colorful/__init__.py", line 3, in <module>
        from django.utils import version
    ModuleNotFoundError: No module named 'django'

Maybe the technique used at https://github.com/GaretJax/django-click/blob/master/setup.py#L87-L97 would be a work-around.

Please remove django from install_requires in setup.py

It is hardly possible that anyone would need to install django by installing django-colorful and this line will cause headaches for developers who have installed django in non-standard way (from svn, via symlink, from OS repository, etc).

HTML validation warning

https://validator.w3.org/ flags the script generated by this with a warning. Seems like a simple fix to line 33 in widgets.py
From :
return '''<script type="text/javascript">

To:
return '''<script>

Warning: The type attribute is unnecessary for JavaScript resources.

White default appearing black

When I use a white default (#fff, #FFFFFF), the colour picker defaults to #000000:

class MyModel(models.Model):
    white = RGBColorField(default='#fff')

I've attached a screenshot of this behavour. You can see there that the input has a value of #fff, but the widget is showing black:

screenshot from 2018-08-30 21-45-00

I'm seeing this both in Firefox 63b1 and Chromium 68.

return RGBa

Type of Issue: feature suggestion

description: sometimes there is a need for alpha value side by side the RGB value, we can achieve this by adding another field for alpha, but imagine a use-case that needs to add more than a single color(for example a global theming colors of a website), therefore, it will be better to save and return the entire value as single value (RGBa). this is a great feature for serializers within APIs and headless front-ends as well

Showing the color in the list

Hi,
I created a model with a RGBField.
Then I setted my model admin list_display to: ('color')
where color is my RGBField.

In the list of registered models, the rgb value for the selected color is shown.
Would be amazing if the view was something like the widget.

I do not know if it can be done directly in the django-colorful but if it is possible, it will be pretty cool.

Django version restrictions

Is there any version that is compatible with Django 1.6.5? The installation automatically upgrades/installs Django 1.9 , which is not compatible with my project code.
May I know if there are a number of Django 1.8 code usages in the project, or simply downgrading the version would work in a fork?

South schemamigration fail

With 1.0.0 version I can't create a schemamigration of a model using the RGBColorField.
I got this error:

Traceback (most recent call last):
  File "./manage.py", line 12, in <module>
    execute_from_command_line(sys.argv)
  File "/opt/propilei/django/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/opt/propilei/django/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/propilei/django/local/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/opt/propilei/django/local/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "/opt/propilei/django/local/lib/python2.7/site-packages/south/management/commands/schemamigration.py", line 159, in handle
    action.add_forwards(forwards_actions)
  File "/opt/propilei/django/local/lib/python2.7/site-packages/south/creator/actions.py", line 39, in add_forwards
    forwards.append(self.forwards_code())
  File "/opt/propilei/django/local/lib/python2.7/site-packages/south/creator/actions.py", line 355, in forwards_code
    return self._code(self.old_field, self.new_field, self.new_def)
  File "/opt/propilei/django/local/lib/python2.7/site-packages/south/creator/actions.py", line 349, in _code
    "field_def": self.triple_to_def(new_def),
  File "/opt/propilei/django/local/lib/python2.7/site-packages/south/creator/actions.py", line 63, in triple_to_def
    ", ".join(triple[1] + ["%s=%s" % (kwd, val) for kwd, val in triple[2].items()]), # args and kwds
TypeError: can only concatenate tuple (not "list") to tuple

Downgrading to the 0.1.3 version, schemamigration is created without errors.

return rgb

Hi,
is it possible to have rgb code instead of hex in return?
thanks

optional value support

The RGBColorField can be an optional field, but the colur picker widget does not seem to support it and defaults to black color.

Example model field:

nav_bar_color = RGBColorField(null=True, blank=True)

problem with admin TabularInline for ManyToManyField

I tried to change my charfield to RGBColorField but I'm having issue with admin interface.
The field is used in a ManyToMany through table that I was showing in the admin as TabularInline

# model.py
class Department(models.Model):
    name = models.CharField(max_length=300)
    document_type = models.ManyToManyField(DocumentType, through='DocumentDepartment',
                                           through_fields=('department', 'document_type'))

class DocumentType(models.Model):
    name = models.CharField(max_length=300)
    code = models.CharField(max_length=10)

class DocumentDepartment(models.Model):
    document_type = models.ForeignKey(DocumentType, on_delete=models.CASCADE)
    department = models.ForeignKey(Department, on_delete=models.CASCADE)
    color = RGBColorField()
    # color = models.CharField(default='#3344FF', blank=True, null=True, max_length=10)

# admin.py
class DocumentTypeInline(admin.TabularInline):
    model = Department.document_type.through

class DepartmentAdmin(admin.ModelAdmin):
    list_display = ('name',)
    inlines = [DocumentTypeInline]

With the color field as CharField the admin works properly but if I change it to RGBColorField I'm not able to submit empty inlines.

capture

Any suggestions?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.