-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Patent management v1 backend update #1911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Saumitra-agrahari
wants to merge
2
commits into
FusionIIIT:patent-management-v1
Choose a base branch
from
Saumitra-agrahari:patent-management-v1
base: patent-management-v1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| from django.contrib import admin, messages | ||
| from django.db import transaction | ||
|
|
||
| # Ensure globals admin registrations are loaded before we attach actions. | ||
| import applications.globals.admin # noqa: F401 | ||
| from applications.globals.models import Designation, ExtraInfo, HoldsDesignation | ||
|
|
||
| from .models import ( | ||
| Applicant, | ||
| Application, | ||
| ApplicationSectionI, | ||
| ApplicationSectionII, | ||
| ApplicationSectionIII, | ||
| AssociatedWith, | ||
| Attorney, | ||
| BudgetApproval, | ||
| CommunicationLog, | ||
| ConflictDeclaration, | ||
| Document, | ||
| DocumentVersion, | ||
| ExternalFilingRecord, | ||
| InventorConsent, | ||
| LegalAssessment, | ||
| MaintenanceSchedule, | ||
| NotificationEvent, | ||
| OfficeAction, | ||
| OfficeActionResponse, | ||
| ) | ||
|
|
||
|
|
||
| def _get_or_create_designation(name, full_name, designation_type): | ||
| designation = Designation.objects.filter(name__iexact=name).first() | ||
| if designation: | ||
| updated = False | ||
| if not designation.full_name: | ||
| designation.full_name = full_name | ||
| updated = True | ||
| if not designation.type: | ||
| designation.type = designation_type | ||
| updated = True | ||
| if updated: | ||
| designation.save(update_fields=["full_name", "type"]) | ||
| return designation | ||
|
|
||
| return Designation.objects.create( | ||
| name=name, | ||
| full_name=full_name, | ||
| type=designation_type, | ||
| ) | ||
|
|
||
|
|
||
| def _assign_designation_to_user(user, designation): | ||
| # Keep working=user so middleware and role switching stay consistent. | ||
| _, created = HoldsDesignation.objects.get_or_create( | ||
| user=user, | ||
| designation=designation, | ||
| defaults={"working": user}, | ||
| ) | ||
| return created | ||
|
|
||
|
|
||
| def assign_patent_director_and_pcc_admin(modeladmin, request, queryset): | ||
| """Assign Director + PCC Admin role(s) to selected user(s)""" | ||
| director_designation = _get_or_create_designation( | ||
| name="Director", | ||
| full_name="Director", | ||
| designation_type="administrative", | ||
| ) | ||
| pcc_admin_designation = _get_or_create_designation( | ||
| name="PCC Admin", | ||
| full_name="PCC Admin", | ||
| designation_type="administrative", | ||
| ) | ||
|
|
||
| users = [obj.user for obj in queryset.select_related("user")] | ||
| if not users: | ||
| modeladmin.message_user(request, "No users selected.", level=messages.WARNING) | ||
| return | ||
|
|
||
| director_created_count = 0 | ||
| pcc_created_count = 0 | ||
|
|
||
| with transaction.atomic(): | ||
| for user in users: | ||
| if _assign_designation_to_user(user, director_designation): | ||
| director_created_count += 1 | ||
| if _assign_designation_to_user(user, pcc_admin_designation): | ||
| pcc_created_count += 1 | ||
|
|
||
| modeladmin.message_user( | ||
| request, | ||
| ( | ||
| f"Processed {len(users)} user(s). " | ||
| f"New Director assignments: {director_created_count}. " | ||
| f"New PCC Admin assignments: {pcc_created_count}." | ||
| ), | ||
| level=messages.SUCCESS, | ||
| ) | ||
|
|
||
|
|
||
| assign_patent_director_and_pcc_admin.short_description = "Patent: assign Director + PCC Admin role(s)" | ||
|
|
||
|
|
||
| # Attach role-assignment action to already-registered ExtraInfo admin safely. | ||
| extra_info_admin = admin.site._registry.get(ExtraInfo) | ||
| if extra_info_admin: | ||
| existing_actions = list(getattr(extra_info_admin, "actions", []) or []) | ||
| if assign_patent_director_and_pcc_admin not in existing_actions: | ||
| existing_actions.append(assign_patent_director_and_pcc_admin) | ||
| extra_info_admin.actions = existing_actions | ||
|
|
||
|
|
||
| # Register patent-system models for admin visibility. | ||
| PATENT_MODELS = [ | ||
| Applicant, | ||
| Attorney, | ||
| Application, | ||
| ApplicationSectionI, | ||
| ApplicationSectionII, | ||
| ApplicationSectionIII, | ||
| AssociatedWith, | ||
| Document, | ||
| CommunicationLog, | ||
| ConflictDeclaration, | ||
| LegalAssessment, | ||
| NotificationEvent, | ||
| BudgetApproval, | ||
| ExternalFilingRecord, | ||
| MaintenanceSchedule, | ||
| DocumentVersion, | ||
| InventorConsent, | ||
| OfficeAction, | ||
| OfficeActionResponse, | ||
| ] | ||
|
|
||
| for model in PATENT_MODELS: | ||
| if model not in admin.site._registry: | ||
| admin.site.register(model) | ||
Empty file.
145 changes: 145 additions & 0 deletions
145
FusionIIIT/applications/patent_system/api/serializers.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| from rest_framework import serializers | ||
| from ..models import ( | ||
| AppealRequest, | ||
| Attorney, | ||
| AuditLog, | ||
| BudgetApproval, | ||
| CommunicationLog, | ||
| ConflictDeclaration, | ||
| Document, | ||
| DocumentVersion, | ||
| ExternalFilingRecord, | ||
| InventorConsent, | ||
| LegalAdviceMemo, | ||
| LegalAssessment, | ||
| LicensingRequest, | ||
| MaintenanceSchedule, | ||
| NotificationEvent, | ||
| OfficeAction, | ||
| OfficeActionResponse, | ||
| PriorArtReference, | ||
| ) | ||
|
|
||
| class AttorneySerializer(serializers.ModelSerializer): | ||
| class Meta: | ||
| model = Attorney | ||
| fields = ['id', 'name', 'email', 'phone', 'firm_name'] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| read_only_fields = ['id'] | ||
|
|
||
| class DocumentSerializer(serializers.ModelSerializer): | ||
| class Meta: | ||
| model = Document | ||
| fields = ['id', 'title', 'link', 'created_at', 'updated_at'] | ||
| read_only_fields = ['id', 'created_at', 'updated_at'] | ||
|
|
||
|
|
||
| class CommunicationLogSerializer(serializers.ModelSerializer): | ||
| class Meta: | ||
| model = CommunicationLog | ||
| fields = '__all__' | ||
| read_only_fields = ['id', 'application', 'logged_by', 'created_at', 'updated_at'] | ||
|
|
||
|
|
||
| class ConflictDeclarationSerializer(serializers.ModelSerializer): | ||
| class Meta: | ||
| model = ConflictDeclaration | ||
| fields = '__all__' | ||
| read_only_fields = ['id', 'created_at'] | ||
|
|
||
|
|
||
| class LegalAssessmentSerializer(serializers.ModelSerializer): | ||
| class Meta: | ||
| model = LegalAssessment | ||
| fields = '__all__' | ||
| read_only_fields = ['id', 'created_at'] | ||
|
|
||
|
|
||
| class NotificationEventSerializer(serializers.ModelSerializer): | ||
| class Meta: | ||
| model = NotificationEvent | ||
| fields = '__all__' | ||
| read_only_fields = ['id', 'created_at'] | ||
|
|
||
|
|
||
| class BudgetApprovalSerializer(serializers.ModelSerializer): | ||
| class Meta: | ||
| model = BudgetApproval | ||
| fields = '__all__' | ||
| read_only_fields = ['id', 'created_at', 'decided_at'] | ||
|
|
||
|
|
||
| class ExternalFilingRecordSerializer(serializers.ModelSerializer): | ||
| class Meta: | ||
| model = ExternalFilingRecord | ||
| fields = '__all__' | ||
| read_only_fields = ['id', 'created_at'] | ||
|
|
||
|
|
||
| class MaintenanceScheduleSerializer(serializers.ModelSerializer): | ||
| class Meta: | ||
| model = MaintenanceSchedule | ||
| fields = '__all__' | ||
| read_only_fields = ['id', 'created_at', 'reminder_sent_at', 'paid_at'] | ||
|
|
||
|
|
||
| class DocumentVersionSerializer(serializers.ModelSerializer): | ||
| class Meta: | ||
| model = DocumentVersion | ||
| fields = '__all__' | ||
| read_only_fields = ['id', 'created_at'] | ||
|
|
||
|
|
||
| class InventorConsentSerializer(serializers.ModelSerializer): | ||
| class Meta: | ||
| model = InventorConsent | ||
| fields = '__all__' | ||
| read_only_fields = ['id', 'created_at'] | ||
|
|
||
|
|
||
| class OfficeActionSerializer(serializers.ModelSerializer): | ||
| class Meta: | ||
| model = OfficeAction | ||
| fields = '__all__' | ||
| read_only_fields = ['id', 'created_at'] | ||
|
|
||
|
|
||
| class OfficeActionResponseSerializer(serializers.ModelSerializer): | ||
| class Meta: | ||
| model = OfficeActionResponse | ||
| fields = '__all__' | ||
| read_only_fields = ['id', 'created_at'] | ||
|
|
||
|
|
||
| class LicensingRequestSerializer(serializers.ModelSerializer): | ||
| class Meta: | ||
| model = LicensingRequest | ||
| fields = '__all__' | ||
| read_only_fields = ['id', 'created_at'] | ||
|
|
||
|
|
||
| class AppealRequestSerializer(serializers.ModelSerializer): | ||
| class Meta: | ||
| model = AppealRequest | ||
| fields = '__all__' | ||
| read_only_fields = ['id', 'created_at'] | ||
|
|
||
|
|
||
| class PriorArtReferenceSerializer(serializers.ModelSerializer): | ||
| class Meta: | ||
| model = PriorArtReference | ||
| fields = '__all__' | ||
| read_only_fields = ['id', 'created_at'] | ||
|
|
||
|
|
||
| class LegalAdviceMemoSerializer(serializers.ModelSerializer): | ||
| class Meta: | ||
| model = LegalAdviceMemo | ||
| fields = '__all__' | ||
| read_only_fields = ['id', 'created_at'] | ||
|
|
||
|
|
||
| class AuditLogSerializer(serializers.ModelSerializer): | ||
| class Meta: | ||
| model = AuditLog | ||
| fields = '__all__' | ||
| read_only_fields = ['id', 'created_at'] | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accessing
admin.site._registryis fragile (private API)._registryis an internal Django dict and can be renamed or restructured in a future Django release without a deprecation notice. A safer approach: