Research
Recent Trends in Malicious Packages Targeting Discord
The Socket research team breaks down a sampling of malicious packages that download and execute files, among other suspicious behaviors, targeting the popular Discord platform.
django-generic-positions
Generic app for using a drag & drop position field, wherever you want to.
Readme
This is a generic app for using a drag & drop position field, wherever you want to.
You often have items that should have a position field so that the user can manipulate their ordering by entering intergers into that field. This app allows you to easily add drag and drop functionality to that model's Django admin or even to your frontend.
You don't need to manipulate your models, which means that you can even make third party models that don't have a position field at all position aware.
You need at least the following packages in your virtualenv:
To get the latest stable release from PyPi::
$ pip install django-generic-positions
To get the latest commit from GitHub::
$ pip install -e git://github.com/bitmazk/django-generic-positions.git#egg=generic_positions
Add the app to your INSTALLED_APPS
::
INSTALLED_APPS = [
...
'generic_positions',
]
Add this to your main urls.py
::
urlpatterns = patterns(
'',
url(r'^pos/', include('generic_positions.urls')),
...
)
Run the migrations to create the app's database tables::
$ ./manage.py migrate generic_positions
If you want to add the position feature to the model of a third party app,
do the following in one of your models.py
files::
from django.contrib.contenttypes.fields import GenericRelation
from thirdpartyapp.models import TheModel
TheModel.add_to_class(
'generic_position',
generic.GenericRelation('generic_positions.ObjectPosition'),
)
If you are extending on of your own models, simply add this to your model::
from django.contrib.contenttypes.fields import GenericRelation
class YourModel(models.Model):
...
generic_position = GenericRelation(
'generic_positions.ObjectPosition'
)
IMPORTANT. If you are using multiple models, which have generic relations to
the positioning model, this is what you should NOT do: For some reason there
will be duplicates of your model appearing in the templates. Please don't use
ordering = ['generic_position__position']
.
Usage in templates ++++++++++++++++++
There are several template tags and filters you can use. Let's start with a simple view, which orders the object list by position::
{% load position_tags %}
{% for obj in object_list|order_by_position %}
<p>{{ obj }}</p>
{% endfor %}
You want to reverse the ordering? Go for it::
{% load position_tags %}
{% for obj in object_list|order_by_position:'reverse' %}
<p>{{ obj }}</p>
{% endfor %}
Let's show the current position, too::
{% load position_tags %}
{% for obj in object_list|order_by_position:'reverse' %}
<p>{% position_input obj 'visible' %} » {{ obj }}</p>
{% endfor %}
The position_input
tag will add a hidden field with the position nr. and
if you add visible
it will also append a span element.
If you also want the drag & drop functionality, have a look at the following example of a complete implementation::
{% load position_tags %}
<form method="post" action="{% url "position_bulk_update" %}">
{% csrf_token %}
<ul id="positionContainer">
{% for obj in object_list|order_by_position %}
<li>{{ obj }}{% position_input obj %}</li>
{% endfor %}
</ul>
</form>
# You might want to place these scripts in your base template
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="{{ STATIC_URL }}js/libs/jquery.min.js"><\/script>')</script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>
<script>window.jQuery || document.write('<script src="{{ STATIC_URL }}js/libs/jquery-ui.min.js"><\/script>')</script>
<script type="text/javascript" src="{{ STATIC_URL }}generic_positions/js/reorder.js"></script>
A few things are important here:
position_bulk_update
csrf_token
<ul id="positionContainer">
tag is usually recommended.positionContainer
.{% position_input obj %}
to automatically add the right input field.Usage with Django Admin +++++++++++++++++++++++
If you want to use the drag & drop positioning in the Django admin use::
from generic_positions.admin import GenericPositionsAdmin
admin.site.register(YOUR_MODEL, GenericPositionsAdmin)
See the issue tracker for current and upcoming features.
FAQs
Generic app for using a drag & drop position field, wherever you want to.
We found that django-generic-positions demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
The Socket research team breaks down a sampling of malicious packages that download and execute files, among other suspicious behaviors, targeting the popular Discord platform.
Security News
Socket CEO Feross Aboukhadijeh joins a16z partners to discuss how modern, sophisticated supply chain attacks require AI-driven defenses and explore the challenges and solutions in leveraging AI for threat detection early in the development life cycle.
Security News
NIST's new AI Risk Management Framework aims to enhance the security and reliability of generative AI systems and address the unique challenges of malicious AI exploits.