Code Monkey home page Code Monkey logo

django-recurrence's Introduction

django-recurrence

Jazzband GitHub PyPI release Supported Python versions Supported Django versions Documentation GitHub actions Coverage

django-recurrence is a utility for working with recurring dates in Django.

Functionality

  • Recurrence/Rule objects using a subset of rfc2445 (wraps dateutil.rrule) for specifying recurring date/times,
  • RecurrenceField for storing recurring datetimes in the database, and
  • JavaScript widget.

RecurrenceField provides a Django model field which serializes recurrence information for storage in the database.

For example - say you were storing information about a university course in your app. You could use a model like this:

import recurrence.fields

class Course(models.Model):
    title = models.CharField(max_length=200)
    start = models.TimeField()
    end = models.TimeField()
    recurrences = recurrence.fields.RecurrenceField()

You’ll notice that I’m storing my own start and end time. The recurrence field only deals with recurrences not with specific time information. I have an event that starts at 2pm. Its recurrences would be “every Friday”.

Documentation

For more information on installation and configuration see the documentation at:

https://django-recurrence.readthedocs.io/

Issues

If you have questions or have trouble using the app please file a bug report at:

https://github.com/jazzband/django-recurrence/issues

Contributions

All contributions are welcome!

It is best to separate proposed changes and PRs into small, distinct patches by type so that they can be merged faster into upstream and released quicker.

One way to organize contributions would be to separate PRs for e.g.

  • bugfixes,
  • new features,
  • code and design improvements,
  • documentation improvements, or
  • tooling and CI improvements.

Merging contributions requires passing the checks configured with the CI. This includes running tests and linters successfully on the currently officially supported Python and Django versions.

The test automation is run automatically with GitHub Actions, but you can run it locally with the tox command before pushing commits.

This is a Jazzband project. By contributing you agree to abide by the Contributor Code of Conduct and follow the guidelines.

django-recurrence's People

Contributors

aimeems avatar aleksihakli avatar bheesink avatar cleder avatar denisiko avatar dependabot[bot] avatar dominicrodger avatar edelvalle avatar emperorcezar avatar enkore avatar ericbuckley avatar fladi avatar flipperpa avatar jackatomenapps avatar jleclanche avatar jmu-oir avatar josesanch avatar joshdrake avatar joshuadavidthomas avatar jshwright avatar klavionik avatar lino avatar mihalikv avatar noamkush avatar pytrumpeter avatar s-varga avatar sethboyd avatar sirkonst avatar viveksudani avatar williamrexhardin 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-recurrence's Issues

Tag doesn't match version in setup.py

Can we update the version of setup.py which is tagged at 1.0 to have the version 1.0? The mismatch between the two values is a bit confusing. I'm not familiar enough with tags to do this myself - if neither @tamask or @emperorcezar are, I'll figure it out.

I'm not sure if we should then update the version number in setup.py, to distinguish it from the 1.0 release - perhaps we should make it 1.1-dev or something similar?

Django 1.8 / Python 3.3/3.4 Uncaught ReferenceError: pgettext is not defined

I recently moved over to django 1.8 and Python3. I completely understand that this is experimental for Python 3 and is valid for up to Django 1.7 but I am having an issue.

I continue to get Uncaught ReferenceError: pgettext is not defined. I tried following the instructions:

js_info_dict = {
    'packages': ('recurrence', ),
}
# jsi18n can be anything you like here
urlpatterns += patterns(
    (r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),
)

but I am still getting errors. I am not sure if the errors are "expected" with Django 1.8 or if I might be just doing something wrong.

The error is at:

recurrence.display.weekdays_oneletter = [
    pgettext('Monday first letter', 'M'),   <-- Here
    pgettext('Tuesday first letter', 'T'),
    pgettext('Wednesday first letter', 'W'),

though is probably not too surprising. :-)

Any ideas would be appreciated.

Incorrect date information

I have notice that the widget send Rdates, Exdates and Until dates in UTC format to the server like '20160725T230000Z' but looks like the widget got the timezone info from the browser instead of from the timezone setting

Other issue is that when I access the field information the dates don't have a timezone and it looks like they were converted to the current one.

My browser timezone is UTC+1 and my django TIME_ZONE UTC+2
So in my case the widget send '20160725T230000Z' (datetime.datetime(2016, 7, 25, 23, 0, tzinfo=tzutc())) and when I access the field it contains datetime.datetime(2016, 7, 26, 1, 0).

Any ideas, can this be fixed somehow? Thanks

rrule.to_text() outputs incorrect month

Hi, I have a recurring rule object with this rule:

RRULE:FREQ=YEARLY;BYMONTH=11

When I use its to_text() method, I get:

annually, each December

And actually it should be 'anually, each November'

Léon

How Does this Library Handle dtstart?

It isn't stated clearly in the docs anywhere, and it seems like there are conflicting opinions in both how this library handles dtstart. In the docstrings for base.py and Recurrence it does seem to indicate that dtstart is handled the according the RFC 2445, which uses it as both the starting point for recurrences and as the first recurrence returned.

This is in contrast to how dateutil.rrule handles it, which just uses dtstart as the starting point for recurrences and does not automatically add it as the first occurrence.

It looks like this can be a bit of a pain point for users. #50 #36

Should this be better documented somewhere, to explicitly state that it doesn't follow the way dateutil.rrule handles dtstart and follows more closely to the spec. Or should changing the behavior be considered since it appears to cause issues? I recognize that this would be a big change.

"Add Rule" "Add Date" buttons inoperative in Admin Inline.

django=1.9.12
django-recurrence=1.4.1

When using recurrence in django admin, if recurrence is a field on an inline model and an instance of the inline model is spawned using the "Add whatever" button then the "Add Rule" and "Add Date" buttons in recurrence do not function. The recurrence widget functions normally if the inline object is visible when loading the page.

Warning: RemovedInDjango110Warning: SubfieldBase has been deprecated

When runing this package with Django 1.9.1 I'm getting the warning:

RemovedInDjango110Warning: SubfieldBase has been deprecated. 
Use Field.from_db_value instead.

Because the field:

class RecurrenceField(with_metaclass(SubfieldBase, fields.Field)):
    """
    Field that stores a `recurrence.base.Recurrence` object to the
    database.
    """

Extends the SubfieldBase.

Django 1.7.7/Python 3.4.0: Invalid syntax

So when you try to run the installation and obtain the following:

Traceback (most recent call last):
File "manage.py", line 10, in
execute_from_command_line(sys.argv)
File "/home/envs/event_system/lib/python3.4/site-packages/django/core/management/init.py", line 385, in execute_from_command_line
utility.execute()
File "/home/envs/event_system/lib/python3.4/site-packages/django/core/management/init.py", line 354, in execute
django.setup()
File "/home/envs/event_system/lib/python3.4/site-packages/django/init.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/envs/event_system/lib/python3.4/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/home/envs/event_system/lib/python3.4/site-packages/django/apps/config.py", line 87, in create
module = import_module(entry)
File "/home/envs/event_system/lib/python3.4/importlib/init.py", line 104, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 2231, in _gcd_import
File "", line 2214, in _find_and_load
File "", line 2203, in _find_and_load_unlocked
File "", line 1200, in _load_unlocked
File "", line 1129, in _exec
File "", line 1448, in exec_module
File "", line 321, in _call_with_frames_removed
File "/home/envs/event_system/lib/python3.4/site-packages/recurrence/init.py", line 1, in
from recurrence.base import (
File "/home/envs/event_system/lib/python3.4/site-packages/recurrence/base.py", line 850
except exceptions.ValidationError, error:
^
SyntaxError: invalid syntax

Therefore, the code does not compatible with Python3?

Using inc=True and dtstart with between() incorrectly always includes the dtstart time

Creating a weekly Monday recurrence. Then getting all the occurrences between 2015-08-02 (Sunday) and 2015-08-11 (Tuesday) should return 2015-08-03 (Monday) and 2015-08-10 (Monday).

However, if I use the inc=True option to make start/end times inclusive and also use the dtstart option to specify the start date (lets me find occurrences in the past), it always includes the dtstart value as one of the occurrences.

Here is the code (version 1.2.0) demonstrating the bug:

recurrence.Recurrence(rrules=[recurrence.Rule(recurrence.WEEKLY, byday=recurrence.MONDAY)]).between(datetime.datetime(2015, 8, 2), datetime.datetime(2015, 8, 11), inc=True, dtstart=datetime.datetime(2015, 8, 2))

This results in:

[datetime.datetime(2015, 8, 2, 0, 0), datetime.datetime(2015, 8, 3, 0, 0), datetime.datetime(2015, 8, 10, 0, 0)]

Expected:

[datetime.datetime(2015, 8, 3, 0, 0), datetime.datetime(2015, 8, 10, 0, 0)]

Adding Russian i18n

Thank you for so much for this great project!

I'm working on Django 1.8 project with Russian language and i want use your application. But i can't deal with languages in it. I found different locales in recurrence/locale and i know how gettext is working but when i change my default Django language to some locale that are already presented in locale e.g. i set

LANGUAGE_CODE = 'fr'

admin language are changing to French language, but recurrence widget is still in English. Also i add js i18n url:

js_info_dict = {
    'packages': ('recurrence', ),
}
# jsi18n can be anything you like here
urlpatterns += (
    url(r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),
)

But JS widget is still use English. What am i doing wrong?

ps. I want to add Russian localization on reccurence project but at this point i can't uderstand why i18n doesn't work for me.

Widget js is raising errors

Using the minimal Course model from the docs, I've created the following template, and a suitable create view and model form to match:

<!DOCTYPE html>
<html lang="en_US">
<head>
  {{ form.media }}
</head>

<body>
  <h1>Create Course</h1>

  <form action="" method="post">{% csrf_token %}
    {{ form.as_p }}
    <input type="submit" value="Submit" />
  </form>
</body>
</html>

However, when actually accessing this view, I see these three errors show up in Firebug, and the recurrence field is rendered as just a plain text input.

ReferenceError: django is not defined
    if (!django.catalog) {
ReferenceError: gettext is not defined
    'inclusion': gettext('including'), 'exclusion': gettext('excluding')
TypeError: recurrence.display.labels is undefined
    recurrence.display.labels.add_rule, {

This is using django-recurrence==1.0.3, pip installed from PyPI.

bool(recurrence) always True

# recurrence/base.py
class Recurrence(object):
    def __nonzero__(self):
        if (self.dtstart or self.dtend or
            tuple(self.rrules) or tuple(self.exrules),
            tuple(self.rdates) or tuple(self.exdates)):
            return True
        else:
            return False

It seems like this function always returns True since the comma here makes the tested expression a two-tuple which is True in boolean context.

See also 0fdde40#commitcomment-7619127

Add example usage of RecurrenceField and RecurrenceModelField to the README

Currently, I'm finding it difficult to use this code because it requires that I look under the hood quite a bit. I am still unsure when/where to use the RecurrenceField as opposed to the RecurrenceModelField in the Event model that I've defined in my project.

Good example usage in the documentation at the models.py and views.py level will make this project more accessible to individuals that have time constraints.

Widget should using JQuery or Something

Currently the widget is very homegrown. It works great, but is difficulty to grep and modify. I propose a rewrite into JQuery/Backbone or something to keep the widget code minimal and maintainable.

Fourth of the month

First, I was really pleased to find this app. It is going to be a huge help for me. Thanks.

I was a little surprised, for the monthly repeating, to see First, Second, Third and Last. But no Fourth. Is there a reason not to have a Fourth. Is there a reason? I must be missing something.

Recurrence model filter

I have an event model that has a start and end time as well as a RecurrenceField, which is not required (not all events have recurrences). I've looked at the documentation and the tests, but it's not clear how one would get all recurrences for all event models without checking every event object for its recurrences. Is it possible to do something like this:

for item in Event.objects.filter(start__range=(start, end), recurrences=recurrences.between(start, end, dtstart=start, inc=True)):
    //do something with event

1.10 support

With Django 1.10 I get:

...
  File "/home/jmk/.virtualenvs/home-budgets/lib/python3.5/site-packages/recurrence/fields.py", line 3, in <module>
    from django.db.models.fields.subclassing import Creator
ImportError: No module named 'django.db.models.fields.subclassing'

Seems like there is an s too much there. Shouldn't it be django.db.models.field.subclassing?
I guess it's a 1.10 refactor.

Widget Rule definitions should allow day, day of month, month selection for all frequencies

tl;dr

The dateutil docs give examples like:

list(rrule(YEARLY, interval=4, count=3, bymonth=11,
               byweekday=TU, bymonthday=(2,3,4,5,6,7,8),
               dtstart=parse("19961105T090000")))
[datetime.datetime(1996, 11, 5, 9, 0),
 datetime.datetime(2000, 11, 7, 9, 0),
 datetime.datetime(2004, 11, 2, 9, 0)]

but we can't specify months AND days of week in the same rule in the django-recurrence widget

Detail

I need to specify a range for certain days of the week, but only for particular months of the year (for seasonal activities). I can achieve an example of this in python with:

list(rrule(YEARLY, bymonth=(1,2,3,7,9), byweekday=(SA,SU), count=10))

(list and count included for readability of output)

As awesome as django-recurrence is, each frequency tab (eg Annually, Weekly) only supports options relative to that type, so Annually doesn't let me specify for which weekdays, for example. I can add another rule, but that is a logical OR which means that dates are included if they match the first rule or the second rule.

One way around this would be for me to use an Exclude, but this seems to only be a single day in the month (when I choose Annually and my months). Let me know if I'm missing something here.

Another way would be an enhancement to the widget. It seems from the dateutil docs that the Frequency selected is only relevant for interval and bysetpos. This means that any Frequency can have day of week, week of year, etc. So the widget would need reworking so that regardless of Annually / Monthly / Weekly / Daily selected, the month, day of month, and day of week selectors would always be visible.

Discussion welcome

Release 1.4.1

@emperorcezar - there are quite a few bits in 1.4.1, so now seems like a good time to get a release out. Would you mind doing the honours?

Recurrence.between() doesn't exclude Feb 29th when Recurrence has empty dtstart and inclusion is Daily

The following failing test describes the issue:

https://github.com/django-recurrence/django-recurrence/compare/master...alextreme:feb29-exclusion?expand=1

It's an edge-case that only occurs with between() when the Recurrence is daily and the exclusion is Feb 29th and dtstart isn't filled in.

I've been able to easily work around it by either setting dtstart or providing an alternative exclusion rule, but I'm noting this issue in case anyone else stumbles upon it (today or over 4 years).

prompts unsaved changes warning

On submitting the main form browser prompts unsaved changes warning when rule or date was added.
It's bad for user experience

It seems that in every single rule or date a form tag was used, I guess that what causes this bad experience or I made something wrong?

Widget wrong visualization with django-recurrence + django-admin-bootstrap

As per title, when trying to use the two together, I obtain this:

1
2

Basically, the widget is rendered under the other parts of the form, and I'm unable to fix it without messing up with the css code... I don't know if I'd rather ask django-admin-bootstrap developers, but I hope you can point me somewhere with this. Thank you for your help!

exdate set in admin ui is saved at 00:00, while comparision is made against exact dtstart time

When one sets an exclude date in the admin ui, the exdate gets ignored by the between function. It seems that the admin ui passes a date object into the model, that is then cast into a datetime object resulting in timings like 00:00. Since the between function only matches against exact datetime, the exdate does not match.

>>> s.recurrences.dtstart
datetime.datetime(2017, 5, 7, 1, 0)
>>> s.recurrences.exdates
[datetime.datetime(2017, 5, 10, 0, 0)]
>>> s.recurrences.between(datetime.datetime(2017,5,9), datetime.datetime(2017,5,12))
[datetime.datetime(2017, 5, 9, 1, 0), datetime.datetime(2017, 5, 10, 1, 0), datetime.datetime(2017, 5, 11, 1, 0)]

When setting the correct time programmatically everything works as expected:

>>> s.recurrences.exdates[0] = datetime.datetime(2017, 5, 10, 1, 0)
>>> s.recurrences.exdates
[datetime.datetime(2017, 5, 10, 1, 0)]
>>> s.recurrences.between(datetime.datetime(2017,5,9), datetime.datetime(2017,5,12))
[datetime.datetime(2017, 5, 9, 1, 0), datetime.datetime(2017, 5, 11, 1, 0)]

I assume the date passed from the admin ui widget needs some kind of normalization to set a correct time or the exdate should be implemented time agnostic at all.

Can't save None into a RecurrenceField

Steps to reproduce:

from django.db import models
from recurrence.fields import RecurrenceField

class Event(models.Model):
    name = models.CharField(max_length=100)
    recurs = RecurrenceField(blank=True, null=True)

Then try saving implicit None:

>>> from test_recurs.models import Event
>>> event = Event(name="foobar")
>>> event.save()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/dom/.virtualenvs/recurrence/local/lib/python2.7/site-packages/django/db/models/base.py", line 463, in save
    self.save_base(using=using, force_insert=force_insert, force_update=force_update)
  File "/home/dom/.virtualenvs/recurrence/local/lib/python2.7/site-packages/django/db/models/base.py", line 551, in save_base
    result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw)
  File "/home/dom/.virtualenvs/recurrence/local/lib/python2.7/site-packages/django/db/models/manager.py", line 203, in _insert
    return insert_query(self.model, objs, fields, **kwargs)
  File "/home/dom/.virtualenvs/recurrence/local/lib/python2.7/site-packages/django/db/models/query.py", line 1593, in insert_query
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/home/dom/.virtualenvs/recurrence/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 911, in execute_sql
    for sql, params in self.as_sql():
  File "/home/dom/.virtualenvs/recurrence/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 872, in as_sql
    for obj in self.query.objs
  File "/home/dom/.virtualenvs/recurrence/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 292, in get_db_prep_save
    prepared=False)
  File "/home/dom/.virtualenvs/recurrence/local/lib/python2.7/site-packages/recurrence/fields.py", line 38, in get_db_prep_value
    return recurrence.serialize(value)
  File "/home/dom/.virtualenvs/recurrence/local/lib/python2.7/site-packages/recurrence/base.py", line 851, in serialize
    raise exceptions.SerializationError(error.args[0])
SerializationError: incompatible object

Save explicit None:

>>> event = Event(name="foobar", recurs=None)
>>> event.save()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/dom/.virtualenvs/recurrence/local/lib/python2.7/site-packages/django/db/models/base.py", line 463, in save
    self.save_base(using=using, force_insert=force_insert, force_update=force_update)
  File "/home/dom/.virtualenvs/recurrence/local/lib/python2.7/site-packages/django/db/models/base.py", line 551, in save_base
    result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw)
  File "/home/dom/.virtualenvs/recurrence/local/lib/python2.7/site-packages/django/db/models/manager.py", line 203, in _insert
    return insert_query(self.model, objs, fields, **kwargs)
  File "/home/dom/.virtualenvs/recurrence/local/lib/python2.7/site-packages/django/db/models/query.py", line 1593, in insert_query
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/home/dom/.virtualenvs/recurrence/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 911, in execute_sql
    for sql, params in self.as_sql():
  File "/home/dom/.virtualenvs/recurrence/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 872, in as_sql
    for obj in self.query.objs
  File "/home/dom/.virtualenvs/recurrence/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 292, in get_db_prep_save
    prepared=False)
  File "/home/dom/.virtualenvs/recurrence/local/lib/python2.7/site-packages/recurrence/fields.py", line 38, in get_db_prep_value
    return recurrence.serialize(value)
  File "/home/dom/.virtualenvs/recurrence/local/lib/python2.7/site-packages/recurrence/base.py", line 851, in serialize
    raise exceptions.SerializationError(error.args[0])
SerializationError: incompatible object

I'm pretty sure this used to work with the version of django-recurrence I bundled into my app (I discovered this when removing my bundled version and switching to django-recurrence 1.0).

I'll take a look at this, unless anyone has immediate ideas of what's wrong.

Finding all generated occurrences of model

I am using this to generate a range of instances of a model (Event) based on the rules set at creation time but I want the form that produces them to redirect to a page which lists all the generated occurrences, once they've been created.

Is there an easy way to do this or do I have to manage it myself using a new model to connect them all or something maybe?

I was kind of hoping I could do something like

event.recurrences.instances()

to get hold of them.

Or is this something I would have to manage myself?

Specify BiWeekly start date of a recurrence?

I'm trying to schedule a biweekly recurrence (every other Friday), but it seems to set the starting Friday automatically? Is it possible to specify the Friday it starts on and I'm just missing it?

Filtering using recurrence field

In the documentation I clearly see that there are only options for getting the occurrences for every single model object. Is there any way to filter the queryset using the recurrence field ?

For example, Can I filter the queryset by finding which all events that has recurrences for today ? (similar to http://swingtime.nerdfog.com/docs/models.html#occurrencemanager). It is fine if I take all the rows from the db and query in the python code since I am going to have 10 rows at the most.

I have been looking at django-eventtools. eventtools seems not having the form widget as recurrence field. Just curious to know if there are any possiblilities in django-recurrence.

Questionable handling of aware timestamps

When generating weekly occurrences that cross a dst change boundary for an aware base datetime, the time in the normalized datetimes doesn't stay the same.

For example, for
2014-10-22 10:30 CEST with a weekly recurrence, the next generated datetime is
2014-10-29 10:30 CEST, which normalizes to
2014-10-29 9:30 CET. What I want though is
2014-10-29 10:30 CET.

We work around that by passing only naive datetimes as dtstart to recurrences:

        tz = timezone.get_default_timezone()
        dtstart = timezone.make_naive(self.start_datetime, tz)
        return map(lambda o: timezone.make_aware(o, tz),
                   self.recurrence.occurrences(dtstart=dtstart, dtend=dtend))

I wouldn't say the current implementation is necessarily wrong - it's just a different use case, where each occurrence is exactly 7*24 hours apart. I'd argue though that the other use case is more common.

I don't have time right now to tackle this myself. However, in the long run I'd like to get the workaround out of our code.

Add missing Basque translations

PR #88 (from @mir06) added some new strings that need translations in Basque, specifically:

  • Last
  • Second last
  • 2nd last
  • Third last
  • 3rd last
  • Fourth last
  • 4th last

I'm hoping @unaizalakain might be able to help us out.

Widget should include a field for dtstart

The javascript part of RecurrenceWidget should include a way to add a start date to a rule. Right now none is saved. This leads to a dtstart of datetime.now() when the occurrences are generated.
For most users this is probably not a desired behavior.

Add start date in a rule in admin widget

Hi,

i want to set event recurrences in the admin widget with a start date but i dont find how to do this, start date of my rules automatically take a datetime.now()

from datetime import datetime
import recurrence


myrule = recurrence.Rule(
    recurrence.DAILY
)

pattern = recurrence.Recurrence(
    dtstart=datetime(2015, 10, 2, 0, 0, 0),
    dtend=datetime(2015, 10, 9, 0, 0, 0),
    rrules=[myrule, ]
)

It thats i want, i got an event started a 2october with daily recurences to 9 october, i check to python dateutil and its easy to do this directly with it too. In your app i really enjoy the admin widget, my users can easy enter complex recursive events with it, but if they can't set a start date will difficult.

in recurrence.fields we can see this : " Field that stores a recurrence.base.Recurrence object to the
database."

Ok i go in base.Recurrence i see this :

`dtstart` : datetime.datetime
        Optionally specify the first occurrence. This defaults to
        `datetime.datetime.now()` when the occurrence set is
        generated.

Im in this case, it generate me an automatic start date.

In recurrences.forms.RecurrenceField :

`accept_dtstart` : bool
            Whether to accept a dtstart value passed in the input.

Im really confuse, how to set a dtstart in the input?

Thanks for your help

Update tested version

Currently, tox.ini has:

envlist = {py26}-{14,15,16},{py27}-{14,15,16,17},{py33,py34}-{15,16,17},docs,flake8

We should probably drop official support for Python 2.6 entirely, and start testing Django 1.8 and 1.9. We should also probably stop testing Django 1.4-1.7, since those are also EOL (see the docs). We should also start testing with Python 3.5.

This will help with work on #63.

Needs some docs

This project looks like may be quite useful, but it could really use some documentation.

Programmatically create recurrences

I really like this project, but for my requirement I would also need the possibility to create some recurrences programmatically. I cannot seem to figure out how to create the recurrences attribute of a Course instance (example from your docs) by code.

Could you make a short addition to the docs on how to do this? Thanks!

Update:
I figured it out by looking into your tests. I will just add the steps should anyone be interested:

  1. Create a base.Rule object
  2. Create a base.Recurrence object, and add the created Rule object to the rules attribute
  3. Assign the Recurrence object to the recurrences attribute of a Course (see doc example)

EXRULE not working...

I have created a rule that should occur every year from 1st to 10th of december.

Rule definition:

RRULE:FREQ=MONTHLY;BYMONTHDAY=1,2,3,4,5,6,7,8,9,10
EXRULE:FREQ=YEARLY;BYMONTH=1,2,3,4,5,6,7,8,9,10,11

In [100]: robj = recurrence.deserialize(rule)
In [102]: robj.occurrences().after(datetime.datetime.utcnow())
Out[102]: datetime.datetime(2015, 3, 5, 18, 8, 40)

any ideas?

Problem with "May" month

I'm finishing the Italian translation for django-recurrence (which I will release here of course, if you want).

There is a problem with the fifth month though. Its translation within the months table and the calendar widget seems to be referring to the same line, which is causing troubles, in sense that it's either like this:

1

or this:

2

I've noticed that on djangojs.po:390, you're passing from Apr to June, and May is skipped.
I was born in May, so it's double trouble for me :)
Joking apart, can this be fixed somehow?
Thanks.

Incorrect occurrences when using rule + excluded date

I'm seeing incorrect occurrences when defining a recurrence in the following way:

(new rule) Daily, until some date, or occurs N times
(new date) Excluding some date

My Django model my_object has a RecurrenceField named recurrences. Today is March 24th, I define a daily rule on every day until March 29th and I exclude Friday March 28th.

list(my_object.recurrences.occurrences()) produces:

[datetime.datetime(2014, 3, 25, 0, 42, 44), datetime.datetime(2014, 3, 26, 0, 42, 44), datetime.datetime(2014, 3, 27, 0, 42, 44), datetime.datetime(2014, 3, 28, 0, 42, 44), datetime.datetime(2014, 3, 29, 0, 42, 44)]

which seems incorrect, as it includes datetime.datetime(2014, 3, 28, 0, 42, 44).


Digging in, it seems that the exdates are matched "exactly" and that any difference in the hour values will produce seemingly incorrect occurrences, as seen above.

Fetching my_object.recurrences.exdates[0] returns datetime.datetime(2014, 3, 28, 4, 0).

If I then fetch my_object.recurrences.occurrences(dtstart=datetime(2014, 3, 24, 4))) I do see that March 28th is excluded:

[datetime.datetime(2014, 3, 24, 4, 0), datetime.datetime(2014, 3, 25, 4, 0), datetime.datetime(2014, 3, 26, 4, 0), datetime.datetime(2014, 3, 27, 4, 0), datetime.datetime(2014, 3, 29, 4, 0)]


Any ideas how to fix this? :-) Cheers!

Daylight Savings Time - Incorrect Date

When I set an rdate or exdate through the widget it makes a new date using my browser's timezone, if the date is in a daylight savings time period it includes that info:

2017-01-20 -> 2017-01-20 T050000 (EST)

2017-04-21 -> 2017-04-21 T040000 (EDT)

What happens is that gets passed to the recurrence field as:

EXDATE:20170120T050000Z

EXDATE:20170421T040000Z

The deserialize function puts that into UTC time and stores them as:

2017-01-20 00:00:00

2017-04-20 23:00:00

The deserialize function doesn't take into account the daylight savings time on the 04-21 date and subtracts 5 hours instead of 4 and when displayed the date is then off (excludes April 20th instead of April 21st)

I am not sure exactly where this is happening, somewhere its getting the EXDATE:20170421T040000Z and adding the localtz as EST not EDT and takes 5 hours off not 4 hours resulting in the error.

edit

Figured it out - settings.TIME_ZONE was set to EST and it needed to be US/Eastern

Javascript widget not working.

I am using django-recurrence for a project. When I try to use the javascript widget for the form, it does not render correctly in the browser (both safari and chrome). Here's the screen shot
screen shot 2016-10-24 at 12 44 18

And here's the snippet for the html:
screen shot 2016-10-24 at 12 49 26

I am pretty sure the the static assets are loading correctly cuz the terminal prints out the static assets requests and it is serving the assets correctly.

Javascript widget, timezone problem

Hi...

I definitely don't solve my timezones problems, maybe i can got here some advice about this, or soon ill have no hair in my head :p

Settings.py :

TIME_ZONE = 'UTC'
USE_TZ = True

This isnt my local timezone ("Europe, Paris") but i have read that is better to work with UTC and just convert the output datetime if needed.

Explications :

No problem with rules, they seems work correctly, i can get all of them with my event app.

But when i enter a random date (in the admin widget), for exemple i create an occurrences for "2015-10-06", this is save at "2015-10-05 22:00" or "2015-10-05 23:00" that's depend... i have try to debug it at some place :

  • in recurrence-widget.js at line:1610 i put a console.log(this.date); Thats show me the date selected when i choose it in js calendar, so in my case if i select 2015-10-06 thats return me
    "Date {Tue Oct 06 2015 00:00:00 GMT+0200}"

Im in french timezone on my computer, the javascript take the client timezone, normal.

  • When i save my model i have set a clean method like this :

    def clean(self):

    arrayocc = []
    for i in self.recurrences.occurrences():
    
        arrayocc.append(i)
    
    raise ValidationError(arrayocc)
    

At this step thats raise me this date : 2015-10-05 22:00:00

  • And a simple last test, i set the timzone of my computer at UTC, saved a date, this is saved at : 2015-10-06 23:00:00 , the good day but at 23:00:00...why?

That's look like a javascript date problem,no?

I got no problem when i use basic django dateTimeField in my models

At changelog for 1.2.0 in the docs :
Added a French translation (#32) - this may be backwards incompatible if have overriden the widget JavaScript such that there is no language_code member of your recurrence object;

For the moment i don't use the translation but i don't really understand what are you tell us here^^

i can perform more test if you want.

Hope im clear.

Thanks

Use DateField instead DateTimeField

Hi,

Thanks for this app really usefull, i use it for an event app.

The problem is i dont need time with my date, that just contrain me to do more loop for find events, i have try to change DateTimeField to DateField in models.py at line 8,9,25 and 36. After that i delete and recreate reccurence field im my events models, but i always get a DateTimeField.

my views and templates for exemple, i have a list of category that event match the date :

views :

def get_date1(request,date):
    categ_array = []

    eventDate = datetime.strptime(date,'%Y-%m-%d').date()

    date_categ = Category.objects.all()

    for categ in date_categ:
        try: 
            getEvent = categ.event_set.all(is_cancelled=False)

            for event in getEvent:
                for occ in event.recurrences.occurrences():
                    if occ.date() == eventDate:
                        if categ not in categ_array:
                            categ_array.append(categ)
        except:
            pass
    return render(request, 'agenda/date1.html', locals())

templates :

{% for categ in categ_array %}

        <h2>{{categ.name}}</h2>

        {% for event in categ.getEvent %}

            {%for i in event.recurrences.occurrences%}

                {% if i.date = eventDate %}

                  <li> {{event.title}}</li>

                {% endif %}

            {% endfor %}

        {% endfor %}

    {% endif %}

{% endfor %}

As you see i have to test "for i in event.recurrences.occurrences, if i.date = eventDate", if havent this Time field i could just do "if eventDate in event.recurrences.occurrences" i think my app can be more fast like that.

Thanks for your help

How to configure frequencies

The code comments state that by default all frequencies are enabled. However in reality in django admin only the first 4 are enabled.

How can I enable all recurrence frequencies? ie Hourly, Minutely.

frequencies

(Could be solved by better documentation #23)

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.