Skip to content

Commit

Permalink
Merge pull request #721 from ODM2/develop
Browse files Browse the repository at this point in the history
Bug Fixes for 0.17.0
  • Loading branch information
ptomasula authored May 7, 2024
2 parents dc214be + eaeeada commit 0d66b9c
Show file tree
Hide file tree
Showing 11 changed files with 350 additions and 326 deletions.
604 changes: 301 additions & 303 deletions src/accounts/user.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<br>
<div class="row">
<div class="form-group col-sm-12 col-md-6 sampling-feature-fields">
{% if user.is_staff %}
<div class="form-field {% if form.organization_id.field.required %} required-field{% endif %}{% if form.organization_id.errors %} has-error{% endif %}"
data-field="{{ form.organization_id.display_name }}">
<label class="control-label"
Expand All @@ -18,7 +17,6 @@
</div>
{{ form.organization_id|add_class:"form-control input-sm" }}
</div>
{% endif %}

<div class="form-field {% if form.sampling_feature_code.field.required %} required-field{% endif %}{% if form.sampling_feature_code.errors %} has-error{% endif %}"
data-field="{{ form.sampling_feature_code.name }}">
Expand Down
6 changes: 3 additions & 3 deletions src/dataloaderinterface/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@

from odm2 import odm2datamodels
from sqlalchemy import text
from odm2.crud.organization import read_organization_names
from odm2 import create_session

class LoginRequiredMixin(object):
@classmethod
Expand Down Expand Up @@ -409,12 +411,10 @@ def get_form(self, form_class=None):
user = self.request.user
organization_ids = [a.organization.organization_id for a in user.affiliation]
#for staff/admins if users is site admin they should see all organizations
if not user.is_staff:
if user.is_staff:
organization_ids = None

choices = []
from odm2.crud.organizations import read_organization_names
from odm2 import create_session
session = create_session()
organizations = read_organization_names(session, organization_ids)

Expand Down
15 changes: 6 additions & 9 deletions src/dataloaderservices/csv_templates/source_info_template.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# Source Information
# ------------------
# Organization: {affiliation.organization}
# SourceLink: {source_link}
# ContactName: {affiliation.account_id.accountfirstname} {affiliation.account_id.accountlastname}
# Phone: {affiliation.primary_phone}
# Email: {affiliation.primary_email}
# Citation: {citation}
#
# Source Information
# ------------------
# Organization: {organization.display_name}
# SourceLink: {source_link}
# Citation: {citation}
#
7 changes: 4 additions & 3 deletions src/dataloaderservices/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def post(self, request, format=None):
height = form.cleaned_data["height"]
notes = form.cleaned_data["sensor_notes"]

#create action-by record
# create action-by record
affiliation = None
for a in self.request.user.affiliation:
if a.organization_id == registration.organization_id:
Expand Down Expand Up @@ -682,7 +682,8 @@ def generate_metadata(
# Write Source Information data

# affiliation = tsr.result.feature_action.action.people.first()
affiliation = site_sensor.registration.odm2_affiliation
# affiliation = site_sensor.registration.odm2_affiliation
organization = site_sensor.registration.organization
annotation = tsr.result.annotations.first()
citation = (
annotation.citation.title if annotation and annotation.citation else ""
Expand All @@ -706,7 +707,7 @@ def generate_metadata(
)

metadata += CSVDataApi.read_file("source_info_template.txt").format(
affiliation=affiliation, citation=citation, source_link=source_link
organization=organization, citation=citation, source_link=source_link
)

return metadata
Expand Down
2 changes: 2 additions & 0 deletions src/odm2/crud/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import odm2.crud.organization
import odm2.crud.users
28 changes: 28 additions & 0 deletions src/odm2/crud/organizations.py → src/odm2/crud/organization.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import datetime

from typing import List, Optional, Tuple
from sqlalchemy.orm import Session

Expand All @@ -6,6 +8,32 @@
models = odm2datamodels.models
session = odm2datamodels.odm2_engine.session_maker

def create_individual_organization(
account: models.Accounts,
session: Session = session(),
) -> None:
#create organization model
organization = models.Organizations()
organization.organizationtypecv = 'Individual'
organization.organizationcode = f'individual_org_account_{account.accountid}'
organization.organizationname = f'individual_org_account_{account.accountid}'

#create organization record
session.add(organization)
session.commit()

#make affiliation record to tie new organization to account
affiliation = models.Affiliations()
affiliation.organizationid=organization.organizationid
affiliation.isprimaryorganizationcontact=True
affiliation.affiliationstartdate = datetime.today()
affiliation.primaryemail = account.accountemail
affiliation.accountid = account.accountid

#add record to database
session.add(affiliation)
session.commit()

def read_organization_names(
session: Session = session(),
organization_ids:Optional[List[int]]=None,
Expand Down
1 change: 1 addition & 0 deletions src/odm2/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import odm2.models.base
3 changes: 3 additions & 0 deletions src/odm2/models/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from sqlalchemy.orm import declarative_base

Base = declarative_base()
6 changes: 1 addition & 5 deletions src/odm2/models/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
from sqlalchemy import orm
import sqlalchemy as sqla
from sqlalchemy.dialects import postgresql as pg
from sqlalchemy.orm import declarative_base

Base = declarative_base()

from odm2.models.base import Base

class TimeSeriesResults(Base):
"""http://odm2.github.io/ODM2/schemas/ODM2_Current/tables/ODM2Results_TimeSeriesResults.html"""
Expand Down Expand Up @@ -47,7 +44,6 @@ class TimeSeriesResults(Base):
"aggregationstaticcv", sqla.ForeignKey("cv_aggregationstatistic.term")
)


class TimeSeriesResultValues(Base):
"""http://odm2.github.io/ODM2/schemas/ODM2_Current/tables/ODM2Results_TimeSeriesResultValues.html"""

Expand Down
2 changes: 1 addition & 1 deletion src/streamwatch/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def get_context_data(self, **kwargs):
] = user.is_authenticated and user.can_administer_site(
registration.sampling_feature_id
)
context["is_site_owner"] = user.id == registration.django_user
context["is_site_owner"] = registration.organization_id in user.organization_id
context["sampling_feature_code"] = self.kwargs[self.slug_field]
context["action_id"] = int(self.kwargs["pk"])
return context
Expand Down

0 comments on commit 0d66b9c

Please sign in to comment.