create account

RE: Copropiedad Integral | Parking module administration by kit.andres

View this thread on: hive.blogpeakd.comecency.com

Viewing a response to: @amosbastian/re-kitandres-copropiedad-integral-or-administration-of-the-parking-module-20180622t225116379z

· @kit.andres · (edited)
$9.17
Hi @amosbastian. I took your recommendation to make a code refactoring of the [buildings application views](https://github.com/augustakingfoundation/copropiedadintegral_web/tree/master/buildings). therefore, I have taken the views.py file and I have split this into [different files](https://github.com/augustakingfoundation/copropiedadintegral_web/tree/master/buildings/views), depending on the specific modules that are being worked on. Here is the [commit](https://github.com/augustakingfoundation/copropiedadintegral_web/pull/24/commits/8ba11fe0a744860242da7c2aa4ff4922f5749995) for these changes. This if to avoid a very long file (thousands of lines) with different modules functionalities. There are still many pending modules that should be included in this section.

Trying to find parts of code that can be reduced to common functions to reduce repetitive code, I have found that the process of the formsets (owners formset and leaseholders formset) in the Unit form, and in the update unit form can be reduced to a common function. In this [commit](https://github.com/augustakingfoundation/copropiedadintegral_web/pull/24/commits/8ed38ec34f02064ebfdb7e182db9ca21343a290a) are the code changes related to this update.

About the shared functions in the [ParkingLot classes](https://github.com/augustakingfoundation/copropiedadintegral_web/blob/master/buildings/views/parking_lots.py#L26), I suppose you're talking about the `def test_func(self):`, or about the `get_object(self, queryset=None):` functions, per example. I tried to find a way to reduce it. All the classes defined in the [ParkingLots module](https://github.com/augustakingfoundation/copropiedadintegral_web/blob/master/buildings/views/parking_lots.py) are inheriting their structure from the  [Django generic views](https://docs.djangoproject.com/en/2.0/topics/class-based-views/) (CreateView, UpdateView, DeleteView). These methods are inherited from Django, and have some specific function. Per example, the `def test_func(self):`should be overwritten to define the user permission. If this method returns False or None, a 403 forbidden error will be raised.  The `get_object(self, queryset=None):` method is used for example, in an UpdateView to define the object that must be instanced in the form, in a DetailView to define the object that we want to show, and in a DeleteView to define the object that we want to delete. So, they are methods that must be defined in each class view. A way to reduce it could be to create a new class and define there the common methods in our classes, and define the classes inheriting from this new class, but I think that it only will be practical if our classes inherit from the same Django class based view. Per example if all classes in the ParkingLot module are inherited from the UpdateForm class, but all ParkingLot classes are inherited  from different classes. Also, in this methods there are variables that depends of the *url* parameters, and the parameters are different in some views.

I can't find an efficient way to reduce it, but I will be ready to listen to all suggestions ;). Thank you sr, now the code is much better and more organized.
👍  ,
properties (23)
authorkit.andres
permlinkre-amosbastian-re-kitandres-copropiedad-integral-or-administration-of-the-parking-module-20180623t174501624z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"users":["amosbastian"],"links":["https://github.com/augustakingfoundation/copropiedadintegral_web/tree/master/buildings","https://github.com/augustakingfoundation/copropiedadintegral_web/tree/master/buildings/views","https://github.com/augustakingfoundation/copropiedadintegral_web/pull/24/commits/8ba11fe0a744860242da7c2aa4ff4922f5749995","https://github.com/augustakingfoundation/copropiedadintegral_web/pull/24/commits/8ed38ec34f02064ebfdb7e182db9ca21343a290a","https://github.com/augustakingfoundation/copropiedadintegral_web/blob/master/buildings/views/parking_lots.py#L26","https://github.com/augustakingfoundation/copropiedadintegral_web/blob/master/buildings/views/parking_lots.py","https://docs.djangoproject.com/en/2.0/topics/class-based-views/"],"app":"steemit/0.1"}
created2018-06-23 17:45:03
last_update2018-06-23 20:08:51
depth2
children1
last_payout2018-06-30 17:45:03
cashout_time1969-12-31 23:59:59
total_payout_value6.877 HBD
curator_payout_value2.291 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length3,173
author_reputation31,454,326,251,184
root_title"Copropiedad Integral | Parking module administration"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id61,941,062
net_rshares4,591,675,159,115
author_curate_reward""
vote details (2)
@utopian-io ·
Hey @kit.andres
Here's a tip for your valuable feedback! @Utopian-io loves and incentivises informative comments.

**Contributing on Utopian**
Learn how to contribute on <a href="https://join.utopian.io">our website</a>.

**Want to chat? Join us on Discord https://discord.gg/h52nFrV.**

<a href="https://v2.steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1">Vote for Utopian Witness!</a>
properties (22)
authorutopian-io
permlink20180624t085648419z
categoryutopian-io
json_metadata{"tags":["utopian.tip"],"app":"utopian-io"}
created2018-06-24 08:56:48
last_update2018-06-24 08:56:48
depth3
children0
last_payout2018-07-01 08:56:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length410
author_reputation152,955,367,999,756
root_title"Copropiedad Integral | Parking module administration"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id62,019,943
net_rshares0