AttributeError: 'function' object has no attribute 'env' - odoo-13

I am trying to select some data from the database.
I tried to call a function like this :
class Test(models.Model):
_name = 'test.test'
_description = 'test.test'
emri = fields.Char()
mbiemri = fields.Char()
qyteti = fields.Char()
def getdata(self):
data = self.env['test3'].search([])
print(data)
I am getting this error : AttributeError: 'function' object has no attribute 'env'

Related

Django 'int' object is not iterable when trying to update objects in views

I am getting this error when trying to update objects from False to True. here is my code:
class ListNoti(LoginRequiredMixin,ListView):
raise_exception = True
model = Notifications
template_name = 'notifications/notifications.html'
def get_context_data(self, **kwargs):
data = super(ListNoti,self).get_context_data(**kwargs)
data['noti'] = Notifications.objects.filter(receiver=self.request.user,is_seen=False).order_by('-date').update(is_seen=True)
return data
.update(is_seen=True) raising this error TypeError at /notification/ 'int' object is not iterable
I solved this issue after using queryset in my views. here is my full code:
class ListNoti(LoginRequiredMixin,ListView):
raise_exception = True
model = Notifications
template_name = 'notifications/notifications.html'
def get_queryset(self):
data = Notifications.objects.filter(receiver=self.request.user).update(is_seen=True)
return data
def get_context_data(self, **kwargs):
data = super(ListNoti,self).get_context_data(**kwargs)
data['noti'] = Notifications.objects.filter(receiver=self.request.user)
return data

Selenium w/Python3 class_status = like.get_attribute("class") AttributeError: 'str' object has no attribute 'get_attribute' facing this issue

Selenium w/Python3 class_status = like.get_attribute("class") AttributeError: 'str' object has no attribute 'get_attribute' facing this issue
I am facing this issue when I call the first function is called but the number 2 function is not working
class Like():
def __init__(self,video_xpath,like_refiq):
self.video_xpath = video_xpath
self.like_refiq=like_refiq
# self.dislike=dislike
def like_dislike(self):
like =self.video_xpath
time.sleep(5)
# count = like.text
class_status = like.get_attribute("class")
if class_status == "selected":
like.click()
time.sleep(3)
# alredy_like_cls_status = like.get_attribute("class")
alredy_count = like.text
return print(f"creation un{alredy_count} {self.like_refiq} count")
elif class_status == "":
like.click()
time.sleep(3)
# non_like_cls_status = like.get_attribute("class")
non_count = like.text
return print(f"creation {non_count} {self.like_refiq} count")
else:
assert False
class Refiq(Like):
pass
like_path=driver.find_element_by_xpath("//w-creation-detail-popup//li[1]//a[1]")
Like_dislike=Like(video_xpath=like_path,like_refiq="like")
Like_dislike.like_dislike()
# like dislike function call
refq_unfrefiq=Refiq(video_xpath="//w-creation-detail-popup//li[2]//a[1]",like_refiq="refiq")
refq_unfrefiq.like_dislike()
You have assigned the like variable a string by like =self.video_xpath.
So, it's correct, click is a sting and you can't apply .get_attribute("class") on string object.
click is not a webelement object.

AttributeError: 'NoneType' object has no attribute 'data' in displaying linked list

I'm trying to display linked list elements in the form of a list but keep getting this error:
AttributeError: 'NoneType' object has no attribute 'data'
class Node:
def __init__(self,data=None,next=None):
self.data = data
self.next = next
class LinkedList:
def __init__(self):
self.head = None
def insert_at_beginning(self,data):
node = Node(data,self.head)
self.head = node
def display(self):
elements = []
currNode = self.head
while currNode:
currNode = currNode.next
elements.append(currNode.data)
print(elements)
if __name__ == "__main__":
ll = LinkedList()
ll.insert_at_beginning(1)
ll.insert_at_beginning(2)
ll.insert_at_beginning(3)
ll.display()
Can anyone explain the error here?
After the while loop, append data first then go to the next. You're getting the error because if currNode.next is null then it's showing the object has no attribute 'data'. So, append first then go to next. If currNode.next is null then the loop will stop.
while currNode:
elements.append(currNode.data)
currNode = currNode.next

Object has no attribute but attribute is defined

I have defined an attribute in a custom class, but I keep receiving an AttributeError when I try to access it.
class SMainWindow(QMainWindow):
def __init__(self):
# Constructor
super(SMainWindow, self).__init__()
self.myapp = PyQtApp()
self.layout = QVBoxLayout()
self.label_text = ''
self.settings = scrudb.retrieve_settings('current')
self.competition = self.retrieve_competition()
self.set_competition(self.competition.id)
self.label = QLabel(self.label_text)
self.button_scrutineer = QPushButton('Scrutineer Competition')
self.button_comps = QPushButton('Change Competition')
self.button_comp = QPushButton('Edit Competition Details')
self.button_dancers = QPushButton('Add/Edit Competitors')
self.button_judges = QPushButton('Add/Edit Judges')
self.button_dancerGroups = QPushButton(
'Define Competitor Groups & Dances')
self.button_import = QPushButton('Import CSV')
self.button_delete = QPushButton('Delete Competition')
self.button_exit = QPushButton('Exit')
self.button_comps.clicked.connect(self.select_competition)
self.button_delete.clicked.connect(self.delete_competition)
self.button_exit.clicked.connect(self.exit_app)
if (self.competition == None):
self.disable_buttons()
self.layout.addWidget(self.label)
self.layout.addWidget(self.button_scrutineer)
self.layout.addWidget(self.button_comps)
self.layout.addWidget(self.button_comp)
self.layout.addWidget(self.button_dancers)
self.layout.addWidget(self.button_judges)
self.layout.addWidget(self.button_dancerGroups)
self.layout.addWidget(self.button_import)
self.layout.addWidget(self.button_delete)
self.layout.addWidget(self.button_exit)
self.myapp.setLayout(self.layout)
def set_competition(self, comp_id):
self.competition = scrudb.retrieve_competition(comp_id)
if (self.competition != None):
self.label_text = ('<center>Competition:<br><strong>%s</strong><br>%8s<br>%s</center>' % (self.competition.name, self.get_formatted_date(self.competition.eventDate), self.competition.location))
self.label.setText(self.label_text)
self.settings.lastComp = self.competition.id
scrudb.set_settings(self.settings)
return self.competition
else:
self.label_text = ('<center>No Competition Selected</center>')
return None
File "/Users/majikpig/mu_code/src/main/python/scruinterface1.py", line 182, in set_competition
self.label.setText(self.label_text)
AttributeError: 'SMainWindow' object has no attribute 'label'
You need to change order of fields ... in set competition function you try to access field, which you haven't defined yet.
self.set_competition(self.competition.id)
self.label = QLabel(self.label_text)

How to handle object null in python

I am using flask. When I do not pass StartingSequenceNumber to flask app then How can I handle null object.
class Meta():
def __init__(self, j):
self.__dict__ = json.loads(j)
in bootstrap.py
meta = Meta(request.get_data().decode())
if meta.StartingSequenceNumber is not None:
# do something
Error : AttributeError: 'Meta' object has no attribute 'StartingSequenceNumber'
You could use the hasattr() built-in function (https://docs.python.org/3/library/functions.html#hasattr) which will return True if the object has the attribute :
if hasattr(object, 'attribute'):
# do smthg
else:
# do smthg else
But it would be better to used try & except blocks and throw an AttributeError
try:
doSmthg()
except AttributeError:
# do smthg else

Resources