#265 Some code beautification in bugzilla widget
Merged 7 years ago by sayanchowdhury. Opened 7 years ago by vivekanand1101.
vivekanand1101/fedora-hubs beauty_bz  into  develop

file modified
+35 -28
@@ -11,11 +11,15 @@ 

  template = templating.environment.get_template('templates/bugzilla.html')

  position = 'right'

  

+ 

  @argument(name="username",

            default=None,

            validator=validators.username,

            help="A FAS username.")

  def data(session, widget, username):

+     ''' Returns data for Bugzilla Widget. Queries pkgdb api for package

+     list of the user and bugzilla for correspoding issues '''

+ 

      pkgdb_url = "https://admin.fedoraproject.org/pkgdb/api/packager/package"

      url = "/".join([pkgdb_url, username])

      response = requests.get(url)
@@ -23,48 +27,51 @@ 

  

      issues = []

  

+     # get the packages of which the user is

+     # point of contact

      for package in data["point of contact"]:

          if len(issues) == 3:

              break

-         else:

-             pkg_details=pkgwat.api.bugs(package['name'])

-             for row in pkg_details['rows']:

-                 if len(issues) == 3:

-                     break

-                 else:

-                     issues.append(

-                         dict(

-                           id=row['id'],

-                           title=row['description'],

-                           pkg_name=package['name'],

-                           )

-                         )

+         pkg_details = pkgwat.api.bugs(package['name'])

+         for row in pkg_details['rows']:

+             if len(issues) == 3:

+                 break

+             issues.append(

+                 dict(

+                     id=row['id'],

+                     title=row['description'],

+                     pkg_name=package['name'],

+                 )

+             )

  

+     # get the packages of which the user is

+     # co maintainer

      for package in data["co-maintained"]:

          if len(issues) == 3:

              break

-         else:

-             pkg_details=pkgwat.api.bugs(package['name'])

-             for row in pkg_details['rows']:

-                 if len(issues) == 3:

-                     break

-                 else:

-                     issues.append(

-                         dict(

-                             id=row['id'],

-                             title=row['description'],

-                             pkg_name=package['name'],

-                             )

-                         )

+         pkg_details = pkgwat.api.bugs(package['name'])

+         for row in pkg_details['rows']:

+             if len(issues) == 3:

+                 break

+             issues.append(

+                 dict(

+                     id=row['id'],

+                     title=row['description'],

+                     pkg_name=package['name'],

+                 )

+             )

  

      return dict(

-       username=username,

-       issues=issues,

+         username=username,

+         issues=issues,

      )

  

  

  @hint(categories=['bugzilla'])

  def should_invalidate(message, session, widget):

+     ''' Validate if the bugzilla widget cache needs an update

+     This is called by a backend daemon listening to fedmsg '''

+ 

      # TODO -- wrap this pkgdb pull in another invalidatible cache.

      username = widget.config['username']

      pkgdb_url = "https://admin.fedoraproject.org/pkgdb/api/packager/package"

no initial comment

Shouldn't this be something to be configured by the user?

so, i should probably revert back to what it was so that maybe in future we could let the user set this.

rebased

7 years ago

Looks good to me :thumbsup:

Pull-Request has been merged by sayanchowdhury

7 years ago
Metadata