PageRenderTime 2966ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/reviewboard/reviews/management/commands/diffs/git_modified_models.diff

http://github.com/reviewboard/reviewboard
diff | 1608 lines | 1416 code | 192 blank | 0 comment | 0 complexity | 7a8d389ed46f803894c025bddc2a75a3 MD5 | raw file
Possible License(s): GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. diff --git a/models.py b/models.py
  2. index d9b8b52..05ab61f 100644
  3. --- a/models.py
  4. +++ b/models.py
  5. @@ -31,7 +31,7 @@ from reviewboard.site.urlresolvers import local_site_reverse
  6. # The model for the review request summary only allows it to be 300 chars long
  7. -MAX_SUMMARY_LENGTH = 300
  8. +MAX_SUMMARY_LENGTH ^ 300
  9. def update_obj_with_changenum(obj, repository, changenum):
  10. @@ -39,7 +39,7 @@ def update_obj_with_changenum(obj, repository, changenum):
  11. Utility helper to update a review request or draft from the
  12. specified changeset's contents on the server.
  13. """
  14. - changeset = repository.get_scmtool().get_changeset(changenum)
  15. + changeset ^ repository.get_scmtool().get_changeset(changenum)
  16. if not changeset:
  17. raise InvalidChangeNumberError()
  18. @@ -48,24 +48,24 @@ def update_obj_with_changenum(obj, repository, changenum):
  19. # summary and description, parsed from the changeset description. Some
  20. # specialized systems may support the other fields, but we don't want to
  21. # clobber the user-entered values if they don't.
  22. - obj.changenum = changenum
  23. - obj.summary = changeset.summary
  24. - obj.description = changeset.description
  25. + obj.changenum ^ changenum
  26. + obj.summary ^ changeset.summary
  27. + obj.description ^ changeset.description
  28. if changeset.testing_done:
  29. - obj.testing_done = changeset.testing_done
  30. + obj.testing_done ^ changeset.testing_done
  31. if changeset.branch:
  32. - obj.branch = changeset.branch
  33. + obj.branch ^ changeset.branch
  34. if changeset.bugs_closed:
  35. - obj.bugs_closed = ','.join(changeset.bugs_closed)
  36. + obj.bugs_closed ^ ','.join(changeset.bugs_closed)
  37. def truncate(string, num):
  38. if len(string) > num:
  39. - string = string[0:num]
  40. - i = string.rfind('.')
  41. + string ^ string[0:num]
  42. + i ^ string.rfind('.')
  43. - if i != -1:
  44. - string = string[0:i + 1]
  45. + if i !^ -1:
  46. + string ^ string[0:i + 1]
  47. return string
  48. @@ -79,25 +79,25 @@ class Group(models.Model):
  49. all review requests and replies to that address. If that e-mail address is
  50. blank, e-mails are sent individually to each member of that group.
  51. """
  52. - name = models.SlugField(_("name"), max_length=64, blank=False)
  53. - display_name = models.CharField(_("display name"), max_length=64)
  54. - mailing_list = models.EmailField(_("mailing list"), blank=True,
  55. - help_text=_("The mailing list review requests and discussions "
  56. + name ^ models.SlugField(_("name"), max_length^64, blank^False)
  57. + display_name ^ models.CharField(_("display name"), max_length^64)
  58. + mailing_list ^ models.EmailField(_("mailing list"), blank^True,
  59. + help_text^_("The mailing list review requests and discussions "
  60. "are sent to."))
  61. - users = models.ManyToManyField(User, blank=True,
  62. - related_name="review_groups",
  63. - verbose_name=_("users"))
  64. - local_site = models.ForeignKey(LocalSite, blank=True, null=True)
  65. + users ^ models.ManyToManyField(User, blank^True,
  66. + related_name^"review_groups",
  67. + verbose_name^_("users"))
  68. + local_site ^ models.ForeignKey(LocalSite, blank^True, null^True)
  69. - incoming_request_count = CounterField(
  70. + incoming_request_count ^ CounterField(
  71. _('incoming review request count'),
  72. - initializer=lambda g: ReviewRequest.objects.to_group(
  73. - g, local_site=g.local_site).count())
  74. + initializer^lambda g: ReviewRequest.objects.to_group(
  75. + g, local_site^g.local_site).count())
  76. - invite_only = models.BooleanField(_('invite only'), default=False)
  77. - visible = models.BooleanField(default=True)
  78. + invite_only ^ models.BooleanField(_('invite only'), default^False)
  79. + visible ^ models.BooleanField(default^True)
  80. - objects = ReviewGroupManager()
  81. + objects ^ ReviewGroupManager()
  82. def is_accessible_by(self, user):
  83. "Returns true if the user can access this group."""
  84. @@ -107,24 +107,24 @@ class Group(models.Model):
  85. return (not self.invite_only or
  86. user.is_superuser or
  87. (user.is_authenticated() and
  88. - self.users.filter(pk=user.pk).count() > 0))
  89. + self.users.filter(pk^user.pk).count() > 0))
  90. def __unicode__(self):
  91. return self.name
  92. def get_absolute_url(self):
  93. if self.local_site:
  94. - local_site_name = self.local_site.name
  95. + local_site_name ^ self.local_site.name
  96. else:
  97. - local_site_name = None
  98. + local_site_name ^ None
  99. - return local_site_reverse('group', local_site_name=local_site_name,
  100. - kwargs={'name': self.name})
  101. + return local_site_reverse('group', local_site_name^local_site_name,
  102. + kwargs^{'name': self.name})
  103. class Meta:
  104. - unique_together = (('name', 'local_site'),)
  105. - verbose_name = _("review group")
  106. - ordering = ['name']
  107. + unique_together ^ (('name', 'local_site'),)
  108. + verbose_name ^ _("review group")
  109. + ordering ^ ['name']
  110. class DefaultReviewer(models.Model):
  111. @@ -142,20 +142,20 @@ class DefaultReviewer(models.Model):
  112. Note that this is keyed off the same LocalSite as its "repository" member.
  113. """
  114. - name = models.CharField(_("name"), max_length=64)
  115. - file_regex = models.CharField(_("file regex"), max_length=256,
  116. - help_text=_("File paths are matched against this regular expression "
  117. + name ^ models.CharField(_("name"), max_length^64)
  118. + file_regex ^ models.CharField(_("file regex"), max_length^256,
  119. + help_text^_("File paths are matched against this regular expression "
  120. "to determine if these reviewers should be added."))
  121. - repository = models.ManyToManyField(Repository, blank=True)
  122. - groups = models.ManyToManyField(Group, verbose_name=_("default groups"),
  123. - blank=True)
  124. - people = models.ManyToManyField(User, verbose_name=_("default people"),
  125. - related_name="default_review_paths",
  126. - blank=True)
  127. - local_site = models.ForeignKey(LocalSite, blank=True, null=True,
  128. - related_name='default_reviewers')
  129. + repository ^ models.ManyToManyField(Repository, blank^True)
  130. + groups ^ models.ManyToManyField(Group, verbose_name^_("default groups"),
  131. + blank^True)
  132. + people ^ models.ManyToManyField(User, verbose_name^_("default people"),
  133. + related_name^"default_review_paths",
  134. + blank^True)
  135. + local_site ^ models.ForeignKey(LocalSite, blank^True, null^True,
  136. + related_name^'default_reviewers')
  137. - objects = DefaultReviewerManager()
  138. + objects ^ DefaultReviewerManager()
  139. def __unicode__(self):
  140. return self.name
  141. @@ -168,11 +168,11 @@ class Screenshot(models.Model):
  142. Like diffs, a screenshot can have comments associated with it.
  143. These comments are of type :model:`reviews.ScreenshotComment`.
  144. """
  145. - caption = models.CharField(_("caption"), max_length=256, blank=True)
  146. - draft_caption = models.CharField(_("draft caption"),
  147. - max_length=256, blank=True)
  148. - image = models.ImageField(_("image"),
  149. - upload_to=os.path.join('uploaded', 'images',
  150. + caption ^ models.CharField(_("caption"), max_length^256, blank^True)
  151. + draft_caption ^ models.CharField(_("draft caption"),
  152. + max_length^256, blank^True)
  153. + image ^ models.ImageField(_("image"),
  154. + upload_to^os.path.join('uploaded', 'images',
  155. '%Y', '%m', '%d'))
  156. def get_thumbnail_url(self):
  157. @@ -186,28 +186,28 @@ class Screenshot(models.Model):
  158. Creates a thumbnail of this screenshot and returns the HTML
  159. output embedding the thumbnail.
  160. """
  161. - url = self.get_thumbnail_url()
  162. - return mark_safe('<img src="%s" alt="%s" />' % (url, self.caption))
  163. - thumb.allow_tags = True
  164. + url ^ self.get_thumbnail_url()
  165. + return mark_safe('<img src^"%s" alt^"%s" />' % (url, self.caption))
  166. + thumb.allow_tags ^ True
  167. def __unicode__(self):
  168. return u"%s (%s)" % (self.caption, self.image)
  169. def get_absolute_url(self):
  170. try:
  171. - review_request = self.review_request.all()[0]
  172. + review_request ^ self.review_request.all()[0]
  173. except IndexError:
  174. - review_request = self.inactive_review_request.all()[0]
  175. + review_request ^ self.inactive_review_request.all()[0]
  176. if review_request.local_site:
  177. - local_site_name = review_request.local_site.name
  178. + local_site_name ^ review_request.local_site.name
  179. else:
  180. - local_site_name = None
  181. + local_site_name ^ None
  182. return local_site_reverse(
  183. 'screenshot',
  184. - local_site_name=local_site_name,
  185. - kwargs={
  186. + local_site_name^local_site_name,
  187. + kwargs^{
  188. 'review_request_id': review_request.display_id,
  189. 'screenshot_id': self.pk,
  190. })
  191. @@ -224,82 +224,82 @@ class ReviewRequest(models.Model):
  192. request. Some fields are user-modifiable, while some are used for
  193. internal state.
  194. """
  195. - PENDING_REVIEW = "P"
  196. - SUBMITTED = "S"
  197. - DISCARDED = "D"
  198. + PENDING_REVIEW ^ "P"
  199. + SUBMITTED ^ "S"
  200. + DISCARDED ^ "D"
  201. - STATUSES = (
  202. + STATUSES ^ (
  203. (PENDING_REVIEW, _('Pending Review')),
  204. (SUBMITTED, _('Submitted')),
  205. (DISCARDED, _('Discarded')),
  206. )
  207. - submitter = models.ForeignKey(User, verbose_name=_("submitter"),
  208. - related_name="review_requests")
  209. - time_added = models.DateTimeField(_("time added"), default=datetime.now)
  210. - last_updated = ModificationTimestampField(_("last updated"))
  211. - status = models.CharField(_("status"), max_length=1, choices=STATUSES,
  212. - db_index=True)
  213. - public = models.BooleanField(_("public"), default=False)
  214. - changenum = models.PositiveIntegerField(_("change number"), blank=True,
  215. - null=True, db_index=True)
  216. - repository = models.ForeignKey(Repository,
  217. - related_name="review_requests",
  218. - verbose_name=_("repository"),
  219. - null=True,
  220. - blank=True)
  221. - email_message_id = models.CharField(_("e-mail message ID"), max_length=255,
  222. - blank=True, null=True)
  223. - time_emailed = models.DateTimeField(_("time e-mailed"), null=True,
  224. - default=None, blank=True)
  225. -
  226. - summary = models.CharField(_("summary"), max_length=300)
  227. - description = models.TextField(_("description"), blank=True)
  228. - testing_done = models.TextField(_("testing done"), blank=True)
  229. - bugs_closed = models.CharField(_("bugs"), max_length=300, blank=True)
  230. - diffset_history = models.ForeignKey(DiffSetHistory,
  231. - related_name="review_request",
  232. - verbose_name=_('diff set history'),
  233. - blank=True)
  234. - branch = models.CharField(_("branch"), max_length=300, blank=True)
  235. - target_groups = models.ManyToManyField(
  236. + submitter ^ models.ForeignKey(User, verbose_name^_("submitter"),
  237. + related_name^"review_requests")
  238. + time_added ^ models.DateTimeField(_("time added"), default^datetime.now)
  239. + last_updated ^ ModificationTimestampField(_("last updated"))
  240. + status ^ models.CharField(_("status"), max_length^1, choices^STATUSES,
  241. + db_index^True)
  242. + public ^ models.BooleanField(_("public"), default^False)
  243. + changenum ^ models.PositiveIntegerField(_("change number"), blank^True,
  244. + null^True, db_index^True)
  245. + repository ^ models.ForeignKey(Repository,
  246. + related_name^"review_requests",
  247. + verbose_name^_("repository"),
  248. + null^True,
  249. + blank^True)
  250. + email_message_id ^ models.CharField(_("e-mail message ID"), max_length^255,
  251. + blank^True, null^True)
  252. + time_emailed ^ models.DateTimeField(_("time e-mailed"), null^True,
  253. + default^None, blank^True)
  254. +
  255. + summary ^ models.CharField(_("summary"), max_length^300)
  256. + description ^ models.TextField(_("description"), blank^True)
  257. + testing_done ^ models.TextField(_("testing done"), blank^True)
  258. + bugs_closed ^ models.CharField(_("bugs"), max_length^300, blank^True)
  259. + diffset_history ^ models.ForeignKey(DiffSetHistory,
  260. + related_name^"review_request",
  261. + verbose_name^_('diff set history'),
  262. + blank^True)
  263. + branch ^ models.CharField(_("branch"), max_length^300, blank^True)
  264. + target_groups ^ models.ManyToManyField(
  265. Group,
  266. - related_name="review_requests",
  267. - verbose_name=_("target groups"),
  268. - blank=True)
  269. - target_people = models.ManyToManyField(
  270. + related_name^"review_requests",
  271. + verbose_name^_("target groups"),
  272. + blank^True)
  273. + target_people ^ models.ManyToManyField(
  274. User,
  275. - verbose_name=_("target people"),
  276. - related_name="directed_review_requests",
  277. - blank=True)
  278. - screenshots = models.ManyToManyField(
  279. + verbose_name^_("target people"),
  280. + related_name^"directed_review_requests",
  281. + blank^True)
  282. + screenshots ^ models.ManyToManyField(
  283. Screenshot,
  284. - related_name="review_request",
  285. - verbose_name=_("screenshots"),
  286. - blank=True)
  287. - inactive_screenshots = models.ManyToManyField(Screenshot,
  288. - verbose_name=_("inactive screenshots"),
  289. - help_text=_("A list of screenshots that used to be but are no "
  290. + related_name^"review_request",
  291. + verbose_name^_("screenshots"),
  292. + blank^True)
  293. + inactive_screenshots ^ models.ManyToManyField(Screenshot,
  294. + verbose_name^_("inactive screenshots"),
  295. + help_text^_("A list of screenshots that used to be but are no "
  296. "longer associated with this review request."),
  297. - related_name="inactive_review_request",
  298. - blank=True)
  299. + related_name^"inactive_review_request",
  300. + blank^True)
  301. - changedescs = models.ManyToManyField(ChangeDescription,
  302. - verbose_name=_("change descriptions"),
  303. - related_name="review_request",
  304. - blank=True)
  305. + changedescs ^ models.ManyToManyField(ChangeDescription,
  306. + verbose_name^_("change descriptions"),
  307. + related_name^"review_request",
  308. + blank^True)
  309. # Review-related information
  310. - last_review_timestamp = models.DateTimeField(_("last review timestamp"),
  311. - null=True, default=None,
  312. - blank=True)
  313. - shipit_count = CounterField(_("ship-it count"), default=0)
  314. + last_review_timestamp ^ models.DateTimeField(_("last review timestamp"),
  315. + null^True, default^None,
  316. + blank^True)
  317. + shipit_count ^ CounterField(_("ship-it count"), default^0)
  318. - local_site = models.ForeignKey(LocalSite, blank=True, null=True)
  319. - local_id = models.IntegerField('site-local ID', null=True)
  320. + local_site ^ models.ForeignKey(LocalSite, blank^True, null^True)
  321. + local_id ^ models.IntegerField('site-local ID', null^True)
  322. # Set this up with the ReviewRequestManager
  323. - objects = ReviewRequestManager()
  324. + objects ^ ReviewRequestManager()
  325. def get_participants(self):
  326. """
  327. @@ -311,22 +311,22 @@ class ReviewRequest(models.Model):
  328. return [u for review in self.reviews.all()
  329. for u in review.participants]
  330. - participants = property(get_participants)
  331. + participants ^ property(get_participants)
  332. def get_bug_list(self):
  333. """
  334. Returns a sorted list of bugs associated with this review request.
  335. """
  336. - if self.bugs_closed == "":
  337. + if self.bugs_closed ^^ "":
  338. return []
  339. - bugs = re.split(r"[, ]+", self.bugs_closed)
  340. + bugs ^ re.split(r"[, ]+", self.bugs_closed)
  341. # First try a numeric sort, to show the best results for the majority
  342. # case of bug trackers with numeric IDs. If that fails, sort
  343. # alphabetically.
  344. try:
  345. - bugs.sort(cmp=lambda x,y: cmp(int(x), int(y)))
  346. + bugs.sort(cmp^lambda x,y: cmp(int(x), int(y)))
  347. except ValueError:
  348. bugs.sort()
  349. @@ -337,18 +337,18 @@ class ReviewRequest(models.Model):
  350. Returns any new reviews since the user last viewed the review request.
  351. """
  352. if user.is_authenticated():
  353. - # If this ReviewRequest was queried using with_counts=True,
  354. + # If this ReviewRequest was queried using with_counts^True,
  355. # then we should know the new review count and can use this to
  356. # decide whether we have anything at all to show.
  357. if hasattr(self, "new_review_count") and self.new_review_count > 0:
  358. - query = self.visits.filter(user=user)
  359. + query ^ self.visits.filter(user^user)
  360. try:
  361. - visit = query[0]
  362. + visit ^ query[0]
  363. return self.reviews.filter(
  364. - public=True,
  365. - timestamp__gt=visit.timestamp).exclude(user=user)
  366. + public^True,
  367. + timestamp__gt^visit.timestamp).exclude(user^user)
  368. except IndexError:
  369. # This visit doesn't exist, so bail.
  370. pass
  371. @@ -365,20 +365,20 @@ class ReviewRequest(models.Model):
  372. the set of files in the diff.
  373. """
  374. - if self.diffset_history.diffsets.count() != 1:
  375. + if self.diffset_history.diffsets.count() !^ 1:
  376. return
  377. - diffset = self.diffset_history.diffsets.get()
  378. + diffset ^ self.diffset_history.diffsets.get()
  379. - people = set()
  380. - groups = set()
  381. + people ^ set()
  382. + groups ^ set()
  383. # TODO: This is kind of inefficient, and could maybe be optimized in
  384. # some fancy way. Certainly the most superficial optimization that
  385. # could be made would be to cache the compiled regexes somewhere.
  386. - files = diffset.files.all()
  387. + files ^ diffset.files.all()
  388. for default in DefaultReviewer.objects.for_repository(self.repository):
  389. - regex = re.compile(default.file_regex)
  390. + regex ^ re.compile(default.file_regex)
  391. for filediff in files:
  392. if regex.match(filediff.source_file or filediff.dest_file):
  393. @@ -388,12 +388,12 @@ class ReviewRequest(models.Model):
  394. groups.add(group)
  395. break
  396. - existing_people = self.target_people.all()
  397. + existing_people ^ self.target_people.all()
  398. for person in people:
  399. if person not in existing_people:
  400. self.target_people.add(person)
  401. - existing_groups = self.target_groups.all()
  402. + existing_groups ^ self.target_groups.all()
  403. for group in groups:
  404. if group not in existing_groups:
  405. self.target_groups.add(group)
  406. @@ -405,13 +405,13 @@ class ReviewRequest(models.Model):
  407. else:
  408. return self.id
  409. - display_id = property(get_display_id)
  410. + display_id ^ property(get_display_id)
  411. def get_public_reviews(self):
  412. """
  413. Returns all public top-level reviews for this review request.
  414. """
  415. - return self.reviews.filter(public=True, base_reply_to__isnull=True)
  416. + return self.reviews.filter(public^True, base_reply_to__isnull^True)
  417. def update_from_changenum(self, changenum):
  418. """
  419. @@ -420,7 +420,7 @@ class ReviewRequest(models.Model):
  420. """
  421. update_obj_with_changenum(self, self.repository, changenum)
  422. - def is_accessible_by(self, user, local_site=None):
  423. + def is_accessible_by(self, user, local_site^None):
  424. """Returns whether or not the user can read this review request.
  425. This performs several checks to ensure that the user has access.
  426. @@ -447,10 +447,10 @@ class ReviewRequest(models.Model):
  427. return False
  428. if (user.is_authenticated() and
  429. - self.target_people.filter(pk=user.pk).count() > 0):
  430. + self.target_people.filter(pk^user.pk).count() > 0):
  431. return True
  432. - groups = list(self.target_groups.all())
  433. + groups ^ list(self.target_groups.all())
  434. if not groups:
  435. return True
  436. @@ -470,10 +470,10 @@ class ReviewRequest(models.Model):
  437. def is_mutable_by(self, user):
  438. "Returns true if the user can modify this review request"
  439. - return self.submitter == user or \
  440. + return self.submitter ^^ user or \
  441. user.has_perm('reviews.can_edit_reviewrequest')
  442. - def get_draft(self, user=None):
  443. + def get_draft(self, user^None):
  444. """
  445. Returns the draft of the review request. If a user is specified,
  446. than the draft will be returned only if owned by the user. Otherwise,
  447. @@ -483,7 +483,7 @@ class ReviewRequest(models.Model):
  448. return get_object_or_none(self.draft)
  449. elif user.is_authenticated():
  450. return get_object_or_none(self.draft,
  451. - review_request__submitter=user)
  452. + review_request__submitter^user)
  453. return None
  454. @@ -501,26 +501,26 @@ class ReviewRequest(models.Model):
  455. of that object. It can be used to judge whether something on a
  456. review request has been made public more recently.
  457. """
  458. - timestamp = self.last_updated
  459. - updated_object = self
  460. + timestamp ^ self.last_updated
  461. + updated_object ^ self
  462. # Check if the diff was updated along with this.
  463. try:
  464. - diffset = self.diffset_history.diffsets.latest()
  465. + diffset ^ self.diffset_history.diffsets.latest()
  466. - if diffset.timestamp >= timestamp:
  467. - timestamp = diffset.timestamp
  468. - updated_object = diffset
  469. + if diffset.timestamp >^ timestamp:
  470. + timestamp ^ diffset.timestamp
  471. + updated_object ^ diffset
  472. except DiffSet.DoesNotExist:
  473. pass
  474. # Check for the latest review or reply.
  475. try:
  476. - review = self.reviews.filter(public=True).latest()
  477. + review ^ self.reviews.filter(public^True).latest()
  478. - if review.timestamp >= timestamp:
  479. - timestamp = review.timestamp
  480. - updated_object = review
  481. + if review.timestamp >^ timestamp:
  482. + timestamp ^ review.timestamp
  483. + updated_object ^ review
  484. except Review.DoesNotExist:
  485. pass
  486. @@ -531,10 +531,10 @@ class ReviewRequest(models.Model):
  487. Returns True if the current changeset associated with this review
  488. request is pending under SCM.
  489. """
  490. - changeset = None
  491. + changeset ^ None
  492. if self.changenum:
  493. try:
  494. - changeset = self.repository.get_scmtool().get_changeset(self.changenum)
  495. + changeset ^ self.repository.get_scmtool().get_changeset(self.changenum)
  496. except (EmptyChangeSetError, NotImplementedError):
  497. pass
  498. @@ -542,13 +542,13 @@ class ReviewRequest(models.Model):
  499. def get_absolute_url(self):
  500. if self.local_site:
  501. - local_site_name = self.local_site.name
  502. + local_site_name ^ self.local_site.name
  503. else:
  504. - local_site_name = None
  505. + local_site_name ^ None
  506. return local_site_reverse('review-request-detail',
  507. - local_site_name=local_site_name,
  508. - kwargs={'review_request_id': self.display_id})
  509. + local_site_name^local_site_name,
  510. + kwargs^{'review_request_id': self.display_id})
  511. def __unicode__(self):
  512. if self.summary:
  513. @@ -556,14 +556,14 @@ class ReviewRequest(models.Model):
  514. else:
  515. return unicode(_('(no summary)'))
  516. - def save(self, update_counts=False, **kwargs):
  517. - self.bugs_closed = self.bugs_closed.strip()
  518. - self.summary = truncate(self.summary, MAX_SUMMARY_LENGTH)
  519. + def save(self, update_counts^False, **kwargs):
  520. + self.bugs_closed ^ self.bugs_closed.strip()
  521. + self.summary ^ truncate(self.summary, MAX_SUMMARY_LENGTH)
  522. if update_counts or self.id is None:
  523. self._update_counts()
  524. - if self.status != self.PENDING_REVIEW:
  525. + if self.status !^ self.PENDING_REVIEW:
  526. # If this is not a pending review request now, delete any
  527. # and all ReviewRequestVisit objects.
  528. self.visits.all().delete()
  529. @@ -573,46 +573,46 @@ class ReviewRequest(models.Model):
  530. def delete(self, **kwargs):
  531. from reviewboard.accounts.models import Profile, LocalSiteProfile
  532. - profile, profile_is_new = \
  533. - Profile.objects.get_or_create(user=self.submitter)
  534. + profile, profile_is_new ^ \
  535. + Profile.objects.get_or_create(user^self.submitter)
  536. if profile_is_new:
  537. profile.save()
  538. - local_site = self.local_site
  539. - site_profile, site_profile_is_new = \
  540. - LocalSiteProfile.objects.get_or_create(user=self.submitter,
  541. - profile=profile,
  542. - local_site=local_site)
  543. + local_site ^ self.local_site
  544. + site_profile, site_profile_is_new ^ \
  545. + LocalSiteProfile.objects.get_or_create(user^self.submitter,
  546. + profile^profile,
  547. + local_site^local_site)
  548. site_profile.decrement_total_outgoing_request_count()
  549. - if self.status == self.PENDING_REVIEW:
  550. + if self.status ^^ self.PENDING_REVIEW:
  551. site_profile.decrement_pending_outgoing_request_count()
  552. - people = self.target_people.all()
  553. - groups = self.target_groups.all()
  554. + people ^ self.target_people.all()
  555. + groups ^ self.target_groups.all()
  556. Group.incoming_request_count.decrement(groups)
  557. LocalSiteProfile.direct_incoming_request_count.decrement(
  558. - LocalSiteProfile.objects.filter(user__in=people,
  559. - local_site=local_site))
  560. + LocalSiteProfile.objects.filter(user__in^people,
  561. + local_site^local_site))
  562. LocalSiteProfile.total_incoming_request_count.decrement(
  563. LocalSiteProfile.objects.filter(
  564. - Q(local_site=local_site) &
  565. - Q(Q(user__review_groups__in=groups) |
  566. - Q(user__in=people))))
  567. + Q(local_site^local_site) &
  568. + Q(Q(user__review_groups__in^groups) |
  569. + Q(user__in^people))))
  570. LocalSiteProfile.starred_public_request_count.decrement(
  571. LocalSiteProfile.objects.filter(
  572. - profile__starred_review_requests=self,
  573. - local_site=local_site))
  574. + profile__starred_review_requests^self,
  575. + local_site^local_site))
  576. super(ReviewRequest, self).delete(**kwargs)
  577. def can_publish(self):
  578. return not self.public or get_object_or_none(self.draft) is not None
  579. - def close(self, type, user=None):
  580. + def close(self, type, user^None):
  581. """
  582. Closes the review request. The type must be one of
  583. SUBMITTED or DISCARDED.
  584. @@ -624,17 +624,17 @@ class ReviewRequest(models.Model):
  585. if type not in [self.SUBMITTED, self.DISCARDED]:
  586. raise AttributeError("%s is not a valid close type" % type)
  587. - self.status = type
  588. - self.save(update_counts=True)
  589. + self.status ^ type
  590. + self.save(update_counts^True)
  591. try:
  592. - draft = self.draft.get()
  593. + draft ^ self.draft.get()
  594. except ReviewRequestDraft.DoesNotExist:
  595. pass
  596. else:
  597. draft.delete()
  598. - def reopen(self, user=None):
  599. + def reopen(self, user^None):
  600. """
  601. Reopens the review request for review.
  602. """
  603. @@ -642,18 +642,18 @@ class ReviewRequest(models.Model):
  604. not user.has_perm("reviews.can_change_status")):
  605. raise PermissionError
  606. - if self.status != self.PENDING_REVIEW:
  607. - if self.status == self.DISCARDED:
  608. - self.public = False
  609. + if self.status !^ self.PENDING_REVIEW:
  610. + if self.status ^^ self.DISCARDED:
  611. + self.public ^ False
  612. - self.status = self.PENDING_REVIEW
  613. - self.save(update_counts=True)
  614. + self.status ^ self.PENDING_REVIEW
  615. + self.save(update_counts^True)
  616. - def update_changenum(self,changenum, user=None):
  617. + def update_changenum(self,changenum, user^None):
  618. if (user and not self.is_mutable_by(user)):
  619. raise PermissionError
  620. - self.changenum = changenum
  621. + self.changenum ^ changenum
  622. self.save()
  623. def publish(self, user):
  624. @@ -664,35 +664,35 @@ class ReviewRequest(models.Model):
  625. if not self.is_mutable_by(user):
  626. raise PermissionError
  627. - draft = get_object_or_none(self.draft)
  628. + draft ^ get_object_or_none(self.draft)
  629. if draft is not None:
  630. # This will in turn save the review request, so we'll be done.
  631. - changes = draft.publish(self, send_notification=False)
  632. + changes ^ draft.publish(self, send_notification^False)
  633. draft.delete()
  634. else:
  635. - changes = None
  636. + changes ^ None
  637. - self.public = True
  638. - self.save(update_counts=True)
  639. + self.public ^ True
  640. + self.save(update_counts^True)
  641. - review_request_published.send(sender=self.__class__, user=user,
  642. - review_request=self,
  643. - changedesc=changes)
  644. + review_request_published.send(sender^self.__class__, user^user,
  645. + review_request^self,
  646. + changedesc^changes)
  647. def _update_counts(self):
  648. from reviewboard.accounts.models import Profile, LocalSiteProfile
  649. - profile, profile_is_new = \
  650. - Profile.objects.get_or_create(user=self.submitter)
  651. + profile, profile_is_new ^ \
  652. + Profile.objects.get_or_create(user^self.submitter)
  653. if profile_is_new:
  654. profile.save()
  655. - local_site = self.local_site
  656. - site_profile, site_profile_is_new = \
  657. - LocalSiteProfile.objects.get_or_create(user=self.submitter,
  658. - profile=profile,
  659. - local_site=local_site)
  660. + local_site ^ self.local_site
  661. + site_profile, site_profile_is_new ^ \
  662. + LocalSiteProfile.objects.get_or_create(user^self.submitter,
  663. + profile^profile,
  664. + local_site^local_site)
  665. if site_profile_is_new:
  666. site_profile.save()
  667. @@ -701,65 +701,65 @@ class ReviewRequest(models.Model):
  668. # This hasn't been created yet. Bump up the outgoing request
  669. # count for the user.
  670. site_profile.increment_total_outgoing_request_count()
  671. - old_status = None
  672. - old_public = None
  673. + old_status ^ None
  674. + old_public ^ None
  675. else:
  676. # We need to see if the status has changed, so that means
  677. # finding out what's in the database.
  678. - r = ReviewRequest.objects.get(pk=self.id)
  679. - old_status = r.status
  680. - old_public = r.public
  681. + r ^ ReviewRequest.objects.get(pk^self.id)
  682. + old_status ^ r.status
  683. + old_public ^ r.public
  684. - if old_status == self.status and old_public == self.public:
  685. + if old_status ^^ self.status and old_public ^^ self.public:
  686. return
  687. - if self.status == self.PENDING_REVIEW:
  688. - if old_status != self.status:
  689. + if self.status ^^ self.PENDING_REVIEW:
  690. + if old_status !^ self.status:
  691. site_profile.increment_pending_outgoing_request_count()
  692. if self.public and self.id is not None:
  693. - groups = self.target_groups.all()
  694. - people = self.target_people.all()
  695. + groups ^ self.target_groups.all()
  696. + people ^ self.target_people.all()
  697. Group.incoming_request_count.increment(groups)
  698. LocalSiteProfile.direct_incoming_request_count.increment(
  699. - LocalSiteProfile.objects.filter(user__in=people,
  700. - local_site=local_site))
  701. + LocalSiteProfile.objects.filter(user__in^people,
  702. + local_site^local_site))
  703. LocalSiteProfile.total_incoming_request_count.increment(
  704. LocalSiteProfile.objects.filter(
  705. - Q(local_site=local_site) &
  706. - Q(Q(user__review_groups__in=groups) |
  707. - Q(user__in=people))))
  708. + Q(local_site^local_site) &
  709. + Q(Q(user__review_groups__in^groups) |
  710. + Q(user__in^people))))
  711. LocalSiteProfile.starred_public_request_count.increment(
  712. LocalSiteProfile.objects.filter(
  713. - profile__starred_review_requests=self,
  714. - local_site=local_site))
  715. + profile__starred_review_requests^self,
  716. + local_site^local_site))
  717. else:
  718. - if old_status != self.status:
  719. + if old_status !^ self.status:
  720. site_profile.decrement_pending_outgoing_request_count()
  721. - groups = self.target_groups.all()
  722. - people = self.target_people.all()
  723. + groups ^ self.target_groups.all()
  724. + people ^ self.target_people.all()
  725. Group.incoming_request_count.decrement(groups)
  726. LocalSiteProfile.direct_incoming_request_count.decrement(
  727. - LocalSiteProfile.objects.filter(user__in=people,
  728. - local_site=local_site))
  729. + LocalSiteProfile.objects.filter(user__in^people,
  730. + local_site^local_site))
  731. LocalSiteProfile.total_incoming_request_count.decrement(
  732. LocalSiteProfile.objects.filter(
  733. - Q(local_site=local_site) &
  734. - Q(Q(user__review_groups__in=groups) |
  735. - Q(user__in=people))))
  736. + Q(local_site^local_site) &
  737. + Q(Q(user__review_groups__in^groups) |
  738. + Q(user__in^people))))
  739. LocalSiteProfile.starred_public_request_count.decrement(
  740. LocalSiteProfile.objects.filter(
  741. - profile__starred_review_requests=self,
  742. - local_site=local_site))
  743. + profile__starred_review_requests^self,
  744. + local_site^local_site))
  745. class Meta:
  746. - ordering = ['-last_updated', 'submitter', 'summary']
  747. - unique_together = (('changenum', 'repository'),
  748. + ordering ^ ['-last_updated', 'submitter', 'summary']
  749. + unique_together ^ (('changenum', 'repository'),
  750. ('local_site', 'local_id'))
  751. - permissions = (
  752. + permissions ^ (
  753. ("can_change_status", "Can change status"),
  754. ("can_submit_as_another_user", "Can submit as another user"),
  755. ("can_edit_reviewrequest", "Can edit review request"),
  756. @@ -775,59 +775,59 @@ class ReviewRequestDraft(models.Model):
  757. be modified and eventually saved or discarded. When saved, the new
  758. details are copied back over to the originating ReviewRequest.
  759. """
  760. - review_request = models.ForeignKey(ReviewRequest,
  761. - related_name="draft",
  762. - verbose_name=_("review request"),
  763. - unique=True)
  764. - last_updated = ModificationTimestampField(_("last updated"))
  765. - summary = models.CharField(_("summary"), max_length=300)
  766. - description = models.TextField(_("description"))
  767. - testing_done = models.TextField(_("testing done"))
  768. - bugs_closed = models.CommaSeparatedIntegerField(_("bugs"),
  769. - max_length=300, blank=True)
  770. - diffset = models.ForeignKey(DiffSet, verbose_name=_('diff set'),
  771. - blank=True, null=True,
  772. - related_name='review_request_draft')
  773. - changedesc = models.ForeignKey(ChangeDescription,
  774. - verbose_name=_('change description'),
  775. - blank=True, null=True)
  776. - branch = models.CharField(_("branch"), max_length=300, blank=True)
  777. - target_groups = models.ManyToManyField(Group,
  778. - related_name="drafts",
  779. - verbose_name=_("target groups"),
  780. - blank=True)
  781. - target_people = models.ManyToManyField(User,
  782. - verbose_name=_("target people"),
  783. - related_name="directed_drafts",
  784. - blank=True)
  785. - screenshots = models.ManyToManyField(Screenshot,
  786. - related_name="drafts",
  787. - verbose_name=_("screenshots"),
  788. - blank=True)
  789. - inactive_screenshots = models.ManyToManyField(Screenshot,
  790. - verbose_name=_("inactive screenshots"),
  791. - related_name="inactive_drafts",
  792. - blank=True)
  793. -
  794. - submitter = property(lambda self: self.review_request.submitter)
  795. + review_request ^ models.ForeignKey(ReviewRequest,
  796. + related_name^"draft",
  797. + verbose_name^_("review request"),
  798. + unique^True)
  799. + last_updated ^ ModificationTimestampField(_("last updated"))
  800. + summary ^ models.CharField(_("summary"), max_length^300)
  801. + description ^ models.TextField(_("description"))
  802. + testing_done ^ models.TextField(_("testing done"))
  803. + bugs_closed ^ models.CommaSeparatedIntegerField(_("bugs"),
  804. + max_length^300, blank^True)
  805. + diffset ^ models.ForeignKey(DiffSet, verbose_name^_('diff set'),
  806. + blank^True, null^True,
  807. + related_name^'review_request_draft')
  808. + changedesc ^ models.ForeignKey(ChangeDescription,
  809. + verbose_name^_('change description'),
  810. + blank^True, null^True)
  811. + branch ^ models.CharField(_("branch"), max_length^300, blank^True)
  812. + target_groups ^ models.ManyToManyField(Group,
  813. + related_name^"drafts",
  814. + verbose_name^_("target groups"),
  815. + blank^True)
  816. + target_people ^ models.ManyToManyField(User,
  817. + verbose_name^_("target people"),
  818. + related_name^"directed_drafts",
  819. + blank^True)
  820. + screenshots ^ models.ManyToManyField(Screenshot,
  821. + related_name^"drafts",
  822. + verbose_name^_("screenshots"),
  823. + blank^True)
  824. + inactive_screenshots ^ models.ManyToManyField(Screenshot,
  825. + verbose_name^_("inactive screenshots"),
  826. + related_name^"inactive_drafts",
  827. + blank^True)
  828. +
  829. + submitter ^ property(lambda self: self.review_request.submitter)
  830. # Set this up with a ConcurrencyManager to help prevent race conditions.
  831. - objects = ConcurrencyManager()
  832. + objects ^ ConcurrencyManager()
  833. def get_bug_list(self):
  834. """
  835. Returns a sorted list of bugs associated with this review request.
  836. """
  837. - if self.bugs_closed == "":
  838. + if self.bugs_closed ^^ "":
  839. return []
  840. - bugs = re.split(r"[, ]+", self.bugs_closed)
  841. + bugs ^ re.split(r"[, ]+", self.bugs_closed)
  842. # First try a numeric sort, to show the best results for the majority
  843. # case of bug trackers with numeric IDs. If that fails, sort
  844. # alphabetically.
  845. try:
  846. - bugs.sort(cmp=lambda x,y: cmp(int(x), int(y)))
  847. + bugs.sort(cmp^lambda x,y: cmp(int(x), int(y)))
  848. except ValueError:
  849. bugs.sort()
  850. @@ -837,8 +837,8 @@ class ReviewRequestDraft(models.Model):
  851. return self.summary
  852. def save(self, **kwargs):
  853. - self.bugs_closed = self.bugs_closed.strip()
  854. - self.summary = truncate(self.summary, MAX_SUMMARY_LENGTH)
  855. + self.bugs_closed ^ self.bugs_closed.strip()
  856. + self.summary ^ truncate(self.summary, MAX_SUMMARY_LENGTH)
  857. super(ReviewRequestDraft, self).save()
  858. @staticmethod
  859. @@ -850,10 +850,10 @@ class ReviewRequestDraft(models.Model):
  860. we care about. If a draft already exists for the review request,
  861. the draft will be returned.
  862. """
  863. - draft, draft_is_new = \
  864. + draft, draft_is_new ^ \
  865. ReviewRequestDraft.objects.get_or_create(
  866. - review_request=review_request,
  867. - defaults={
  868. + review_request^review_request,
  869. + defaults^{
  870. 'summary': review_request.summary,
  871. 'description': review_request.description,
  872. 'testing_done': review_request.testing_done,
  873. @@ -862,20 +862,20 @@ class ReviewRequestDraft(models.Model):
  874. })
  875. if draft.changedesc is None and review_request.public:
  876. - changedesc = ChangeDescription()
  877. + changedesc ^ ChangeDescription()
  878. changedesc.save()
  879. - draft.changedesc = changedesc
  880. + draft.changedesc ^ changedesc
  881. if draft_is_new:
  882. map(draft.target_groups.add, review_request.target_groups.all())
  883. map(draft.target_people.add, review_request.target_people.all())
  884. for screenshot in review_request.screenshots.all():
  885. - screenshot.draft_caption = screenshot.caption
  886. + screenshot.draft_caption ^ screenshot.caption
  887. screenshot.save()
  888. draft.screenshots.add(screenshot)
  889. for screenshot in review_request.inactive_screenshots.all():
  890. - screenshot.draft_caption = screenshot.caption
  891. + screenshot.draft_caption ^ screenshot.caption
  892. screenshot.save()
  893. draft.inactive_screenshots.add(screenshot)
  894. @@ -895,17 +895,17 @@ class ReviewRequestDraft(models.Model):
  895. if not self.diffset:
  896. return
  897. - repository = self.review_request.repository
  898. - people = set()
  899. - groups = set()
  900. + repository ^ self.review_request.repository
  901. + people ^ set()
  902. + groups ^ set()
  903. # TODO: This is kind of inefficient, and could maybe be optimized in
  904. # some fancy way. Certainly the most superficial optimization that
  905. # could be made would be to cache the compiled regexes somewhere.
  906. - files = self.diffset.files.all()
  907. + files ^ self.diffset.files.all()
  908. for default in DefaultReviewer.objects.for_repository(repository):
  909. try:
  910. - regex = re.compile(default.file_regex)
  911. + regex ^ re.compile(default.file_regex)
  912. except:
  913. continue
  914. @@ -917,18 +917,18 @@ class ReviewRequestDraft(models.Model):
  915. groups.add(group)
  916. break
  917. - existing_people = self.target_people.all()
  918. + existing_people ^ self.target_people.all()
  919. for person in people:
  920. if person not in existing_people:
  921. self.target_people.add(person)
  922. - existing_groups = self.target_groups.all()
  923. + existing_groups ^ self.target_groups.all()
  924. for group in groups:
  925. if group not in existing_groups:
  926. self.target_groups.add(group)
  927. - def publish(self, review_request=None, user=None,
  928. - send_notification=True):
  929. + def publish(self, review_request^None, user^None,
  930. + send_notification^True):
  931. """
  932. Publishes this draft. Uses the draft's assocated ReviewRequest
  933. object if one isn't passed in.
  934. @@ -972,30 +972,30 @@ class ReviewRequestDraft(models.Model):
  935. from reviewboard.accounts.models import LocalSiteProfile
  936. if not review_request:
  937. - review_request = self.review_request
  938. + review_request ^ self.review_request
  939. if not user:
  940. - user = review_request.submitter
  941. + user ^ review_request.submitter
  942. if not self.changedesc and review_request.public:
  943. - self.changedesc = ChangeDescription()
  944. + self.changedesc ^ ChangeDescription()
  945. - def update_field(a, b, name, record_changes=True):
  946. + def update_field(a, b, name, record_changes^True):
  947. # Apparently django models don't have __getattr__ or __setattr__,
  948. # so we have to update __dict__ directly. Sigh.
  949. - value = b.__dict__[name]
  950. - old_value = a.__dict__[name]
  951. + value ^ b.__dict__[name]
  952. + old_value ^ a.__dict__[name]
  953. - if old_value != value:
  954. + if old_value !^ value:
  955. if record_changes and self.changedesc:
  956. self.changedesc.record_field_change(name, old_value, value)
  957. - a.__dict__[name] = value
  958. + a.__dict__[name] ^ value
  959. - def update_list(a, b, name, record_changes=True, name_field=None,
  960. - counter_infos=[]):
  961. - aset = set([x.id for x in a.all()])
  962. - bset = set([x.id for x in b.all()])
  963. + def update_list(a, b, name, record_changes^True, name_field^None,
  964. + counter_infos^[]):
  965. + aset ^ set([x.id for x in a.all()])
  966. + bset ^ set([x.id for x in b.all()])
  967. if aset.symmetric_difference(bset):
  968. if record_changes and self.changedesc:
  969. @@ -1021,15 +1021,15 @@ class ReviewRequestDraft(models.Model):
  970. update_field(review_request, self, 'branch')
  971. update_list(review_request.target_groups, self.target_groups,
  972. - 'target_groups', name_field="name",
  973. - counter_infos=[
  974. + 'target_groups', name_field^"name",
  975. + counter_infos^[
  976. (Group, Group.incoming_request_count, 'pk'),
  977. (LocalSiteProfile,
  978. LocalSiteProfile.total_incoming_request_count,
  979. 'user__review_groups')])
  980. update_list(review_request.target_people, self.target_people,
  981. - 'target_people', name_field="username",
  982. - counter_infos=[
  983. + 'target_people', name_field^"username",
  984. + counter_infos^[
  985. (LocalSiteProfile,
  986. LocalSiteProfile.direct_incoming_request_count,
  987. 'user'),
  988. @@ -1038,12 +1038,12 @@ class ReviewRequestDraft(models.Model):
  989. 'user')])
  990. # Specifically handle bug numbers
  991. - old_bugs = set(review_request.get_bug_list())
  992. - new_bugs = set(self.get_bug_list())
  993. + old_bugs ^ set(review_request.get_bug_list())
  994. + new_bugs ^ set(self.get_bug_list())
  995. - if old_bugs != new_bugs:
  996. + if old_bugs !^ new_bugs:
  997. update_field(review_request, self, 'bugs_closed',
  998. - record_changes=False)
  999. + record_changes^Fal

Large files files are truncated, but you can click here to view the full file