-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yaghoubi
committed
Sep 30, 2024
1 parent
362d594
commit 622989a
Showing
383 changed files
with
57,742 additions
and
699 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
include django_daisy/_version.py | ||
include README.md | ||
recursive-include django_daisy * | ||
global-exclude *.pyc |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from django import forms | ||
from django.db import models | ||
|
||
|
||
class CheckBoxModelField(models.CharField): | ||
def formfield(self, **kwargs): | ||
return forms.ChoiceField( | ||
choices=self.choices, | ||
widget=forms.RadioSelect, | ||
label=self.verbose_name, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from django import forms | ||
from django.db import models | ||
|
||
|
||
class CkeditorWidget(forms.Textarea): | ||
class Media: | ||
js = ( | ||
'admin/fields/ckeditor_init.js', | ||
) | ||
|
||
|
||
class CkeditorField(models.TextField): | ||
|
||
def __init__(self, *args, column_type='mediumtext', inline=False, **kwargs): | ||
# specifies column type choices are text | mediumtext | longtext | ||
# default is mediumtext | ||
self.column_type = column_type | ||
self.inline = inline | ||
super().__init__(*args, **kwargs) | ||
|
||
def formfield(self, **kwargs): | ||
_class = "ckeditor-field" if self.inline else "ckeditor-field" | ||
kwargs['widget'] = CkeditorWidget(attrs={'class': _class}) | ||
return super().formfield(**{ | ||
'max_length': self.max_length, | ||
**({} if self.choices is not None else {'widget': forms.Textarea}), | ||
**kwargs, | ||
}) | ||
|
||
def db_type(self, connection): | ||
if connection.settings_dict['ENGINE'] == 'django.db.backends.mysql': | ||
return self.column_type | ||
elif connection.settings_dict['ENGINE'] == 'django.db.backends.postgresql': | ||
return 'text' | ||
|
||
return super().db_type(connection) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from django.db.models import CharField | ||
from django.forms import fields | ||
|
||
|
||
class CommaSepWidget(fields.TextInput): | ||
""" | ||
tokenfield tags field widget | ||
""" | ||
template_name = 'django/forms/widgets/comma_seperate.html' | ||
|
||
class Media: | ||
js = ( | ||
'admin/panel/global_assets/js/plugins/forms/tags/tokenfield.min.js', | ||
) | ||
|
||
def __init__(self, attrs=None): | ||
default_attrs = { | ||
'class': 'tokenfield', | ||
} | ||
if attrs: | ||
default_attrs.update(attrs) | ||
super().__init__(default_attrs) | ||
|
||
|
||
class CommaSepModelField(CharField): | ||
description = "keyword field with comma separate in CharField" | ||
|
||
def __init__(self, *args, db_collation=None, **kwargs): | ||
kwargs['max_length'] = 255 | ||
super().__init__(*args, **kwargs) | ||
|
||
def formfield(self, **kwargs): | ||
# override widget field | ||
defaults = {'widget': CommaSepWidget} | ||
|
||
return super().formfield(**defaults) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from django.db import models | ||
from django import forms | ||
from django.forms.widgets import Textarea | ||
|
||
|
||
class JsonKeyValueWidget(Textarea): | ||
template_name = 'django/forms/widgets/keyvalue_field.html' | ||
|
||
def __init__(self, attrs={}): | ||
attrs['class'] = 'keyvalue-json-editor-field' | ||
super().__init__(attrs) | ||
|
||
class Media: | ||
js = ( | ||
'admin/fields/keyvalue_field/script.js', | ||
) | ||
css = { | ||
'all': ( | ||
'admin/fields/keyvalue_field/style.css', | ||
) | ||
} | ||
|
||
|
||
class JsonKeyValueField(models.JSONField): | ||
description = "custom json key value field" | ||
|
||
def formfield(self, **kwargs): | ||
return super().formfield(**{ | ||
'widget': JsonKeyValueWidget, | ||
'encoder': self.encoder, | ||
'decoder': self.decoder, | ||
**kwargs, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from django.db import models | ||
from django import forms | ||
|
||
|
||
class SummernoteField(models.TextField): | ||
|
||
def __init__(self, *args, column_type='mediumtext', **kwargs): | ||
# specifies column type choices are text | mediumtext | longtext | ||
# default is mediumtext | ||
self.column_type = column_type | ||
super(SummernoteField, self).__init__(*args, **kwargs) | ||
|
||
def formfield(self, **kwargs): | ||
kwargs['widget'] = forms.Textarea(attrs={'class': 'summernote'}) | ||
return super().formfield(**{ | ||
'max_length': self.max_length, | ||
**({} if self.choices is not None else {'widget': forms.Textarea}), | ||
**kwargs, | ||
}) | ||
|
||
def db_type(self, connection): | ||
if connection.settings_dict['ENGINE'] == 'django.db.backends.mysql': | ||
return self.column_type | ||
elif connection.settings_dict['ENGINE'] == 'django.db.backends.postgresql': | ||
return 'text' | ||
|
||
return super(SummernoteField, self).db_type(connection) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from django.db.models import PositiveBigIntegerField | ||
from django.forms import fields | ||
|
||
|
||
class ThousandSepWidget(fields.TextInput): | ||
template_name = 'django/forms/widgets/thousand_sep.html' | ||
|
||
def format_value(self, value): | ||
# Format the value with thousand separators | ||
# e.g., 200000 => '200,000' | ||
return '{:,}'.format(int(value)) if value else None | ||
|
||
def value_from_datadict(self, data, files, name): | ||
if value := super().value_from_datadict(data, files, name): | ||
return value.replace(',', '') | ||
return '' | ||
|
||
class Media: | ||
js = ( | ||
'admin/fields/thousand_sep_field.js', | ||
) | ||
|
||
|
||
class ThousandSepField(PositiveBigIntegerField): | ||
description = "number field with thousand separate eg: 200,000" | ||
|
||
def formfield(self, **kwargs): | ||
return super().formfield(**{ | ||
'widget': ThousandSepWidget, | ||
}) | ||
|
||
# def from_db_value(self, value, expression, connection): | ||
# if value is None: | ||
# return value | ||
# return locale.format_string("%d", value, grouping=True) | ||
|
||
def get_prep_value(self, value): | ||
# Convert formatted value back to integer for storage | ||
if isinstance(value, str): | ||
value = value.replace(',', '') | ||
return super().get_prep_value(value) | ||
|
||
def value_to_string(self, obj): | ||
value = self.value_from_object(obj) | ||
return self.to_python(value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from django import forms | ||
from django.db import models | ||
|
||
|
||
class TinyWidget(forms.Textarea): | ||
class Media: | ||
js = ( | ||
'admin/fields/tiny_init.js', | ||
) | ||
|
||
|
||
class TinyEditorField(models.TextField): | ||
|
||
def __init__(self, *args, column_type='mediumtext', inline=False, **kwargs): | ||
# specifies column type choices are text | mediumtext | longtext | ||
# default is mediumtext | ||
self.column_type = column_type | ||
self.inline = inline | ||
super().__init__(*args, **kwargs) | ||
|
||
def formfield(self, **kwargs): | ||
_class = "editor-field" if not self.inline else "editor-inline-field" | ||
kwargs['widget'] = TinyWidget(attrs={'class': _class}) | ||
return super().formfield(**{ | ||
'max_length': self.max_length, | ||
**({} if self.choices is not None else {'widget': forms.Textarea}), | ||
**kwargs, | ||
}) | ||
|
||
def db_type(self, connection): | ||
if connection.settings_dict['ENGINE'] == 'django.db.backends.mysql': | ||
return self.column_type | ||
elif connection.settings_dict['ENGINE'] == 'django.db.backends.postgresql': | ||
return 'text' | ||
|
||
return super().db_type(connection) |
Binary file not shown.
Oops, something went wrong.