Code Monkey home page Code Monkey logo

Comments (15)

dominicrodger avatar dominicrodger commented on August 17, 2024

Thanks for the prod @jbradberry - I'll see what I can get done over the next few weeks.

from django-recurrence.

hozano avatar hozano commented on August 17, 2024

Concerning this topic, I am trying to use this project, but I don't know how to get all occurrences in a specific date for all stored recurrence events. Is it possible with the current version?

from django-recurrence.

dominicrodger avatar dominicrodger commented on August 17, 2024

@hozano - I'm not sure what you're trying to do. What do your models look like? What result are you trying to get?

I've spent the last week building up test coverage to get an idea of how the pieces of this project fit together (fixing a few bugs in the process, and adding Python 3 support :)). This week I'll start work on documentation. After that, I'll see what it'd take to add support for Django 1.7.

from django-recurrence.

dominicrodger avatar dominicrodger commented on August 17, 2024

We now have basic docs up at https://django-recurrence.readthedocs.org/.

There's not much in the way of usage documentation yet - I'll be expanding it over the next few days. One thing that has confused me (and I'm pretty sure confused @emperorcezar in the past) - does anyone know when you should use RecurrenceModelField instead of RecurrenceField (cc @tamask)?

At the moment I've only documented RecurrenceField, because it's the only one I've used.

from django-recurrence.

mbertheau avatar mbertheau commented on August 17, 2024

@dominicrodger I guess you use it when you want database-level access to the recurrence info, for example for filtering.

from django-recurrence.

dominicrodger avatar dominicrodger commented on August 17, 2024

Hmmm - I can't make RecurrenceModelField work at all. Can anyone else? If I do something like this:

# models.py
class EventWithModelField(models.Model):
    recurs = RecurrenceModelField()

# somewhere else
rule = Rule(
    recurrence.WEEKLY,
    byday=recurrence.TU
)

limits = Recurrence(
    dtstart=datetime(2014, 1, 1, 0, 0, 0),
    dtend=datetime(2014, 2, 3, 0, 0, 0),
    rrules=[rule]
)

event = EventWithModelField.objects.create(
    recurs=limits
)

I get:

tests/test_saving.py:200: in test_recurrence_object_is_saved_with_model_field
    recurs=limits
../../local/lib/python2.7/site-packages/django/db/models/manager.py:137: in create
    return self.get_query_set().create(**kwargs)
../../local/lib/python2.7/site-packages/django/db/models/query.py:377: in create
    obj.save(force_insert=True, using=self.db)
../../local/lib/python2.7/site-packages/django/db/models/base.py:463: in save
    self.save_base(using=using, force_insert=force_insert, force_update=force_update)
../../local/lib/python2.7/site-packages/django/db/models/base.py:551: in save_base
    result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw)
../../local/lib/python2.7/site-packages/django/db/models/manager.py:203: in _insert
    return insert_query(self.model, objs, fields, **kwargs)
../../local/lib/python2.7/site-packages/django/db/models/query.py:1592: in insert_query
    query.insert_values(fields, objs, raw=raw)
../../local/lib/python2.7/site-packages/django/db/models/sql/subqueries.py:170: in insert_values
    value = getattr(obj, field.attname)
E   AttributeError: 'EventWithModelField' object has no attribute 'recurs_id'

Can anyone see what I'm doing wrong? If no one can figure out how to use it, I vote we just remove it from the code.

from django-recurrence.

mbertheau avatar mbertheau commented on August 17, 2024

I think you need to add in the RecurrenceManager. If I do that, I get:

>>> EventWithModelField.objects.create(recurs=r.limits)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/models/manager.py", line 92, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/models/query.py", line 372, in create
    obj.save(force_insert=True, using=self.db)
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/models/base.py", line 591, in save
    force_update=force_update, update_fields=update_fields)
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/models/base.py", line 619, in save_base
    updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/models/base.py", line 700, in _save_table
    result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/models/base.py", line 733, in _do_insert
    using=using, raw=raw)
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/models/manager.py", line 92, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/models/query.py", line 921, in _insert
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 919, in execute_sql
    for sql, params in self.as_sql():
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 877, in as_sql
    for obj in self.query.objs
  File "/home/markus/src/django-recurrence/recurrence/fields.py", line 94, in pre_save
    model = models.Recurrence.objects.create_from_recurrence_object(obj)
  File "/home/markus/src/django-recurrence/recurrence/managers.py", line 101, in create_from_recurrence_object
    choices.INCLUSION, rrule, recurrence_model)
  File "/home/markus/src/django-recurrence/recurrence/managers.py", line 65, in create_from_rule_object
    param=param, value=weekday.number, index=weekday.index)
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 714, in create
    return super(RelatedManager, self.db_manager(db)).create(**kwargs)
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/models/manager.py", line 92, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/models/query.py", line 372, in create
    obj.save(force_insert=True, using=self.db)
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/models/base.py", line 591, in save
    force_update=force_update, update_fields=update_fields)
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/models/base.py", line 619, in save_base
    updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/models/base.py", line 700, in _save_table
    result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/models/base.py", line 733, in _do_insert
    using=using, raw=raw)
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/models/manager.py", line 92, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/models/query.py", line 921, in _insert
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 920, in execute_sql
    cursor.execute(sql, params)
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 81, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 485, in execute
    return Database.Cursor.execute(self, query, params)
IntegrityError: recurrence_param.index may not be NULL

I fix(?) that with:

@@ -60,11 +60,11 @@ class RuleManager(manager.Manager):
             for value in value_list:
                 if param == 'byday':
                     # see recurrence.base docstrings about byday handling
                     weekday = recurrence.to_weekday(value)
                     rule_model.params.create(
-                        param=param, value=weekday.number, index=weekday.index)
+                        param=param, value=weekday.number, index=weekday.index or 0)
                 else:
                     rule_model.params.create(param=param, value=value)

         return rule_model

Then I get

>>> EventWithModelField.objects.create(recurs=r.limits)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/models/manager.py", line 92, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/models/query.py", line 372, in create
    obj.save(force_insert=True, using=self.db)
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/models/base.py", line 591, in save
    force_update=force_update, update_fields=update_fields)
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/models/base.py", line 619, in save_base
    updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/models/base.py", line 700, in _save_table
    result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/models/base.py", line 733, in _do_insert
    using=using, raw=raw)
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/models/manager.py", line 92, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/models/query.py", line 921, in _insert
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 920, in execute_sql
    cursor.execute(sql, params)
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 81, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
  File "/home/markus/.virtualenvs/rectest/local/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 485, in execute
    return Database.Cursor.execute(self, query, params)
OperationalError: no such table: foobar_eventwithmodelfield

Which leads me to believe that that code maybe worked with Django 1.1 or 1.2, the version current at the time when RecurrenceModelField was written.

from django-recurrence.

dominicrodger avatar dominicrodger commented on August 17, 2024

That seems plausible (I just tried running our tests on Django 1.1, but pytest-django . I'm inclined just to remove RecurrenceModelField, together with RecurrenceModelDescriptor. I also have a feeling that'd mean we don't need any of models.py and managers.py (though we should leave that file around, since older versions of Django - pre 1.7 I think - need an empty models.py).

I'm sad for the number of tests I wrote that will have turned out to be unnecessary, but less code is good methinks.

Any objections?

from django-recurrence.

mbertheau avatar mbertheau commented on August 17, 2024

I can imagine the usefulness of RecurrenceModelField, but we're not using it right now, so I'm personally ok with removing it :)

Thanks by the way for bringing django-recurrence back to life! :)

from django-recurrence.

dominicrodger avatar dominicrodger commented on August 17, 2024

I've removed RecurrenceModelField in e58ead9. I think it's probably possible to empty out models.py, but I'll leave that for now.

There's still a bit of work to do on the docs - mostly just documenting some common use cases (I've started on this here). If there's anything in particular anyone is keen to see, feel free to add a comment here, or submit a pull request.

I'll close this when I've documented:

  1. What's changed in 1.1.0 (I still need to fill out the list of fixed bugs);
  2. How to handle the fact that the Recurrence objects the widget creates don't have dtstart or dtend, so you need to specify those if using between et al.
  3. How to use count, before, after, and occurrences, (I've already documented between) which are the main functions on Recurrence.

from django-recurrence.

jbradberry avatar jbradberry commented on August 17, 2024

A definite improvement, but it could also use a bit about making use of the form media.

from django-recurrence.

dominicrodger avatar dominicrodger commented on August 17, 2024

Thanks @jbradberry - what are you looking to document? there's not a lot you can do to configure the form media - I've literally never done anything to make it appear, beyond adding recurrence to my INSTALLED_APPS setting, and making sure I'm making static files available in the normal way. Is there something you had to dig around for? I've had a look around forms.py, and I just can't see any interesting configuration points to document πŸ˜•

from django-recurrence.

jbradberry avatar jbradberry commented on August 17, 2024

Well, see #27 for the problem I'm having. I'm not sure if the errors I'm seeing are due to not having done something that I should have done but didn't realize, or what.

from django-recurrence.

dominicrodger avatar dominicrodger commented on August 17, 2024

OK - thanks. Genuinely appreciate you taking the time to file these things - hopefully it'll save other people some trouble πŸ‘

from django-recurrence.

dominicrodger avatar dominicrodger commented on August 17, 2024

This should now be all set - if anyone sees other things that need documenting (probably #20 at the least), feel free to file new issues. The documentation can be read at https://django-recurrence.readthedocs.org/.

from django-recurrence.

Related Issues (20)

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.